Files
leanote/public/tinymce/plugins/spellchecker/plugin.min.js
2015-01-08 23:33:14 +08:00

1 line
6.5 KiB
JavaScript

!function(e,t){"use strict";function n(e,t){for(var n,r=[],i=0;i<e.length;++i){if(n=c[e[i]]||o(e[i]),!n)throw"module definition dependecy not found: "+e[i];r.push(n)}t.apply(null,r)}function r(e,r,o){if("string"!=typeof e)throw"invalid module definition, module id must be defined and be a string";if(r===t)throw"invalid module definition, dependencies must be specified";if(o===t)throw"invalid module definition, definition function must be specified";n(r,function(){c[e]=o.apply(null,arguments)})}function o(t){for(var n=e,r=t.split(/[.\/]/),o=0;o<r.length;++o){if(!n[r[o]])return;n=n[r[o]]}return n}function i(n){for(var r=0;r<n.length;r++){for(var o=e,i=n[r],a=i.split(/[.\/]/),l=0;l<a.length-1;++l)o[a[l]]===t&&(o[a[l]]={}),o=o[a[l]];o[a[a.length-1]]=c[i]}}var c={};r("tinymce/spellcheckerplugin/DomTextMatcher",[],function(){return function(e,t,n){function r(e){if(!e[0])throw"findAndReplaceDOMText cannot handle zero-length matches";var t=e.index;return[t,t+e[0].length,[e[0]]]}function o(e){var t;if(3===e.nodeType)return e.data;if(p[e.nodeName]&&!h[e.nodeName])return"";if(t="",(h[e.nodeName]||g[e.nodeName])&&(t+="\n"),e=e.firstChild)do t+=o(e);while(e=e.nextSibling);return t}function i(e,t,n){var r,o,i,c,a=[],l=0,d=e,s=t.shift(),u=0;e:for(;;){if((h[d.nodeName]||g[d.nodeName])&&l++,3===d.nodeType&&(!o&&d.length+l>=s[1]?(o=d,c=s[1]-l):r&&a.push(d),!r&&d.length+l>s[0]&&(r=d,i=s[0]-l),l+=d.length),r&&o){if(d=n({startNode:r,startNodeIndex:i,endNode:o,endNodeIndex:c,innerNodes:a,match:s[2],matchIndex:u}),l-=o.length-c,r=null,o=null,a=[],s=t.shift(),u++,!s)break}else{if((!p[d.nodeName]||h[d.nodeName])&&d.firstChild){d=d.firstChild;continue}if(d.nextSibling){d=d.nextSibling;continue}}for(;;){if(d.nextSibling){d=d.nextSibling;break}if(d.parentNode===e)break e;d=d.parentNode}}}function c(e){var t;if("function"!=typeof e){var n=e.nodeType?e:f.createElement(e);t=function(e,t){var r=n.cloneNode(!1);return r.setAttribute("data-mce-index",t),e&&r.appendChild(f.createTextNode(e)),r}}else t=e;return function(e){var n,r,o,i=e.startNode,c=e.endNode,a=e.matchIndex;if(i===c){var l=i;o=l.parentNode,e.startNodeIndex>0&&(n=f.createTextNode(l.data.substring(0,e.startNodeIndex)),o.insertBefore(n,l));var d=t(e.match[0],a);return o.insertBefore(d,l),e.endNodeIndex<l.length&&(r=f.createTextNode(l.data.substring(e.endNodeIndex)),o.insertBefore(r,l)),l.parentNode.removeChild(l),d}n=f.createTextNode(i.data.substring(0,e.startNodeIndex)),r=f.createTextNode(c.data.substring(e.endNodeIndex));for(var s=t(i.data.substring(e.startNodeIndex),a),u=[],h=0,p=e.innerNodes.length;p>h;++h){var g=e.innerNodes[h],m=t(g.data,a);g.parentNode.replaceChild(m,g),u.push(m)}var v=t(c.data.substring(0,e.endNodeIndex),a);return o=i.parentNode,o.insertBefore(n,i),o.insertBefore(s,i),o.removeChild(i),o=c.parentNode,o.insertBefore(v,c),o.insertBefore(r,c),o.removeChild(c),v}}function a(e){var t=[];return l(function(n,r){e(n,r)&&t.push(n)}),m=t,this}function l(e){for(var t=0,n=m.length;n>t&&e(m[t],t)!==!1;t++);return this}function d(e){return m.length&&(v=m.length,i(t,m,c(e))),this}var s,u,f,h,p,g,m=[],v=0;if(f=t.ownerDocument,h=n.getBlockElements(),p=n.getWhiteSpaceElements(),g=n.getShortEndedElements(),u=o(t),u&&e.global)for(;s=e.exec(u);)m.push(r(s));return{text:u,count:v,matches:m,each:l,filter:a,mark:d}}}),r("tinymce/spellcheckerplugin/Plugin",["tinymce/spellcheckerplugin/DomTextMatcher","tinymce/PluginManager","tinymce/util/Tools","tinymce/ui/Menu","tinymce/dom/DOMUtils","tinymce/util/JSONRequest","tinymce/util/URI"],function(e,t,n,r,o,i,c){t.add("spellchecker",function(t,a){function l(e){for(var t in e)return!1;return!0}function d(e,i){var c=[],a=m[i];n.each(a,function(e){c.push({text:e,onclick:function(){t.insertContent(e),u()}})}),c.push.apply(c,[{text:"-"},{text:"Ignore",onclick:function(){h(e,i)}},{text:"Ignore all",onclick:function(){h(e,i,!0)}},{text:"Finish",onclick:p}]),x=new r({items:c,context:"contextmenu",onautohide:function(e){-1!=e.target.className.indexOf("spellchecker")&&e.preventDefault()},onhide:function(){x.remove(),x=null}}),x.renderTo(document.body);var l=o.DOM.getPos(t.getContentAreaContainer()),d=t.dom.getPos(e);l.x+=d.x,l.y+=d.y,x.moveTo(l.x,l.y+e.offsetHeight)}function s(){function n(e){return t.setProgressState(!1),l(e)?(t.windowManager.alert("No misspellings found"),void(v=!1)):(m=e,o.filter(function(t){return!!e[t[2][0]]}).mark(t.dom.create("span",{"class":"mce-spellchecker-word","data-mce-bogus":1})),o=null,void t.fire("SpellcheckStart"))}function r(e,n,r){i.sendRPC({url:new c(a).toAbsolute(N.spellchecker_rpc_url),method:e,params:{lang:N.spellchecker_language||"en",words:n},success:function(e){r(e)},error:function(e,n){e="JSON Parse error."==e?"Non JSON response:"+n.responseText:"Error: "+e,t.windowManager.alert(e),t.setProgressState(!1),o=null,v=!1}})}var o,d=[],s={};if(v)return void p();v=!0;var u=t.getParam("spellchecker_wordchar_pattern")||new RegExp('[^\\s!"#$%&()*+,-./:;<=>?@[\\]^_{|}`§©«®±¶·¸»¼½¾¿×÷¤”“„]+',"g");o=new e(u,t.getBody(),t.schema).each(function(e){var t=e[2][0];if(!s[t]){if(/^\d+$/.test(t)||1==t.length)return;d.push(t),s[t]=!0}}),t.setProgressState(!0);var f=N.spellchecker_callback||r;f("spellcheck",d,n)}function u(){t.dom.select("span.mce-spellchecker-word").length||p()}function f(e){var t=e.parentNode;t.insertBefore(e.firstChild,e),e.parentNode.removeChild(e)}function h(e,r,o){o?n.each(t.dom.select("span.mce-spellchecker-word"),function(e){var t=e.innerText||e.textContent;t==r&&f(e)}):f(e),u()}function p(){var e,n,r;for(v=!1,r=t.getBody(),n=r.getElementsByTagName("span"),e=n.length;e--;)r=n[e],r.getAttribute("data-mce-index")&&f(r);t.fire("SpellcheckEnd")}function g(e){var n,r,o,i,c,a=-1;for(e=""+e,n=t.getBody().getElementsByTagName("span"),r=0;r<n.length&&(o=n[r],"mce-spellchecker-word"!=o.className||(a=o.getAttribute("data-mce-index"),a===e&&(a=e,i||(i=o.firstChild),c=o.firstChild),a===e||!c));r++);var l=t.dom.createRng();return l.setStart(i,0),l.setEnd(c,c.length),t.selection.setRng(l),l}var m,v,x,N=t.settings;t.on("click",function(e){if("mce-spellchecker-word"==e.target.className){e.preventDefault();var t=g(e.target.getAttribute("data-mce-index"));d(e.target,t.toString())}}),t.addMenuItem("spellchecker",{text:"Spellcheck",context:"tools",onclick:s,selectable:!0,onPostRender:function(){var e=this;t.on("SpellcheckStart SpellcheckEnd",function(){e.active(v)})}}),t.addButton("spellchecker",{tooltip:"Spellcheck",onclick:s,onPostRender:function(){var e=this;t.on("SpellcheckStart SpellcheckEnd",function(){e.active(v)})}}),t.on("remove",function(){x&&(x.remove(),x=null)})})}),i(["tinymce/spellcheckerplugin/DomTextMatcher","tinymce/spellcheckerplugin/Plugin"])}(this);