Mercurial > public > sg101
comparison media/js/tiny_mce/plugins/spellchecker/editor_plugin_src.js @ 217:237710206167
Update TinyMCE to 3.3.6
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 01 Jun 2010 04:49:29 +0000 |
parents | 149c3567fec1 |
children | 6ed2932901fa |
comparison
equal
deleted
inserted
replaced
216:fe900598f81c | 217:237710206167 |
---|---|
25 init : function(ed, url) { | 25 init : function(ed, url) { |
26 var t = this, cm; | 26 var t = this, cm; |
27 | 27 |
28 t.url = url; | 28 t.url = url; |
29 t.editor = ed; | 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 } | |
30 | 45 |
31 // Register commands | 46 // Register commands |
32 ed.addCommand('mceSpellCheck', function() { | 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 | |
33 if (!t.active) { | 54 if (!t.active) { |
34 ed.setProgressState(1); | 55 ed.setProgressState(1); |
35 t._sendRPC('checkWords', [t.selectedLang, t._getWords()], function(r) { | 56 t._sendRPC('checkWords', [t.selectedLang, t._getWords()], function(r) { |
36 if (r.length > 0) { | 57 if (r.length > 0) { |
37 t.active = 1; | 58 t.active = 1; |
38 t._markWords(r); | 59 t._markWords(r); |
39 ed.setProgressState(0); | 60 ed.setProgressState(0); |
40 ed.nodeChanged(); | 61 ed.nodeChanged(); |
41 } else { | 62 } else { |
42 ed.setProgressState(0); | 63 ed.setProgressState(0); |
43 ed.windowManager.alert('spellchecker.no_mpell'); | 64 |
65 if (ed.getParam('spellchecker_report_no_misspellings', true)) | |
66 ed.windowManager.alert('spellchecker.no_mpell'); | |
44 } | 67 } |
45 }); | 68 }); |
46 } else | 69 } else |
47 t._done(); | 70 t._done(); |
48 }); | 71 }); |
90 | 113 |
91 createControl : function(n, cm) { | 114 createControl : function(n, cm) { |
92 var t = this, c, ed = t.editor; | 115 var t = this, c, ed = t.editor; |
93 | 116 |
94 if (n == 'spellchecker') { | 117 if (n == 'spellchecker') { |
118 // Use basic button if we use the native spellchecker | |
119 if (t.rpcUrl == '{backend}') { | |
120 // Create simple toggle button if we have native support | |
121 if (t.hasSupport) | |
122 c = cm.createButton(n, {title : 'spellchecker.desc', cmd : 'mceSpellCheck', scope : t}); | |
123 | |
124 return c; | |
125 } | |
126 | |
95 c = cm.createSplitButton(n, {title : 'spellchecker.desc', cmd : 'mceSpellCheck', scope : t}); | 127 c = cm.createSplitButton(n, {title : 'spellchecker.desc', cmd : 'mceSpellCheck', scope : t}); |
96 | 128 |
97 c.onRenderMenu.add(function(c, m) { | 129 c.onRenderMenu.add(function(c, m) { |
98 m.add({title : 'spellchecker.langs', 'class' : 'mceMenuItemTitle'}).setDisabled(1); | 130 m.add({title : 'spellchecker.langs', 'class' : 'mceMenuItemTitle'}).setDisabled(1); |
99 each(t.languages, function(v, k) { | 131 each(t.languages, function(v, k) { |
142 | 174 |
143 return re; | 175 return re; |
144 }, | 176 }, |
145 | 177 |
146 _getWords : function() { | 178 _getWords : function() { |
147 var ed = this.editor, wl = [], tx = '', lo = {}; | 179 var ed = this.editor, wl = [], tx = '', lo = {}, rawWords = []; |
148 | 180 |
149 // Get area text | 181 // Get area text |
150 this._walk(ed.getBody(), function(n) { | 182 this._walk(ed.getBody(), function(n) { |
151 if (n.nodeType == 3) | 183 if (n.nodeType == 3) |
152 tx += n.nodeValue + ' '; | 184 tx += n.nodeValue + ' '; |
153 }); | 185 }); |
154 | 186 |
155 // Split words by separator | 187 // split the text up into individual words |
156 tx = tx.replace(new RegExp('([0-9]|[' + this._getSeparators() + '])', 'g'), ' '); | 188 if (ed.getParam('spellchecker_word_pattern')) { |
157 tx = tinymce.trim(tx.replace(/(\s+)/g, ' ')); | 189 // look for words that match the pattern |
190 rawWords = tx.match('(' + ed.getParam('spellchecker_word_pattern') + ')', 'gi'); | |
191 } else { | |
192 // Split words by separator | |
193 tx = tx.replace(new RegExp('([0-9]|[' + this._getSeparators() + '])', 'g'), ' '); | |
194 tx = tinymce.trim(tx.replace(/(\s+)/g, ' ')); | |
195 rawWords = tx.split(' '); | |
196 } | |
158 | 197 |
159 // Build word array and remove duplicates | 198 // Build word array and remove duplicates |
160 each(tx.split(' '), function(v) { | 199 each(rawWords, function(v) { |
161 if (!lo[v]) { | 200 if (!lo[v]) { |
162 wl.push(v); | 201 wl.push(v); |
163 lo[v] = 1; | 202 lo[v] = 1; |
164 } | 203 } |
165 }); | 204 }); |
240 if (dom.hasClass(e.target, 'mceItemHiddenSpellWord')) { | 279 if (dom.hasClass(e.target, 'mceItemHiddenSpellWord')) { |
241 m.removeAll(); | 280 m.removeAll(); |
242 m.add({title : 'spellchecker.wait', 'class' : 'mceMenuItemTitle'}).setDisabled(1); | 281 m.add({title : 'spellchecker.wait', 'class' : 'mceMenuItemTitle'}).setDisabled(1); |
243 | 282 |
244 t._sendRPC('getSuggestions', [t.selectedLang, dom.decode(e.target.innerHTML)], function(r) { | 283 t._sendRPC('getSuggestions', [t.selectedLang, dom.decode(e.target.innerHTML)], function(r) { |
284 var ignoreRpc; | |
285 | |
245 m.removeAll(); | 286 m.removeAll(); |
246 | 287 |
247 if (r.length > 0) { | 288 if (r.length > 0) { |
248 m.add({title : 'spellchecker.sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); | 289 m.add({title : 'spellchecker.sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); |
249 each(r, function(v) { | 290 each(r, function(v) { |
255 | 296 |
256 m.addSeparator(); | 297 m.addSeparator(); |
257 } else | 298 } else |
258 m.add({title : 'spellchecker.no_sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); | 299 m.add({title : 'spellchecker.no_sug', 'class' : 'mceMenuItemTitle'}).setDisabled(1); |
259 | 300 |
301 ignoreRpc = t.editor.getParam("spellchecker_enable_ignore_rpc", ''); | |
260 m.add({ | 302 m.add({ |
261 title : 'spellchecker.ignore_word', | 303 title : 'spellchecker.ignore_word', |
262 onclick : function() { | 304 onclick : function() { |
305 var word = e.target.innerHTML; | |
306 | |
263 dom.remove(e.target, 1); | 307 dom.remove(e.target, 1); |
264 t._checkDone(); | 308 t._checkDone(); |
309 | |
310 // tell the server if we need to | |
311 if (ignoreRpc) { | |
312 ed.setProgressState(1); | |
313 t._sendRPC('ignoreWord', [t.selectedLang, word], function(r) { | |
314 ed.setProgressState(0); | |
315 }); | |
316 } | |
265 } | 317 } |
266 }); | 318 }); |
267 | 319 |
268 m.add({ | 320 m.add({ |
269 title : 'spellchecker.ignore_words', | 321 title : 'spellchecker.ignore_words', |
270 onclick : function() { | 322 onclick : function() { |
271 t._removeWords(dom.decode(e.target.innerHTML)); | 323 var word = e.target.innerHTML; |
324 | |
325 t._removeWords(dom.decode(word)); | |
272 t._checkDone(); | 326 t._checkDone(); |
327 | |
328 // tell the server if we need to | |
329 if (ignoreRpc) { | |
330 ed.setProgressState(1); | |
331 t._sendRPC('ignoreWords', [t.selectedLang, word], function(r) { | |
332 ed.setProgressState(0); | |
333 }); | |
334 } | |
273 } | 335 } |
274 }); | 336 }); |
337 | |
338 | |
339 if (t.editor.getParam("spellchecker_enable_learn_rpc")) { | |
340 m.add({ | |
341 title : 'spellchecker.learn_word', | |
342 onclick : function() { | |
343 var word = e.target.innerHTML; | |
344 | |
345 dom.remove(e.target, 1); | |
346 t._checkDone(); | |
347 | |
348 ed.setProgressState(1); | |
349 t._sendRPC('learnWord', [t.selectedLang, word], function(r) { | |
350 ed.setProgressState(0); | |
351 }); | |
352 } | |
353 }); | |
354 } | |
275 | 355 |
276 m.update(); | 356 m.update(); |
277 }); | 357 }); |
278 | 358 |
279 ed.selection.select(e.target); | 359 ed.selection.select(e.target); |
313 t.editor.nodeChanged(); | 393 t.editor.nodeChanged(); |
314 } | 394 } |
315 }, | 395 }, |
316 | 396 |
317 _sendRPC : function(m, p, cb) { | 397 _sendRPC : function(m, p, cb) { |
318 var t = this, url = t.editor.getParam("spellchecker_rpc_url", "{backend}"); | 398 var t = this; |
319 | |
320 if (url == '{backend}') { | |
321 t.editor.setProgressState(0); | |
322 alert('Please specify: spellchecker_rpc_url'); | |
323 return; | |
324 } | |
325 | 399 |
326 JSONRequest.sendRPC({ | 400 JSONRequest.sendRPC({ |
327 url : url, | 401 url : t.rpcUrl, |
328 method : m, | 402 method : m, |
329 params : p, | 403 params : p, |
330 success : cb, | 404 success : cb, |
331 error : function(e, x) { | 405 error : function(e, x) { |
332 t.editor.setProgressState(0); | 406 t.editor.setProgressState(0); |