From d9344fc349e8c5765898c90bf5061e56cd21c8a0 Mon Sep 17 00:00:00 2001 From: svncommit Date: Tue, 15 Apr 2008 21:22:00 +0000 Subject: HTML editing fixes, upgrade to TinyMCE v3.0.6 --- program/js/tiny_mce/plugins/spellchecker/changelog | 11 - .../spellchecker/classes/TinyGoogleSpell.class.php | 107 --- .../spellchecker/classes/TinyPspell.class.php | 64 -- .../spellchecker/classes/TinyPspellShell.class.php | 121 --- .../js/tiny_mce/plugins/spellchecker/config.php | 26 - .../tiny_mce/plugins/spellchecker/css/content.css | 6 +- .../plugins/spellchecker/css/spellchecker.css | 34 - .../tiny_mce/plugins/spellchecker/editor_plugin.js | 2 +- .../plugins/spellchecker/editor_plugin_src.js | 814 +++++++-------------- .../plugins/spellchecker/images/spellchecker.gif | Bin 591 -> 0 bytes .../tiny_mce/plugins/spellchecker/images/wline.gif | Bin 46 -> 0 bytes .../js/tiny_mce/plugins/spellchecker/img/wline.gif | Bin 0 -> 46 bytes .../js/tiny_mce/plugins/spellchecker/langs/en.js | 15 - .../js/tiny_mce/plugins/spellchecker/tinyspell.php | 142 ---- 14 files changed, 284 insertions(+), 1058 deletions(-) delete mode 100644 program/js/tiny_mce/plugins/spellchecker/changelog delete mode 100644 program/js/tiny_mce/plugins/spellchecker/classes/TinyGoogleSpell.class.php delete mode 100644 program/js/tiny_mce/plugins/spellchecker/classes/TinyPspell.class.php delete mode 100644 program/js/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php delete mode 100644 program/js/tiny_mce/plugins/spellchecker/config.php delete mode 100644 program/js/tiny_mce/plugins/spellchecker/css/spellchecker.css delete mode 100644 program/js/tiny_mce/plugins/spellchecker/images/spellchecker.gif delete mode 100644 program/js/tiny_mce/plugins/spellchecker/images/wline.gif create mode 100644 program/js/tiny_mce/plugins/spellchecker/img/wline.gif delete mode 100644 program/js/tiny_mce/plugins/spellchecker/langs/en.js delete mode 100644 program/js/tiny_mce/plugins/spellchecker/tinyspell.php (limited to 'program/js/tiny_mce/plugins/spellchecker') diff --git a/program/js/tiny_mce/plugins/spellchecker/changelog b/program/js/tiny_mce/plugins/spellchecker/changelog deleted file mode 100644 index 608fcd56d..000000000 --- a/program/js/tiny_mce/plugins/spellchecker/changelog +++ /dev/null @@ -1,11 +0,0 @@ -Version 1.0.2 (2006-08-02) - Added new spellchecker_report_mispellings option, contributed by Jeremy B. - Fixed various regexp bugs and issues. Some where contributed by Jeremy B. - Fixed the Google speller class so it uses curl, patch contributed by Yuriy Kramar. - Fixed encoding issues with language specific characters, patch contributed by codepit. - Fixed bug where the spellchecker wasn't working in MSIE if the editor was placed in a P tag. -Version 1.0.1 (2006-05-05) - Since sourceforge has a serious bug when it comes to replacing files with the same name this release was necessary. - Goggle spellchecker class was added. -Version 1.0 (2006-05-03) - Official first release. diff --git a/program/js/tiny_mce/plugins/spellchecker/classes/TinyGoogleSpell.class.php b/program/js/tiny_mce/plugins/spellchecker/classes/TinyGoogleSpell.class.php deleted file mode 100644 index 7be929731..000000000 --- a/program/js/tiny_mce/plugins/spellchecker/classes/TinyGoogleSpell.class.php +++ /dev/null @@ -1,107 +0,0 @@ -lang = $lang; - $this->spellurl = $config['googlespell.url']; - } - - // Returns array with bad words or false if failed. - function checkWords($word_array) { - $words = array (); - $wordstr = implode(' ', $word_array); - - $matches = $this->_getMatches($wordstr); - - for ($i = 0; $i < count($matches); $i++) - $words[] = $this->unhtmlentities(mb_substr($wordstr, $matches[$i][1], $matches[$i][2], "UTF-8")); - - return $words; - } - - function unhtmlentities($string) { - $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string); - $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string); - - $trans_tbl = get_html_translation_table(HTML_ENTITIES); - $trans_tbl = array_flip($trans_tbl); - - return strtr($string, $trans_tbl); - } - - // Returns array with suggestions or false if failed. - function getSuggestion($word) { - $sug = array (); - - $matches = $this->_getMatches($word); - - if (count($matches) > 0) - $sug = explode("\t", utf8_encode($this->unhtmlentities($matches[0][4]))); - - return $sug; - } - - function _xmlChars($string) { - $trans = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES); - - foreach ($trans as $k => $v) - $trans[$k] = "&#" . ord($k) . ";"; - - return strtr($string, $trans); - } - - function _getMatches($word_list) { - $url = $this->spellurl . "&" . $this->lang; - - $path = preg_replace("/^https?:\/\//i", "", $url); - - // Setup XML request - $xml = '' . $word_list . ''; - - $header = "POST " . $path . " HTTP/1.0 \r\n"; - $header .= "MIME-Version: 1.0 \r\n"; - $header .= "Content-type: application/PTI26 \r\n"; - $header .= "Content-length: " . strlen($xml) . " \r\n"; - $header .= "Content-transfer-encoding: text \r\n"; - $header .= "Request-number: 1 \r\n"; - $header .= "Document-type: Request \r\n"; - $header .= "Interface-Version: Test 1.4 \r\n"; - $header .= "Connection: close \r\n\r\n"; - $header .= $xml; - //$this->_debugData($xml); - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - $xml = curl_exec($ch); - curl_close($ch); - - //$this->_debugData($xml); - - // Grab and parse content - preg_match_all('/([^<]*)<\/c>/', $xml, $matches, PREG_SET_ORDER); - - return $matches; - } - - function _debugData($data) { - $fh = @ fopen("debug.log", 'a+'); - @ fwrite($fh, $data); - @ fclose($fh); - } -} - -// Setup classname, should be the same as the name of the spellchecker class -$spellCheckerConfig['class'] = "TinyGoogleSpell"; -?> diff --git a/program/js/tiny_mce/plugins/spellchecker/classes/TinyPspell.class.php b/program/js/tiny_mce/plugins/spellchecker/classes/TinyPspell.class.php deleted file mode 100644 index 21fb19448..000000000 --- a/program/js/tiny_mce/plugins/spellchecker/classes/TinyPspell.class.php +++ /dev/null @@ -1,64 +0,0 @@ -lang = $lang; - $this->mode = $mode; - $this->plink = false; - $this->errorMsg = array(); - - if (!function_exists("pspell_new")) { - $this->errorMsg[] = "PSpell not found."; - return; - } - - $this->plink = pspell_new($this->lang, $this->spelling, $this->jargon, $this->encoding, $this->mode); - } - - // Returns array with bad words or false if failed. - function checkWords($wordArray) { - if (!$this->plink) { - $this->errorMsg[] = "No PSpell link found for checkWords."; - return array(); - } - - $wordError = array(); - foreach($wordArray as $word) { - if(!pspell_check($this->plink, trim($word))) - $wordError[] = $word; - } - - return $wordError; - } - - // Returns array with suggestions or false if failed. - function getSuggestion($word) { - if (!$this->plink) { - $this->errorMsg[] = "No PSpell link found for getSuggestion."; - return array(); - } - - return pspell_suggest($this->plink, $word); - } -} - -// Setup classname, should be the same as the name of the spellchecker class -$spellCheckerConfig['class'] = "TinyPspell"; - -?> \ No newline at end of file diff --git a/program/js/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php b/program/js/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php deleted file mode 100644 index 348cac3d8..000000000 --- a/program/js/tiny_mce/plugins/spellchecker/classes/TinyPspellShell.class.php +++ /dev/null @@ -1,121 +0,0 @@ -lang = $lang; - $this->mode = $mode; - $this->error = false; - $this->errorMsg = array(); - - $this->tmpfile = tempnam($config['tinypspellshell.tmp'], "tinyspell"); - - if(preg_match("#win#i",php_uname())) - $this->cmd = $config['tinypspellshell.aspell'] . " -a --lang=". $this->lang." --encoding=utf-8 -H < $this->tmpfile 2>&1"; - else - $this->cmd = "cat ". $this->tmpfile ." | " . $config['tinypspellshell.aspell'] . " -a --encoding=utf-8 -H --lang=". $this->lang; - } - - // Returns array with bad words or false if failed. - function checkWords($wordArray) { - if ($fh = fopen($this->tmpfile, "w")) { - fwrite($fh, "!\n"); - foreach($wordArray as $key => $value) - fwrite($fh, "^" . $value . "\n"); - fclose($fh); - } else { - $this->errorMsg[] = "PSpell not found."; - return array(); - } - - $data = shell_exec($this->cmd); - @unlink($this->tmpfile); - - $returnData = array(); - $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY); - - foreach($dataArr as $dstr) { - $matches = array(); - - // Skip this line. - if (strpos($dstr, "@") === 0) - continue; - - preg_match("/\& (.*) .* .*: .*/i", $dstr, $matches); - - if (!empty($matches[1])) - $returnData[] = $matches[1]; - } - - return $returnData; - } - - // Returns array with suggestions or false if failed. - function getSuggestion($word) { - if (function_exists("mb_convert_encoding")) - $word = mb_convert_encoding($word, "ISO-8859-1", mb_detect_encoding($word, "UTF-8")); - else - $word = utf8_encode($word); - - if ($fh = fopen($this->tmpfile, "w")) { - fwrite($fh, "!\n"); - fwrite($fh, "^$word\n"); - fclose($fh); - } else - die("Error opening tmp file."); - - $data = shell_exec($this->cmd); - - @unlink($this->tmpfile); - - $returnData = array(); - $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY); - - foreach($dataArr as $dstr) { - $matches = array(); - - // Skip this line. - if (strpos($dstr, "@") === 0) - continue; - - preg_match("/\& .* .* .*: (.*)/i", $dstr, $matches); - - if (!empty($matches[1])) { - // For some reason, the exec version seems to add commas? - $returnData[] = str_replace(",", "", $matches[1]); - } - } - return $returnData; - } - - function _debugData($data) { - $fh = @fopen("debug.log", 'a+'); - @fwrite($fh, $data); - @fclose($fh); - } - -} - -// Setup classname, should be the same as the name of the spellchecker class -$spellCheckerConfig['class'] = "TinyPspellShell"; - -?> \ No newline at end of file diff --git a/program/js/tiny_mce/plugins/spellchecker/config.php b/program/js/tiny_mce/plugins/spellchecker/config.php deleted file mode 100644 index 6622248c0..000000000 --- a/program/js/tiny_mce/plugins/spellchecker/config.php +++ /dev/null @@ -1,26 +0,0 @@ - \ No newline at end of file diff --git a/program/js/tiny_mce/plugins/spellchecker/css/content.css b/program/js/tiny_mce/plugins/spellchecker/css/content.css index fb82733cd..24efa0217 100644 --- a/program/js/tiny_mce/plugins/spellchecker/css/content.css +++ b/program/js/tiny_mce/plugins/spellchecker/css/content.css @@ -1,5 +1 @@ -.mceItemHiddenSpellWord { - background: url('../images/wline.gif') repeat-x bottom left; - bo2rder-bottom: 1px dashed red; - cursor: default; -} +.mceItemHiddenSpellWord {background:url(../img/wline.gif) repeat-x bottom left; cursor:default;} diff --git a/program/js/tiny_mce/plugins/spellchecker/css/spellchecker.css b/program/js/tiny_mce/plugins/spellchecker/css/spellchecker.css deleted file mode 100644 index aa4a8ea3b..000000000 --- a/program/js/tiny_mce/plugins/spellchecker/css/spellchecker.css +++ /dev/null @@ -1,34 +0,0 @@ -.mceMsgBox { - border: 1px solid gray; - padding: 8px; -} - -.mceMsgBox span { - vertical-align: top; - color: #555555; -} - -/* Misc */ - -.mceBlockBox { - display: none; - position: absolute; - left: 0; - top: 0; - z-index: 100; - filter:progid:DXImageTransform.Microsoft.Alpha(style=0, opacity=60); - -moz-opacity:0.6; - opacity: 0.6; - background-color: white; -} - -.mceMsgBox { - display: none; - z-index: 101; - position: absolute; - left: 0; - top: 0; - font-family: Arial, Verdana, Tahoma, Helvetica; - font-weight: bold; - font-size: 11px; -} diff --git a/program/js/tiny_mce/plugins/spellchecker/editor_plugin.js b/program/js/tiny_mce/plugins/spellchecker/editor_plugin.js index dbcda6a56..9cb679961 100644 --- a/program/js/tiny_mce/plugins/spellchecker/editor_plugin.js +++ b/program/js/tiny_mce/plugins/spellchecker/editor_plugin.js @@ -1 +1 @@ -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',author:'Moxiecode Systems AB',authorurl:'http://tinymce.moxiecode.com',infourl:'http://tinymce.moxiecode.com/tinymce/docs/plugin_spellchecker.html',version:tinyMCE.majorVersion+"."+tinyMCE.minorVersion};},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){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;switch(command){case"mceSpellCheck":if(!inst.spellcheckerOn){inst.spellCheckerBookmark=inst.selection.getBookmark();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();e.innerHTML=''+tinyMCE.getLang('lang_spellchecker_swait','',true)+'';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){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)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;i0){t.active=1;t._markWords(r);ed.setProgressState(0);ed.nodeChanged();}else{ed.setProgressState(0);ed.windowManager.alert('spellchecker.no_mpell');}});}else t._done();});ed.onInit.add(function(){if(ed.settings.content_css!==false)ed.dom.loadCSS(url+'/css/content.css');});ed.onClick.add(t._showMenu,t);ed.onContextMenu.add(t._showMenu,t);ed.onBeforeGetContent.add(function(){if(t.active)t._removeWords();});ed.onNodeChange.add(function(ed,cm){cm.setActive('spellchecker',t.active);});ed.onSetContent.add(function(){t._done();});ed.onBeforeGetContent.add(function(){t._done();});ed.onBeforeExecCommand.add(function(ed,cmd){if(cmd=='mceFullScreen')t._done();});t.languages={};each(ed.getParam('spellchecker_languages','+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv','hash'),function(v,k){if(k.indexOf('+')===0){k=k.substring(1);t.selectedLang=v;}t.languages[k]=v;});},createControl:function(n,cm){var t=this,c,ed=t.editor;if(n=='spellchecker'){c=cm.createSplitButton(n,{title:'spellchecker.desc',cmd:'mceSpellCheck',scope:t});c.onRenderMenu.add(function(c,m){m.add({title:'spellchecker.langs','class':'mceMenuItemTitle'}).setDisabled(1);each(t.languages,function(v,k){var o={icon:1},mi;o.onclick=function(){mi.setSelected(1);t.selectedItem.setSelected(0);t.selectedItem=mi;t.selectedLang=v;};o.title=k;mi=m.add(o);mi.setSelected(v==t.selectedLang);if(v==t.selectedLang)t.selectedItem=mi;})});return c;}},_walk:function(n,f){var d=this.editor.getDoc(),w;if(d.createTreeWalker){w=d.createTreeWalker(n,NodeFilter.SHOW_TEXT,null,false);while((n=w.nextNode())!=null)f.call(this,n);}else tinymce.walk(n,f,'childNodes');},_getSeparators:function(){var re='',i,str=this.editor.getParam('spellchecker_word_separator_chars','\\s!"#$%&()*+,-./:;<=>?@[\]^_{|}����������������\u201d\u201c');for(i=0;i$1$2');v=v.replace(r3,'$1$2');dom.replace(dom.create('span',{'class':'mceItemHidden'},v),n);}}});se.moveToBookmark(b);},_showMenu:function(ed,e){var t=this,ed=t.editor,m=t._menu,p1,dom=ed.dom,vp=dom.getViewPort(ed.getWin());if(!m){p1=DOM.getPos(ed.getContentAreaContainer());m=ed.controlManager.createDropMenu('spellcheckermenu',{offset_x:p1.x,offset_y:p1.y,'class':'mceNoIcons'});t._menu=m;}if(dom.hasClass(e.target,'mceItemHiddenSpellWord')){m.removeAll();m.add({title:'spellchecker.wait','class':'mceMenuItemTitle'}).setDisabled(1);t._sendRPC('getSuggestions',[t.selectedLang,dom.decode(e.target.innerHTML)],function(r){m.removeAll();if(r.length>0){m.add({title:'spellchecker.sug','class':'mceMenuItemTitle'}).setDisabled(1);each(r,function(v){m.add({title:v,onclick:function(){dom.replace(ed.getDoc().createTextNode(v),e.target);t._checkDone();}});});m.addSeparator();}else m.add({title:'spellchecker.no_sug','class':'mceMenuItemTitle'}).setDisabled(1);m.add({title:'spellchecker.ignore_word',onclick:function(){dom.remove(e.target,1);t._checkDone();}});m.add({title:'spellchecker.ignore_words',onclick:function(){t._removeWords(dom.decode(e.target.innerHTML));t._checkDone();}});m.update();});ed.selection.select(e.target);p1=dom.getPos(e.target);m.showMenu(p1.x,p1.y+e.target.offsetHeight-vp.y);return tinymce.dom.Event.cancel(e);}else m.hideMenu();},_checkDone:function(){var t=this,ed=t.editor,dom=ed.dom,o;each(dom.select('span'),function(n){if(n&&dom.hasClass(n,'mceItemHiddenSpellWord')){o=true;return false;}});if(!o)t._done();},_done:function(){var t=this,la=t.active;if(t.active){t.active=0;t._removeWords();if(t._menu)t._menu.hideMenu();if(la)t.editor.nodeChanged();}},_sendRPC:function(m,p,cb){var t=this,url=t.editor.getParam("spellchecker_rpc_url","{backend}");if(url=='{backend}'){t.editor.setProgressState(0);alert('Please specify: spellchecker_rpc_url');return;}JSONRequest.sendRPC({url:url,method:m,params:p,success:cb,error:function(e,x){t.editor.setProgressState(0);t.editor.windowManager.alert(e.errstr||('Error response: '+x.responseText));}});}});tinymce.PluginManager.add('spellchecker',tinymce.plugins.SpellcheckerPlugin);})(); \ No newline at end of file diff --git a/program/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js b/program/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js index 196d24640..c913c4603 100644 --- a/program/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js +++ b/program/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js @@ -1,588 +1,338 @@ /** - * $Id: editor_plugin_src.js 28 2006-08-01 16:02:56Z spocke $ + * $Id: editor_plugin_src.js 425 2007-11-21 15:17:39Z spocke $ * * @author Moxiecode - * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved. + * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. */ -tinyMCE.importPluginLanguagePack('spellchecker', 'en,fr,sv,nn,nb'); - -// Plucin static class -var TinyMCE_SpellCheckerPlugin = { - _contextMenu : new TinyMCE_Menu(), - _menu : new TinyMCE_Menu(), - _counter : 0, - _ajaxPage : '/tinyspell.php', - - getInfo : function() { - return { - longname : 'Spellchecker', - author : 'Moxiecode Systems AB', - authorurl : 'http://tinymce.moxiecode.com', - infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_spellchecker.html', - version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion - }; - }, - - 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; - - // Handle click on word - if ((e.type == "click" || e.type == "contextmenu") && elm) { - do { - if (tinyMCE.getAttrib(elm, 'class') == "mceItemHiddenSpellWord") { - inst.spellCheckerElm = elm; - - // Setup arguments - 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; +(function() { + var JSONRequest = tinymce.util.JSONRequest, each = tinymce.each, DOM = tinymce.DOM; + + tinymce.create('tinymce.plugins.SpellcheckerPlugin', { + getInfo : function() { + return { + longname : 'Spellchecker', + author : 'Moxiecode Systems AB', + authorurl : 'http://tinymce.moxiecode.com', + infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker', + version : tinymce.majorVersion + "." + tinymce.minorVersion + }; + }, + + init : function(ed, url) { + var t = this, cm; + + t.url = url; + t.editor = ed; + + // Register commands + ed.addCommand('mceSpellCheck', function() { + if (!t.active) { + ed.setProgressState(1); + t._sendRPC('checkWords', [t.selectedLang, t._getWords()], function(r) { + if (r.length > 0) { + t.active = 1; + t._markWords(r); + ed.setProgressState(0); + ed.nodeChanged(); + } else { + ed.setProgressState(0); + ed.windowManager.alert('spellchecker.no_mpell'); + } + }); + } else + t._done(); + }); + + ed.onInit.add(function() { + if (ed.settings.content_css !== false) + ed.dom.loadCSS(url + '/css/content.css'); + }); + + ed.onClick.add(t._showMenu, t); + ed.onContextMenu.add(t._showMenu, t); + ed.onBeforeGetContent.add(function() { + if (t.active) + t._removeWords(); + }); + + ed.onNodeChange.add(function(ed, cm) { + cm.setActive('spellchecker', t.active); + }); + + ed.onSetContent.add(function() { + t._done(); + }); + + ed.onBeforeGetContent.add(function() { + t._done(); + }); + + ed.onBeforeExecCommand.add(function(ed, cmd) { + if (cmd == 'mceFullScreen') + t._done(); + }); + + // Find selected language + t.languages = {}; + each(ed.getParam('spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv', 'hash'), function(v, k) { + if (k.indexOf('+') === 0) { + k = k.substring(1); + t.selectedLang = v; } - } 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; - }, + t.languages[k] = v; + }); + }, - _getBlockBoxLayer : function(inst) { - if (!inst.spellCheckerBoxL) - inst.spellCheckerBoxL = new TinyMCE_Layer(inst.editorId + '_spellcheckerBlockBox', false); + createControl : function(n, cm) { + var t = this, c, ed = t.editor; - return inst.spellCheckerBoxL; - }, + if (n == 'spellchecker') { + c = cm.createSplitButton(n, {title : 'spellchecker.desc', cmd : 'mceSpellCheck', scope : t}); - _buildSettingsMenu : function(inst, lang) { - var i, ar = tinyMCE.getParam('spellchecker_languages', '+English=en').split(','), p; - var self = TinyMCE_SpellCheckerPlugin, m = self._menu, c; + c.onRenderMenu.add(function(c, m) { + m.add({title : 'spellchecker.langs', 'class' : 'mceMenuItemTitle'}).setDisabled(1); + each(t.languages, function(v, k) { + var o = {icon : 1}, mi; - m.clear(); - m.addTitle(tinyMCE.getLang('lang_spellchecker_langs', '', true)); + o.onclick = function() { + mi.setSelected(1); + t.selectedItem.setSelected(0); + t.selectedItem = mi; + t.selectedLang = v; + }; - 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) { - 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); + // Internal functions - 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'; - }, + _walk : function(n, f) { + var d = this.editor.getDoc(), w; - _onMenuEvent : function(inst, m, n) { - TinyMCE_SpellCheckerPlugin._buildSettingsMenu(inst, inst.spellCheckerLang); - }, + if (d.createTreeWalker) { + w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false); - 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; + while ((n = w.nextNode()) != null) + f.call(this, n); + } else + tinymce.walk(n, f, 'childNodes'); + }, - // Handle commands - switch (command) { - case "mceSpellCheck": - if (!inst.spellcheckerOn) { - inst.spellCheckerBookmark = inst.selection.getBookmark(); + _getSeparators : function() { + var re = '', i, str = this.editor.getParam('spellchecker_word_separator_chars', '\\s!"#$%&()*+,-./:;<=>?@[\]^_{|}§©«®±¶·¸»¼½¾¿×÷¤\u201d\u201c'); - // 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); + // Build word separator regexp + for (i=0; i'; - mb.show(); - mb.moveRelativeTo(co, 'cc'); + _getWords : function() { + var ed = this.editor, wl = [], tx = '', lo = {}; - if (tinyMCE.isMSIE && !tinyMCE.isOpera) { - nl = co.getElementsByTagName('select'); - for (i=0; i?@[\]^_{|}§©«®±¶·¸»¼½¾¿×÷¤\u201d\u201c'); - - for (i=0; i 0) - wl[wl.length] = nl[i]; - } + }); - return wl.join(' '); - }, + se.moveToBookmark(b); + }, - _removeWords : function(doc, word) { - var i, c, nl = doc.getElementsByTagName("span"); - var self = TinyMCE_SpellCheckerPlugin; - var inst = tinyMCE.selectedInstance, b = inst ? inst.selection.getBookmark() : null; + _markWords : function(wl) { + var r1, r2, r3, r4, r5, w = '', ed = this.editor, re = this._getSeparators(), dom = ed.dom, nl = []; + var se = ed.selection, b = se.getBookmark(); - 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]); - } + each(wl, function(v) { + w += (w ? '|' : '') + v; + }); - if (b) - 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; + r1 = new RegExp('([' + re + '])(' + w + ')([' + re + '])', 'g'); + r2 = new RegExp('^(' + w + ')', 'g'); + r3 = new RegExp('(' + w + ')([' + re + ']?)$', 'g'); + r4 = new RegExp('^(' + w + ')([' + re + ']?)$', 'g'); + r5 = new RegExp('(' + w + ')([' + re + '])', 'g'); - for (i=nl.length-1; i>=0; i--) { - c = tinyMCE.getAttrib(nl[i], 'class'); + // Collect all text nodes + this._walk(this.editor.getBody(), function(n) { + if (n.nodeType == 3) { + nl.push(n); + } + }); - if (c == 'mceItemHiddenSpellWord') - w++; - } + // Wrap incorrect words in spans + each(nl, function(n) { + var v; - return w; - }, + if (n.nodeType == 3) { + v = n.nodeValue; - _removeWord : function(e) { - if (e != null) - tinyMCE.setOuterHTML(e, e.innerHTML); - }, + if (r1.test(v) || r2.test(v) || r3.test(v) || r4.test(v)) { + v = dom.encode(v); + v = v.replace(r5, '$1$2'); + v = v.replace(r3, '$1$2'); - _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(); + dom.replace(dom.create('span', {'class' : 'mceItemHidden'}, v), n); + } + } + }); - for (i=0; i 0) - w += wl[i] + ((i == wl.length-1) ? '' : '|'); - } + se.moveToBookmark(b); + }, - for (i=0; i$1$2'); - nv = nv.replace(r3, '$1$2'); + if (!m) { + p1 = DOM.getPos(ed.getContentAreaContainer()); + //p2 = DOM.getPos(ed.getContainer()); - nn = doc.createElement('span'); - nn.className = "mceItemHidden"; - nn.innerHTML = nv; + m = ed.controlManager.createDropMenu('spellcheckermenu', { + offset_x : p1.x, + offset_y : p1.y, + 'class' : 'mceNoIcons' + }); - // Remove old text node - nl[i].parentNode.replaceChild(nn, nl[i]); + t._menu = m; } - } - }, - _buildMenu : function(sg, max) { - var i, self = TinyMCE_SpellCheckerPlugin, cm = self._contextMenu; + if (dom.hasClass(e.target, 'mceItemHiddenSpellWord')) { + m.removeAll(); + m.add({title : 'spellchecker.wait', 'class' : 'mceMenuItemTitle'}).setDisabled(1); + + t._sendRPC('getSuggestions', [t.selectedLang, dom.decode(e.target.innerHTML)], function(r) { + m.removeAll(); + + if (r.length > 0) { + m.add({title : 'spellchecker.sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); + each(r, function(v) { + m.add({title : v, onclick : function() { + dom.replace(ed.getDoc().createTextNode(v), e.target); + t._checkDone(); + }}); + }); + + m.addSeparator(); + } else + m.add({title : 'spellchecker.no_sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); + + m.add({ + title : 'spellchecker.ignore_word', + onclick : function() { + dom.remove(e.target, 1); + t._checkDone(); + } + }); + + m.add({ + title : 'spellchecker.ignore_words', + onclick : function() { + t._removeWords(dom.decode(e.target.innerHTML)); + t._checkDone(); + } + }); + + m.update(); + }); + + ed.selection.select(e.target); + p1 = dom.getPos(e.target); + m.showMenu(p1.x, p1.y + e.target.offsetHeight - vp.y); + + return tinymce.dom.Event.cancel(e); + } else + m.hideMenu(); + }, + + _checkDone : function() { + var t = this, ed = t.editor, dom = ed.dom, o; + + each(dom.select('span'), function(n) { + if (n && dom.hasClass(n, 'mceItemHiddenSpellWord')) { + o = true; + return false; + } + }); - cm.clear(); + if (!o) + t._done(); + }, - if (sg != null) { - cm.addTitle(tinyMCE.getLang('lang_spellchecker_sug', '', true)); + _done : function() { + var t = this, la = t.active; - for (i=0; i'; - die; - } - - // Basic config - $defaultLanguage = $spellCheckerConfig['default.language']; - $defaultMode = $spellCheckerConfig['default.mode']; - - // Normaly not required to configure - $defaultSpelling = $spellCheckerConfig['default.spelling']; - $defaultJargon = $spellCheckerConfig['default.jargon']; - $defaultEncoding = $spellCheckerConfig['default.encoding']; - $outputType = "xml"; // Do not change - - // Get input parameters. - - $check = urldecode($_REQUEST['check']); - $cmd = sanitize($_REQUEST['cmd']); - $lang = sanitize($_REQUEST['lang'], "strict"); - $mode = sanitize($_REQUEST['mode'], "strict"); - $spelling = sanitize($_REQUEST['spelling'], "strict"); - $jargon = sanitize($_REQUEST['jargon'], "strict"); - $encoding = sanitize($_REQUEST['encoding'], "strict"); - $sg = sanitize($_REQUEST['sg'], "bool"); - $words = array(); - - $validRequest = true; - - if (empty($check)) - $validRequest = false; - - if (empty($lang)) - $lang = $defaultLanguage; - - if (empty($mode)) - $mode = $defaultMode; - - if (empty($spelling)) - $spelling = $defaultSpelling; - - if (empty($jargon)) - $jargon = $defaultJargon; - - if (empty($encoding)) - $encoding = $defaultEncoding; - - function sanitize($str, $type="strict") { - switch ($type) { - case "strict": - $str = preg_replace("/[^a-zA-Z0-9_\-]/i", "", $str); - break; - case "loose": - $str = preg_replace("//i", "<", $str); - break; - case "bool": - if ($str == "true" || $str == true) - $str = true; - else - $str = false; - break; - } - - return $str; - } - - $result = array(); - $tinyspell = new $spellCheckerConfig['class']($spellCheckerConfig, $lang, $mode, $spelling, $jargon, $encoding); - - if (count($tinyspell->errorMsg) == 0) { - switch($cmd) { - case "spell": - // Space for non-exec version and \n for the exec version. - $words = preg_split("/ |\n/", $check, -1, PREG_SPLIT_NO_EMPTY); - $result = $tinyspell->checkWords($words); - break; - - case "suggest": - $result = $tinyspell->getSuggestion($check); - break; - - default: - // Just use this for now. - $tinyspell->errorMsg[] = "No command."; - $outputType = $outputType . "error"; - break; - } - } else - $outputType = $outputType . "error"; - - if (!$result) - $result = array(); - - // Output data - switch($outputType) { - case "xml": - header('Content-type: text/xml; charset=utf-8'); - $body = ''; - $body .= "\n"; - - if (count($result) == 0) - $body .= ''; - else - $body .= ''. urlencode(implode(" ", $result)) .''; - - echo $body; - break; - case "xmlerror"; - header('Content-type: text/xml; charset=utf-8'); - $body = ''; - $body .= "\n"; - $body .= 'errorMsg) .'" />'; - echo $body; - break; - case "html": - var_dump($result); - break; - case "htmlerror": - echo "Error"; - break; - } - -?> -- cgit v1.2.3