Adding mathjax v2.2 see #5231

1.10.x
Julio Montoya 12 years ago
parent 1ad62cf628
commit 0873763b87
  1. 85
      main/inc/lib/javascript/ckeditor/plugins/mathjax/dev/mathjax.html
  2. 78
      main/inc/lib/javascript/ckeditor/plugins/mathjax/dialogs/mathjax.js
  3. BIN
      main/inc/lib/javascript/ckeditor/plugins/mathjax/icons/hidpi/mathjax.png
  4. BIN
      main/inc/lib/javascript/ckeditor/plugins/mathjax/icons/mathjax.png
  5. BIN
      main/inc/lib/javascript/ckeditor/plugins/mathjax/images/loader.gif
  6. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/ca.js
  7. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/cs.js
  8. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/cy.js
  9. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/el.js
  10. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/en-gb.js
  11. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/en.js
  12. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/es.js
  13. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/fi.js
  14. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/ja.js
  15. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/km.js
  16. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/nb.js
  17. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/nl.js
  18. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/no.js
  19. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/ru.js
  20. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/sv.js
  21. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/uk.js
  22. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/zh-cn.js
  23. 13
      main/inc/lib/javascript/ckeditor/plugins/mathjax/lang/zh.js
  24. 454
      main/inc/lib/javascript/ckeditor/plugins/mathjax/plugin.js

@ -0,0 +1,85 @@
<!DOCTYPE html>
<!--
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
-->
<html>
<head>
<title>Widgets: MathJax &mdash; CKEditor Sample</title>
<meta charset="utf-8">
<script src="../../../ckeditor.js"></script>
<link href="../../../samples/sample.css" rel="stylesheet">
<meta name="ckeditor-sample-name" content="Mathematics">
<meta name="ckeditor-sample-group" content="Plugins">
<meta name="ckeditor-sample-description" content="Create mathematical equations in TeX and display them in visual form.">
<meta name="ckeditor-sample-isnew" content="1">
<script>
CKEDITOR.disableAutoInline = true;
document.domain = 'ckeditor.dev';
</script>
</head>
<body>
<h1 class="samples">
<a href="../../../samples/index.html">CKEditor Samples</a> &raquo; Widgets: MathJax
</h1>
<textarea id="editor1" cols="10" rows="10">
<h1>Apollo 11</h1>
<div style="background:red;color:blue">
<p><strong>Apollo 11</strong>&nbsp;was the&nbsp;spaceflight&nbsp;that landed the first humans, Americans <a href="http://en.wikipedia.org/wiki/Neil_Armstrong">Neil Armstrong</a>&nbsp;and&nbsp;<a href="http://en.wikipedia.org/wiki/Buzz_Aldrin">Buzz Aldrin</a> <span class="math-tex">\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)</span>. Armstrong became the first to step onto the lunar surface 6 hours later. Armstrong spent about two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&nbsp;kg) of lunar material for return to Earth. A third member of the mission,&nbsp;Michael Collins, piloted the&nbsp;command spacecraft&nbsp;alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.</p>
</div>
<p>Foo foo <span class="userclass mjx">\(J_\alpha(x) = \sum\limits_{m=0}^\infty \frac{(-1)^m}{m! \, \Gamma(m + \alpha + 1)}{\left({\frac{x}{2}}\right)}^{2 m + \alpha}\)</span> bar bar.</p>
<p>Launched by a&nbsp;Saturn V&nbsp;rocket from&nbsp;Kennedy Space Center&nbsp;in&nbsp;Merritt Island, Florida&nbsp;on July 16, Apollo 11 was the fifth manned mission of <a href="http://en.wikipedia.org/wiki/NASA">NASA</a>&#39;s&nbsp;Apollo program. The Apollo&nbsp;spacecraft&nbsp;had three parts: aCommand Module&nbsp;with a cabin for the three astronauts which was the only part which landed back on Earth; a&nbsp;Service Module&nbsp;which supported the Command Module with propulsion, electrical power, oxygen and water; and a&nbsp;Lunar Module&nbsp;for landing on the Moon. After being sent to the Moon by the Saturn V&#39;s upper stage, the astronauts separated the spacecraft from it and travelled for three days until they entered into lunar orbit. Armstrong and Aldrin then moved into the Lunar Module and landed in the&nbsp;Sea of Tranquility. They stayed a total of about 21 and a half hours on the lunar surface. After lifting off in the upper part of the Lunar Module and rejoining Collins in the Command Module, they returned to Earth and landed in the&nbsp;Pacific Ocean&nbsp;.</p>
</textarea>
<div id="editor2" contenteditable="true" cols="10" rows="10">
<h1>Apollo 11</h1>
<div style="background:red;color:blue">
<p><strong>Apollo 11</strong>&nbsp;was the&nbsp;spaceflight&nbsp;that landed the first humans, Americans <a href="http://en.wikipedia.org/wiki/Neil_Armstrong">Neil Armstrong</a>&nbsp;and&nbsp;<a href="http://en.wikipedia.org/wiki/Buzz_Aldrin">Buzz Aldrin</a> <span class="math-tex">\(x = {-b \pm \sqrt{b^2-4ac} \over 2a}\)</span>. Armstrong became the first to step onto the lunar surface 6 hours later. Armstrong spent about two and a half hours outside the spacecraft, Aldrin slightly less; and together they collected 47.5 pounds (21.5&nbsp;kg) of lunar material for return to Earth. A third member of the mission,&nbsp;Michael Collins, piloted the&nbsp;command spacecraft&nbsp;alone in lunar orbit until Armstrong and Aldrin returned to it for the trip back to Earth.</p>
</div>
<p>Foo foo <span class="userclass mjx">\(J_\alpha(x) = \sum\limits_{m=0}^\infty \frac{(-1)^m}{m! \, \Gamma(m + \alpha + 1)}{\left({\frac{x}{2}}\right)}^{2 m + \alpha}\)</span> bar bar.</p>
<p>Launched by a&nbsp;Saturn V&nbsp;rocket from&nbsp;Kennedy Space Center&nbsp;in&nbsp;Merritt Island, Florida&nbsp;on July 16, Apollo 11 was the fifth manned mission of <a href="http://en.wikipedia.org/wiki/NASA">NASA</a>&#39;s&nbsp;Apollo program. The Apollo&nbsp;spacecraft&nbsp;had three parts: aCommand Module&nbsp;with a cabin for the three astronauts which was the only part which landed back on Earth; a&nbsp;Service Module&nbsp;which supported the Command Module with propulsion, electrical power, oxygen and water; and a&nbsp;Lunar Module&nbsp;for landing on the Moon. After being sent to the Moon by the Saturn V&#39;s upper stage, the astronauts separated the spacecraft from it and travelled for three days until they entered into lunar orbit. Armstrong and Aldrin then moved into the Lunar Module and landed in the&nbsp;Sea of Tranquility. They stayed a total of about 21 and a half hours on the lunar surface. After lifting off in the upper part of the Lunar Module and rejoining Collins in the Command Module, they returned to Earth and landed in the&nbsp;Pacific Ocean&nbsp;.</p>
</div>
<script>
CKEDITOR.stylesSet.add('my_custom_style', [
{ name: 'My Custom Block', element: 'h1', styles: { color: 'blue'} }
]);
CKEDITOR.replace( 'editor1', {
extraPlugins: 'mathjax',
height: 350,
allowedContent: true,
// mathJaxLib: './truncated-mathjax/MathJax.js?config=TeX-AMS_HTML',
mathJaxClass: 'mjx'
} );
CKEDITOR.inline( 'editor2', {
extraPlugins: 'mathjax',
height: 350,
allowedContent: true,
// mathJaxLib: './truncated-mathjax/MathJax.js?config=TeX-AMS_HTML',
mathJaxClass: 'mjx'
} );
</script>
<div id="footer">
<hr>
<p>
CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
</p>
<p id="copy">
Copyright &copy; 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
Knabben. All rights reserved.
</p>
</div>
</body>
</html>

@ -0,0 +1,78 @@
/**
* @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
'use strict';
CKEDITOR.dialog.add( 'mathjax', function( editor ) {
var preview,
lang = editor.lang.mathjax;
return {
title: lang.title,
minWidth: 350,
minHeight: 100,
contents: [
{
id: 'info',
elements: [
{
id: 'equation',
type: 'textarea',
label: lang.dialogInput,
onLoad: function( widget ) {
var that = this;
if ( !( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) ) {
this.getInputElement().on( 'keyup', function() {
// Add \( and \) for preview.
preview.setValue( '\\(' + that.getInputElement().getValue() + '\\)' );
} );
}
},
setup: function( widget ) {
// Remove \( and \).
this.setValue( CKEDITOR.plugins.mathjax.trim( widget.data.math ) );
},
commit: function( widget ) {
// Add \( and \) to make TeX be parsed by MathJax by default.
widget.setData( 'math', '\\(' + this.getValue() + '\\)' );
}
},
{
id: 'documentation',
type: 'html',
html:
'<div style="width:100%;text-align:right;margin:-8px 0 10px">' +
'<a class="cke_mathjax_doc" href="' + lang.docUrl + '" target="_black" style="cursor:pointer;color:#00B2CE;text-decoration:underline">' +
lang.docLabel +
'</a>' +
'</div>'
},
( !( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) ) && {
id: 'preview',
type: 'html',
html:
'<div style="width:100%;text-align:center;">' +
'<iframe style="border:0;width:0;height:0;font-size:20px" scrolling="no" frameborder="0" allowTransparency="true" src="' + CKEDITOR.plugins.mathjax.fixSrc + '"></iframe>' +
'</div>',
onLoad: function( widget ) {
var iFrame = CKEDITOR.document.getById( this.domId ).getChild( 0 );
preview = new CKEDITOR.plugins.mathjax.frameWrapper( iFrame, editor );
},
setup: function( widget ) {
preview.setValue( widget.data.math );
}
}
]
}
]
};
} );

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'ca', {
title: 'Matemàtiques a TeX',
button: 'Matemàtiques',
dialogInput: 'Escriu el TeX aquí',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'Documentació TeX',
loading: 'carregant...',
pathName: 'matemàtiques'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'cs', {
title: 'Matematika v TeXu',
button: 'Matematika',
dialogInput: 'Zde napište TeXový kód',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'Dokumentace k TeXu',
loading: 'Nahrává se...',
pathName: 'Matematika'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'cy', {
title: 'Mathemateg mewn TeX',
button: 'Math',
dialogInput: 'Ysgrifennwch eich TeX yma',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'Dogfennaeth TeX',
loading: 'llwytho...',
pathName: 'math'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'el', {
title: 'Μαθηματικά με τη γλώσσα TeX',
button: 'Μαθηματικά',
dialogInput: 'Γράψτε κώδικα TeX εδώ',
docUrl: 'http:// MISSING //en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'Τεκμηρίωση TeX',
loading: 'γίνεται φόρτωση...',
pathName: 'μαθηματικά'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'en-gb', {
title: 'Mathematics in TeX',
button: 'Math',
dialogInput: 'Write you TeX here',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeX documentation',
loading: 'loading...',
pathName: 'math'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'en', {
title: 'Mathematics in TeX',
button: 'Math',
dialogInput: 'Write your TeX here',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeX documentation',
loading: 'loading...',
pathName: 'math'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'es', {
title: 'Matemáticas en TeX',
button: 'Matemáticas',
dialogInput: 'Escribe tu TeX aquí',
docUrl: 'http://es.wikipedia.org/wiki/TeX',
docLabel: 'Documentación de TeX',
loading: 'cargando...',
pathName: 'matemáticas'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'fi', {
title: 'Matematiikkaa TeX:llä',
button: 'Matematiikka',
dialogInput: 'Kirjoita TeX:iä tähän',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeX dokumentaatio',
loading: 'lataa...',
pathName: 'matematiikka'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'ja', {
title: 'TeX形式の数式',
button: '数式',
dialogInput: 'TeX形式の数式を入力してください',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeXの解説',
loading: '読み込み中…',
pathName: 'math'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'km', {
title: 'គណង TeX',
button: 'គណត',
dialogInput: 'សរសរ TeX របសនក',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'ឯកសអតថបទ TeX',
loading: 'កក..',
pathName: 'គណត'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'nb', {
title: 'Matematikk i TeX',
button: 'Matte',
dialogInput: 'Skriv TeX-koden her',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeX-dokumentasjon',
loading: 'laster...',
pathName: 'matte'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'nl', {
title: 'Wiskunde in TeX',
button: 'Wiskunde',
dialogInput: 'Typ hier uw TeX',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeX documentatie',
loading: 'laden...',
pathName: 'wiskunde'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'no', {
title: 'Matematikk i TeX',
button: 'Matte',
dialogInput: 'Skriv TeX-koden her',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeX-dokumentasjon',
loading: 'laster...',
pathName: 'matte'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'ru', {
title: 'Математика в TeX-системе',
button: 'Математика',
dialogInput: 'Введите здесь TeX',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeX документация',
loading: 'загрузка...',
pathName: 'мат.'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'sv', {
title: 'Mattematik i TeX',
button: 'Matte',
dialogInput: 'Skriv din TeX här',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeX dokumentation',
loading: 'laddar',
pathName: 'matte'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'uk', {
title: 'Математика у TeX',
button: 'Математика',
dialogInput: 'Наберіть тут на TeX\'у',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'Документація про TeX',
loading: 'завантажується…',
pathName: 'математика'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'zh-cn', {
title: 'TeX 语法的数学公式编辑器',
button: '数学公式',
dialogInput: '在此编写您的 TeX 指令',
docUrl: 'http://zh.wikipedia.org/wiki/TeX',
docLabel: 'TeX 语法(可以参考维基百科自身关于数学公式显示方式的帮助)',
loading: '正在加载...',
pathName: '数字公式'
} );

@ -0,0 +1,13 @@
/*
Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang( 'mathjax', 'zh', {
title: '以 TeX 表示數學',
button: '數學',
dialogInput: '請輸入 TeX',
docUrl: 'http://en.wikibooks.org/wiki/LaTeX/Mathematics',
docLabel: 'TeX 說明文件',
loading: '載入中…',
pathName: '數學'
} );

@ -0,0 +1,454 @@
/**
* @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
/**
* @fileOverview [Mathematical Formulas](http://ckeditor.com/addon/mathjax) plugin.
*/
'use strict';
( function() {
var cdn = 'http:\/\/cdn.mathjax.org\/mathjax\/2.2-latest\/MathJax.js?config=TeX-AMS_HTML';
CKEDITOR.plugins.add( 'mathjax', {
lang: 'ca,cs,cy,el,en,en-gb,es,fi,ja,km,nb,nl,no,ru,sv,uk,zh,zh-cn', // %REMOVE_LINE_CORE%
requires: 'widget,dialog',
icons: 'mathjax',
hidpi: true, // %REMOVE_LINE_CORE%
init: function( editor ) {
var cls = editor.config.mathJaxClass || 'math-tex';
editor.widgets.add( 'mathjax', {
inline: true,
dialog: 'mathjax',
button: editor.lang.mathjax.button,
mask: true,
allowedContent: 'span(!' + cls + ')',
pathName: editor.lang.mathjax.pathName,
template: '<span class="' + cls + '" style="display:inline-block" data-cke-survive=1></span>',
parts: {
span: 'span'
},
defaults: {
math: '\\(x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}\\)'
},
init: function() {
var iframe = this.parts.span.getChild( 0 );
// Check if span contains iframe and create it otherwise.
if ( !iframe || iframe.type != CKEDITOR.NODE_ELEMENT || !iframe.is( 'iframe' ) ) {
iframe = new CKEDITOR.dom.element( 'iframe' );
iframe.setAttributes( {
style: 'border:0;width:0;height:0',
scrolling: 'no',
frameborder: 0,
allowTransparency: true,
src: CKEDITOR.plugins.mathjax.fixSrc
} );
this.parts.span.append( iframe );
}
// Wait for ready because on some browsers iFrame will not
// have document element until it is put into document.
// This is a problem when you crate widget using dialog.
this.once( 'ready', function() {
// Src attribute must be recreated to fix custom domain error after undo
// (see iFrame.removeAttribute( 'src' ) in frameWrapper.load).
if ( CKEDITOR.env.ie )
iframe.setAttribute( 'src', CKEDITOR.plugins.mathjax.fixSrc );
this.frameWrapper = new CKEDITOR.plugins.mathjax.frameWrapper( iframe, editor );
this.frameWrapper.setValue( this.data.math );
} );
},
data: function() {
if ( this.frameWrapper )
this.frameWrapper.setValue( this.data.math );
},
upcast: function( el, data ) {
if ( !( el.name == 'span' && el.hasClass( cls ) ) )
return;
if ( el.children.length > 1 || el.children[ 0 ].type != CKEDITOR.NODE_TEXT )
return;
data.math = el.children[ 0 ].value;
// Add style display:inline-block to have proper height of widget wrapper and mask.
var attrs = el.attributes;
if ( attrs.style )
attrs.style += ';display:inline-block';
else
attrs.style = 'display:inline-block';
// Add attribute to prevent deleting empty span in data processing.
attrs[ 'data-cke-survive' ] = 1;
el.children[ 0 ].remove();
return el;
},
downcast: function( el ) {
el.children[ 0 ].replaceWith( new CKEDITOR.htmlParser.text( this.data.math ) );
// Remove style display:inline-block.
var attrs = el.attributes;
attrs.style = attrs.style.replace( /display:\s?inline-block;?\s?/, '' );
if ( attrs.style === '' )
delete attrs.style;
return el;
}
} );
// Add dialog.
CKEDITOR.dialog.add( 'mathjax', this.path + 'dialogs/mathjax.js' );
// Add MathJax script to page preview.
editor.on( 'contentPreview', function( evt ) {
evt.data.dataValue = evt.data.dataValue.replace( /<\/head>/,
'<script src="' + ( editor.config.mathJaxLib ? CKEDITOR.getUrl( editor.config.mathJaxLib ) : cdn ) + '"><\/script><\/head>' );
} );
editor.on( 'paste', function( evt ) {
// Firefox does remove iFrame elements from pasted content so this event do the same on other browsers.
// Also iFrame in paste content is reason of "Unspecified error" in IE9 (#10857).
var regex = new RegExp( '<span[^>]*?' + cls + '.*?<\/span>', 'ig' );
evt.data.dataValue = evt.data.dataValue.replace( regex, function( match ) {
return match.replace( /(<iframe.*?\/iframe>)/i, '' );
} );
} );
}
} );
/**
* @private
* @class CKEDITOR.plugins.mathjax
*/
CKEDITOR.plugins.mathjax = {};
/**
* A variable to fix problems with `iframe`. This variable is global
* because it is used in both the widget and the dialog window.
*
* @private
* @property CKEDITOR.plugins.mathjax.fixSrc
* @member CKEDITOR.plugins.mathjax
*/
CKEDITOR.plugins.mathjax.fixSrc =
// In Firefox src must exist and be different than about:blank to emit load event.
CKEDITOR.env.gecko ? 'javascript:true' :
// Support for custom document.domain in IE.
CKEDITOR.env.ie ? 'javascript:' +
'void((function(){' + encodeURIComponent(
'document.open();' +
'(' + CKEDITOR.tools.fixDomain + ')();' +
'document.close();'
) + '})())' :
// In Chrome src must be undefined to emit load event.
'javascript:void(0)';
/**
* Loading indicator image generated by preloaders.net.
*
* @private
* @property CKEDITOR.plugins.mathjax.loadingIcon
* @member CKEDITOR.plugins.mathjax
*/
CKEDITOR.plugins.mathjax.loadingIcon = CKEDITOR.plugins.get( 'mathjax' ).path + 'images/loader.gif';
/**
* Computes predefined styles and copies them to another element.
*
* @private
* @member CKEDITOR.plugins.mathjax
* @param {CKEDITOR.dom.element} from Copy source.
* @param {CKEDITOR.dom.element} to Copy target.
*/
CKEDITOR.plugins.mathjax.copyStyles = function( from, to ) {
var stylesToCopy = [ 'color', 'font-family', 'font-style', 'font-weight', 'font-variant', 'font-size' ];
for ( var i = 0; i < stylesToCopy.length; i++ ) {
var key = stylesToCopy[ i ],
val = from.getComputedStyle( key );
if ( val )
to.setStyle( key, val );
}
};
/**
* Trims MathJax value from '\(1+1=2\)' to '1+1=2'.
*
* @private
* @member CKEDITOR.plugins.mathjax
* @param {String} value String to trim.
* @returns {String} Trimed string.
*/
CKEDITOR.plugins.mathjax.trim = function( value ) {
var begin = value.indexOf( '\\(' ) + 2,
end = value.lastIndexOf( '\\)' );
return value.substring( begin, end );
};
/**
* FrameWrapper is responsible for communication between the MathJax library
* and the `iframe` element that is used for rendering mathematical formulas
* inside the editor.
* It lets you create visual mathematics by using the
* {@link CKEDITOR.plugins.mathjax.frameWrapper#setValue setValue} method.
*
* @private
* @class CKEDITOR.plugins.mathjax.frameWrapper
* @constructor Creates a class instance.
* @param {CKEDITOR.dom.element} iFrame The `iframe` element to be wrapped.
* @param {CKEDITOR.editor} editor The editor instance.
*/
if ( !( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) ) {
CKEDITOR.plugins.mathjax.frameWrapper = function( iFrame, editor ) {
var buffer, preview, value, newValue,
doc = iFrame.getFrameDocument(),
// Is MathJax loaded and ready to work.
isInit = false,
// Is MathJax parsing Tex.
isRunning = false,
// Function called when MathJax is loaded.
loadedHandler = CKEDITOR.tools.addFunction( function() {
preview = doc.getById( 'preview' );
buffer = doc.getById( 'buffer' );
isInit = true;
if ( newValue )
update();
// Private! For test usage only.
CKEDITOR.fire( 'mathJaxLoaded', iFrame );
} ),
// Function called when MathJax finish his job.
updateDoneHandler = CKEDITOR.tools.addFunction( function() {
CKEDITOR.plugins.mathjax.copyStyles( iFrame, preview );
preview.setHtml( buffer.getHtml() );
editor.fire( 'lockSnapshot' );
iFrame.setStyles( {
height: 0,
width: 0
} );
// Set iFrame dimensions.
var height = Math.max( doc.$.body.offsetHeight, doc.$.documentElement.offsetHeight ),
width = Math.max( preview.$.offsetWidth, doc.$.body.scrollWidth );
iFrame.setStyles( {
height: height + 'px',
width: width + 'px'
} );
editor.fire( 'unlockSnapshot' );
// Private! For test usage only.
CKEDITOR.fire( 'mathJaxUpdateDone', iFrame );
// If value changed in the meantime update it again.
if ( value != newValue )
update();
else
isRunning = false;
} );
iFrame.on( 'load', load );
load();
function load() {
doc = iFrame.getFrameDocument();
if ( doc.getById( 'preview' ) )
return;
// Because of IE9 bug in a src attribute can not be javascript
// when you undo (#10930). If you have iFrame with javascript in src
// and call insertBefore on such element then IE9 will see crash.
if ( CKEDITOR.env.ie )
iFrame.removeAttribute( 'src' );
doc.write( '<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<meta charset="utf-8">' +
'<script type="text/x-mathjax-config">' +
// MathJax configuration, disable messages.
'MathJax.Hub.Config( {' +
'showMathMenu: false,' +
'messageStyle: "none"' +
'} );' +
// Get main CKEDITOR form parent.
'function getCKE() {' +
'if ( typeof window.parent.CKEDITOR == \'object\' ) {' +
'return window.parent.CKEDITOR;' +
'} else {' +
'return window.parent.parent.CKEDITOR;' +
'}' +
'}' +
// Run MathJax.Hub with its actual parser and call callback function after that.
// Because MathJax.Hub is asynchronous create MathJax.Hub.Queue to wait with callback.
'function update() {' +
'MathJax.Hub.Queue(' +
'[ \'Typeset\', MathJax.Hub, this.buffer ],' +
'function() {' +
'getCKE().tools.callFunction( ' + updateDoneHandler + ' );' +
'}' +
');' +
'}' +
// Run MathJax for the first time, when the script is loaded.
// Callback function will be called then it's done.
'MathJax.Hub.Queue( function() {' +
'getCKE().tools.callFunction(' + loadedHandler + ');' +
'} );' +
'</script>' +
// Load MathJax lib.
'<script src="' + ( editor.config.mathJaxLib || cdn ) + '"></script>' +
'</head>' +
'<body style="padding:0;margin:0;background:transparent;overflow:hidden">' +
'<span id="preview"></span>' +
// Render everything here and after that copy it to the preview.
'<span id="buffer" style="display:none"></span>' +
'</body>' +
'</html>' );
}
// Run MathJax parsing Tex.
function update() {
isRunning = true;
value = newValue;
editor.fire( 'lockSnapshot' );
buffer.setHtml( value );
// Set loading indicator.
preview.setHtml( '<img src=' + CKEDITOR.plugins.mathjax.loadingIcon + ' alt=' + editor.lang.mathjax.loading + '>' );
iFrame.setStyles( {
height: '16px',
width: '16px',
display: 'inline',
'vertical-align': 'middle'
} );
editor.fire( 'unlockSnapshot' );
// Run MathJax.
doc.getWindow().$.update( value );
}
return {
/**
* Sets the TeX value to be displayed in the `iframe` element inside
* the editor. This function will activate the MathJax
* library which interprets TeX expressions and converts them into
* their representation that is displayed in the editor.
*
* @param {String} value TeX string.
*/
setValue: function( value ) {
newValue = value;
if ( isInit && !isRunning )
update();
}
};
};
} else {
// In IE8 MathJax does not work stable so instead of using standard
// frame wrapper it is replaced by placeholder to show pure TeX in iframe.
CKEDITOR.plugins.mathjax.frameWrapper = function( iFrame, editor ) {
iFrame.getFrameDocument().write( '<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<meta charset="utf-8">' +
'</head>' +
'<body style="padding:0;margin:0;background:transparent;overflow:hidden">' +
'<span style="white-space:nowrap;" id="tex"></span>' +
'</body>' +
'</html>' );
return {
setValue: function( value ) {
var doc = iFrame.getFrameDocument(),
tex = doc.getById( 'tex' );
tex.setHtml( CKEDITOR.plugins.mathjax.trim( value ) );
CKEDITOR.plugins.mathjax.copyStyles( iFrame, tex );
editor.fire( 'lockSnapshot' );
iFrame.setStyles( {
width: Math.min( 250, tex.$.offsetWidth ) + 'px',
height: doc.$.body.offsetHeight + 'px',
display: 'inline',
'vertical-align': 'middle'
} );
editor.fire( 'unlockSnapshot' );
}
};
};
}
} )();
/**
* Sets the path to the MathJax library. It can be both a local
* resource and a location different than the default CDN.
*
* Please note that this must be a full or absolute path.
*
* config.mathJaxLib = 'http:\/\/example.com\/libs\/MathJax.js';
*
* @cfg {String} [mathJaxLib='http:\/\/cdn.mathjax.org\/mathjax\/2.2-latest\/MathJax.js?config=TeX-AMS_HTML']
* @member CKEDITOR.config
*/
/**
* Sets the default class for `span` elements that will be
* converted into [Mathematical Formulas](http://ckeditor.com/addon/mathjax)
* widgets.
*
* If you set it to the following:
*
* config.mathJaxClass = 'my-math';
*
* The code below will be recognized as a Mathematical Formulas widget.
*
* <span class="my-math">\( \sqrt{4} = 2 \)</span>
*
* @cfg {String} [mathJaxClass='math-tex']
* @member CKEDITOR.config
*/
Loading…
Cancel
Save