summaryrefslogtreecommitdiff
blob: b79487c8763201dbc12519f695c9baf12a152c18 (plain)
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){function t(){p=new window.AtDCore,p.map=_,p._isTinyMCE=!0,p.getAttrib=function(e,t){return f.getAttrib(e,t)},p.findSpans=function(e){return void 0===e?f.select("span"):f.select("span",e)},p.hasClass=function(e,t){return f.hasClass(e,t)},p.contents=function(e){return e.childNodes},p.replaceWith=function(e,t){return f.replace(t,e)},p.create=function(e){return f.create("span",{class:"mceItemHidden","data-mce-bogus":1},e)},p.removeParent=function(e){return f.remove(e,!0),e},p.remove=function(e){f.remove(e)},p.setIgnoreStrings(e.getParam("atd_ignore_strings",[]).join(",")),p.showTypes(e.getParam("atd_show_types",""))}function n(e,t){return window.AtD_l10n_r0ar&&window.AtD_l10n_r0ar[e]||t}function o(e){return e.className&&/\bhidden(GrammarError|SpellError|Suggestion)\b/.test(e.className)}function r(t){return p.markMyWords(p.contents(e.getBody()),t)}function i(){e.dom.select("span.hiddenSpellError, span.hiddenGrammarError, span.hiddenSuggestion").length||(m&&m.hideMenu(),s())}function a(t,n,o){var r=e.dom;o?_(e.dom.select("span.hiddenSpellError, span.hiddenGrammarError, span.hiddenSuggestion"),function(e){(e.innerText||e.textContent)===n&&r.remove(e,!0)}):r.remove(t,!0),i()}function s(){for(var t,n=e.dom,o=new RegExp("mceItemHidden|hidden(((Grammar|Spell)Error)|Suggestion)"),r=n.select("span"),i=r.length;i--;)t=r[i],t.className&&o.test(t.className)&&n.remove(t,!0);e.setContent(e.getContent({format:"raw"}),{format:"raw"}),g=!1,e.nodeChanged(),e.fire("SpellcheckEnd")}function c(t,n,o){var r=e.getParam("atd_rpc_id","12345678"),i=e.getParam("atd_rpc_url","{backend}");if("{backend}"===i||"12345678"===r)return void window.alert("Please specify: atd_rpc_url and atd_rpc_id");e.setProgressState(!0),tinymce.util.XHR.send({url:i+"/"+t,content_type:"text/xml",type:"POST",data:"data="+encodeURI(n).replace(/&/g,"%26")+"&key="+r,success:o,error:function(t,n,o){e.setProgressState(),window.alert(t+"\n"+n.status+"\nAt: "+o.url)}})}function d(){}function l(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(){d(t)}}):d(t),p.setIgnoreStrings(t)}function u(t){var r,s,c,d=[],u=t.innerText||t.textContent,g=p.findSuggestion(t);g?(d.push({text:g.description,classes:"atd-menu-title",disabled:!0}),g.suggestions.length&&(d.push({text:"-"}),_(g.suggestions,function(e){d.push({text:e,onclick:function(){p.applySuggestion(t,e),i()}})}))):d.push({text:n("menu_title_no_suggestions","No suggestions"),classes:"atd-menu-title",disabled:!0}),g&&g.moreinfo&&(d.push({text:"-"}),d.push({text:n("menu_option_explain","Explain..."),onclick:function(){e.windowManager.open({title:n("menu_option_explain","Explain..."),url:g.moreinfo,width:480,height:380,inline:!0})}})),d.push.apply(d,[{text:"-"},{text:n("menu_option_ignore_once","Ignore suggestion"),onclick:function(){a(t,u)}}]),e.getParam("atd_ignore_enable")?d.push({text:n("menu_option_ignore_always","Ignore always"),onclick:function(){l(u),a(t,u,!0)}}):d.push({text:n("menu_option_ignore_all","Ignore all"),onclick:function(){a(t,u,!0)}}),m=new tinymce.ui.Menu({items:d,context:"contextmenu",onautohide:function(e){o(e.target)&&e.preventDefault()},onhide:function(){m.remove(),m=null}}),m.renderTo(document.body),r=tinymce.DOM.getPos(e.getContentAreaContainer()),c=e.dom.getPos(t),s=e.dom.getRoot(),"BODY"===s.nodeName?(c.x-=s.ownerDocument.documentElement.scrollLeft||s.scrollLeft,c.y-=s.ownerDocument.documentElement.scrollTop||s.scrollTop):(c.x-=s.scrollLeft,c.y-=s.scrollTop),r.x+=c.x,r.y+=c.y,m.moveTo(r.x,r.y+t.offsetHeight)}var m,g,p,f,_=tinymce.each;e.on("init",function(){void 0!==window.AtDCore&&(f=e.dom,t(),e.addCommand("mceWritingImprovementTool",function(t){var o,i=0;if("function"!=typeof t&&(t=function(){}),void 0!==window.AtD_proofread_click_count&&window.AtD_proofread_click_count++,g)return void s();c("checkDocument",e.getContent({format:"raw"}),function(a,s){return e.setProgressState(),200===s.status&&"html"!==s.responseText.substr(1,4)&&s.responseXML?null!==s.responseXML.getElementsByTagName("message").item(0)?void e.windowManager.alert(s.responseXML.getElementsByTagName("message").item(0).firstChild.data,t(0)):(o=p.processXML(s.responseXML),o.count>0&&(i=r(o.errors)),i?(g=!0,e.fire("SpellcheckStart")):e.windowManager.alert(n("message_no_errors_found","No writing errors were found.")),void t(i)):void e.windowManager.alert(n("message_server_error","There was a problem communicating with the Proofreading service. Try again in one minute."),t(0))})}),!1!==e.settings.content_css&&f.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){o(t.target)&&(t.preventDefault(),e.selection.select(t.target),u(t.target))}))}),e.addMenuItem("spellchecker",{text:n("button_proofread_tooltip","Proofread Writing"),context:"tools",cmd:"mceWritingImprovementTool",onPostRender:function(){var t=this;e.on("SpellcheckStart SpellcheckEnd",function(){t.active(g)})}}),e.addButton("spellchecker",{tooltip:n("button_proofread_tooltip","Proofread Writing"),cmd:"mceWritingImprovementTool",onPostRender:function(){var t=this;e.on("SpellcheckStart SpellcheckEnd",function(){t.active(g)})}}),e.on("remove",function(){m&&(m.remove(),m=null)})});