mathjax.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or http://ckeditor.com/license
  4. */
  5. 'use strict';
  6. CKEDITOR.dialog.add( 'mathjax', function( editor ) {
  7. var preview,
  8. lang = editor.lang.mathjax;
  9. return {
  10. title: lang.title,
  11. minWidth: 350,
  12. minHeight: 100,
  13. contents: [
  14. {
  15. id: 'info',
  16. elements: [
  17. {
  18. id: 'equation',
  19. type: 'textarea',
  20. label: lang.dialogInput,
  21. onLoad: function() {
  22. var that = this;
  23. if ( !( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) ) {
  24. this.getInputElement().on( 'keyup', function() {
  25. // Add \( and \) for preview.
  26. preview.setValue( '\\(' + that.getInputElement().getValue() + '\\)' );
  27. } );
  28. }
  29. },
  30. setup: function( widget ) {
  31. // Remove \( and \).
  32. this.setValue( CKEDITOR.plugins.mathjax.trim( widget.data.math ) );
  33. },
  34. commit: function( widget ) {
  35. // Add \( and \) to make TeX be parsed by MathJax by default.
  36. widget.setData( 'math', '\\(' + this.getValue() + '\\)' );
  37. }
  38. },
  39. {
  40. id: 'documentation',
  41. type: 'html',
  42. html:
  43. '<div style="width:100%;text-align:right;margin:-8px 0 10px">' +
  44. '<a class="cke_mathjax_doc" href="' + lang.docUrl + '" target="_black" style="cursor:pointer;color:#00B2CE;text-decoration:underline">' +
  45. lang.docLabel +
  46. '</a>' +
  47. '</div>'
  48. },
  49. ( !( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) ) && {
  50. id: 'preview',
  51. type: 'html',
  52. html:
  53. '<div style="width:100%;text-align:center;">' +
  54. '<iframe style="border:0;width:0;height:0;font-size:20px" scrolling="no" frameborder="0" allowTransparency="true" src="' + CKEDITOR.plugins.mathjax.fixSrc + '"></iframe>' +
  55. '</div>',
  56. onLoad: function() {
  57. var iFrame = CKEDITOR.document.getById( this.domId ).getChild( 0 );
  58. preview = new CKEDITOR.plugins.mathjax.frameWrapper( iFrame, editor );
  59. },
  60. setup: function( widget ) {
  61. preview.setValue( widget.data.math );
  62. }
  63. }
  64. ]
  65. }
  66. ]
  67. };
  68. } );