Changeset 5134 in subversion
- Timestamp:
- Aug 26, 2011 3:32:39 AM (21 months ago)
- Location:
- branches/devel-spellcheck/roundcubemail
- Files:
-
- 7 edited
-
config/main.inc.php.dist (modified) (1 diff)
-
program/include/rcube_spellchecker.php (modified) (15 diffs)
-
program/js/tiny_mce/plugins/spellchecker/editor_plugin.js (modified) (1 diff)
-
program/localization/en_US/labels.inc (modified) (1 diff)
-
program/steps/settings/func.inc (modified) (2 diffs)
-
program/steps/settings/save_prefs.inc (modified) (2 diffs)
-
program/steps/utils/spell_html.inc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/devel-spellcheck/roundcubemail/config/main.inc.php.dist
r5111 r5134 433 433 // Leave empty for default set of available language. 434 434 $rcmail_config['spellcheck_languages'] = NULL; 435 436 // Makes that words with all letters capitalized will be ignored (e.g. GOOGLE) 437 $rcmail_config['spellcheck_ignore_caps'] = false; 438 439 // Makes that words with numbers will be ignored (e.g. g00gle) 440 $rcmail_config['spellcheck_ignore_nums'] = false; 441 442 // Makes that words with symbols will be ignored (e.g. g@@gle) 443 $rcmail_config['spellcheck_ignore_syms'] = false; 435 444 436 445 // don't let users set pagesize to more than this value if set -
branches/devel-spellcheck/roundcubemail/program/include/rcube_spellchecker.php
r4817 r5134 35 35 private $rc; 36 36 private $error; 37 private $separator = '/[ !"#$%&()*+\\,\/\n:;<=>?@\[\]^_{|}-]+|\.[^\w]/'; 38 37 private $separator = '/[\s\r\n\t\(\)\/\[\]{}<>\\"]+|[:;?!,\.]([^\w]|$)/'; 38 private $options = array(); 39 39 40 40 41 // default settings … … 51 52 function __construct($lang = 'en') 52 53 { 53 $this->rc = rcmail::get_instance();54 $this->rc = rcmail::get_instance(); 54 55 $this->engine = $this->rc->config->get('spellcheck_engine', 'googie'); 55 $this->lang = $lang ? $lang : 'en';56 $this->lang = $lang ? $lang : 'en'; 56 57 57 58 if ($this->engine == 'pspell' && !extension_loaded('pspell')) { … … 61 62 'message' => "Pspell extension not available"), true, true); 62 63 } 64 65 $this->options = array( 66 'ignore_syms' => $this->rc->config->get('spellcheck_ignore_syms'), 67 'ignore_nums' => $this->rc->config->get('spellcheck_ignore_nums'), 68 'ignore_caps' => $this->rc->config->get('spellcheck_ignore_caps'), 69 ); 63 70 } 64 71 … … 72 79 * @return bool True when no mispelling found, otherwise false 73 80 */ 74 function check($text, $is_html =false)81 function check($text, $is_html = false) 75 82 { 76 83 // convert to plain text … … 117 124 } 118 125 119 return $this->_googie_suggestions($word); 120 } 121 126 return $this->_googie_suggestions($word); 127 } 128 122 129 123 130 /** … … 180 187 } 181 188 182 return $ out;189 return $result; 183 190 } 184 191 … … 212 219 $text = preg_split($this->separator, $text, NULL, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE); 213 220 214 $diff = 0;215 $matches = array();221 $diff = 0; 222 $matches = array(); 216 223 217 224 foreach ($text as $w) { … … 220 227 $len = mb_strlen($word); 221 228 222 if ($word && preg_match('/[^0-9\.]/', $word) && !pspell_check($this->plink, $word)) { 229 // skip exceptions 230 if ($this->is_exception($word)) { 231 } 232 else if (!pspell_check($this->plink, $word)) { 223 233 $suggestions = pspell_suggest($this->plink, $word); 224 234 … … 241 251 private function _pspell_words($text = null, $is_html=false) 242 252 { 253 $result = array(); 254 243 255 if ($text) { 244 256 // init spellchecker … … 258 270 foreach ($text as $w) { 259 271 $word = trim($w[0]); 260 if ($word && preg_match('/[^0-9\.]/', $word) && !pspell_check($this->plink, $word)) { 272 273 // skip exceptions 274 if ($this->is_exception($word)) { 275 continue; 276 } 277 278 if (!pspell_check($this->plink, $word)) { 261 279 $result[] = $word; 262 280 } … … 265 283 return $result; 266 284 } 267 268 $result = array();269 285 270 286 foreach ($this->matches as $m) { … … 331 347 332 348 // Google has some problem with spaces, use \n instead 333 $ text = str_replace(' ', "\n", $text);334 335 $ text = '<?xml version="1.0" encoding="utf-8" ?>'349 $gtext = str_replace(' ', "\n", $text); 350 351 $gtext = '<?xml version="1.0" encoding="utf-8" ?>' 336 352 .'<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">' 337 .'<text>' . $ text . '</text>'353 .'<text>' . $gtext . '</text>' 338 354 .'</spellrequest>'; 339 355 … … 342 358 $out = "POST $path HTTP/1.0\r\n"; 343 359 $out .= "Host: " . str_replace('ssl://', '', $host) . "\r\n"; 344 $out .= "Content-Length: " . strlen($ text) . "\r\n";360 $out .= "Content-Length: " . strlen($gtext) . "\r\n"; 345 361 $out .= "Content-Type: application/x-www-form-urlencoded\r\n"; 346 362 $out .= "Connection: Close\r\n\r\n"; 347 $out .= $ text;363 $out .= $gtext; 348 364 fwrite($fp, $out); 349 365 … … 358 374 359 375 preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $store, $matches, PREG_SET_ORDER); 376 377 // skip exceptions (if appropriate options are enabled) 378 if (!empty($this->options['ignore_syms']) || !empty($this->options['ignore_nums']) || !empty($this->options['ignore_caps'])) { 379 foreach ($matches as $idx => $m) { 380 $word = mb_substr($text, $m[1], $m[2], RCMAIL_CHARSET); 381 // skip exceptions 382 if ($this->is_exception($word)) { 383 unset($matches[$idx]); 384 } 385 } 386 } 360 387 361 388 return $matches; … … 414 441 return $h2t->get_text(); 415 442 } 443 444 445 /** 446 * Check if the specified word is an exception accoring to 447 * spellcheck options. 448 * 449 * @param string $word The word 450 * 451 * @return bool True if the word is an exception, False otherwise 452 */ 453 public function is_exception($word) 454 { 455 // Contain only symbols (e.g. "+9,0", "2:2") 456 if (!$word || preg_match('/^[0-9@#$%^&_+~*=:;?!,.-]+$/', $word)) 457 return true; 458 459 // Contain symbols (e.g. "g@@gle"), all symbols excluding separators 460 if (!empty($this->options['ignore_syms']) && preg_match('/[@#$%^&_+~*=-]/', $word)) 461 return true; 462 463 // Contain numbers (e.g. "g00g13") 464 if (!empty($this->options['ignore_nums']) && preg_match('/[0-9]/', $word)) 465 return true; 466 467 // Blocked caps (e.g. "GOOGLE") 468 if (!empty($this->options['ignore_caps']) && $word == mb_strtoupper($word)) 469 return true; 470 471 return false; 472 } 416 473 } -
branches/devel-spellcheck/roundcubemail/program/js/tiny_mce/plugins/spellchecker/editor_plugin.js
r4676 r5134 1 (function(){var a=tinymce.util.JSONRequest,c=tinymce.each,b=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(e,f){var g=this,d;g.url=f;g.editor=e;g.rpcUrl=e.getParam("spellchecker_rpc_url","{backend}");if(g.rpcUrl=="{backend}"){if(tinymce.isIE){return}g.hasSupport=true;e.onContextMenu.addToTop(function(h,i){if(g.active){return false}})}e.addCommand("mceSpellCheck",function(){if(g.rpcUrl=="{backend}"){g.editor.getBody().spellcheck=g.active=!g.active;return}if(!g.active){e.setProgressState(1);g._sendRPC("checkWords",[g.selectedLang,g._getWords()],function(h){if(h.length>0){g.active=1;g._markWords(h);e.setProgressState(0);e.nodeChanged()}else{e.setProgressState(0);if(e.getParam("spellchecker_report_no_misspellings",true)){e.windowManager.alert("spellchecker.no_mpell")}}})}else{g._done()}});if(e.settings.content_css!==false){e.contentCSS.push(f+"/css/content.css")}e.onClick.add(g._showMenu,g);e.onContextMenu.add(g._showMenu,g);e.onBeforeGetContent.add(function(){if(g.active){g._removeWords()}});e.onNodeChange.add(function(i,h){h.setActive("spellchecker",g.active)});e.onSetContent.add(function(){g._done()});e.onBeforeGetContent.add(function(){g._done()});e.onBeforeExecCommand.add(function(h,i){if(i=="mceFullScreen"){g._done()}});g.languages={};c(e.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(i,h){if(h.indexOf("+")===0){h=h.substring(1);g.selectedLang=i}g.languages[h]=i})},createControl:function(h,d){var f=this,g,e=f.editor;if(h=="spellchecker"){if(f.rpcUrl=="{backend}"){if(f.hasSupport){g=d.createButton(h,{title:"spellchecker.desc",cmd:"mceSpellCheck",scope:f})}return g}g=d.createSplitButton(h,{title:"spellchecker.desc",cmd:"mceSpellCheck",scope:f});g.onRenderMenu.add(function(j,i){i.add({title:"spellchecker.langs","class":"mceMenuItemTitle"}).setDisabled(1);c(f.languages,function(n,m){var p={icon:1},l;p.onclick=function(){if(n==f.selectedLang){return}l.setSelected(1);f.selectedItem.setSelected(0);f.selectedItem=l;f.selectedLang=n};p.title=m;l=i.add(p);l.setSelected(n==f.selectedLang);if(n==f.selectedLang){f.selectedItem=l}})});return g}},_walk:function(i,g){var h=this.editor.getDoc(),e;if(h.createTreeWalker){e=h.createTreeWalker(i,NodeFilter.SHOW_TEXT,null,false);while((i=e.nextNode())!=null){g.call(this,i)}}else{tinymce.walk(i,g,"childNodes")}},_getSeparators:function(){var e="",d,f=this.editor.getParam("spellchecker_word_separator_chars",'\\s!"#$%&()*+,-./:;<=>?@[]^_{|}§©«®±¶·ž»ŒœŸ¿×÷€\u201d\u201c');for(d=0;d<f.length;d++){e+="\\"+f.charAt(d)}return e},_getWords:function(){var e=this.editor,g=[],d="",f={},h=[];this._walk(e.getBody(),function(i){if(i.nodeType==3){d+=i.nodeValue+" "}});if(e.getParam("spellchecker_word_pattern")){h=d.match("("+e.getParam("spellchecker_word_pattern")+")","gi")}else{d=d.replace(new RegExp("([0-9]|["+this._getSeparators()+"])","g")," ");d=tinymce.trim(d.replace(/(\s+)/g," "));h=d.split(" ")}c(h,function(i){if(!f[i]){g.push(i);f[i]=1}});return g},_removeWords:function(e){var f=this.editor,h=f.dom,g=f.selection,d=g.getBookmark();c(h.select("span").reverse(),function(i){if(i&&(h.hasClass(i,"mceItemHiddenSpellWord")||h.hasClass(i,"mceItemHidden"))){if(!e||h.decode(i.innerHTML)==e){h.remove(i,1)}}});g.moveToBookmark(d)},_markWords:function(l){var g=this.editor,f=g.dom,j=g.getDoc(),h=g.selection,i=h.getBookmark(),d=[],k=l.join("|"),m=this._getSeparators(),e=new RegExp("(^|["+m+"])("+k+")(?=["+m+"]|$)","g");this._walk(g.getBody(),function(o){if(o.nodeType==3){d.push(o)}});c(d,function(t){var r,q,o,s,p=t.nodeValue;if(e.test(p)){p=f.encode(p);q=f.create("span",{"class":"mceItemHidden"});if(tinymce.isIE){p=p.replace(e,"$1<mcespell>$2</mcespell>");while((s=p.indexOf("<mcespell>"))!=-1){o=p.substring(0,s);if(o.length){r=j.createTextNode(f.decode(o));q.appendChild(r)}p=p.substring(s+10);s=p.indexOf("</mcespell>");o=p.substring(0,s);p=p.substring(s+11);q.appendChild(f.create("span",{"class":"mceItemHiddenSpellWord"},o))}if(p.length){r=j.createTextNode(f.decode(p));q.appendChild(r)}}else{q.innerHTML=p.replace(e,'$1<span class="mceItemHiddenSpellWord">$2</span>')}f.replace(q,t)}});h.moveToBookmark(i)},_showMenu:function(h,j){var i=this,h=i.editor,d=i._menu,l,k=h.dom,g=k.getViewPort(h.getWin()),f=j.target;j=0;if(!d){d=h.controlManager.createDropMenu("spellcheckermenu",{"class":"mceNoIcons"});i._menu=d}if(k.hasClass(f,"mceItemHiddenSpellWord")){d.removeAll();d.add({title:"spellchecker.wait","class":"mceMenuItemTitle"}).setDisabled(1);i._sendRPC("getSuggestions",[i.selectedLang,k.decode(f.innerHTML)],function(m){var e;d.removeAll();if(m.length>0){d.add({title:"spellchecker.sug","class":"mceMenuItemTitle"}).setDisabled(1);c(m,function(n){d.add({title:n,onclick:function(){k.replace(h.getDoc().createTextNode(n),f);i._checkDone()}})});d.addSeparator()}else{d.add({title:"spellchecker.no_sug","class":"mceMenuItemTitle"}).setDisabled(1)}e=i.editor.getParam("spellchecker_enable_ignore_rpc","");d.add({title:"spellchecker.ignore_word",onclick:function(){var n=f.innerHTML;k.remove(f,1);i._checkDone();if(e){h.setProgressState(1);i._sendRPC("ignoreWord",[i.selectedLang,n],function(o){h.setProgressState(0)})}}});d.add({title:"spellchecker.ignore_words",onclick:function(){var n=f.innerHTML;i._removeWords(k.decode(n));i._checkDone();if(e){h.setProgressState(1);i._sendRPC("ignoreWords",[i.selectedLang,n],function(o){h.setProgressState(0)})}}});if(i.editor.getParam("spellchecker_enable_learn_rpc")){d.add({title:"spellchecker.learn_word",onclick:function(){var n=f.innerHTML;k.remove(f,1);i._checkDone();h.setProgressState(1);i._sendRPC("learnWord",[i.selectedLang,n],function(o){h.setProgressState(0)})}})}d.update()});l=k.getPos(h.getContentAreaContainer());d.settings.offset_x=l.x;d.settings.offset_y=l.y;h.selection.select(f);l=k.getPos(f);d.showMenu(l.x,l.y+f.offsetHeight-g.y);return tinymce.dom.Event.cancel(j)}else{d.hideMenu()}},_checkDone:function(){var e=this,d=e.editor,g=d.dom,f;c(g.select("span"),function(h){if(h&&g.hasClass(h,"mceItemHiddenSpellWord")){f=true;return false}});if(!f){e._done()}},_done:function(){var d=this,e=d.active;if(d.active){d.active=0;d._removeWords();if(d._menu){d._menu.hideMenu()}if(e){d.editor.nodeChanged()}}},_sendRPC:function(e,g,d){var f=this;a.sendRPC({url:f.rpcUrl,method:e,params:g,success:d,error:function(i,h){f.editor.setProgressState(0);f.editor.windowManager.alert(i.errstr||("Error response: "+h.responseText))}})}});tinymce.PluginManager.add("spellchecker",tinymce.plugins.SpellcheckerPlugin)})(); 1 /** 2 * editor_plugin_src.js 3 * 4 * Copyright 2009, Moxiecode Systems AB 5 * Released under LGPL License. 6 * 7 * License: http://tinymce.moxiecode.com/license 8 * Contributing: http://tinymce.moxiecode.com/contributing 9 */ 10 11 (function() { 12 var JSONRequest = tinymce.util.JSONRequest, each = tinymce.each, DOM = tinymce.DOM; 13 14 tinymce.create('tinymce.plugins.SpellcheckerPlugin', { 15 getInfo : function() { 16 return { 17 longname : 'Spellchecker', 18 author : 'Moxiecode Systems AB', 19 authorurl : 'http://tinymce.moxiecode.com', 20 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker', 21 version : tinymce.majorVersion + "." + tinymce.minorVersion 22 }; 23 }, 24 25 init : function(ed, url) { 26 var t = this, cm; 27 28 t.url = url; 29 t.editor = ed; 30 t.rpcUrl = ed.getParam("spellchecker_rpc_url", "{backend}"); 31 32 if (t.rpcUrl == '{backend}') { 33 // Sniff if the browser supports native spellchecking (Don't know of a better way) 34 if (tinymce.isIE) 35 return; 36 37 t.hasSupport = true; 38 39 // Disable the context menu when spellchecking is active 40 ed.onContextMenu.addToTop(function(ed, e) { 41 if (t.active) 42 return false; 43 }); 44 } 45 46 // Register commands 47 ed.addCommand('mceSpellCheck', function() { 48 if (t.rpcUrl == '{backend}') { 49 // Enable/disable native spellchecker 50 t.editor.getBody().spellcheck = t.active = !t.active; 51 return; 52 } 53 54 if (!t.active) { 55 ed.setProgressState(1); 56 t._sendRPC('checkWords', [t.selectedLang, t._getWords()], function(r) { 57 if (r.length > 0) { 58 t.active = 1; 59 t._markWords(r); 60 ed.setProgressState(0); 61 ed.nodeChanged(); 62 } else { 63 ed.setProgressState(0); 64 65 if (ed.getParam('spellchecker_report_no_misspellings', true)) 66 ed.windowManager.alert('spellchecker.no_mpell'); 67 } 68 }); 69 } else 70 t._done(); 71 }); 72 73 if (ed.settings.content_css !== false) 74 ed.contentCSS.push(url + '/css/content.css'); 75 76 ed.onClick.add(t._showMenu, t); 77 ed.onContextMenu.add(t._showMenu, t); 78 ed.onBeforeGetContent.add(function() { 79 if (t.active) 80 t._removeWords(); 81 }); 82 83 ed.onNodeChange.add(function(ed, cm) { 84 cm.setActive('spellchecker', t.active); 85 }); 86 87 ed.onSetContent.add(function() { 88 t._done(); 89 }); 90 91 ed.onBeforeGetContent.add(function() { 92 t._done(); 93 }); 94 95 ed.onBeforeExecCommand.add(function(ed, cmd) { 96 if (cmd == 'mceFullScreen') 97 t._done(); 98 }); 99 100 // Find selected language 101 t.languages = {}; 102 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) { 103 if (k.indexOf('+') === 0) { 104 k = k.substring(1); 105 t.selectedLang = v; 106 } 107 108 t.languages[k] = v; 109 }); 110 }, 111 112 createControl : function(n, cm) { 113 var t = this, c, ed = t.editor; 114 115 if (n == 'spellchecker') { 116 // Use basic button if we use the native spellchecker 117 if (t.rpcUrl == '{backend}') { 118 // Create simple toggle button if we have native support 119 if (t.hasSupport) 120 c = cm.createButton(n, {title : 'spellchecker.desc', cmd : 'mceSpellCheck', scope : t}); 121 122 return c; 123 } 124 125 c = cm.createSplitButton(n, {title : 'spellchecker.desc', cmd : 'mceSpellCheck', scope : t}); 126 127 c.onRenderMenu.add(function(c, m) { 128 m.add({title : 'spellchecker.langs', 'class' : 'mceMenuItemTitle'}).setDisabled(1); 129 each(t.languages, function(v, k) { 130 var o = {icon : 1}, mi; 131 132 o.onclick = function() { 133 if (v == t.selectedLang) { 134 return; 135 } 136 mi.setSelected(1); 137 t.selectedItem.setSelected(0); 138 t.selectedItem = mi; 139 t.selectedLang = v; 140 }; 141 142 o.title = k; 143 mi = m.add(o); 144 mi.setSelected(v == t.selectedLang); 145 146 if (v == t.selectedLang) 147 t.selectedItem = mi; 148 }) 149 }); 150 151 return c; 152 } 153 }, 154 155 // Internal functions 156 157 _walk : function(n, f) { 158 var d = this.editor.getDoc(), w; 159 160 if (d.createTreeWalker) { 161 w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false); 162 163 while ((n = w.nextNode()) != null) 164 f.call(this, n); 165 } else 166 tinymce.walk(n, f, 'childNodes'); 167 }, 168 169 _getSeparators : function() { 170 var re = '', i, str = this.editor.getParam('spellchecker_word_separator_chars', '\\s!"#$%&()*+,-./:;<=>?@[\]^_{|}§©«®±¶·ž»ŒœŸ¿×÷€\u201d\u201c'); 171 172 // Build word separator regexp 173 for (i=0; i<str.length; i++) 174 re += '\\' + str.charAt(i); 175 176 return re; 177 }, 178 179 _getWords : function() { 180 var ed = this.editor, wl = [], tx = '', lo = {}, rawWords = []; 181 182 // Get area text 183 this._walk(ed.getBody(), function(n) { 184 if (n.nodeType == 3) 185 tx += n.nodeValue + ' '; 186 }); 187 188 // split the text up into individual words 189 if (ed.getParam('spellchecker_word_pattern')) { 190 // look for words that match the pattern 191 rawWords = tx.match('(' + ed.getParam('spellchecker_word_pattern') + ')', 'gi'); 192 } else { 193 // Split words by separator 194 tx = tx.replace(new RegExp('([0-9]|[' + this._getSeparators() + '])', 'g'), ' '); 195 tx = tinymce.trim(tx.replace(/(\s+)/g, ' ')); 196 rawWords = tx.split(' '); 197 } 198 199 // Build word array and remove duplicates 200 each(rawWords, function(v) { 201 if (!lo[v]) { 202 wl.push(v); 203 lo[v] = 1; 204 } 205 }); 206 207 return wl; 208 }, 209 210 _removeWords : function(w) { 211 var ed = this.editor, dom = ed.dom, se = ed.selection, b = se.getBookmark(); 212 213 each(dom.select('span').reverse(), function(n) { 214 if (n && (dom.hasClass(n, 'mceItemHiddenSpellWord') || dom.hasClass(n, 'mceItemHidden'))) { 215 if (!w || dom.decode(n.innerHTML) == w) 216 dom.remove(n, 1); 217 } 218 }); 219 220 se.moveToBookmark(b); 221 }, 222 223 _markWords : function(wl) { 224 var ed = this.editor, dom = ed.dom, doc = ed.getDoc(), se = ed.selection, b = se.getBookmark(), nl = [], 225 w = wl.join('|'), re = this._getSeparators(), rx = new RegExp('(^|[' + re + '])(' + w + ')(?=[' + re + ']|$)', 'g'); 226 227 // Collect all text nodes 228 this._walk(ed.getBody(), function(n) { 229 if (n.nodeType == 3) { 230 nl.push(n); 231 } 232 }); 233 234 // Wrap incorrect words in spans 235 each(nl, function(n) { 236 var node, elem, txt, pos, v = n.nodeValue; 237 238 if (rx.test(v)) { 239 // Encode the content 240 v = dom.encode(v); 241 // Create container element 242 elem = dom.create('span', {'class' : 'mceItemHidden'}); 243 244 // Following code fixes IE issues by creating text nodes 245 // using DOM methods instead of innerHTML. 246 // Bug #3124: <PRE> elements content is broken after spellchecking. 247 // Bug #1408: Preceding whitespace characters are removed 248 // @TODO: I'm not sure that both are still issues on IE9. 249 if (tinymce.isIE) { 250 // Enclose mispelled words with temporal tag 251 v = v.replace(rx, '$1<mcespell>$2</mcespell>'); 252 // Loop over the content finding mispelled words 253 while ((pos = v.indexOf('<mcespell>')) != -1) { 254 // Add text node for the content before the word 255 txt = v.substring(0, pos); 256 if (txt.length) { 257 node = doc.createTextNode(dom.decode(txt)); 258 elem.appendChild(node); 259 } 260 v = v.substring(pos+10); 261 pos = v.indexOf('</mcespell>'); 262 txt = v.substring(0, pos); 263 v = v.substring(pos+11); 264 // Add span element for the word 265 elem.appendChild(dom.create('span', {'class' : 'mceItemHiddenSpellWord'}, txt)); 266 } 267 // Add text node for the rest of the content 268 if (v.length) { 269 node = doc.createTextNode(dom.decode(v)); 270 elem.appendChild(node); 271 } 272 } else { 273 // Other browsers preserve whitespace characters on innerHTML usage 274 elem.innerHTML = v.replace(rx, '$1<span class="mceItemHiddenSpellWord">$2</span>'); 275 } 276 277 // Finally, replace the node with the container 278 dom.replace(elem, n); 279 } 280 }); 281 282 se.moveToBookmark(b); 283 }, 284 285 _showMenu : function(ed, e) { 286 var t = this, ed = t.editor, m = t._menu, p1, dom = ed.dom, vp = dom.getViewPort(ed.getWin()), wordSpan = e.target; 287 288 e = 0; // Fixes IE memory leak 289 290 if (!m) { 291 m = ed.controlManager.createDropMenu('spellcheckermenu', {'class' : 'mceNoIcons'}); 292 t._menu = m; 293 } 294 295 if (dom.hasClass(wordSpan, 'mceItemHiddenSpellWord')) { 296 m.removeAll(); 297 m.add({title : 'spellchecker.wait', 'class' : 'mceMenuItemTitle'}).setDisabled(1); 298 299 t._sendRPC('getSuggestions', [t.selectedLang, dom.decode(wordSpan.innerHTML)], function(r) { 300 var ignoreRpc; 301 302 m.removeAll(); 303 304 if (r.length > 0) { 305 m.add({title : 'spellchecker.sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); 306 each(r, function(v) { 307 m.add({title : v, onclick : function() { 308 dom.replace(ed.getDoc().createTextNode(v), wordSpan); 309 t._checkDone(); 310 }}); 311 }); 312 313 m.addSeparator(); 314 } else 315 m.add({title : 'spellchecker.no_sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); 316 317 ignoreRpc = t.editor.getParam("spellchecker_enable_ignore_rpc", ''); 318 m.add({ 319 title : 'spellchecker.ignore_word', 320 onclick : function() { 321 var word = wordSpan.innerHTML; 322 323 dom.remove(wordSpan, 1); 324 t._checkDone(); 325 326 // tell the server if we need to 327 if (ignoreRpc) { 328 ed.setProgressState(1); 329 t._sendRPC('ignoreWord', [t.selectedLang, word], function(r) { 330 ed.setProgressState(0); 331 }); 332 } 333 } 334 }); 335 336 m.add({ 337 title : 'spellchecker.ignore_words', 338 onclick : function() { 339 var word = wordSpan.innerHTML; 340 341 t._removeWords(dom.decode(word)); 342 t._checkDone(); 343 344 // tell the server if we need to 345 if (ignoreRpc) { 346 ed.setProgressState(1); 347 t._sendRPC('ignoreWords', [t.selectedLang, word], function(r) { 348 ed.setProgressState(0); 349 }); 350 } 351 } 352 }); 353 354 355 if (t.editor.getParam("spellchecker_enable_learn_rpc")) { 356 m.add({ 357 title : 'spellchecker.learn_word', 358 onclick : function() { 359 var word = wordSpan.innerHTML; 360 361 dom.remove(wordSpan, 1); 362 t._checkDone(); 363 364 ed.setProgressState(1); 365 t._sendRPC('learnWord', [t.selectedLang, word], function(r) { 366 ed.setProgressState(0); 367 }); 368 } 369 }); 370 } 371 372 m.update(); 373 }); 374 375 p1 = dom.getPos(ed.getContentAreaContainer()); 376 m.settings.offset_x = p1.x; 377 m.settings.offset_y = p1.y; 378 379 ed.selection.select(wordSpan); 380 p1 = dom.getPos(wordSpan); 381 m.showMenu(p1.x, p1.y + wordSpan.offsetHeight - vp.y); 382 383 return tinymce.dom.Event.cancel(e); 384 } else 385 m.hideMenu(); 386 }, 387 388 _checkDone : function() { 389 var t = this, ed = t.editor, dom = ed.dom, o; 390 391 each(dom.select('span'), function(n) { 392 if (n && dom.hasClass(n, 'mceItemHiddenSpellWord')) { 393 o = true; 394 return false; 395 } 396 }); 397 398 if (!o) 399 t._done(); 400 }, 401 402 _done : function() { 403 var t = this, la = t.active; 404 405 if (t.active) { 406 t.active = 0; 407 t._removeWords(); 408 409 if (t._menu) 410 t._menu.hideMenu(); 411 412 if (la) 413 t.editor.nodeChanged(); 414 } 415 }, 416 417 _sendRPC : function(m, p, cb) { 418 var t = this; 419 420 JSONRequest.sendRPC({ 421 url : t.rpcUrl, 422 method : m, 423 params : p, 424 success : cb, 425 error : function(e, x) { 426 t.editor.setProgressState(0); 427 t.editor.windowManager.alert(e.errstr || ('Error response: ' + x.responseText)); 428 } 429 }); 430 } 431 }); 432 433 // Register plugin 434 tinymce.PluginManager.add('spellchecker', tinymce.plugins.SpellcheckerPlugin); 435 })(); -
branches/devel-spellcheck/roundcubemail/program/localization/en_US/labels.inc
r5040 r5134 425 425 $labels['defaultaddressbook'] = 'Add new contacts to the selected addressbook'; 426 426 $labels['spellcheckbeforesend'] = 'Check spelling before sending a message'; 427 $labels['spellcheckoptions'] = 'Spellcheck Options'; 428 $labels['spellcheckignoresyms'] = 'Ignore words with symbols'; 429 $labels['spellcheckignorenums'] = 'Ignore words with numbers'; 430 $labels['spellcheckignorecaps'] = 'Ignore words with all letters capitalized'; 427 431 428 432 $labels['folder'] = 'Folder'; -
branches/devel-spellcheck/roundcubemail/program/steps/settings/func.inc
r4875 r5134 449 449 450 450 $blocks = array( 451 'main' => array('name' => Q(rcube_label('mainoptions'))), 452 'sig' => array('name' => Q(rcube_label('signatureoptions'))), 451 'main' => array('name' => Q(rcube_label('mainoptions'))), 452 'spellcheck' => array('name' => Q(rcube_label('spellcheckoptions'))), 453 'sig' => array('name' => Q(rcube_label('signatureoptions'))), 453 454 ); 454 455 … … 550 551 $input_spellcheck = new html_checkbox(array('name' => '_spellcheck_before_send', 'id' => $field_id, 'value' => 1)); 551 552 552 $blocks[' main']['options']['spellcheck_before_send'] = array(553 $blocks['spellcheck']['options']['spellcheck_before_send'] = array( 553 554 'title' => html::label($field_id, Q(rcube_label('spellcheckbeforesend'))), 554 555 'content' => $input_spellcheck->show($config['spellcheck_before_send']?1:0), 555 556 ); 557 } 558 559 if ($config['enable_spellcheck']) { 560 foreach (array('syms', 'nums', 'caps') as $key) { 561 $key = 'spellcheck_ignore_'.$key; 562 if (!isset($no_override[$key])) { 563 $input_spellcheck = new html_checkbox(array('name' => '_'.$key, 'id' => 'rcmfd_'.$key, 'value' => 1)); 564 565 $blocks['spellcheck']['options'][$key] = array( 566 'title' => html::label($field_id, Q(rcube_label(str_replace('_', '', $key)))), 567 'content' => $input_spellcheck->show($config[$key]?1:0), 568 ); 569 } 570 } 556 571 } 557 572 -
branches/devel-spellcheck/roundcubemail/program/steps/settings/save_prefs.inc
r5132 r5134 72 72 'reply_same_folder' => isset($_POST['_reply_same_folder']) ? TRUE : FALSE, 73 73 'spellcheck_before_send' => isset($_POST['_spellcheck_before_send']) ? TRUE : FALSE, 74 'spellcheck_ignore_syms' => isset($_POST['_spellcheck_ignore_syms']) ? TRUE : FALSE, 75 'spellcheck_ignore_nums' => isset($_POST['_spellcheck_ignore_nums']) ? TRUE : FALSE, 76 'spellcheck_ignore_caps' => isset($_POST['_spellcheck_ignore_caps']) ? TRUE : FALSE, 74 77 'show_sig' => isset($_POST['_show_sig']) ? intval($_POST['_show_sig']) : 1, 75 78 'top_posting' => !empty($_POST['_top_posting']), … … 168 171 } 169 172 } 170 173 171 174 break; 172 175 } -
branches/devel-spellcheck/roundcubemail/program/steps/utils/spell_html.inc
r4815 r5134 41 41 $result['result'] = $spellchecker->get_suggestions($data); 42 42 } 43 43 console($result); 44 44 if ($error = $spellchecker->error()) { 45 45 echo '{"error":{"errstr":"' . addslashes($error) . '","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}';
Note: See TracChangeset
for help on using the changeset viewer.
