1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
/* Do not modify this file directly. It is compiled from other files. */
/* global tinymce */
/*
* TinyMCE Writing Improvement Tool Plugin
* Author: Raphael Mudge (raffi@automattic.com)
*
* Updated for TinyMCE 4.0
*
* http://www.afterthedeadline.com
*
* Distributed under the LGPL
*
* Derived from:
* $Id: editor_plugin_src.js 425 2007-11-21 15:17:39Z spocke $
*
* @author Moxiecode
* @copyright Copyright (C) 2004-2008, Moxiecode Systems AB, All rights reserved.
*
* Moxiecode Spell Checker plugin released under the LGPL with TinyMCE
*/
tinymce.PluginManager.add("AtD",function(e){var t,n,o,r,i=tinymce.each;function a(e,t){return window.AtD_l10n_r0ar&&window.AtD_l10n_r0ar[e]||t}function s(e){return e.className&&/\bhidden(GrammarError|SpellError|Suggestion)\b/.test(e.className)}function c(){e.dom.select("span.hiddenSpellError, span.hiddenGrammarError, span.hiddenSuggestion").length||(t&&t.hide(),d())}function l(t,n,o){var r=e.dom;o?i(e.dom.select("span.hiddenSpellError, span.hiddenGrammarError, span.hiddenSuggestion"),function(e){(e.innerText||e.textContent)===n&&r.remove(e,!0)}):r.remove(t,!0),c()}function d(){for(var t,o=e.dom,r=new RegExp("mceItemHidden|hidden(((Grammar|Spell)Error)|Suggestion)"),i=o.select("span"),a=i.length;a--;)(t=i[a]).className&&r.test(t.className)&&o.remove(t,!0);e.setContent(e.getContent({format:"raw"}),{format:"raw"}),n=!1,e.nodeChanged(),e.fire("SpellcheckEnd")}function u(n){var r,d,u,m=[],g=n.innerText||n.textContent,p=o.findSuggestion(n);p?(m.push({text:p.description,classes:"atd-menu-title",disabled:!0}),p.suggestions.length&&(m.push({text:"-"}),i(p.suggestions,function(e){m.push({text:e,onclick:function(){o.applySuggestion(n,e),c()}})}))):m.push({text:a("menu_title_no_suggestions","No suggestions"),classes:"atd-menu-title",disabled:!0}),p&&p.moreinfo&&(m.push({text:"-"}),m.push({text:a("menu_option_explain","Explain..."),onclick:function(){e.windowManager.open({title:a("menu_option_explain","Explain..."),url:p.moreinfo,width:480,height:380,inline:!0})}})),m.push.apply(m,[{text:"-"},{text:a("menu_option_ignore_once","Ignore suggestion"),onclick:function(){l(n,g)}}]),e.getParam("atd_ignore_enable")?m.push({text:a("menu_option_ignore_always","Ignore always"),onclick:function(){!function(t){var n=e.getParam("atd_ignore_rpc_url");n&&"{backend}"!==n&&tinymce.util.XHR.send({url:n+encodeURIComponent(t)+"&key="+e.getParam("atd_rpc_id","12345678"),content_type:"text/xml",type:"GET",error:function(){}}),o.setIgnoreStrings(t)}(g),l(n,g,!0)}}):m.push({text:a("menu_option_ignore_all","Ignore all"),onclick:function(){l(n,g,!0)}}),(t=new tinymce.ui.Menu({items:m,context:"contextmenu",onautohide:function(e){s(e.target)&&e.preventDefault()},onhide:function(){t.remove(),t=null}})).renderTo(document.body),r=tinymce.DOM.getPos(e.getContentAreaContainer()),u=e.dom.getPos(n),"BODY"===(d=e.dom.getRoot()).nodeName?(u.x-=d.ownerDocument.documentElement.scrollLeft||d.scrollLeft,u.y-=d.ownerDocument.documentElement.scrollTop||d.scrollTop):(u.x-=d.scrollLeft,u.y-=d.scrollTop),r.x+=u.x,r.y+=u.y,t.moveTo(r.x,r.y+n.offsetHeight)}e.on("init",function(){void 0!==window.AtDCore&&(r=e.dom,(o=new window.AtDCore).map=i,o._isTinyMCE=!0,o.getAttrib=function(e,t){return r.getAttrib(e,t)},o.findSpans=function(e){return void 0===e?r.select("span"):r.select("span",e)},o.hasClass=function(e,t){return r.hasClass(e,t)},o.contents=function(e){return e.childNodes},o.replaceWith=function(e,t){return r.replace(t,e)},o.create=function(e){return r.create("span",{class:"mceItemHidden","data-mce-bogus":1},e)},o.removeParent=function(e){return r.remove(e,!0),e},o.remove=function(e){r.remove(e)},o.setIgnoreStrings(e.getParam("atd_ignore_strings",[]).join(",")),o.showTypes(e.getParam("atd_show_types","")),e.addCommand("mceWritingImprovementTool",function(t){var r,i,s,c,l,u,m=0;("function"!=typeof t&&(t=function(){}),void 0!==window.AtD_proofread_click_count&&window.AtD_proofread_click_count++,n)?d():(i="checkDocument",s=e.getContent({format:"raw"}),c=function(i,s){var c;e.setProgressState(),200===s.status&&"html"!==s.responseText.substr(1,4)&&s.responseXML?null===s.responseXML.getElementsByTagName("message").item(0)?((r=o.processXML(s.responseXML)).count>0&&(c=r.errors,m=o.markMyWords(o.contents(e.getBody()),c)),m?(n=!0,e.fire("SpellcheckStart")):e.windowManager.alert(a("message_no_errors_found","No writing errors were found.")),t(m)):e.windowManager.alert(s.responseXML.getElementsByTagName("message").item(0).firstChild.data,t(0)):e.windowManager.alert(a("message_server_error","There was a problem communicating with the Proofreading service. Try again in one minute."),t(0))},l=e.getParam("atd_rpc_id","12345678"),"{backend}"!==(u=e.getParam("atd_rpc_url","{backend}"))&&"12345678"!==l?(e.setProgressState(!0),tinymce.util.XHR.send({url:u+"/"+i,content_type:"text/xml",type:"POST",data:"data="+encodeURI(s).replace(/&/g,"%26")+"&key="+l,success:c,error:function(t,n,o){e.setProgressState(),window.alert(t+"\n"+n.status+"\nAt: "+o.url)}})):window.alert("Please specify: atd_rpc_url and atd_rpc_id"))}),!1!==e.settings.content_css&&r.addStyle(".hiddenSpellError{border-bottom:2px solid red;cursor:default;}.hiddenGrammarError{border-bottom:2px solid green;cursor:default;}.hiddenSuggestion{border-bottom:2px solid blue;cursor:default;}"),tinymce.DOM.addStyle("div.mce-floatpanel{z-index:150100 !important;}"),e.on("click",function(t){s(t.target)&&(t.preventDefault(),e.selection.select(t.target),u(t.target))}))}),e.addMenuItem("spellchecker",{text:a("button_proofread_tooltip","Proofread Writing"),context:"tools",cmd:"mceWritingImprovementTool",onPostRender:function(){var t=this;e.on("SpellcheckStart SpellcheckEnd",function(){t.active(n)})}}),e.addButton("spellchecker",{tooltip:a("button_proofread_tooltip","Proofread Writing"),cmd:"mceWritingImprovementTool",onPostRender:function(){var t=this;e.on("SpellcheckStart SpellcheckEnd",function(){t.active(n)})}}),e.on("remove",function(){t&&(t.remove(),t=null)})});
|