!function(a,b){"use strict";function c(a,b){for(var c,d=[],f=0;f=h.end?(e=k,g=h.end-j):d&&i.push(k),!d&&k.length+j>h.start&&(d=k,f=h.start-j),j+=k.length),d&&e){if(k=c({startNode:d,startNodeIndex:f,endNode:e,endNodeIndex:g,innerNodes:i,match:h.text,matchIndex:l}),j-=e.length-g,d=null,e=null,i=[],h=b.shift(),l++,!h)break}else{if((!x[k.nodeName]||w[k.nodeName])&&k.firstChild){k=k.firstChild;continue}if(k.nextSibling){k=k.nextSibling;continue}}for(;;){if(k.nextSibling){k=k.nextSibling;break}if(k.parentNode===a)break a;k=k.parentNode}}}function f(a){function b(b,c){var d=z[c];d.stencil||(d.stencil=a(d));var e=d.stencil.cloneNode(!1);return e.setAttribute("data-mce-index",c),b&&e.appendChild(A.doc.createTextNode(b)),e}return function(a){var c,d,e,f=a.startNode,g=a.endNode,h=a.matchIndex,i=A.doc;if(f===g){var j=f;e=j.parentNode,a.startNodeIndex>0&&(c=i.createTextNode(j.data.substring(0,a.startNodeIndex)),e.insertBefore(c,j));var k=b(a.match,h);return e.insertBefore(k,j),a.endNodeIndexn;++n){var p=a.innerNodes[n],q=b(p.data,h);p.parentNode.replaceChild(q,p),m.push(q)}var r=b(g.data.substring(0,a.endNodeIndex),h);return e=f.parentNode,e.insertBefore(c,f),e.insertBefore(l,f),e.removeChild(f),e=g.parentNode,e.insertBefore(r,g),e.insertBefore(d,g),e.removeChild(g),r}}function g(a){var b=a.parentNode;b.insertBefore(a.firstChild,a),a.parentNode.removeChild(a)}function h(b){var c=a.getElementsByTagName("*"),d=[];b="number"==typeof b?""+b:null;for(var e=0;eb&&a(z[b],b)!==!1;b++);return this}function l(b){return z.length&&e(a,z,f(b)),this}function m(a,b){if(v&&a.global)for(;u=a.exec(v);)z.push(c(u,b));return this}function n(a){var b,c=h(a?i(a):null);for(b=c.length;b--;)g(c[b]);return this}function o(a){return z[a.getAttribute("data-mce-index")]}function p(a){return h(i(a))[0]}function q(a,b,c){return z.push({start:a,end:a+b,text:v.substr(a,b),data:c}),this}function r(a){var c=h(i(a)),d=b.dom.createRng();return d.setStartBefore(c[0]),d.setEndAfter(c[c.length-1]),d}function s(a,c){var d=r(a);return d.deleteContents(),c.length>0&&d.insertNode(b.dom.doc.createTextNode(c)),d}function t(){return z.splice(0,z.length),n(),this}var u,v,w,x,y,z=[],A=b.dom;return w=b.schema.getBlockElements(),x=b.schema.getWhiteSpaceElements(),y=b.schema.getShortEndedElements(),v=d(a),{text:v,matches:z,each:k,filter:j,reset:t,matchFromElement:o,elementFromMatch:p,find:m,add:q,wrap:l,unwrap:n,replace:s,rangeFromMatch:r,indexOf:i}}}),d("tinymce/spellcheckerplugin/Plugin",["tinymce/spellcheckerplugin/DomTextMatcher","tinymce/PluginManager","tinymce/util/Tools","tinymce/ui/Menu","tinymce/dom/DOMUtils","tinymce/util/XHR","tinymce/util/URI","tinymce/util/JSON"],function(a,b,c,d,e,f,g,h){b.add("spellchecker",function(b,i){function j(){return E.textMatcher||(E.textMatcher=new a(b.getBody(),b)),E.textMatcher}function k(a,b){var d=[];return c.each(b,function(a){d.push({selectable:!0,text:a.name,data:a.value})}),d}function l(a){for(var b in a)return!1;return!0}function m(a,f){var g=[],h=A[a];c.each(h,function(a){g.push({text:a,onclick:function(){b.insertContent(b.dom.encode(a)),b.dom.remove(f),r()}})}),g.push({text:"-"}),D&&g.push({text:"Add to Dictionary",onclick:function(){s(a,f)}}),g.push.apply(g,[{text:"Ignore",onclick:function(){t(a,f)}},{text:"Ignore all",onclick:function(){t(a,f,!0)}}]),C=new d({items:g,context:"contextmenu",onautohide:function(a){-1!=a.target.className.indexOf("spellchecker")&&a.preventDefault()},onhide:function(){C.remove(),C=null}}),C.renderTo(document.body);var i=e.DOM.getPos(b.getContentAreaContainer()),j=b.dom.getPos(f[0]),k=b.dom.getRoot();"BODY"==k.nodeName?(j.x-=k.ownerDocument.documentElement.scrollLeft||k.scrollLeft,j.y-=k.ownerDocument.documentElement.scrollTop||k.scrollTop):(j.x-=k.scrollLeft,j.y-=k.scrollTop),i.x+=j.x,i.y+=j.y,C.moveTo(i.x,i.y+f[0].offsetHeight)}function n(){return b.getParam("spellchecker_wordchar_pattern")||new RegExp('[^\\s!"#$%&()*+,-./:;<=>?@[\\]^_{|}`\xa7\xa9\xab\xae\xb1\xb6\xb7\xb8\xbb\xbc\xbd\xbe\xbf\xd7\xf7\xa4\u201d\u201c\u201e\xa0\u2002\u2003\u2009]+',"g")}function o(a,b,d,e){var j={method:a},k="";"spellcheck"==a&&(j.text=b,j.lang=F.spellchecker_language),"addToDictionary"==a&&(j.word=b),c.each(j,function(a,b){k&&(k+="&"),k+=b+"="+encodeURIComponent(a)}),f.send({url:new g(i).toAbsolute(F.spellchecker_rpc_url),type:"post",content_type:"application/x-www-form-urlencoded",data:k,success:function(a){a=h.parse(a),a?a.error?e(a.error):d(a):e("Sever response wasn't proper JSON.")},error:function(a,b){e("Spellchecker request error: "+b.status)}})}function p(a,b,c,d){var e=F.spellchecker_callback||o;e.call(E,a,b,c,d)}function q(){function a(a){b.windowManager.alert(a),b.setProgressState(!1),u()}return B?void u():(u(),b.setProgressState(!0),p("spellcheck",j().text,y,a),void b.focus())}function r(){b.dom.select("span.mce-spellchecker-word").length||u()}function s(a,c){b.setProgressState(!0),p("addToDictionary",a,function(){b.setProgressState(!1),b.dom.remove(c,!0),r()},function(a){b.windowManager.alert(a),b.setProgressState(!1)})}function t(a,d,e){b.selection.collapse(),e?c.each(b.dom.select("span.mce-spellchecker-word"),function(c){c.getAttribute("data-mce-word")==a&&b.dom.remove(c,!0)}):b.dom.remove(d,!0),r()}function u(){j().reset(),E.textMatcher=null,B&&(B=!1,b.fire("SpellcheckEnd"))}function v(a){var b=a.getAttribute("data-mce-index");return"number"==typeof b?""+b:b}function w(a){var d,e=[];if(d=c.toArray(b.getBody().getElementsByTagName("span")),d.length)for(var f=0;f0){var e=b.dom.createRng();e.setStartBefore(d[0]),e.setEndAfter(d[d.length-1]),b.selection.setRng(e),m(c.getAttribute("data-mce-word"),d)}}}),b.addMenuItem("spellchecker",{text:"Spellcheck",context:"tools",onclick:q,selectable:!0,onPostRender:function(){var a=this;a.active(B),b.on("SpellcheckStart SpellcheckEnd",function(){a.active(B)})}});var H={tooltip:"Spellcheck",onclick:q,onPostRender:function(){var a=this;b.on("SpellcheckStart SpellcheckEnd",function(){a.active(B)})}};z.length>1&&(H.type="splitbutton",H.menu=z,H.onshow=x,H.onselect=function(a){F.spellchecker_language=a.control.settings.data}),b.addButton("spellchecker",H),b.addCommand("mceSpellCheck",q),b.on("remove",function(){C&&(C.remove(),C=null)}),b.on("change",r),this.getTextMatcher=j,this.getWordCharPattern=n,this.markErrors=y,this.getLanguage=function(){return F.spellchecker_language},F.spellchecker_language=F.spellchecker_language||F.language||"en"})}),f(["tinymce/spellcheckerplugin/DomTextMatcher"])}(this);