diff --git a/wp-includes/js/tinymce/plugins/spellchecker/editor_plugin.js b/wp-includes/js/tinymce/plugins/spellchecker/editor_plugin.js index 9e0329cf6a..865b332a19 100755 --- a/wp-includes/js/tinymce/plugins/spellchecker/editor_plugin.js +++ b/wp-includes/js/tinymce/plugins/spellchecker/editor_plugin.js @@ -1 +1,630 @@ -tinyMCE.importPluginLanguagePack('spellchecker','en,fr,sv,nn,nb');var TinyMCE_SpellCheckerPlugin={_contextMenu:new TinyMCE_Menu(),_menu:new TinyMCE_Menu(),_counter:0,_ajaxPage:'/tinyspell.php',getInfo:function(){return{longname:'Spellchecker PHP',author:'Moxiecode Systems AB',authorurl:'http://tinymce.moxiecode.com',infourl:'http://tinymce.moxiecode.com/tinymce/docs/plugin_spellchecker.html',version:"1.0.3"};},handleEvent:function(e){var elm=tinyMCE.isMSIE?e.srcElement:e.target;var inst=tinyMCE.selectedInstance,args='';var self=TinyMCE_SpellCheckerPlugin;var cm=self._contextMenu;var p,p2,x,y,sx,sy,h,elm;if((e.type=="click"||e.type=="contextmenu")&&elm){do{if(tinyMCE.getAttrib(elm,'class')=="mceItemHiddenSpellWord"){inst.spellCheckerElm=elm;args+='id='+inst.editorId+"|"+(++self._counter);args+='&cmd=suggest&check='+encodeURIComponent(elm.innerHTML);args+='&lang='+escape(inst.spellCheckerLang);elm=inst.spellCheckerElm;p=tinyMCE.getAbsPosition(inst.iframeElement);p2=tinyMCE.getAbsPosition(elm);h=parseInt(elm.offsetHeight);sx=inst.getBody().scrollLeft;sy=inst.getBody().scrollTop;x=p.absLeft+p2.absLeft-sx;y=p.absTop+p2.absTop-sy+h;cm.clear();cm.addTitle(tinyMCE.getLang('lang_spellchecker_wait','',true));cm.show();cm.moveTo(x,y);inst.selection.selectNode(elm,false,false);self._sendAjax(self.baseURL+self._ajaxPage,self._ajaxResponse,'post',args);tinyMCE.cancelEvent(e);return false;}}while((elm=elm.parentNode));}return true;},initInstance:function(inst){var self=TinyMCE_SpellCheckerPlugin,m=self._menu,cm=self._contextMenu,e;tinyMCE.importCSS(inst.getDoc(),tinyMCE.baseURL+"/plugins/spellchecker/css/content.css");if(!tinyMCE.hasMenu('spellcheckercontextmenu')){tinyMCE.importCSS(document,tinyMCE.baseURL+"/plugins/spellchecker/css/spellchecker.css");cm.init({drop_menu:false});tinyMCE.addMenu('spellcheckercontextmenu',cm);}if(!tinyMCE.hasMenu('spellcheckermenu')){m.init({});tinyMCE.addMenu('spellcheckermenu',m);}inst.spellCheckerLang='en';self._buildSettingsMenu(inst,null);e=self._getBlockBoxLayer(inst).create('div','mceBlockBox',document.getElementById(inst.editorId+'_parent'));self._getMsgBoxLayer(inst).create('div','mceMsgBox',document.getElementById(inst.editorId+'_parent'));},_getMsgBoxLayer:function(inst){if(!inst.spellCheckerMsgBoxL)inst.spellCheckerMsgBoxL=new TinyMCE_Layer(inst.editorId+'_spellcheckerMsgBox',false);return inst.spellCheckerMsgBoxL;},_getBlockBoxLayer:function(inst){if(!inst.spellCheckerBoxL)inst.spellCheckerBoxL=new TinyMCE_Layer(inst.editorId+'_spellcheckerBlockBox',false);return inst.spellCheckerBoxL;},_buildSettingsMenu:function(inst,lang){var i,ar=tinyMCE.getParam('spellchecker_languages','+English=en').split(','),p;var self=TinyMCE_SpellCheckerPlugin,m=self._menu,c;m.clear();m.addTitle(tinyMCE.getLang('lang_spellchecker_langs','',true));for(i=0;i';h+='';h+='';h+='';}else{if(tinyMCE.isMSIE&&!tinyMCE.isOpera)h+='';else h+='';h+='';h+='';h+='';h+='';}return h;},_menuButtonEvent:function(e,o){var t=this;window.setTimeout(function(){t._menuButtonEvent2(e,o);},1);},_menuButtonEvent2:function(e,o){if(o.className=='mceMenuButtonFocus')return;if(e=='over')o.className=o.className+' mceMenuHover';else o.className=o.className.replace(/\s.*$/,'');},_toggleMenu:function(editor_id,id){var self=TinyMCE_SpellCheckerPlugin;var e=document.getElementById(editor_id+'_spellchecker');var inst=tinyMCE.getInstanceById(editor_id);if(self._menu.isVisible()){tinyMCE.hideMenus();return;}tinyMCE.lastMenuBtnClass=e.className.replace(/\s.*$/,'');tinyMCE.switchClass(editor_id+'_spellchecker','mceMenuButtonFocus');self._menu.moveRelativeTo(e,'bl');self._menu.moveBy(tinyMCE.isMSIE&&!tinyMCE.isOpera?0:1,-1);if(tinyMCE.isOpera)self._menu.moveBy(0,-2);self._onMenuEvent(inst,self._menu,'show');self._menu.show();tinyMCE.lastSelectedMenuBtn=editor_id+'_spellchecker';},_onMenuEvent:function(inst,m,n){TinyMCE_SpellCheckerPlugin._buildSettingsMenu(inst,inst.spellCheckerLang);},execCommand:function(editor_id,element,command,user_interface,value){var inst=tinyMCE.getInstanceById(editor_id),self=TinyMCE_SpellCheckerPlugin,args='',co,bb,mb,nl,i,e,mbs;switch(command){case"mceSpellCheck":if(!inst.spellcheckerOn){inst.spellCheckerBookmark=inst.selection.getBookmark();if(tinyMCE.isRealIE)tinyMCE.setInnerHTML(inst.getBody(),inst.getBody().innerHTML);args+='id='+inst.editorId+"|"+(++self._counter);args+='&cmd=spell&check='+encodeURIComponent(self._getWordList(inst.getBody())).replace(/\'/g,'%27');args+='&lang='+escape(inst.spellCheckerLang);co=document.getElementById(inst.editorId+'_parent').firstChild;bb=self._getBlockBoxLayer(inst);bb.moveRelativeTo(co,'tl');bb.resizeTo(co.offsetWidth,co.offsetHeight);bb.show();mb=self._getMsgBoxLayer(inst);e=mb.getElement();if(e.childNodes[0])e.removeChild(e.childNodes[0]);mbs=document.createElement("span");mbs.innerHTML=''+tinyMCE.getLang('lang_spellchecker_swait','',true)+'';e.appendChild(mbs);mb.show();mb.moveRelativeTo(co,'cc');if(tinyMCE.isMSIE&&!tinyMCE.isOpera){nl=co.getElementsByTagName('select');for(i=0;i?@[\]^_{|}\u201d\u201c');for(i=0;i0)wl[wl.length]=nl[i];}return wl.join(' ');},_removeWords:function(doc,word,cleanup){var i,c,nl=doc.getElementsByTagName("span");var self=TinyMCE_SpellCheckerPlugin;var inst=tinyMCE.selectedInstance,b=inst?inst.selection.getBookmark():null;word=typeof(word)=='undefined'?null:word;for(i=nl.length-1;i>=0;i--){c=tinyMCE.getAttrib(nl[i],'class');if((c=='mceItemHiddenSpellWord'||c=='mceItemHidden')&&(word==null||nl[i].innerHTML==word))self._removeWord(nl[i]);}if(b&&!cleanup)inst.selection.moveToBookmark(b);},_checkDone:function(inst){var self=TinyMCE_SpellCheckerPlugin;var w=self._countWords(inst);if(w==0){self._removeWords(inst.getDoc());inst.spellcheckerOn=false;tinyMCE.switchClass(inst.editorId+'_spellchecker','mceMenuButton');}},_countWords:function(inst){var i,w=0,nl=inst.getDoc().getElementsByTagName("span"),c;var self=TinyMCE_SpellCheckerPlugin;for(i=nl.length-1;i>=0;i--){c=tinyMCE.getAttrib(nl[i],'class');if(c=='mceItemHiddenSpellWord')w++;}return w;},_removeWord:function(e){if(e!=null)tinyMCE.setOuterHTML(e,e.innerHTML);},_markWords:function(doc,n,wl){var i,nv,nn,nl=tinyMCE.getNodeTree(n,new Array(),3);var r1,r2,r3,r4,r5,w='';var re=TinyMCE_SpellCheckerPlugin._getWordSeparators();for(i=0;i0)w+=wl[i]+((i==wl.length-1)?'':'|');}for(i=0;i$1$2');nv=nv.replace(r3,'$1$2');nn=doc.createElement('span');nn.className="mceItemHidden";nn.innerHTML=nv;nl[i].parentNode.replaceChild(nn,nl[i]);}}},_buildMenu:function(sg,max){var i,self=TinyMCE_SpellCheckerPlugin,cm=self._contextMenu;cm.clear();if(sg!=null){cm.addTitle(tinyMCE.getLang('lang_spellchecker_sug','',true));for(i=0;i'; + h += ''; + h += ''; + h += ''; + } else { + if (tinyMCE.isMSIE && !tinyMCE.isOpera) + h += ''; + else + h += ''; + + h += ''; + h += ''; + h += ''; + h += ''; + } + + return h; + }, + + _menuButtonEvent : function(e, o) { + var t = this; + + // Give IE some time since it's buggy!! :( + window.setTimeout(function() { + t._menuButtonEvent2(e, o); + }, 1); + }, + + _menuButtonEvent2 : function(e, o) { + if (o.className == 'mceMenuButtonFocus') + return; + + if (e == 'over') + o.className = o.className + ' mceMenuHover'; + else + o.className = o.className.replace(/\s.*$/, ''); + }, + + _toggleMenu : function(editor_id, id) { + var self = TinyMCE_SpellCheckerPlugin; + var e = document.getElementById(editor_id + '_spellchecker'); + var inst = tinyMCE.getInstanceById(editor_id); + + if (self._menu.isVisible()) { + tinyMCE.hideMenus(); + return; + } + + tinyMCE.lastMenuBtnClass = e.className.replace(/\s.*$/, ''); + tinyMCE.switchClass(editor_id + '_spellchecker', 'mceMenuButtonFocus'); + + self._menu.moveRelativeTo(e, 'bl'); + self._menu.moveBy(tinyMCE.isMSIE && !tinyMCE.isOpera ? 0 : 1, -1); + + if (tinyMCE.isOpera) + self._menu.moveBy(0, -2); + + self._onMenuEvent(inst, self._menu, 'show'); + + self._menu.show(); + + tinyMCE.lastSelectedMenuBtn = editor_id + '_spellchecker'; + }, + + _onMenuEvent : function(inst, m, n) { + TinyMCE_SpellCheckerPlugin._buildSettingsMenu(inst, inst.spellCheckerLang); + }, + + execCommand : function(editor_id, element, command, user_interface, value) { + var inst = tinyMCE.getInstanceById(editor_id), self = TinyMCE_SpellCheckerPlugin, args = '', co, bb, mb, nl, i, e, mbs; + + // Handle commands + switch (command) { + case "mceSpellCheck": + if (!inst.spellcheckerOn) { + inst.spellCheckerBookmark = inst.selection.getBookmark(); + + // Fix for IE bug: #1610184 + if (tinyMCE.isRealIE) + tinyMCE.setInnerHTML(inst.getBody(), inst.getBody().innerHTML); + + // Setup arguments + args += 'id=' + inst.editorId + "|" + (++self._counter); + args += '&cmd=spell&check=' + encodeURIComponent(self._getWordList(inst.getBody())).replace(/\'/g, '%27'); + args += '&lang=' + escape(inst.spellCheckerLang); + + co = document.getElementById(inst.editorId + '_parent').firstChild; + bb = self._getBlockBoxLayer(inst); + bb.moveRelativeTo(co, 'tl'); + bb.resizeTo(co.offsetWidth, co.offsetHeight); + bb.show(); + + // Setup message box + mb = self._getMsgBoxLayer(inst); + e = mb.getElement(); + + if (e.childNodes[0]) + e.removeChild(e.childNodes[0]); + + mbs = document.createElement("span"); + mbs.innerHTML = '' + tinyMCE.getLang('lang_spellchecker_swait', '', true) + ''; + e.appendChild(mbs); + + mb.show(); + mb.moveRelativeTo(co, 'cc'); + + if (tinyMCE.isMSIE && !tinyMCE.isOpera) { + nl = co.getElementsByTagName('select'); + for (i=0; i 500) + text = text.substring(500); + + inst.spellcheckerOn = false; + tinyMCE.switchClass(inst.editorId + '_spellchecker', 'mceMenuButton'); + alert("Could not execute AJAX call, server didn't return valid a XML.\nResponse: " + text); + return; + } + + err = el.getAttribute("error"); + + if (err == "true") { + inst.spellcheckerOn = false; + tinyMCE.switchClass(inst.editorId + '_spellchecker', 'mceMenuButton'); + alert(el.getAttribute("msg")); + return; + } + + switch (cmd) { + case "spell": + if (xml.documentElement.firstChild) { + self._markWords(inst.getDoc(), inst.getBody(), decodeURIComponent(el.firstChild.nodeValue).split('+')); + inst.selection.moveToBookmark(inst.spellCheckerBookmark); + + if(tinyMCE.getParam('spellchecker_report_misspellings', false)) + alert(tinyMCE.getLang('lang_spellchecker_mpell_found', '', true, {words : self._countWords(inst)})); + } else + alert(tinyMCE.getLang('lang_spellchecker_no_mpell', '', true)); + + self._checkDone(inst); + + // Odd stuff FF removed useCSS, disable state for it + inst.useCSS = false; + + break; + + case "suggest": + self._buildMenu(el.firstChild ? decodeURIComponent(el.firstChild.nodeValue).split('+') : null, 10); + self._contextMenu.show(); + break; + } + }, + + _getWordSeparators : function() { + var i, re = '', ch = tinyMCE.getParam('spellchecker_word_separator_chars', '\\s!"#$%&()*+,-./:;<=>?@[\]^_{|}§©«®±¶·¸»¼½¾¿×÷¤\u201d\u201c'); + + for (i=0; i 0) + wl[wl.length] = nl[i]; + } + + return wl.join(' '); + }, + + _removeWords : function(doc, word, cleanup) { + var i, c, nl = doc.getElementsByTagName("span"); + var self = TinyMCE_SpellCheckerPlugin; + var inst = tinyMCE.selectedInstance, b = inst ? inst.selection.getBookmark() : null; + + word = typeof(word) == 'undefined' ? null : word; + + for (i=nl.length-1; i>=0; i--) { + c = tinyMCE.getAttrib(nl[i], 'class'); + + if ((c == 'mceItemHiddenSpellWord' || c == 'mceItemHidden') && (word == null || nl[i].innerHTML == word)) + self._removeWord(nl[i]); + } + + if (b && !cleanup) + inst.selection.moveToBookmark(b); + }, + + _checkDone : function(inst) { + var self = TinyMCE_SpellCheckerPlugin; + var w = self._countWords(inst); + + if (w == 0) { + self._removeWords(inst.getDoc()); + inst.spellcheckerOn = false; + tinyMCE.switchClass(inst.editorId + '_spellchecker', 'mceMenuButton'); + } + }, + + _countWords : function(inst) { + var i, w = 0, nl = inst.getDoc().getElementsByTagName("span"), c; + var self = TinyMCE_SpellCheckerPlugin; + + for (i=nl.length-1; i>=0; i--) { + c = tinyMCE.getAttrib(nl[i], 'class'); + + if (c == 'mceItemHiddenSpellWord') + w++; + } + + return w; + }, + + _removeWord : function(e) { + if (e != null) + tinyMCE.setOuterHTML(e, e.innerHTML); + }, + + _markWords : function(doc, n, wl) { + var i, nv, nn, nl = tinyMCE.getNodeTree(n, new Array(), 3); + var r1, r2, r3, r4, r5, w = ''; + var re = TinyMCE_SpellCheckerPlugin._getWordSeparators(); + + for (i=0; i 0) + w += wl[i] + ((i == wl.length-1) ? '' : '|'); + } + + for (i=0; i$1$2'); + nv = nv.replace(r3, '$1$2'); + + nn = doc.createElement('span'); + nn.className = "mceItemHidden"; + nn.innerHTML = nv; + + // Remove old text node + nl[i].parentNode.replaceChild(nn, nl[i]); + } + } + }, + + _buildMenu : function(sg, max) { + var i, self = TinyMCE_SpellCheckerPlugin, cm = self._contextMenu; + + cm.clear(); + + if (sg != null) { + cm.addTitle(tinyMCE.getLang('lang_spellchecker_sug', '', true)); + + for (i=0; i