/*
 Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
 For licensing, see LICENSE.md or http://ckeditor.com/license
*/
(function(){var f="http://cdn.mathjax.org/mathjax/2.2-latest/MathJax.js?config=TeX-AMS_HTML";CKEDITOR.plugins.add("mathjax",{lang:"en,ja",requires:"widget,dialog",icons:"mathjax",hidpi:!0,init:function(b){var c=b.config.mathJaxClass||"math-tex";b.widgets.add("mathjax",{inline:!0,dialog:"mathjax",button:b.lang.mathjax.button,mask:!0,allowedContent:"span(!"+c+")",pathName:b.lang.mathjax.pathName,template:'<span class="'+c+'" 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 a=this.parts.span.getChild(0);if(!a||a.type!=CKEDITOR.NODE_ELEMENT||!a.is("iframe"))a=new CKEDITOR.dom.element("iframe"),a.setAttributes({style:"border:0;width:0;height:0",scrolling:"no",frameborder:0,allowTransparency:!0,src:CKEDITOR.plugins.mathjax.fixSrc}),this.parts.span.append(a);this.once("ready",function(){CKEDITOR.env.ie&&a.setAttribute("src",CKEDITOR.plugins.mathjax.fixSrc);this.frameWrapper=new CKEDITOR.plugins.mathjax.frameWrapper(a,
b);this.frameWrapper.setValue(this.data.math)})},data:function(){this.frameWrapper&&this.frameWrapper.setValue(this.data.math)},upcast:function(a,b){if("span"==a.name&&a.hasClass(c)&&!(1<a.children.length||a.children[0].type!=CKEDITOR.NODE_TEXT)){b.math=a.children[0].value;var e=a.attributes;e.style=e.style?e.style+";display:inline-block":"display:inline-block";e["data-cke-survive"]=1;a.children[0].remove();return a}},downcast:function(a){a.children[0].replaceWith(new CKEDITOR.htmlParser.text(this.data.math));
var b=a.attributes;b.style=b.style.replace(/display:\s?inline-block;?\s?/,"");""===b.style&&delete b.style;return a}});CKEDITOR.dialog.add("mathjax",this.path+"dialogs/mathjax.js");b.on("contentPreview",function(a){a.data.dataValue=a.data.dataValue.replace(/<\/head>/,'<script src="'+(b.config.mathJaxLib?CKEDITOR.getUrl(b.config.mathJaxLib):f)+'"><\/script></head>')});b.on("paste",function(a){a.data.dataValue=a.data.dataValue.replace(RegExp("<span[^>]*?"+c+".*?</span>","ig"),function(a){return a.replace(/(<iframe.*?\/iframe>)/i,
"")})})}});CKEDITOR.plugins.mathjax={};CKEDITOR.plugins.mathjax.fixSrc=CKEDITOR.env.gecko?"javascript:true":CKEDITOR.env.ie?"javascript:void((function(){"+encodeURIComponent("document.open();("+CKEDITOR.tools.fixDomain+")();document.close();")+"})())":"javascript:void(0)";CKEDITOR.plugins.mathjax.loadingIcon=CKEDITOR.plugins.get("mathjax").path+"images/loader.gif";CKEDITOR.plugins.mathjax.frameWrapper=function(b,c){function a(){d=b.getFrameDocument();d.getById("preview")||(CKEDITOR.env.ie&&b.removeAttribute("src"),
d.write('<!DOCTYPE html><html><head><meta charset="utf-8"><script type="text/x-mathjax-config">MathJax.Hub.Config( {showMathMenu: false,messageStyle: "none"} );function getCKE() {if ( typeof window.parent.CKEDITOR == \'object\' ) {return window.parent.CKEDITOR;} else {return window.parent.parent.CKEDITOR;}}function update() {MathJax.Hub.Queue([ \'Typeset\', MathJax.Hub, this.buffer ],function() {getCKE().tools.callFunction( '+n+" );});}MathJax.Hub.Queue( function() {getCKE().tools.callFunction("+
o+');} );<\/script><script src="'+(c.config.mathJaxLib||f)+'"><\/script></head><body style="padding:0;margin:0;background:transparent;overflow:hidden"><span id="preview"></span><span id="buffer" style="display:none"></span></body></html>'))}function l(){m=!0;j=k;c.fire("lockSnapshot");e.setHtml(j);g.setHtml("<img src="+CKEDITOR.plugins.mathjax.loadingIcon+" alt="+c.lang.mathjax.loading+">");b.setStyles({height:"16px",width:"16px",display:"inline","vertical-align":"middle"});c.fire("unlockSnapshot");
d.getWindow().$.update(j)}var e,g,j,k,d=b.getFrameDocument(),h=!1,m=!1,o=CKEDITOR.tools.addFunction(function(){g=d.getById("preview");e=d.getById("buffer");h=!0;k&&l();CKEDITOR.fire("mathJaxLoaded",b)}),n=CKEDITOR.tools.addFunction(function(){for(var a="color font-family font-style font-weight font-variant font-size".split(" "),i=0;i<a.length;i++){var f=a[i],h=b.getComputedStyle(f);h&&g.setStyle(f,h)}g.setHtml(e.getHtml());c.fire("lockSnapshot");b.setStyles({height:0,width:0});a=Math.max(d.$.body.offsetHeight,
d.$.documentElement.offsetHeight);i=Math.max(g.$.offsetWidth,d.$.body.scrollWidth);b.setStyles({height:a+"px",width:i+"px"});c.fire("unlockSnapshot");CKEDITOR.fire("mathJaxUpdateDone",b);j!=k?l():m=!1});b.on("load",a);a();return{setValue:function(a){k=a;h&&!m&&l()}}}})();