wsc.js 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. (function() {
  6. // Create support tools
  7. var appTools = (function(){
  8. var inited = {};
  9. var _init = function(handler) {
  10. if (window.addEventListener) {
  11. window.addEventListener('message', handler, false);
  12. } else {
  13. window.attachEvent("onmessage", handler);
  14. }
  15. };
  16. var unbindHandler = function(handler) {
  17. if (window.removeEventListener) {
  18. window.removeEventListener('message', handler, false);
  19. } else {
  20. window.detachEvent('onmessage', handler);
  21. }
  22. };
  23. var _sendCmd = function(o) {
  24. var str,
  25. type = Object.prototype.toString,
  26. objObject = "[object Object]",
  27. fn = o.fn || null,
  28. id = o.id || '',
  29. target = o.target || window,
  30. message = o.message || {
  31. 'id': id
  32. };
  33. if (o.message && type.call(o.message) == objObject) {
  34. (o.message.id) ? o.message.id : o.message.id = id;
  35. message = o.message;
  36. }
  37. str = window.JSON.stringify(message, fn);
  38. target.postMessage(str, '*');
  39. };
  40. var _hashCreate = function(o, fn) {
  41. fn = fn || null;
  42. var str = window.JSON.stringify(o, fn);
  43. return str;
  44. };
  45. var _hashParse = function(str, fn) {
  46. fn = fn || null;
  47. return window.JSON.parse(str, fn);
  48. };
  49. var setCookie = function(name, value, options) {
  50. options = options || {};
  51. var expires = options.expires;
  52. if (typeof expires == "number" && expires) {
  53. var d = new Date();
  54. d.setTime(d.getTime() + expires*1000);
  55. expires = options.expires = d;
  56. }
  57. if (expires && expires.toUTCString) {
  58. options.expires = expires.toUTCString();
  59. }
  60. value = encodeURIComponent(value);
  61. var updatedCookie = name + "=" + value;
  62. for(var propName in options) {
  63. var propValue = options[propName];
  64. updatedCookie += "; " + propName;
  65. if (propValue !== true) {
  66. updatedCookie += "=" + propValue;
  67. }
  68. }
  69. document.cookie = updatedCookie;
  70. };
  71. var getCookie = function(name) {
  72. var matches = document.cookie.match(new RegExp(
  73. "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  74. ));
  75. return matches ? decodeURIComponent(matches[1]) : undefined;
  76. };
  77. var deleteCookie = function(name) {
  78. setCookie(name, "", { expires: -1 });
  79. };
  80. var findFocusable = function(ckEl) {
  81. var result = null,
  82. focusableSelectors = 'a[href], area[href], input, select, textarea, button, *[tabindex], *[contenteditable]';
  83. if(ckEl) {
  84. result = ckEl.find(focusableSelectors);
  85. }
  86. return result;
  87. };
  88. var getStyle = function(el, prop) {
  89. if(document.defaultView && document.defaultView.getComputedStyle) {
  90. return document.defaultView.getComputedStyle(el, null)[prop];
  91. } else if(el.currentStyle) {
  92. return el.currentStyle[prop];
  93. } else {
  94. return el.style[prop];
  95. }
  96. };
  97. var isHidden = function(el) {
  98. return el.offsetWidth === 0 || el.offsetHeight == 0 || getStyle(el, 'display') === 'none';
  99. };
  100. var isVisible = function(el) {
  101. return !isHidden(el);
  102. };
  103. var hasClass = function (obj, cname) {
  104. return !!(obj.className ? obj.className.match(new RegExp('(\\s|^)'+cname+'(\\s|$)')) : false);
  105. };
  106. return {
  107. postMessage: {
  108. init: _init,
  109. send: _sendCmd,
  110. unbindHandler: unbindHandler
  111. },
  112. hash: {
  113. create: function() {
  114. },
  115. parse: function() {
  116. }
  117. },
  118. cookie: {
  119. set: setCookie,
  120. get: getCookie,
  121. remove: deleteCookie
  122. },
  123. misc: {
  124. findFocusable: findFocusable,
  125. isVisible: isVisible,
  126. hasClass: hasClass
  127. }
  128. };
  129. })();
  130. var NS = NS || {};
  131. NS.TextAreaNumber = null;
  132. NS.load = true;
  133. NS.cmd = {
  134. "SpellTab": 'spell',
  135. "Thesaurus": 'thes',
  136. "GrammTab": 'grammar'
  137. };
  138. NS.dialog = null;
  139. NS.optionNode = null;
  140. NS.selectNode = null;
  141. NS.grammerSuggest = null;
  142. NS.textNode = {};
  143. NS.iframeMain = null;
  144. NS.dataTemp = '';
  145. NS.div_overlay = null;
  146. NS.textNodeInfo = {};
  147. NS.selectNode = {};
  148. NS.selectNodeResponce = {};
  149. NS.langList = null;
  150. NS.langSelectbox = null;
  151. NS.banner = '';
  152. NS.show_grammar = null;
  153. NS.div_overlay_no_check = null;
  154. NS.targetFromFrame = {};
  155. NS.onLoadOverlay = null;
  156. NS.LocalizationComing = {};
  157. NS.OverlayPlace = null;
  158. NS.sessionid = '';
  159. NS.LocalizationButton = {
  160. 'ChangeTo_button': {
  161. 'instance' : null,
  162. 'text' : 'Change to',
  163. 'localizationID': 'ChangeTo'
  164. },
  165. 'ChangeAll': {
  166. 'instance' : null,
  167. 'text' : 'Change All'
  168. },
  169. 'IgnoreWord': {
  170. 'instance' : null,
  171. 'text' : 'Ignore word'
  172. },
  173. 'IgnoreAllWords': {
  174. 'instance' : null,
  175. 'text' : 'Ignore all words'
  176. },
  177. 'Options': {
  178. 'instance' : null,
  179. 'text' : 'Options',
  180. 'optionsDialog': {
  181. 'instance' : null
  182. }
  183. },
  184. 'AddWord': {
  185. 'instance' : null,
  186. 'text' : 'Add word'
  187. },
  188. 'FinishChecking_button': {
  189. 'instance' : null,
  190. 'text' : 'Finish Checking',
  191. 'localizationID': 'FinishChecking'
  192. },
  193. 'FinishChecking_button_block': {
  194. 'instance' : null,
  195. 'text' : 'Finish Checking',
  196. 'localizationID': 'FinishChecking'
  197. }
  198. };
  199. NS.LocalizationLabel = {
  200. 'ChangeTo_label': {
  201. 'instance' : null,
  202. 'text' : 'Change to',
  203. 'localizationID': 'ChangeTo'
  204. },
  205. 'Suggestions': {
  206. 'instance' : null,
  207. 'text' : 'Suggestions'
  208. },
  209. 'Categories': {
  210. 'instance' : null,
  211. 'text' : 'Categories'
  212. },
  213. 'Synonyms': {
  214. 'instance' : null,
  215. 'text' : 'Synonyms'
  216. }
  217. };
  218. var SetLocalizationButton = function(obj) {
  219. var el, localizationID;
  220. for(var i in obj) {
  221. el = NS.dialog.getContentElement(NS.dialog._.currentTabId, i);
  222. if(el) {
  223. el = el.getElement();
  224. } else {
  225. el = obj[i].instance.getElement().getFirst() || obj[i].instance.getElement();
  226. }
  227. localizationID = obj[i].localizationID || i;
  228. el.setText(NS.LocalizationComing[localizationID]);
  229. }
  230. };
  231. var SetLocalizationLabel = function(obj) {
  232. var el, localizationID;
  233. for(var i in obj) {
  234. el = NS.dialog.getContentElement(NS.dialog._.currentTabId, i);
  235. if(!el) {
  236. el = obj[i].instance;
  237. }
  238. if(el.setLabel) {
  239. localizationID = obj[i].localizationID || i;
  240. el.setLabel(NS.LocalizationComing[localizationID] + ':');
  241. }
  242. }
  243. };
  244. var OptionsConfirm = function(state) {
  245. if (state) {
  246. nameNode.setValue('');
  247. }
  248. };
  249. var iframeOnload = false;
  250. var nameNode, selectNode, frameId;
  251. NS.framesetHtml = function(tab) {
  252. var str = '<iframe id=' + NS.iframeNumber + '_' + tab + ' frameborder="0" allowtransparency="1" style="width:100%;border: 1px solid #AEB3B9;overflow: auto;background:#fff; border-radius: 3px;"></iframe>';
  253. return str;
  254. };
  255. NS.setIframe = function(that, nameTab) {
  256. var iframe,
  257. str = NS.framesetHtml(nameTab),
  258. iframeId = NS.iframeNumber + '_' + nameTab,
  259. // tmp.html from wsc/dialogs
  260. iframeInnerHtml =
  261. '<!DOCTYPE html>' +
  262. '<html>' +
  263. '<head>' +
  264. '<meta charset="UTF-8">' +
  265. '<title>iframe</title>' +
  266. '<style>' +
  267. 'html,body{' +
  268. 'margin: 0;' +
  269. 'height: 100%;' +
  270. 'font: 13px/1.555 "Trebuchet MS", sans-serif;' +
  271. '}' +
  272. 'a{' +
  273. 'color: #888;' +
  274. 'font-weight: bold;' +
  275. 'text-decoration: none;' +
  276. 'border-bottom: 1px solid #888;' +
  277. '}' +
  278. '.main-box {' +
  279. 'color:#252525;' +
  280. 'padding: 3px 5px;' +
  281. 'text-align: justify;' +
  282. '}' +
  283. '.main-box p{margin: 0 0 14px;}' +
  284. '.main-box .cerr{' +
  285. 'color: #f00000;' +
  286. 'border-bottom-color: #f00000;' +
  287. '}' +
  288. '</style>' +
  289. '</head>' +
  290. '<body>' +
  291. '<div id="content" class="main-box"></div>' +
  292. '<iframe src="" frameborder="0" id="spelltext" name="spelltext" style="display:none; width: 100%" ></iframe>' +
  293. '<iframe src="" frameborder="0" id="loadsuggestfirst" name="loadsuggestfirst" style="display:none; width: 100%" ></iframe>' +
  294. '<iframe src="" frameborder="0" id="loadspellsuggestall" name="loadspellsuggestall" style="display:none; width: 100%" ></iframe>' +
  295. '<iframe src="" frameborder="0" id="loadOptionsForm" name="loadOptionsForm" style="display:none; width: 100%" ></iframe>' +
  296. '<script>' +
  297. '(function(window) {' +
  298. // Constructor Manager PostMessage
  299. 'var ManagerPostMessage = function() {' +
  300. 'var _init = function(handler) {' +
  301. 'if (document.addEventListener) {' +
  302. 'window.addEventListener("message", handler, false);' +
  303. '} else {' +
  304. 'window.attachEvent("onmessage", handler);' +
  305. '};' +
  306. '};' +
  307. 'var _sendCmd = function(o) {' +
  308. 'var str,' +
  309. 'type = Object.prototype.toString,' +
  310. 'fn = o.fn || null,' +
  311. 'id = o.id || "",' +
  312. 'target = o.target || window,' +
  313. 'message = o.message || { "id": id };' +
  314. 'if (o.message && type.call(o.message) == "[object Object]") {' +
  315. '(o.message["id"]) ? o.message["id"] : o.message["id"] = id;' +
  316. 'message = o.message;' +
  317. '};' +
  318. 'str = JSON.stringify(message, fn);' +
  319. 'target.postMessage(str, "*");' +
  320. '};' +
  321. 'return {' +
  322. 'init: _init,' +
  323. 'send: _sendCmd' +
  324. '};' +
  325. '};' +
  326. 'var manageMessageTmp = new ManagerPostMessage;' +
  327. 'var appString = (function(){' +
  328. 'var spell = parent.CKEDITOR.config.wsc.DefaultParams.scriptPath;' +
  329. 'var serverUrl = parent.CKEDITOR.config.wsc.DefaultParams.serviceHost;' +
  330. 'return serverUrl + spell;' +
  331. '})();' +
  332. 'function loadScript(src, callback) {' +
  333. 'var scriptTag = document.createElement("script");' +
  334. 'scriptTag.type = "text/javascript";' +
  335. 'callback ? callback : callback = function() {};' +
  336. 'if(scriptTag.readyState) {' +
  337. //IE
  338. 'scriptTag.onreadystatechange = function() {' +
  339. 'if (scriptTag.readyState == "loaded" ||' +
  340. 'scriptTag.readyState == "complete") {' +
  341. 'scriptTag.onreadystatechange = null;' +
  342. 'setTimeout(function(){scriptTag.parentNode.removeChild(scriptTag)},1);' +
  343. 'callback();' +
  344. '}' +
  345. '};' +
  346. '}else{' +
  347. //Others
  348. 'scriptTag.onload = function() {' +
  349. 'setTimeout(function(){scriptTag.parentNode.removeChild(scriptTag)},1);' +
  350. 'callback();' +
  351. '};' +
  352. '};' +
  353. 'scriptTag.src = src;' +
  354. 'document.getElementsByTagName("head")[0].appendChild(scriptTag);' +
  355. '};' +
  356. 'window.onload = function(){' +
  357. 'loadScript(appString, function(){' +
  358. 'manageMessageTmp.send({' +
  359. '"id": "iframeOnload",' +
  360. '"target": window.parent' +
  361. '});' +
  362. '});' +
  363. '}' +
  364. '})(this);' +
  365. '</script>' +
  366. '</body>' +
  367. '</html>';
  368. that.getElement().setHtml(str);
  369. iframe = document.getElementById(iframeId);
  370. iframe = (iframe.contentWindow) ? iframe.contentWindow : (iframe.contentDocument.document) ? iframe.contentDocument.document : iframe.contentDocument;
  371. iframe.document.open();
  372. iframe.document.write(iframeInnerHtml);
  373. iframe.document.close();
  374. };
  375. NS.setCurrentIframe = function(currentTab) {
  376. var that = NS.dialog._.contents[currentTab].Content,
  377. tabID, iframe;
  378. NS.setIframe(that, currentTab);
  379. };
  380. NS.setHeightBannerFrame = function() {
  381. var height = "90px",
  382. bannerPlaceSpellTab = NS.dialog.getContentElement('SpellTab', 'banner').getElement(),
  383. bannerPlaceGrammTab = NS.dialog.getContentElement('GrammTab', 'banner').getElement(),
  384. bannerPlaceThesaurus = NS.dialog.getContentElement('Thesaurus', 'banner').getElement();
  385. bannerPlaceSpellTab.setStyle('height', height);
  386. bannerPlaceGrammTab.setStyle('height', height);
  387. bannerPlaceThesaurus.setStyle('height', height);
  388. };
  389. NS.setHeightFrame = function() {
  390. var currentTab = NS.dialog._.currentTabId,
  391. tabID = NS.iframeNumber + '_' + currentTab,
  392. iframe = document.getElementById(tabID);
  393. iframe.style.height = '240px';
  394. };
  395. NS.sendData = function(scope) {
  396. var currentTab = scope._.currentTabId,
  397. that = scope._.contents[currentTab].Content,
  398. tabID, iframe;
  399. NS.previousTab = currentTab;
  400. NS.setIframe(that, currentTab);
  401. var loadNewTab = function(event) {
  402. currentTab = scope._.currentTabId;
  403. event = event || window.event;
  404. if (!event.data.getTarget().is('a')) {
  405. return;
  406. }
  407. if(currentTab === NS.previousTab) return;
  408. NS.previousTab = currentTab;
  409. that = scope._.contents[currentTab].Content;
  410. tabID = NS.iframeNumber + '_' + currentTab;
  411. NS.div_overlay.setEnable();
  412. if (!that.getElement().getChildCount()) {
  413. NS.setIframe(that, currentTab);
  414. iframe = document.getElementById(tabID);
  415. NS.targetFromFrame[tabID] = iframe.contentWindow;
  416. } else {
  417. sendData(NS.targetFromFrame[tabID], NS.cmd[currentTab]);
  418. }
  419. };
  420. scope.parts.tabs.removeListener('click', loadNewTab);
  421. scope.parts.tabs.on('click', loadNewTab);
  422. };
  423. NS.buildSelectLang = function(aId) {
  424. var divContainer = new CKEDITOR.dom.element('div'),
  425. selectContainer = new CKEDITOR.dom.element('select'),
  426. id = "wscLang" + aId;
  427. divContainer.addClass("cke_dialog_ui_input_select");
  428. divContainer.setAttribute("role", "presentation");
  429. divContainer.setStyles({
  430. 'height': 'auto',
  431. 'position': 'absolute',
  432. 'right': '0',
  433. 'top': '-1px',
  434. 'width': '160px',
  435. 'white-space': 'normal'
  436. });
  437. selectContainer.setAttribute('id', id);
  438. selectContainer.addClass("cke_dialog_ui_input_select");
  439. selectContainer.setStyles({
  440. 'width': '160px'
  441. });
  442. var currentTabId = NS.dialog._.currentTabId,
  443. frameId = NS.iframeNumber + '_' + currentTabId;
  444. divContainer.append(selectContainer);
  445. return divContainer;
  446. };
  447. NS.buildOptionLang = function(key, aId) {
  448. var id = "wscLang" + aId;
  449. var select = document.getElementById(id),
  450. fragment = document.createDocumentFragment(),
  451. create_option, txt_option,
  452. sort = [];
  453. if(select.options.length === 0) {
  454. for (var lang in key) {
  455. sort.push([lang, key[lang]]);
  456. }
  457. sort.sort();
  458. for (var i = 0; i < sort.length; i++) {
  459. create_option=document.createElement("option");
  460. create_option.setAttribute("value", sort[i][1]);
  461. txt_option = document.createTextNode(sort[i][0]);
  462. create_option.appendChild(txt_option);
  463. fragment.appendChild(create_option);
  464. }
  465. select.appendChild(fragment);
  466. }
  467. // make appropriate option selected according to current selected language
  468. for (var j = 0; j < select.options.length; j++) {
  469. if (select.options[j].value == NS.selectingLang) {
  470. select.options[j].selected = "selected";
  471. }
  472. }
  473. };
  474. NS.buildOptionSynonyms = function(key) {
  475. var syn = NS.selectNodeResponce[key];
  476. var select = getSelect( NS.selectNode['Synonyms'] );
  477. NS.selectNode['Synonyms'].clear();
  478. for (var i = 0; i < syn.length; i++) {
  479. var option = document.createElement('option');
  480. option.text = syn[i];
  481. option.value = syn[i];
  482. select.$.add(option, i);
  483. }
  484. NS.selectNode['Synonyms'].getInputElement().$.firstChild.selected = true;
  485. NS.textNode['Thesaurus'].setValue(NS.selectNode['Synonyms'].getInputElement().getValue());
  486. };
  487. var setBannerInPlace = function(htmlBanner) {
  488. var findBannerPlace = NS.dialog.getContentElement(NS.dialog._.currentTabId, 'banner').getElement();
  489. findBannerPlace.setHtml(htmlBanner);
  490. };
  491. var overlayBlock = function overlayBlock(opt) {
  492. var progress = opt.progress || "",
  493. doc = document,
  494. target = opt.target || doc.body,
  495. overlayId = opt.id || "overlayBlock",
  496. opacity = opt.opacity || "0.9",
  497. background = opt.background || "#f1f1f1",
  498. getOverlay = doc.getElementById(overlayId),
  499. thisOverlay = getOverlay || doc.createElement("div");
  500. thisOverlay.style.cssText = "position: absolute;" +
  501. "top:30px;" +
  502. "bottom:41px;" +
  503. "left:1px;" +
  504. "right:1px;" +
  505. "z-index: 10020;" +
  506. "padding:0;" +
  507. "margin:0;" +
  508. "background:" + background + ";" +
  509. "opacity: " + opacity + ";" +
  510. "filter: alpha(opacity=" + opacity * 100 + ");" +
  511. "display: none;";
  512. thisOverlay.id = overlayId;
  513. if (!getOverlay) {
  514. target.appendChild(thisOverlay);
  515. }
  516. return {
  517. setDisable: function() {
  518. thisOverlay.style.display = "none";
  519. },
  520. setEnable: function() {
  521. thisOverlay.style.display = "block";
  522. }
  523. };
  524. };
  525. var buildRadioInputs = function(key, value, check) {
  526. var divContainer = new CKEDITOR.dom.element('div'),
  527. radioButton = new CKEDITOR.dom.element('input'),
  528. radioLabel = new CKEDITOR.dom.element('label'),
  529. id = "wscGrammerSuggest" + key + "_" + value;
  530. divContainer.addClass("cke_dialog_ui_input_radio");
  531. divContainer.setAttribute("role", "presentation");
  532. divContainer.setStyles({
  533. width: "97%",
  534. padding: "5px",
  535. 'white-space': 'normal'
  536. });
  537. radioButton.setAttributes({
  538. type: "radio",
  539. value: value,
  540. name: 'wscGrammerSuggest',
  541. id: id
  542. });
  543. radioButton.setStyles({
  544. "float":"left"
  545. });
  546. radioButton.on("click", function(data) {
  547. NS.textNode['GrammTab'].setValue(data.sender.getValue());
  548. });
  549. (check) ? radioButton.setAttribute("checked", true) : false;
  550. radioButton.addClass("cke_dialog_ui_radio_input");
  551. radioLabel.appendText(key);
  552. radioLabel.setAttribute("for", id);
  553. radioLabel.setStyles({
  554. 'display': "block",
  555. 'line-height': '16px',
  556. 'margin-left': '18px',
  557. 'white-space': 'normal'
  558. });
  559. divContainer.append(radioButton);
  560. divContainer.append(radioLabel);
  561. return divContainer;
  562. };
  563. var statusGrammarTab = function(aState) { //#19221
  564. aState = aState || 'true';
  565. if(aState !== null && aState == 'false'){
  566. hideGrammTab();
  567. }
  568. };
  569. var langConstructor = function(lang) {
  570. var langSelectBox = new __constructLangSelectbox(lang),
  571. selectId = "wscLang" + NS.dialog.getParentEditor().name,
  572. selectContainer = document.getElementById(selectId),
  573. currentTabId = NS.dialog._.currentTabId,
  574. frameId = NS.iframeNumber + '_' + currentTabId;
  575. NS.buildOptionLang(langSelectBox.setLangList, NS.dialog.getParentEditor().name);
  576. tabView[langSelectBox.getCurrentLangGroup(NS.selectingLang)].onShow();
  577. statusGrammarTab(NS.show_grammar);
  578. selectContainer.onchange = function(e) {
  579. var langGroup = langSelectBox.getCurrentLangGroup(this.value),
  580. currentTabId = NS.dialog._.currentTabId,
  581. cmd;
  582. e = e || window.event;
  583. tabView[langGroup].onShow();
  584. statusGrammarTab(NS.show_grammar);
  585. NS.div_overlay.setEnable();
  586. NS.selectingLang = this.value;
  587. // get command for current opened tan
  588. cmd = NS.cmd[currentTabId];
  589. // check whether current tab can be opened after language switching
  590. if(!langGroup || !tabView[langGroup] || !tabView[langGroup].allowedTabCommands[cmd]) {
  591. // if not so - set default tab to open after reload
  592. cmd = tabView[langGroup].defaultTabCommand;
  593. }
  594. for(var key in NS.cmd) {
  595. if(NS.cmd[key] == cmd) {
  596. NS.previousTab = key;
  597. break;
  598. }
  599. }
  600. appTools.postMessage.send({
  601. 'message': {
  602. 'changeLang': NS.selectingLang,
  603. 'text': NS.dataTemp,
  604. 'cmd': cmd
  605. },
  606. 'target': NS.targetFromFrame[frameId],
  607. 'id': 'selectionLang_outer__page'
  608. });
  609. };
  610. };
  611. var disableButtonSuggest = function(word) {
  612. var changeToButton, changeAllButton,
  613. styleDisable = function(instanceButton) {
  614. var button = NS.dialog.getContentElement(NS.dialog._.currentTabId, instanceButton) || NS.LocalizationButton[instanceButton].instance;
  615. button.getElement().hasClass('cke_disabled') ? button.getElement().setStyle('color', '#a0a0a0') : button.disable();
  616. },
  617. styleEnable = function(instanceButton) {
  618. var button = NS.dialog.getContentElement(NS.dialog._.currentTabId, instanceButton) || NS.LocalizationButton[instanceButton].instance;
  619. button.enable();
  620. button.getElement().setStyle('color', '#333');
  621. };
  622. if (word == 'no_any_suggestions') {
  623. word = 'No suggestions';
  624. changeToButton = NS.dialog.getContentElement(NS.dialog._.currentTabId, 'ChangeTo_button') || NS.LocalizationButton['ChangeTo_button'].instance;
  625. changeToButton.disable();
  626. changeAllButton = NS.dialog.getContentElement(NS.dialog._.currentTabId, 'ChangeAll') || NS.LocalizationButton['ChangeAll'].instance;
  627. changeAllButton.disable();
  628. styleDisable('ChangeTo_button');
  629. styleDisable('ChangeAll');
  630. return word;
  631. } else {
  632. styleEnable('ChangeTo_button');
  633. styleEnable('ChangeAll');
  634. return word;
  635. }
  636. };
  637. function getSelect( obj ) {
  638. if ( obj && obj.domId && obj.getInputElement().$ )
  639. return obj.getInputElement();
  640. else if ( obj && obj.$ )
  641. return obj;
  642. return false;
  643. }
  644. var handlerId = {
  645. iframeOnload: function(response) {
  646. NS.div_overlay.setEnable();
  647. iframeOnload = true;
  648. var currentTab = NS.dialog._.currentTabId,
  649. tabId = NS.iframeNumber + '_' + currentTab;
  650. sendData(NS.targetFromFrame[tabId], NS.cmd[currentTab]);
  651. },
  652. suggestlist: function(response) {
  653. delete response.id;
  654. NS.div_overlay_no_check.setDisable();
  655. hideCurrentFinishChecking();
  656. langConstructor(NS.langList);
  657. var word = disableButtonSuggest(response.word),
  658. suggestionsList = '';
  659. if (word instanceof Array) {
  660. word = response.word[0];
  661. }
  662. word = word.split(',');
  663. suggestionsList = word;
  664. NS.textNode['SpellTab'].setValue(suggestionsList[0]);
  665. var select = getSelect( selectNode );
  666. selectNode.clear();
  667. for (var i = 0; i < suggestionsList.length; i++) {
  668. var option = document.createElement('option');
  669. option.text = suggestionsList[i];
  670. option.value = suggestionsList[i];
  671. select.$.add(option, i);
  672. }
  673. showCurrentTabs();
  674. NS.div_overlay.setDisable();
  675. },
  676. grammerSuggest: function(response) {
  677. delete response.id;
  678. delete response.mocklangs;
  679. hideCurrentFinishChecking();
  680. langConstructor(NS.langList); // Show select language for this command CKEDITOR.config.wsc_cmd
  681. var firstSuggestValue = response.grammSuggest[0];// ? firstSuggestValue = response.grammSuggest[0] : firstSuggestValue = 'No suggestion for this words';
  682. NS.grammerSuggest.getElement().setHtml('');
  683. NS.textNode['GrammTab'].reset();
  684. NS.textNode['GrammTab'].setValue(firstSuggestValue);
  685. NS.textNodeInfo['GrammTab'].getElement().setHtml('');
  686. NS.textNodeInfo['GrammTab'].getElement().setText(response.info);
  687. var arr = response.grammSuggest,
  688. len = arr.length,
  689. check = true;
  690. for (var i = 0; i < len; i++) {
  691. NS.grammerSuggest.getElement().append(buildRadioInputs(arr[i], arr[i], check));
  692. check = false;
  693. }
  694. showCurrentTabs();
  695. NS.div_overlay.setDisable();
  696. },
  697. thesaurusSuggest: function(response) {
  698. delete response.id;
  699. delete response.mocklangs;
  700. hideCurrentFinishChecking();
  701. langConstructor(NS.langList); // Show select language for this command CKEDITOR.config.wsc_cmd
  702. NS.selectNodeResponce = response;
  703. NS.textNode['Thesaurus'].reset();
  704. var select = getSelect( NS.selectNode['Categories'] ),
  705. count = 0;
  706. NS.selectNode['Categories'].clear();
  707. for (var i in response) {
  708. var option = document.createElement('option');
  709. option.text = i;
  710. option.value = i;
  711. select.$.add(option, count);
  712. count++
  713. }
  714. var synKey = NS.selectNode['Categories'].getInputElement().getChildren().$[0].value;
  715. NS.selectNode['Categories'].getInputElement().getChildren().$[0].selected = true;
  716. NS.buildOptionSynonyms(synKey);
  717. showCurrentTabs();
  718. NS.div_overlay.setDisable();
  719. count = 0;
  720. },
  721. finish: function(response) {
  722. delete response.id;
  723. hideCurrentTabs();
  724. showCurrentFinishChecking();
  725. NS.div_overlay.setDisable();
  726. },
  727. settext: function(response) {
  728. delete response.id;
  729. var command = NS.dialog.getParentEditor().getCommand( 'checkspell' ),
  730. editor = NS.dialog.getParentEditor();
  731. //set local storage for synchronization before scayt reinit
  732. if (editor.scayt && editor.wsc.isSsrvSame) {
  733. var wscUDN = editor.wsc.udn;
  734. if (!wscUDN) {
  735. editor.wsc.DataStorage.setData('scayt_user_dictionary_name', '');
  736. } else {
  737. editor.wsc.DataStorage.setData('scayt_user_dictionary_name', wscUDN);
  738. }
  739. }
  740. try {
  741. editor.focus();
  742. } catch(e) {}
  743. editor.setData(response.text, function(){
  744. NS.dataTemp = '';
  745. editor.unlockSelection();
  746. editor.fire('saveSnapshot');
  747. NS.dialog.hide();
  748. });
  749. },
  750. ReplaceText: function(response) {
  751. delete response.id;
  752. NS.div_overlay.setEnable();
  753. NS.dataTemp = response.text;
  754. NS.selectingLang = response.currentLang;
  755. if (response.cmd = 'spell' && response.len !== '0' && response.len) {
  756. NS.div_overlay.setDisable();
  757. } else {
  758. window.setTimeout(function() {
  759. try {
  760. NS.div_overlay.setDisable();
  761. } catch(e) {}
  762. }, 500);
  763. }
  764. SetLocalizationButton(NS.LocalizationButton);
  765. SetLocalizationLabel(NS.LocalizationLabel);
  766. },
  767. options_checkbox_send: function(response) {
  768. delete response.id;
  769. var obj = {
  770. 'osp': appTools.cookie.get('osp'),
  771. 'udn': appTools.cookie.get('udn'),
  772. 'cust_dic_ids': NS.cust_dic_ids
  773. };
  774. var currentTabId = NS.dialog._.currentTabId,
  775. frameId = NS.iframeNumber + '_' + currentTabId;
  776. appTools.postMessage.send({
  777. 'message': obj,
  778. 'target': NS.targetFromFrame[frameId],
  779. 'id': 'options_outer__page'
  780. });
  781. },
  782. getOptions: function(response) {
  783. var udn = response.DefOptions.udn;
  784. NS.LocalizationComing = response.DefOptions.localizationButtonsAndText;
  785. NS.show_grammar = response.show_grammar;
  786. NS.langList = response.lang;
  787. NS.bnr = response.bannerId;
  788. NS.sessionid = response.sessionid;
  789. if (response.bannerId) {
  790. NS.setHeightBannerFrame();
  791. setBannerInPlace(response.banner);
  792. } else {
  793. NS.setHeightFrame();
  794. }
  795. if (udn == 'undefined') {
  796. if (NS.userDictionaryName) {
  797. udn = NS.userDictionaryName;
  798. var obj = {
  799. 'osp': appTools.cookie.get('osp'),
  800. 'udn': NS.userDictionaryName,
  801. 'cust_dic_ids': NS.cust_dic_ids,
  802. 'id': 'options_dic_send',
  803. 'udnCmd': 'create'
  804. };
  805. appTools.postMessage.send({
  806. 'message': obj,
  807. 'target': NS.targetFromFrame[frameId]
  808. });
  809. } else{
  810. udn = '';
  811. }
  812. }
  813. appTools.cookie.set('osp', response.DefOptions.osp);
  814. appTools.cookie.set('udn', udn);
  815. appTools.cookie.set('cust_dic_ids', response.DefOptions.cust_dic_ids);
  816. appTools.postMessage.send({
  817. 'id': 'giveOptions'
  818. });
  819. },
  820. options_dic_send: function(response) {
  821. var obj = {
  822. 'osp': appTools.cookie.get('osp'),
  823. 'udn': appTools.cookie.get('udn'),
  824. 'cust_dic_ids': NS.cust_dic_ids,
  825. 'id': 'options_dic_send',
  826. 'udnCmd': appTools.cookie.get('udnCmd')
  827. };
  828. var currentTabId = NS.dialog._.currentTabId,
  829. frameId = NS.iframeNumber + '_' + currentTabId;
  830. appTools.postMessage.send({
  831. 'message': obj,
  832. 'target': NS.targetFromFrame[frameId]
  833. });
  834. },
  835. data: function(response) {
  836. delete response.id;
  837. },
  838. giveOptions: function() {
  839. },
  840. setOptionsConfirmF:function() {
  841. OptionsConfirm(false);
  842. },
  843. setOptionsConfirmT:function() {
  844. OptionsConfirm(true);
  845. },
  846. clickBusy: function() {
  847. NS.div_overlay.setEnable();
  848. },
  849. suggestAllCame: function() {
  850. NS.div_overlay.setDisable();
  851. NS.div_overlay_no_check.setDisable();
  852. },
  853. TextCorrect: function() {
  854. langConstructor(NS.langList);
  855. }
  856. };
  857. var handlerIncomingData = function(event) {
  858. event = event || window.event;
  859. var response = window.JSON.parse(event.data);
  860. if(response && response.id) {
  861. handlerId[response.id](response);
  862. }
  863. };
  864. var handlerButtonOptions = function(event) {
  865. event = event || window.event;
  866. var currentTabId = NS.dialog._.currentTabId,
  867. frameId = NS.iframeNumber + '_' + currentTabId;
  868. appTools.postMessage.send({
  869. 'message': {
  870. 'cmd': 'Options'
  871. },
  872. 'target': NS.targetFromFrame[frameId],
  873. 'id': 'cmd'
  874. });
  875. };
  876. var sendData = function(frameTarget, cmd, sendText, reset_suggest) {
  877. cmd = cmd || CKEDITOR.config.wsc_cmd;
  878. reset_suggest = reset_suggest || false;
  879. sendText = sendText || NS.dataTemp;
  880. appTools.postMessage.send({
  881. 'message': {
  882. 'customerId': NS.wsc_customerId,
  883. 'text': sendText,
  884. 'txt_ctrl': NS.TextAreaNumber,
  885. 'cmd': cmd,
  886. 'cust_dic_ids': NS.cust_dic_ids,
  887. 'udn': NS.userDictionaryName,
  888. 'slang': NS.selectingLang,
  889. 'reset_suggest': reset_suggest,
  890. 'sessionid': NS.sessionid
  891. },
  892. 'target': frameTarget,
  893. 'id': 'data_outer__page'
  894. });
  895. NS.div_overlay.setEnable();
  896. };
  897. var tabView = {
  898. "superset": {
  899. onShow: function() {
  900. showThesaurusTab();
  901. showGrammTab();
  902. showSpellTab();
  903. },
  904. allowedTabCommands: {
  905. "spell": true,
  906. "grammar": true,
  907. "thes": true
  908. },
  909. defaultTabCommand: "spell"
  910. },
  911. "usual": {
  912. onShow: function() {
  913. hideThesaurusTab();
  914. hideGrammTab();
  915. showSpellTab();
  916. },
  917. allowedTabCommands: {
  918. "spell": true
  919. },
  920. defaultTabCommand: "spell"
  921. },
  922. "rtl": {
  923. onShow: function() {
  924. hideThesaurusTab();
  925. hideGrammTab();
  926. showSpellTab();
  927. },
  928. allowedTabCommands: {
  929. "spell": true
  930. },
  931. defaultTabCommand: "spell"
  932. },
  933. "spellgrammar": {
  934. onShow: function() {
  935. hideThesaurusTab();
  936. showGrammTab();
  937. showSpellTab();
  938. },
  939. allowedTabCommands: {
  940. "spell": true,
  941. "grammar": true
  942. },
  943. defaultTabCommand: "spell"
  944. },
  945. "spellthes": {
  946. onShow: function() {
  947. showThesaurusTab();
  948. hideGrammTab();
  949. showSpellTab();
  950. },
  951. allowedTabCommands: {
  952. "spell": true,
  953. "thes": true
  954. },
  955. defaultTabCommand: "spell"
  956. }
  957. };
  958. var showFirstTab = function(scope) {
  959. var cmdManger = function(cmdView) {
  960. var obj = {};
  961. var _getCmd = function(cmd) {
  962. for (var tabId in cmdView) {
  963. obj[cmdView[tabId]] = tabId;
  964. }
  965. return obj[cmd];
  966. };
  967. return {
  968. getCmdByTab: _getCmd
  969. };
  970. };
  971. var cmdM = new cmdManger(NS.cmd),
  972. tabToOpen = cmdM.getCmdByTab(CKEDITOR.config.wsc_cmd);
  973. scope.selectPage(tabToOpen);
  974. NS.sendData(scope);
  975. };
  976. var showThesaurusTab = function() {
  977. NS.dialog.showPage('Thesaurus');
  978. };
  979. var hideThesaurusTab = function() {
  980. NS.dialog.hidePage('Thesaurus');
  981. };
  982. var showGrammTab = function() {
  983. NS.dialog.showPage('GrammTab');
  984. };
  985. var hideGrammTab = function() {
  986. NS.dialog.hidePage('GrammTab');
  987. };
  988. var showSpellTab = function() {
  989. NS.dialog.showPage('SpellTab');
  990. };
  991. var hideSpellTab = function() {
  992. NS.dialog.hidePage('SpellTab');
  993. };
  994. var showCurrentTabs = function() {
  995. var target = NS.dialog.getContentElement(NS.dialog._.currentTabId, 'bottomGroup').getElement();
  996. target.removeStyle('display');
  997. target.removeStyle('position');
  998. target.removeStyle('left');
  999. target.show();
  1000. };
  1001. var hideCurrentTabs = function() {
  1002. var target = NS.dialog.getContentElement(NS.dialog._.currentTabId, 'bottomGroup').getElement(),
  1003. activeElement = document.activeElement,
  1004. focusableElements;
  1005. target.setStyles({
  1006. display: 'block',
  1007. position: 'absolute',
  1008. left: '-9999px'
  1009. });
  1010. setTimeout(function() {
  1011. target.removeStyle('display');
  1012. target.removeStyle('position');
  1013. target.removeStyle('left');
  1014. target.hide();
  1015. NS.dialog._.editor.focusManager.currentActive.focusNext();
  1016. focusableElements = appTools.misc.findFocusable(NS.dialog.parts.contents);
  1017. if(!appTools.misc.hasClass(activeElement, 'cke_dialog_tab') && !appTools.misc.hasClass(activeElement, 'cke_dialog_contents_body') && appTools.misc.isVisible(activeElement)) {
  1018. try {
  1019. activeElement.focus();
  1020. } catch(e) {}
  1021. } else {
  1022. for(var i = 0, tmpCkEl; i < focusableElements.count(); i++) {
  1023. tmpCkEl = focusableElements.getItem(i);
  1024. if(appTools.misc.isVisible(tmpCkEl.$)) {
  1025. try {
  1026. tmpCkEl.$.focus();
  1027. } catch(e) {}
  1028. break;
  1029. }
  1030. }
  1031. }
  1032. }, 0);
  1033. };
  1034. var showCurrentFinishChecking = function() {
  1035. var target = NS.dialog.getContentElement(NS.dialog._.currentTabId, 'BlockFinishChecking').getElement();
  1036. target.removeStyle('display');
  1037. target.removeStyle('position');
  1038. target.removeStyle('left');
  1039. target.show();
  1040. };
  1041. var hideCurrentFinishChecking = function() {
  1042. var target = NS.dialog.getContentElement(NS.dialog._.currentTabId, 'BlockFinishChecking').getElement(),
  1043. activeElement = document.activeElement,
  1044. focusableElements;
  1045. target.setStyles({
  1046. display: 'block',
  1047. position: 'absolute',
  1048. left: '-9999px'
  1049. });
  1050. setTimeout(function() {
  1051. target.removeStyle('display');
  1052. target.removeStyle('position');
  1053. target.removeStyle('left');
  1054. target.hide();
  1055. NS.dialog._.editor.focusManager.currentActive.focusNext();
  1056. focusableElements = appTools.misc.findFocusable(NS.dialog.parts.contents);
  1057. if(!appTools.misc.hasClass(activeElement, 'cke_dialog_tab') && !appTools.misc.hasClass(activeElement, 'cke_dialog_contents_body') && appTools.misc.isVisible(activeElement)) {
  1058. try {
  1059. activeElement.focus();
  1060. } catch(e) {}
  1061. } else {
  1062. for(var i = 0, tmpCkEl; i < focusableElements.count(); i++) {
  1063. tmpCkEl = focusableElements.getItem(i);
  1064. if(appTools.misc.isVisible(tmpCkEl.$)) {
  1065. try {
  1066. tmpCkEl.$.focus();
  1067. } catch(e) {}
  1068. break;
  1069. }
  1070. }
  1071. }
  1072. }, 0);
  1073. };
  1074. function __constructLangSelectbox(languageGroup) {
  1075. if( !languageGroup ) { throw "Languages-by-groups list are required for construct selectbox"; }
  1076. var that = this,
  1077. o_arr = [],
  1078. priorLang ="en_US",
  1079. priorLangTitle = "",
  1080. currLang = NS.selectingLang;
  1081. for ( var group in languageGroup){
  1082. for ( var langCode in languageGroup[group]){
  1083. var langName = languageGroup[group][langCode];
  1084. if ( langName == priorLang ) {
  1085. priorLangTitle = langName;
  1086. } else {
  1087. o_arr.push( langName );
  1088. }
  1089. }
  1090. }
  1091. o_arr.sort();
  1092. if(priorLangTitle) {
  1093. o_arr.unshift( priorLangTitle );
  1094. }
  1095. var searchGroup = function ( code ){
  1096. for ( var group in languageGroup){
  1097. for ( var langCode in languageGroup[group]){
  1098. if ( langCode.toUpperCase() === code.toUpperCase() ) {
  1099. return group;
  1100. }
  1101. }
  1102. }
  1103. return "";
  1104. };
  1105. var _setLangList = function() {
  1106. var langList = {},
  1107. langArray = [];
  1108. for (var group in languageGroup) {
  1109. for ( var langCode in languageGroup[group]){
  1110. langList[languageGroup[group][langCode]] = langCode;
  1111. }
  1112. }
  1113. return langList;
  1114. };
  1115. var _return = {
  1116. getCurrentLangGroup: function(code) {
  1117. return searchGroup(code);
  1118. },
  1119. setLangList: _setLangList()
  1120. };
  1121. return _return;
  1122. }
  1123. CKEDITOR.dialog.add('checkspell', function(editor) {
  1124. var handlerButtons = function(event) {
  1125. event = event || window.event;
  1126. // because in chrome and safary document.activeElement returns <body> tag. We need to signal that clicked element is active
  1127. this.getElement().focus();
  1128. NS.div_overlay.setEnable();
  1129. var currentTabId = NS.dialog._.currentTabId,
  1130. frameId = NS.iframeNumber + '_' + currentTabId,
  1131. new_word = NS.textNode[currentTabId].getValue(),
  1132. cmd = this.getElement().getAttribute("title-cmd");
  1133. appTools.postMessage.send({
  1134. 'message': {
  1135. 'cmd': cmd,
  1136. 'tabId': currentTabId,
  1137. 'new_word': new_word
  1138. },
  1139. 'target': NS.targetFromFrame[frameId],
  1140. 'id': 'cmd_outer__page'
  1141. });
  1142. if (cmd == 'ChangeTo' || cmd == 'ChangeAll') {
  1143. editor.fire('saveSnapshot');
  1144. }
  1145. if (cmd == 'FinishChecking') {
  1146. editor.config.wsc_onFinish.call(CKEDITOR.document.getWindow().getFrame());
  1147. }
  1148. },
  1149. constraints = {
  1150. minWidth: 560,
  1151. minHeight: 444
  1152. };
  1153. function initView(dialog) {
  1154. var newViewSettings = {
  1155. left: parseInt(editor.config.wsc_left, 10),
  1156. top: parseInt(editor.config.wsc_top, 10),
  1157. width: parseInt(editor.config.wsc_width, 10),
  1158. height: parseInt(editor.config.wsc_height, 10)
  1159. },
  1160. viewSize = CKEDITOR.document.getWindow().getViewPaneSize(),
  1161. currentPosition = dialog.getPosition(),
  1162. currentSize = dialog.getSize(),
  1163. savePosition = 0;
  1164. if(!dialog._.resized) {
  1165. var wrapperHeight = currentSize.height - dialog.parts.contents.getSize('height', !(CKEDITOR.env.gecko || CKEDITOR.env.opera || CKEDITOR.env.ie && CKEDITOR.env.quirks)),
  1166. wrapperWidth = currentSize.width - dialog.parts.contents.getSize('width', 1);
  1167. if(newViewSettings.width < constraints.minWidth || isNaN(newViewSettings.width)) {
  1168. newViewSettings.width = constraints.minWidth;
  1169. }
  1170. if(newViewSettings.width > viewSize.width - wrapperWidth) {
  1171. newViewSettings.width = viewSize.width - wrapperWidth;
  1172. }
  1173. if(newViewSettings.height < constraints.minHeight || isNaN(newViewSettings.height)) {
  1174. newViewSettings.height = constraints.minHeight;
  1175. }
  1176. if(newViewSettings.height > viewSize.height - wrapperHeight) {
  1177. newViewSettings.height = viewSize.height - wrapperHeight;
  1178. }
  1179. currentSize.width = newViewSettings.width + wrapperWidth;
  1180. currentSize.height = newViewSettings.height + wrapperHeight;
  1181. dialog._.fromResizeEvent = false;
  1182. dialog.resize(newViewSettings.width, newViewSettings.height);
  1183. setTimeout(function() {
  1184. dialog._.fromResizeEvent = false;
  1185. CKEDITOR.dialog.fire('resize', {
  1186. dialog: dialog,
  1187. width: newViewSettings.width,
  1188. height: newViewSettings.height
  1189. }, editor);
  1190. }, 300);
  1191. }
  1192. if(!dialog._.moved) {
  1193. savePosition = isNaN(newViewSettings.left) && isNaN(newViewSettings.top) ? 0 : 1;
  1194. if(isNaN(newViewSettings.left)) {
  1195. newViewSettings.left = (viewSize.width - currentSize.width) / 2;
  1196. }
  1197. if(newViewSettings.left < 0) {
  1198. newViewSettings.left = 0;
  1199. }
  1200. if(newViewSettings.left > viewSize.width - currentSize.width) {
  1201. newViewSettings.left = viewSize.width - currentSize.width;
  1202. }
  1203. if(isNaN(newViewSettings.top)) {
  1204. newViewSettings.top = (viewSize.height - currentSize.height) / 2;
  1205. }
  1206. if(newViewSettings.top < 0) {
  1207. newViewSettings.top = 0;
  1208. }
  1209. if(newViewSettings.top > viewSize.height - currentSize.height) {
  1210. newViewSettings.top = viewSize.height - currentSize.height;
  1211. }
  1212. dialog.move(newViewSettings.left, newViewSettings.top, savePosition);
  1213. }
  1214. }
  1215. function createWscObjectForUdAndUdnSyncrhonization() {
  1216. editor.wsc = {};
  1217. //DataStorage object for cookies and localStorage manipulation
  1218. (function( object ) {
  1219. 'use strict';
  1220. var DataTypeManager = {
  1221. separator: '<$>',
  1222. getDataType: function(value) {
  1223. var type;
  1224. if(typeof value === 'undefined') {
  1225. type = 'undefined';
  1226. } else if(value === null) {
  1227. type = 'null';
  1228. } else {
  1229. type = Object.prototype.toString.call(value).slice(8, -1);
  1230. }
  1231. return type;
  1232. },
  1233. convertDataToString: function(value) {
  1234. var str,
  1235. type = this.getDataType(value).toLowerCase();
  1236. str = type + this.separator + value;
  1237. return str;
  1238. },
  1239. // get value type and convert value due to type, since all stored values are String
  1240. restoreDataFromString: function(str) {
  1241. var value = str,
  1242. type,
  1243. separatorStartIndex;
  1244. // @TODO: remove this line much later. Support of old format for options
  1245. str = this.backCompatibility(str);
  1246. if(typeof str === 'string') {
  1247. separatorStartIndex = str.indexOf(this.separator);
  1248. type = str.substring(0, separatorStartIndex);
  1249. value = str.substring(separatorStartIndex + this.separator.length);
  1250. switch(type) {
  1251. case 'boolean':
  1252. value = value === 'true';
  1253. break;
  1254. case 'number':
  1255. value = parseFloat(value);
  1256. break;
  1257. // we assume that we will store string values only, due to performance
  1258. case 'array':
  1259. value = value === '' ? [] : value.split(',');
  1260. break;
  1261. case 'null':
  1262. value = null;
  1263. break;
  1264. case 'undefined':
  1265. value = undefined;
  1266. break;
  1267. }
  1268. }
  1269. return value;
  1270. },
  1271. // old data type support
  1272. // here we trying to convert data from old format into new
  1273. // @TODO: remove this function much later
  1274. backCompatibility: function(str) {
  1275. var convertedStr = str,
  1276. value,
  1277. separatorStartIndex;
  1278. if(typeof str === 'string') {
  1279. separatorStartIndex = str.indexOf(this.separator);
  1280. // is it old format?
  1281. if(separatorStartIndex < 0) {
  1282. // try to get number from string
  1283. value = parseFloat(str);
  1284. // is it not a number?
  1285. if(isNaN(value)) {
  1286. // yes, this is not a number. Lets check is this is an array "[comma,separated,values]"
  1287. if((str[0] === '[') && (str[str.length - 1] === ']')) {
  1288. // this is an array. Lets remove brackets symbols and extract the words
  1289. str = str.replace('[', '');
  1290. str = str.replace(']', '');
  1291. if(str === '') {
  1292. value = [];
  1293. } else {
  1294. value = str.split(',');
  1295. }
  1296. // value = str === '[]' ? [] : str.split(',');
  1297. } else if(str === 'true' || str === 'false') {
  1298. // this is boolean value
  1299. value = str === 'true';
  1300. } else {
  1301. // this is string
  1302. value = str;
  1303. }
  1304. }
  1305. convertedStr = this.convertDataToString(value);
  1306. }
  1307. }
  1308. return convertedStr;
  1309. }
  1310. };
  1311. var LocalStorage = {
  1312. get: function( key ) {
  1313. var value = DataTypeManager.restoreDataFromString( window.localStorage.getItem(key) );
  1314. return value;
  1315. },
  1316. set: function( key, value ) {
  1317. var _value = DataTypeManager.convertDataToString( value );
  1318. window.localStorage.setItem( key, _value );
  1319. },
  1320. del: function( key ) {
  1321. window.localStorage.removeItem( key );
  1322. },
  1323. clear: function() {
  1324. window.localStorage.clear();
  1325. }
  1326. };
  1327. var CookiesStorage = {
  1328. expiration: (function() {
  1329. return 60 * 60 * 24 * 366;
  1330. }()),
  1331. get: function(key) {
  1332. var value = DataTypeManager.restoreDataFromString(this.getCookie(key));
  1333. return value;
  1334. },
  1335. set: function(key, value) {
  1336. var _value = DataTypeManager.convertDataToString(value);
  1337. this.setCookie(key, _value, {expires: this.expiration});
  1338. },
  1339. del: function(key) {
  1340. this.deleteCookie(key);
  1341. },
  1342. getCookie: function(name) {
  1343. var matches = document.cookie.match(new RegExp("(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"));
  1344. return matches ? decodeURIComponent(matches[1]) : undefined;
  1345. },
  1346. setCookie: function(name, value, props) {
  1347. props = props || {};
  1348. var exp = props.expires;
  1349. if (typeof exp === "number" && exp) {
  1350. var d = new Date();
  1351. d.setTime(d.getTime() + exp * 1000);
  1352. exp = props.expires = d;
  1353. }
  1354. if(exp && exp.toUTCString) {
  1355. props.expires = exp.toUTCString();
  1356. }
  1357. value = encodeURIComponent(value);
  1358. var updatedCookie = name + "=" + value;
  1359. for(var propName in props) {
  1360. var propValue = props[propName];
  1361. updatedCookie += "; " + propName;
  1362. if(propValue !== true) {
  1363. updatedCookie += "=" + propValue;
  1364. }
  1365. }
  1366. document.cookie = updatedCookie;
  1367. },
  1368. deleteCookie: function(name) {
  1369. this.setCookie(name, null, {expires: -1});
  1370. },
  1371. // delete all cookies
  1372. clear: function() {
  1373. var cookies = document.cookie.split(";");
  1374. for (var i = 0; i < cookies.length; i++) {
  1375. var cookie = cookies[i];
  1376. var eqPos = cookie.indexOf("=");
  1377. var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
  1378. this.deleteCookie(name);
  1379. }
  1380. }
  1381. };
  1382. var strategy = window.localStorage ? LocalStorage : CookiesStorage;
  1383. var DataStorage = {
  1384. // Get data within storage for key
  1385. getData: function( key ) {
  1386. return strategy.get( key );
  1387. },
  1388. // Set data within storage
  1389. setData: function( key, value ) {
  1390. strategy.set( key, value );
  1391. },
  1392. // Delete data within storage for key
  1393. deleteData: function( key ) {
  1394. strategy.del( key );
  1395. },
  1396. // Clear storage
  1397. clear: function() {
  1398. strategy.clear();
  1399. }
  1400. };
  1401. // Static Module of Storage Data in the localStorage.
  1402. object.DataStorage = DataStorage;
  1403. }( editor.wsc ));
  1404. editor.wsc.operationWithUDN = function(command, UDName) {
  1405. var obj = {
  1406. 'udn': UDName,
  1407. 'id': 'operationWithUDN',
  1408. 'udnCmd': command
  1409. };
  1410. var currentTabId = NS.dialog._.currentTabId,
  1411. frameId = NS.iframeNumber + '_' + currentTabId;
  1412. appTools.postMessage.send({
  1413. 'message': obj,
  1414. 'target': NS.targetFromFrame[frameId]
  1415. });
  1416. };
  1417. editor.wsc.getLocalStorageUDN = function() {
  1418. var udn = editor.wsc.DataStorage.getData('scayt_user_dictionary_name');
  1419. if (!udn) {
  1420. return;
  1421. }
  1422. return udn;
  1423. };
  1424. editor.wsc.getLocalStorageUD = function() {
  1425. var ud = editor.wsc.DataStorage.getData('scayt_user_dictionary');
  1426. if (!ud) {
  1427. return;
  1428. }
  1429. return ud;
  1430. };
  1431. editor.wsc.addWords = function(words, callback) {
  1432. var url = editor.config.wsc.DefaultParams.serviceHost + editor.config.wsc.DefaultParams.ssrvHost +
  1433. '?cmd=dictionary&format=json&' +
  1434. 'customerid=1%3AncttD3-fIoSf2-huzwE4-Y5muI2-mD0Tt-kG9Wz-UEDFC-tYu243-1Uq474-d9Z2l3&' +
  1435. 'action=addword&word='+ words + '&callback=toString&synchronization=true',
  1436. script = document.createElement('script');
  1437. script['type'] = 'text/javascript';
  1438. script['src'] = url;
  1439. document.getElementsByTagName("head")[0].appendChild(script);
  1440. //chrome, firefox, safari
  1441. script.onload = callback;
  1442. //IE
  1443. script.onreadystatechange = function() {
  1444. if (this.readyState === 'loaded') {
  1445. callback();
  1446. }
  1447. };
  1448. };
  1449. editor.wsc.cgiOrigin = function() {
  1450. var wscServiceHostString = editor.config.wsc.DefaultParams.serviceHost,
  1451. wscServiceHostArray = wscServiceHostString.split('/'),
  1452. cgiOrigin = wscServiceHostArray[0] + '//' + wscServiceHostArray[2];
  1453. return cgiOrigin;
  1454. };
  1455. editor.wsc.isSsrvSame = false;
  1456. }
  1457. return {
  1458. title: editor.config.wsc_dialogTitle || editor.lang.wsc.title,
  1459. minWidth: constraints.minWidth,
  1460. minHeight: constraints.minHeight,
  1461. buttons: [CKEDITOR.dialog.cancelButton],
  1462. onLoad: function() {
  1463. NS.dialog = this;
  1464. hideThesaurusTab();
  1465. hideGrammTab();
  1466. showSpellTab();
  1467. //creating wsc object for UD synchronization between wsc and scayt
  1468. if (editor.plugins.scayt) {
  1469. createWscObjectForUdAndUdnSyncrhonization();
  1470. }
  1471. },
  1472. onShow: function() {
  1473. NS.dialog = this;
  1474. editor.lockSelection(editor.getSelection());
  1475. NS.TextAreaNumber = 'cke_textarea_' + editor.name;
  1476. appTools.postMessage.init(handlerIncomingData);
  1477. NS.dataTemp = editor.getData();
  1478. //NS.div_overlay.setDisable();
  1479. NS.OverlayPlace = NS.dialog.parts.tabs.getParent().$;
  1480. if(CKEDITOR && CKEDITOR.config){
  1481. NS.wsc_customerId = editor.config.wsc_customerId;
  1482. NS.cust_dic_ids = editor.config.wsc_customDictionaryIds;
  1483. NS.userDictionaryName = editor.config.wsc_userDictionaryName;
  1484. NS.defaultLanguage = CKEDITOR.config.defaultLanguage;
  1485. var protocol = document.location.protocol == "file:" ? "http:" : document.location.protocol;
  1486. var wscCoreUrl = editor.config.wsc_customLoaderScript || ( protocol + '//loader.webspellchecker.net/sproxy_fck/sproxy.php?plugin=fck2&customerid=' + NS.wsc_customerId + '&cmd=script&doc=wsc&schema=22');
  1487. } else {
  1488. NS.dialog.hide();
  1489. return;
  1490. }
  1491. initView(this);
  1492. CKEDITOR.scriptLoader.load(wscCoreUrl, function(success) {
  1493. if(CKEDITOR.config && CKEDITOR.config.wsc && CKEDITOR.config.wsc.DefaultParams){
  1494. NS.serverLocationHash = CKEDITOR.config.wsc.DefaultParams.serviceHost;
  1495. NS.logotype = CKEDITOR.config.wsc.DefaultParams.logoPath;
  1496. NS.loadIcon = CKEDITOR.config.wsc.DefaultParams.iconPath;
  1497. NS.loadIconEmptyEditor = CKEDITOR.config.wsc.DefaultParams.iconPathEmptyEditor;
  1498. NS.LangComparer = new CKEDITOR.config.wsc.DefaultParams._SP_FCK_LangCompare();
  1499. }else{
  1500. NS.serverLocationHash = DefaultParams.serviceHost;
  1501. NS.logotype = DefaultParams.logoPath;
  1502. NS.loadIcon = DefaultParams.iconPath;
  1503. NS.loadIconEmptyEditor = DefaultParams.iconPathEmptyEditor;
  1504. NS.LangComparer = new _SP_FCK_LangCompare();
  1505. }
  1506. NS.pluginPath = CKEDITOR.getUrl(editor.plugins.wsc.path);
  1507. NS.iframeNumber = NS.TextAreaNumber;
  1508. NS.templatePath = NS.pluginPath + 'dialogs/tmp.html';
  1509. NS.LangComparer.setDefaulLangCode( NS.defaultLanguage );
  1510. NS.currentLang = editor.config.wsc_lang || NS.LangComparer.getSPLangCode( editor.langCode ) || 'en_US';
  1511. NS.selectingLang = NS.currentLang;
  1512. NS.div_overlay = new overlayBlock({
  1513. opacity: "1",
  1514. background: "#fff url(" + NS.loadIcon + ") no-repeat 50% 50%",
  1515. target: NS.OverlayPlace
  1516. });
  1517. var number_ck = NS.dialog.parts.tabs.getId(),
  1518. dialogPartsTab = CKEDITOR.document.getById(number_ck);
  1519. dialogPartsTab.setStyle('width', '97%');
  1520. if (!dialogPartsTab.getElementsByTag('DIV').count()){
  1521. dialogPartsTab.append(NS.buildSelectLang(NS.dialog.getParentEditor().name));
  1522. }
  1523. NS.div_overlay_no_check = new overlayBlock({
  1524. opacity: "1",
  1525. id: 'no_check_over',
  1526. background: "#fff url(" + NS.loadIconEmptyEditor + ") no-repeat 50% 50%",
  1527. target: NS.OverlayPlace
  1528. });
  1529. if (success) {
  1530. showFirstTab(NS.dialog);
  1531. NS.dialog.setupContent(NS.dialog);
  1532. }
  1533. if (editor.plugins.scayt) {
  1534. //is ssrv.cgi path for WSC and scayt same
  1535. editor.wsc.isSsrvSame = (function() {
  1536. var wscSsrvWholePath,
  1537. wscServiceHost = CKEDITOR.config.wsc.DefaultParams.serviceHost.replace('lf/22/js/../../../', '').split('//')[1],
  1538. wscSsrvHost = CKEDITOR.config.wsc.DefaultParams.ssrvHost,
  1539. scaytSsrvWholePath,
  1540. scaytSsrvProtocol,
  1541. scaytSsrvHost,
  1542. scaytSsrvPath,
  1543. scaytSrcUrl = editor.config.scayt_srcUrl,
  1544. scaytSsrvSrcUrlSsrvProtocol,
  1545. scaytSsrvSrcUrlSsrvHost,
  1546. scaytSsrvSrcUrlSsrvPath,
  1547. scaytBasePath,
  1548. scaytBasePathSsrvProtocol,
  1549. scaytBasePathSsrvHost,
  1550. scaytBasePathSsrvPath;
  1551. if (window.SCAYT && window.SCAYT.CKSCAYT) {
  1552. scaytBasePath = SCAYT.CKSCAYT.prototype.basePath;
  1553. scaytBasePathSsrvProtocol = scaytBasePath.split('//')[0];
  1554. scaytBasePathSsrvHost = scaytBasePath.split('//')[1].split('/')[0];
  1555. scaytBasePathSsrvPath = scaytBasePath.split(scaytBasePathSsrvHost + '/')[1].replace('/lf/scayt3/ckscayt/', '') + '/script/ssrv.cgi';
  1556. }
  1557. if (scaytSrcUrl && !scaytBasePath && !editor.config.scayt_servicePath) {
  1558. scaytSsrvSrcUrlSsrvProtocol = scaytSrcUrl.split('//')[0];
  1559. scaytSsrvSrcUrlSsrvHost = scaytSrcUrl.split('//')[1].split('/')[0];
  1560. scaytSsrvSrcUrlSsrvPath = scaytSrcUrl.split(scaytSsrvSrcUrlSsrvHost + '/')[1].replace('/lf/scayt3/ckscayt/ckscayt.js', '') + '/script/ssrv.cgi';
  1561. }
  1562. scaytSsrvProtocol = editor.config.scayt_serviceProtocol || scaytBasePathSsrvProtocol || scaytSsrvSrcUrlSsrvProtocol;
  1563. scaytSsrvHost = editor.config.scayt_serviceHost || scaytBasePathSsrvHost || scaytSsrvSrcUrlSsrvHost;
  1564. scaytSsrvPath = editor.config.scayt_servicePath || scaytBasePathSsrvPath || scaytSsrvSrcUrlSsrvPath;
  1565. wscSsrvWholePath = '//' + wscServiceHost + wscSsrvHost;
  1566. scaytSsrvWholePath = '//' + scaytSsrvHost + '/' + scaytSsrvPath;
  1567. return wscSsrvWholePath === scaytSsrvWholePath;
  1568. })();
  1569. }
  1570. //wsc on scayt UserDictionary and UserDictionaryName synchronization
  1571. if (window.SCAYT && editor.wsc && editor.wsc.isSsrvSame) {
  1572. var cgiOrigin = editor.wsc.cgiOrigin();
  1573. editor.wsc.syncIsDone = false;
  1574. var getUdOrUdn = function (e) {
  1575. if (e.origin === cgiOrigin) {
  1576. var data = JSON.parse(e.data);
  1577. if (data.ud && data.ud !== 'undefined') {
  1578. editor.wsc.ud = data.ud;
  1579. } else if (data.ud === 'undefined') {
  1580. editor.wsc.ud = undefined;
  1581. }
  1582. if (data.udn && data.udn !== 'undefined') {
  1583. editor.wsc.udn = data.udn;
  1584. } else if (data.udn === 'undefined') {
  1585. editor.wsc.udn = undefined;
  1586. }
  1587. if (!editor.wsc.syncIsDone) {
  1588. udSynchronization(editor.wsc.ud);
  1589. editor.wsc.syncIsDone = true;
  1590. }
  1591. }
  1592. };
  1593. var udSynchronization = function(cookieUd) {
  1594. var localStorageUdArray = editor.wsc.getLocalStorageUD(),
  1595. newUd;
  1596. if (localStorageUdArray instanceof Array) {
  1597. newUd = localStorageUdArray.toString();
  1598. }
  1599. if (newUd !== undefined && newUd !== '') {
  1600. setTimeout(function() {
  1601. editor.wsc.addWords(newUd, function() {
  1602. showFirstTab(NS.dialog);
  1603. NS.dialog.setupContent(NS.dialog);
  1604. });
  1605. }, 400);
  1606. }
  1607. };
  1608. if (window.addEventListener){
  1609. addEventListener("message", getUdOrUdn, false);
  1610. } else {
  1611. window.attachEvent("onmessage", getUdOrUdn);
  1612. }
  1613. //wsc on scayt UserDictionaryName synchronization
  1614. setTimeout(
  1615. function() {
  1616. var udn = editor.wsc.getLocalStorageUDN();
  1617. if (udn !== undefined) {
  1618. editor.wsc.operationWithUDN('restore', udn);
  1619. }
  1620. },
  1621. 500); //need to wait spell.js file to load
  1622. }
  1623. });
  1624. },
  1625. onHide: function() {
  1626. var scaytPlugin = CKEDITOR.plugins.scayt,
  1627. scaytInstance = editor.scayt;
  1628. editor.unlockSelection();
  1629. if(scaytPlugin && scaytInstance && scaytPlugin.state[editor.name]) {
  1630. scaytInstance.setMarkupPaused(false);
  1631. }
  1632. NS.dataTemp = '';
  1633. NS.sessionid = '';
  1634. appTools.postMessage.unbindHandler(handlerIncomingData);
  1635. //scayt on wsc UserDictionary and UserDictionaryName synchronization
  1636. if (editor.plugins.scayt && editor.wsc && editor.wsc.isSsrvSame) {
  1637. var wscUDN = editor.wsc.udn,
  1638. wscUD = editor.wsc.ud,
  1639. wscUDarray,
  1640. i;
  1641. if (editor.scayt) { // if SCAYT active
  1642. if (!wscUDN) {
  1643. editor.wsc.DataStorage.setData('scayt_user_dictionary_name', '');
  1644. editor.scayt.removeUserDictionary();
  1645. } else {
  1646. editor.wsc.DataStorage.setData('scayt_user_dictionary_name', wscUDN);
  1647. editor.scayt.restoreUserDictionary(wscUDN);
  1648. }
  1649. if (wscUD) {
  1650. setTimeout(function() {
  1651. wscUDarray = wscUD.split(',');
  1652. for (i = 0; i < wscUDarray.length; i += 1) {
  1653. editor.scayt.addWordToUserDictionary(wscUDarray[i]);
  1654. }
  1655. }, 200); //wait for 'removeUserDictionary' command response
  1656. }
  1657. if (!wscUD) {
  1658. editor.wsc.DataStorage.setData('scayt_user_dictionary', []);
  1659. }
  1660. } else { //if SCAYT not active
  1661. if (!wscUDN) {
  1662. editor.wsc.DataStorage.setData('scayt_user_dictionary_name', '');
  1663. } else {
  1664. editor.wsc.DataStorage.setData('scayt_user_dictionary_name', wscUDN);
  1665. }
  1666. if (wscUD) {
  1667. wscUDarray = wscUD.split(',');
  1668. editor.wsc.DataStorage.setData('scayt_user_dictionary', wscUDarray);
  1669. }
  1670. }
  1671. }
  1672. },
  1673. contents: [
  1674. {
  1675. id: 'SpellTab',
  1676. label: 'SpellChecker',
  1677. accessKey: 'S',
  1678. elements: [
  1679. {
  1680. type: 'html',
  1681. id: 'banner',
  1682. label: 'banner',
  1683. style: '', //TODO
  1684. html: '<div></div>'
  1685. },
  1686. {
  1687. type: 'html',
  1688. id: 'Content',
  1689. label: 'spellContent',
  1690. html: '',
  1691. setup: function(dialog) {
  1692. var tabId = NS.iframeNumber + '_' + dialog._.currentTabId;
  1693. var iframe = document.getElementById(tabId);
  1694. NS.targetFromFrame[tabId] = iframe.contentWindow;
  1695. }
  1696. },
  1697. {
  1698. type: 'hbox',
  1699. id: 'bottomGroup',
  1700. style: 'width:560px; margin: 0 auto;',
  1701. widths: ['50%', '50%'],
  1702. children: [
  1703. {
  1704. type: 'hbox',
  1705. id: 'leftCol',
  1706. align: 'left',
  1707. width: '50%',
  1708. children: [
  1709. {
  1710. type: 'vbox',
  1711. id: 'rightCol1',
  1712. widths: ['50%', '50%'],
  1713. children: [
  1714. {
  1715. type: 'text',
  1716. id: 'ChangeTo_label',
  1717. label: NS.LocalizationLabel['ChangeTo_label'].text + ':',
  1718. labelLayout: 'horizontal',
  1719. labelStyle: 'font: 12px/25px arial, sans-serif;',
  1720. width: '140px',
  1721. 'default': '',
  1722. onShow: function() {
  1723. NS.textNode['SpellTab'] = this;
  1724. NS.LocalizationLabel['ChangeTo_label'].instance = this;
  1725. },
  1726. onHide: function() {
  1727. this.reset();
  1728. }
  1729. },
  1730. {
  1731. type: 'hbox',
  1732. id: 'rightCol',
  1733. align: 'right',
  1734. width: '30%',
  1735. children: [
  1736. {
  1737. type: 'vbox',
  1738. id: 'rightCol_col__left',
  1739. children: [
  1740. {
  1741. type: 'text',
  1742. id: 'labelSuggestions',
  1743. label: NS.LocalizationLabel['Suggestions'].text + ':',
  1744. onShow: function() {
  1745. NS.LocalizationLabel['Suggestions'].instance = this;
  1746. this.getInputElement().setStyles({
  1747. display: 'none'
  1748. });
  1749. }
  1750. },
  1751. {
  1752. type: 'html',
  1753. id: 'logo',
  1754. html: '<img width="99" height="68" border="0" src="" title="WebSpellChecker.net" alt="WebSpellChecker.net" style="display: inline-block;">',
  1755. setup: function(dialog) {
  1756. this.getElement().$.src = NS.logotype;
  1757. this.getElement().getParent().setStyles({
  1758. "text-align": "left"
  1759. });
  1760. }
  1761. }
  1762. ]
  1763. },
  1764. {
  1765. type: 'select',
  1766. id: 'list_of_suggestions',
  1767. labelStyle: 'font: 12px/25px arial, sans-serif;',
  1768. size: '6',
  1769. inputStyle: 'width: 140px; height: auto;',
  1770. items: [['loading...']],
  1771. onShow: function() {
  1772. selectNode = this;
  1773. },
  1774. onChange: function() {
  1775. NS.textNode['SpellTab'].setValue(this.getValue());
  1776. }
  1777. }
  1778. ]
  1779. }
  1780. ]
  1781. }
  1782. ]
  1783. },
  1784. {
  1785. type: 'hbox',
  1786. id: 'rightCol',
  1787. align: 'right',
  1788. width: '50%',
  1789. children: [
  1790. {
  1791. type: 'vbox',
  1792. id: 'rightCol_col__left',
  1793. widths: ['50%', '50%', '50%', '50%'],
  1794. children: [
  1795. {
  1796. type: 'button',
  1797. id: 'ChangeTo_button',
  1798. label: NS.LocalizationButton['ChangeTo_button'].text,
  1799. title: 'Change to',
  1800. style: 'width: 100%;',
  1801. onLoad: function() {
  1802. this.getElement().setAttribute("title-cmd", 'ChangeTo');
  1803. NS.LocalizationButton['ChangeTo_button'].instance = this;
  1804. },
  1805. onClick: handlerButtons
  1806. },
  1807. {
  1808. type: 'button',
  1809. id: 'ChangeAll',
  1810. label: NS.LocalizationButton['ChangeAll'].text,
  1811. title: 'Change All',
  1812. style: 'width: 100%;',
  1813. onLoad: function() {
  1814. this.getElement().setAttribute("title-cmd", this.id);
  1815. NS.LocalizationButton['ChangeAll'].instance = this;
  1816. },
  1817. onClick: handlerButtons
  1818. },
  1819. {
  1820. type: 'button',
  1821. id: 'AddWord',
  1822. label: NS.LocalizationButton['AddWord'].text,
  1823. title: 'Add word',
  1824. style: 'width: 100%;',
  1825. onLoad: function() {
  1826. this.getElement().setAttribute("title-cmd", this.id);
  1827. NS.LocalizationButton['AddWord'].instance = this;
  1828. },
  1829. onClick: handlerButtons
  1830. },
  1831. {
  1832. type: 'button',
  1833. id: 'FinishChecking_button',
  1834. label: NS.LocalizationButton['FinishChecking_button'].text,
  1835. title: 'Finish Checking',
  1836. style: 'width: 100%;margin-top: 9px;',
  1837. onLoad: function() {
  1838. this.getElement().setAttribute("title-cmd", 'FinishChecking');
  1839. NS.LocalizationButton['FinishChecking_button'].instance = this;
  1840. },
  1841. onClick: handlerButtons
  1842. }
  1843. ]
  1844. },
  1845. {
  1846. type: 'vbox',
  1847. id: 'rightCol_col__right',
  1848. widths: ['50%', '50%', '50%'],
  1849. children: [
  1850. {
  1851. type: 'button',
  1852. id: 'IgnoreWord',
  1853. label: NS.LocalizationButton['IgnoreWord'].text,
  1854. title: 'Ignore word',
  1855. style: 'width: 100%;',
  1856. onLoad: function() {
  1857. this.getElement().setAttribute("title-cmd", this.id);
  1858. NS.LocalizationButton['IgnoreWord'].instance = this;
  1859. },
  1860. onClick: handlerButtons
  1861. },
  1862. {
  1863. type: 'button',
  1864. id: 'IgnoreAllWords',
  1865. label: NS.LocalizationButton['IgnoreAllWords'].text,
  1866. title: 'Ignore all words',
  1867. style: 'width: 100%;',
  1868. onLoad: function() {
  1869. this.getElement().setAttribute("title-cmd", this.id);
  1870. NS.LocalizationButton['IgnoreAllWords'].instance = this;
  1871. },
  1872. onClick: handlerButtons
  1873. },
  1874. {
  1875. type: 'button',
  1876. id: 'Options',
  1877. label: NS.LocalizationButton['Options'].text,
  1878. title: 'Option',
  1879. style: 'width: 100%;',
  1880. onLoad: function() {
  1881. NS.LocalizationButton['Options'].instance = this;
  1882. if (document.location.protocol == "file:") {
  1883. this.disable();
  1884. }
  1885. },
  1886. onClick: function() {
  1887. // because in chrome and safary document.activeElement returns <body> tag. We need to signal that clicked element is active
  1888. this.getElement().focus();
  1889. if (document.location.protocol == "file:") {
  1890. alert('WSC: Options functionality is disabled when runing from file system');
  1891. } else {
  1892. activeElement = document.activeElement;
  1893. editor.openDialog('options');
  1894. }
  1895. }
  1896. }
  1897. ]
  1898. }
  1899. ]
  1900. }
  1901. ]
  1902. },
  1903. {
  1904. type: 'hbox',
  1905. id: 'BlockFinishChecking',
  1906. style: 'width:560px; margin: 0 auto;',
  1907. widths: ['70%', '30%'],
  1908. onShow: function() {
  1909. this.getElement().setStyles({
  1910. display: 'block',
  1911. position: 'absolute',
  1912. left: '-9999px'
  1913. });
  1914. },
  1915. onHide: showCurrentTabs,
  1916. children: [
  1917. {
  1918. type: 'hbox',
  1919. id: 'leftCol',
  1920. align: 'left',
  1921. width: '70%',
  1922. children: [
  1923. {
  1924. type: 'vbox',
  1925. id: 'rightCol1',
  1926. setup: function() {
  1927. this.getChild()[0].getElement().$.src = NS.logotype;
  1928. this.getChild()[0].getElement().getParent().setStyles({
  1929. "text-align": "center"
  1930. });
  1931. },
  1932. children: [
  1933. {
  1934. type: 'html',
  1935. id: 'logo',
  1936. html: '<img width="99" height="68" border="0" src="" title="WebSpellChecker.net" alt="WebSpellChecker.net" style="display: inline-block;">'
  1937. }
  1938. ]
  1939. }
  1940. ]
  1941. },
  1942. {
  1943. type: 'hbox',
  1944. id: 'rightCol',
  1945. align: 'right',
  1946. width: '30%',
  1947. children: [
  1948. {
  1949. type: 'vbox',
  1950. id: 'rightCol_col__left',
  1951. children: [
  1952. {
  1953. type: 'button',
  1954. id: 'Option_button',
  1955. label: NS.LocalizationButton['Options'].text,
  1956. title: 'Option',
  1957. style: 'width: 100%;',
  1958. onLoad: function() {
  1959. this.getElement().setAttribute("title-cmd", this.id);
  1960. if (document.location.protocol == "file:") {
  1961. this.disable();
  1962. }
  1963. },
  1964. onClick: function() {
  1965. // because in chrome and safary document.activeElement returns <body> tag. We need to signal that clicked element is active
  1966. this.getElement().focus();
  1967. if (document.location.protocol == "file:") {
  1968. alert('WSC: Options functionality is disabled when runing from file system');
  1969. } else {
  1970. activeElement = document.activeElement;
  1971. editor.openDialog('options');
  1972. }
  1973. }
  1974. },
  1975. {
  1976. type: 'button',
  1977. id: 'FinishChecking_button_block',
  1978. label: NS.LocalizationButton['FinishChecking_button_block'].text,
  1979. title: 'Finish Checking',
  1980. style: 'width: 100%;',
  1981. onLoad: function() {
  1982. this.getElement().setAttribute("title-cmd", 'FinishChecking');
  1983. },
  1984. onClick: handlerButtons
  1985. }
  1986. ]
  1987. }
  1988. ]
  1989. }
  1990. ]
  1991. }
  1992. ]
  1993. },
  1994. {
  1995. id: 'GrammTab',
  1996. label: 'Grammar',
  1997. accessKey: 'G',
  1998. elements: [
  1999. {
  2000. type: 'html',
  2001. id: 'banner',
  2002. label: 'banner',
  2003. style: '', //TODO
  2004. html: '<div></div>'
  2005. },
  2006. {
  2007. type: 'html',
  2008. id: 'Content',
  2009. label: 'GrammarContent',
  2010. html: '',
  2011. setup: function() {
  2012. var tabId = NS.iframeNumber + '_' + NS.dialog._.currentTabId;
  2013. var iframe = document.getElementById(tabId);
  2014. NS.targetFromFrame[tabId] = iframe.contentWindow;
  2015. }
  2016. },
  2017. {
  2018. type: 'vbox',
  2019. id: 'bottomGroup',
  2020. style: 'width:560px; margin: 0 auto;',
  2021. children: [
  2022. {
  2023. type: 'hbox',
  2024. id: 'leftCol',
  2025. widths: ['66%', '34%'],
  2026. children: [
  2027. {
  2028. type: 'vbox',
  2029. children: [
  2030. {
  2031. type: 'text',
  2032. id: 'text',
  2033. label: "Change to:",
  2034. labelLayout: 'horizontal',
  2035. labelStyle: 'font: 12px/25px arial, sans-serif;',
  2036. inputStyle: 'float: right; width: 200px;',
  2037. 'default': '',
  2038. onShow: function() {
  2039. NS.textNode['GrammTab'] = this;
  2040. },
  2041. onHide: function() {
  2042. this.reset();
  2043. }
  2044. },
  2045. {
  2046. type: 'html',
  2047. id: 'html_text',
  2048. html: "<div style='min-height: 17px; line-height: 17px; padding: 5px; text-align: left;background: #F1F1F1;color: #595959; white-space: normal!important;'></div>",
  2049. onShow: function(e) {
  2050. NS.textNodeInfo['GrammTab'] = this;
  2051. }
  2052. },
  2053. {
  2054. type: 'html',
  2055. id: 'radio',
  2056. html: "",
  2057. onShow: function() {
  2058. NS.grammerSuggest = this;
  2059. }
  2060. }
  2061. ]
  2062. },
  2063. {
  2064. type: 'vbox',
  2065. children: [
  2066. {
  2067. type: 'button',
  2068. id: 'ChangeTo_button',
  2069. label: 'Change to',
  2070. title: 'Change to',
  2071. style: 'width: 133px; float: right;',
  2072. onLoad: function() {
  2073. this.getElement().setAttribute("title-cmd", 'ChangeTo');
  2074. },
  2075. onClick: handlerButtons
  2076. },
  2077. {
  2078. type: 'button',
  2079. id: 'IgnoreWord',
  2080. label: 'Ignore word',
  2081. title: 'Ignore word',
  2082. style: 'width: 133px; float: right;',
  2083. onLoad: function() {
  2084. this.getElement().setAttribute("title-cmd", this.id);
  2085. },
  2086. onClick: handlerButtons
  2087. },
  2088. {
  2089. type: 'button',
  2090. id: 'IgnoreAllWords',
  2091. label: 'Ignore Problem',
  2092. title: 'Ignore Problem',
  2093. style: 'width: 133px; float: right;',
  2094. onLoad: function() {
  2095. this.getElement().setAttribute("title-cmd", this.id);
  2096. },
  2097. onClick: handlerButtons
  2098. },
  2099. {
  2100. type: 'button',
  2101. id: 'FinishChecking_button',
  2102. label: NS.LocalizationButton['FinishChecking_button'].text,
  2103. title: 'Finish Checking',
  2104. style: 'width: 133px; float: right; margin-top: 9px;',
  2105. onLoad: function() {
  2106. this.getElement().setAttribute("title-cmd", 'FinishChecking');
  2107. },
  2108. onClick: handlerButtons
  2109. }
  2110. ]
  2111. }
  2112. ]
  2113. }
  2114. ]
  2115. },
  2116. {
  2117. type: 'hbox',
  2118. id: 'BlockFinishChecking',
  2119. style: 'width:560px; margin: 0 auto;',
  2120. widths: ['70%', '30%'],
  2121. onShow: function() {
  2122. this.getElement().setStyles({
  2123. display: 'block',
  2124. position: 'absolute',
  2125. left: '-9999px'
  2126. });
  2127. },
  2128. onHide: showCurrentTabs,
  2129. children: [
  2130. {
  2131. type: 'hbox',
  2132. id: 'leftCol',
  2133. align: 'left',
  2134. width: '70%',
  2135. children: [
  2136. {
  2137. type: 'vbox',
  2138. id: 'rightCol1',
  2139. children: [
  2140. {
  2141. type: 'html',
  2142. id: 'logo',
  2143. html: '<img width="99" height="68" border="0" src="" title="WebSpellChecker.net" alt="WebSpellChecker.net" style="display: inline-block;">',
  2144. setup: function() {
  2145. this.getElement().$.src = NS.logotype;
  2146. this.getElement().getParent().setStyles({
  2147. "text-align": "center"
  2148. });
  2149. }
  2150. }
  2151. ]
  2152. }
  2153. ]
  2154. },
  2155. {
  2156. type: 'hbox',
  2157. id: 'rightCol',
  2158. align: 'right',
  2159. width: '30%',
  2160. children: [
  2161. {
  2162. type: 'vbox',
  2163. id: 'rightCol_col__left',
  2164. children: [
  2165. {
  2166. type: 'button',
  2167. id: 'FinishChecking_button_block',
  2168. label: NS.LocalizationButton['FinishChecking_button_block'].text,
  2169. title: 'Finish Checking',
  2170. style: 'width: 100%;',
  2171. onLoad: function() {
  2172. this.getElement().setAttribute("title-cmd", 'FinishChecking');
  2173. },
  2174. onClick: handlerButtons
  2175. }
  2176. ]
  2177. }
  2178. ]
  2179. }
  2180. ]
  2181. }
  2182. ]
  2183. },
  2184. {
  2185. id: 'Thesaurus',
  2186. label: 'Thesaurus',
  2187. accessKey: 'T',
  2188. elements: [
  2189. {
  2190. type: 'html',
  2191. id: 'banner',
  2192. label: 'banner',
  2193. style: '', //TODO
  2194. html: '<div></div>'
  2195. },
  2196. {
  2197. type: 'html',
  2198. id: 'Content',
  2199. label: 'spellContent',
  2200. html: '',
  2201. setup: function() {
  2202. var tabId = NS.iframeNumber + '_' + NS.dialog._.currentTabId;
  2203. var iframe = document.getElementById(tabId);
  2204. NS.targetFromFrame[tabId] = iframe.contentWindow;
  2205. }
  2206. },
  2207. {
  2208. type: 'vbox',
  2209. id: 'bottomGroup',
  2210. style: 'width:560px; margin: -10px auto; overflow: hidden;',
  2211. children: [
  2212. {
  2213. type: 'hbox',
  2214. widths: ['75%', '25%'],
  2215. children: [
  2216. {
  2217. type: 'vbox',
  2218. children: [
  2219. {
  2220. type: 'hbox',
  2221. widths: ['65%', '35%'],
  2222. children: [
  2223. {
  2224. type: 'text',
  2225. id: 'ChangeTo_label',
  2226. label: NS.LocalizationLabel['ChangeTo_label'].text + ':',
  2227. labelLayout: 'horizontal',
  2228. inputStyle: 'width: 160px;',
  2229. labelStyle: 'font: 12px/25px arial, sans-serif;',
  2230. 'default': '',
  2231. onShow: function(e) {
  2232. NS.textNode['Thesaurus'] = this;
  2233. NS.LocalizationLabel['ChangeTo_label'].instance = this;
  2234. },
  2235. onHide: function() {
  2236. this.reset();
  2237. }
  2238. },
  2239. {
  2240. type: 'button',
  2241. id: 'ChangeTo_button',
  2242. label: NS.LocalizationButton['ChangeTo_button'].text,
  2243. title: 'Change to',
  2244. style: 'width: 121px; margin-top: 1px;',
  2245. onLoad: function() {
  2246. this.getElement().setAttribute("title-cmd", 'ChangeTo');
  2247. NS.LocalizationButton['ChangeTo_button'].instance = this;
  2248. },
  2249. onClick: handlerButtons
  2250. }
  2251. ]
  2252. },
  2253. {
  2254. type: 'hbox',
  2255. children: [
  2256. {
  2257. type: 'select',
  2258. id: 'Categories',
  2259. label: NS.LocalizationLabel['Categories'].text + ':',
  2260. labelStyle: 'font: 12px/25px arial, sans-serif;',
  2261. size: '5',
  2262. inputStyle: 'width: 180px; height: auto;',
  2263. items: [],
  2264. onShow: function() {
  2265. NS.selectNode['Categories'] = this;
  2266. NS.LocalizationLabel['Categories'].instance = this;
  2267. },
  2268. onChange: function() {
  2269. NS.buildOptionSynonyms(this.getValue());
  2270. }
  2271. },
  2272. {
  2273. type: 'select',
  2274. id: 'Synonyms',
  2275. label: NS.LocalizationLabel['Synonyms'].text + ':',
  2276. labelStyle: 'font: 12px/25px arial, sans-serif;',
  2277. size: '5',
  2278. inputStyle: 'width: 180px; height: auto;',
  2279. items: [],
  2280. onShow: function() {
  2281. NS.selectNode['Synonyms'] = this;
  2282. NS.textNode['Thesaurus'].setValue(this.getValue());
  2283. NS.LocalizationLabel['Synonyms'].instance = this;
  2284. },
  2285. onChange: function(e) {
  2286. NS.textNode['Thesaurus'].setValue(this.getValue());
  2287. }
  2288. }
  2289. ]
  2290. }
  2291. ]
  2292. },
  2293. {
  2294. type: 'vbox',
  2295. width: '120px',
  2296. style: "margin-top:46px;",
  2297. children: [
  2298. {
  2299. type: 'html',
  2300. id: 'logotype',
  2301. label: 'WebSpellChecker.net',
  2302. html: '<img width="99" height="68" border="0" src="" title="WebSpellChecker.net" alt="WebSpellChecker.net" style="display: inline-block;">',
  2303. setup: function() {
  2304. this.getElement().$.src = NS.logotype;
  2305. this.getElement().getParent().setStyles({
  2306. "text-align": "center"
  2307. });
  2308. }
  2309. },
  2310. {
  2311. type: 'button',
  2312. id: 'FinishChecking_button',
  2313. label: NS.LocalizationButton['FinishChecking_button'].text,
  2314. title: 'Finish Checking',
  2315. style: 'width: 100%; float: right; margin-top: 9px;',
  2316. onLoad: function() {
  2317. this.getElement().setAttribute("title-cmd", 'FinishChecking');
  2318. },
  2319. onClick: handlerButtons
  2320. }
  2321. ]
  2322. }
  2323. ]
  2324. }
  2325. ]
  2326. },
  2327. {
  2328. type: 'hbox',
  2329. id: 'BlockFinishChecking',
  2330. style: 'width:560px; margin: 0 auto;',
  2331. widths: ['70%', '30%'],
  2332. onShow: function() {
  2333. this.getElement().setStyles({
  2334. display: 'block',
  2335. position: 'absolute',
  2336. left: '-9999px'
  2337. });
  2338. },
  2339. children: [
  2340. {
  2341. type: 'hbox',
  2342. id: 'leftCol',
  2343. align: 'left',
  2344. width: '70%',
  2345. children: [
  2346. {
  2347. type: 'vbox',
  2348. id: 'rightCol1',
  2349. children: [
  2350. {
  2351. type: 'html',
  2352. id: 'logo',
  2353. html: '<img width="99" height="68" border="0" src="" title="WebSpellChecker.net" alt="WebSpellChecker.net" style="display: inline-block;">',
  2354. setup: function() {
  2355. this.getElement().$.src = NS.logotype;
  2356. this.getElement().getParent().setStyles({
  2357. "text-align": "center"
  2358. });
  2359. }
  2360. }
  2361. ]
  2362. }
  2363. ]
  2364. },
  2365. {
  2366. type: 'hbox',
  2367. id: 'rightCol',
  2368. align: 'right',
  2369. width: '30%',
  2370. children: [
  2371. {
  2372. type: 'vbox',
  2373. id: 'rightCol_col__left',
  2374. children: [
  2375. {
  2376. type: 'button',
  2377. id: 'FinishChecking_button_block',
  2378. label: NS.LocalizationButton['FinishChecking_button_block'].text,
  2379. title: 'Finish Checking',
  2380. style: 'width: 100%;',
  2381. onLoad: function() {
  2382. this.getElement().setAttribute("title-cmd", 'FinishChecking');
  2383. },
  2384. onClick: handlerButtons
  2385. }
  2386. ]
  2387. }
  2388. ]
  2389. }
  2390. ]
  2391. }
  2392. ]
  2393. }
  2394. ]
  2395. };
  2396. });
  2397. var activeElement = null;
  2398. // Options dialog
  2399. CKEDITOR.dialog.add('options', function(editor) {
  2400. var dialog = null;
  2401. var linkOnCheckbox = {};
  2402. var checkboxState = {};
  2403. var ospString = null;
  2404. var OptionsTextError = null;
  2405. var cmd = null;
  2406. var set_osp = [];
  2407. var dictionaryState = {
  2408. 'udn': appTools.cookie.get('udn'),
  2409. 'osp': appTools.cookie.get('osp')
  2410. };
  2411. var setHandlerOptions = function() {
  2412. var osp = appTools.cookie.get('osp'),
  2413. strToArr = osp.split("");
  2414. checkboxState['IgnoreAllCapsWords'] = strToArr[0];
  2415. checkboxState['IgnoreWordsNumbers'] = strToArr[1];
  2416. checkboxState['IgnoreMixedCaseWords'] = strToArr[2];
  2417. checkboxState['IgnoreDomainNames'] = strToArr[3];
  2418. };
  2419. var sendDicOptions = function(event) {
  2420. event = event || window.event;
  2421. cmd = this.getElement().getAttribute("title-cmd");
  2422. var osp = [];
  2423. osp[0] = checkboxState['IgnoreAllCapsWords'];
  2424. osp[1] = checkboxState['IgnoreWordsNumbers'];
  2425. osp[2] = checkboxState['IgnoreMixedCaseWords'];
  2426. osp[3] = checkboxState['IgnoreDomainNames'];
  2427. osp = osp.toString().replace(/,/g, "");
  2428. appTools.cookie.set('osp', osp);
  2429. appTools.cookie.set('udnCmd', cmd ? cmd : 'ignore');
  2430. if (cmd == "delete") {
  2431. appTools.postMessage.send({
  2432. 'id': 'options_dic_send'
  2433. });
  2434. } else {
  2435. var udn = '';
  2436. if(nameNode.getValue() !== ''){
  2437. udn = nameNode.getValue();
  2438. }
  2439. appTools.cookie.set('udn', udn);
  2440. appTools.postMessage.send({
  2441. 'id': 'options_dic_send'
  2442. });
  2443. }
  2444. };
  2445. var sendAllOptions = function() {
  2446. var osp = [];
  2447. osp[0] = checkboxState['IgnoreAllCapsWords'];
  2448. osp[1] = checkboxState['IgnoreWordsNumbers'];
  2449. osp[2] = checkboxState['IgnoreMixedCaseWords'];
  2450. osp[3] = checkboxState['IgnoreDomainNames'];
  2451. osp = osp.toString().replace(/,/g, "");
  2452. appTools.cookie.set('osp', osp);
  2453. appTools.postMessage.send({
  2454. 'id': 'options_checkbox_send'
  2455. });
  2456. };
  2457. var cameOptions = function() {
  2458. OptionsTextError.getElement().setHtml(NS.LocalizationComing['error']);
  2459. OptionsTextError.getElement().show();
  2460. };
  2461. return {
  2462. title: NS.LocalizationComing['Options'],
  2463. minWidth: 430,
  2464. minHeight: 130,
  2465. resizable: CKEDITOR.DIALOG_RESIZE_NONE,
  2466. contents: [
  2467. {
  2468. id: 'OptionsTab',
  2469. label: 'Options',
  2470. accessKey: 'O',
  2471. elements: [
  2472. {
  2473. type: 'hbox',
  2474. id: 'options_error',
  2475. children: [
  2476. {
  2477. type: 'html',
  2478. style: "display: block;text-align: center;white-space: normal!important; font-size: 12px;color:red",
  2479. html: '<div></div>',
  2480. onShow: function() {
  2481. OptionsTextError = this;
  2482. }
  2483. }
  2484. ]
  2485. },
  2486. {
  2487. type: 'vbox',
  2488. id: 'Options_content',
  2489. children: [
  2490. {
  2491. type: 'hbox',
  2492. id: 'Options_manager',
  2493. widths: ['52%', '48%'],
  2494. children: [
  2495. {
  2496. type: 'fieldset',
  2497. label: 'Spell Checking Options',
  2498. style: 'border: none;margin-top: 13px;padding: 10px 0 10px 10px',
  2499. onShow: function() {
  2500. this.getInputElement().$.children[0].innerHTML = NS.LocalizationComing['SpellCheckingOptions'];
  2501. },
  2502. children: [
  2503. {
  2504. type: 'vbox',
  2505. id: 'Options_checkbox',
  2506. children: [
  2507. {
  2508. type: 'checkbox',
  2509. id: 'IgnoreAllCapsWords',
  2510. label: 'Ignore All-Caps Words',
  2511. labelStyle: 'margin-left: 5px; font: 12px/16px arial, sans-serif;display: inline-block;white-space: normal;',
  2512. style: "float:left; min-height: 16px;",
  2513. 'default': '',
  2514. onClick: function() {
  2515. checkboxState[this.id] = (!this.getValue()) ? 0 : 1;
  2516. }
  2517. },
  2518. {
  2519. type: 'checkbox',
  2520. id: 'IgnoreWordsNumbers',
  2521. label: 'Ignore Words with Numbers',
  2522. labelStyle: 'margin-left: 5px; font: 12px/16px arial, sans-serif;display: inline-block;white-space: normal;',
  2523. style: "float:left; min-height: 16px;",
  2524. 'default': '',
  2525. onClick: function() {
  2526. checkboxState[this.id] = (!this.getValue()) ? 0 : 1;
  2527. }
  2528. },
  2529. {
  2530. type: 'checkbox',
  2531. id: 'IgnoreMixedCaseWords',
  2532. label: 'Ignore Mixed-Case Words',
  2533. labelStyle: 'margin-left: 5px; font: 12px/16px arial, sans-serif;display: inline-block;white-space: normal;',
  2534. style: "float:left; min-height: 16px;",
  2535. 'default': '',
  2536. onClick: function() {
  2537. checkboxState[this.id] = (!this.getValue()) ? 0 : 1;
  2538. }
  2539. },
  2540. {
  2541. type: 'checkbox',
  2542. id: 'IgnoreDomainNames',
  2543. label: 'Ignore Domain Names',
  2544. labelStyle: 'margin-left: 5px; font: 12px/16px arial, sans-serif;display: inline-block;white-space: normal;',
  2545. style: "float:left; min-height: 16px;",
  2546. 'default': '',
  2547. onClick: function() {
  2548. checkboxState[this.id] = (!this.getValue()) ? 0 : 1;
  2549. }
  2550. }
  2551. ]
  2552. }
  2553. ]
  2554. },
  2555. {
  2556. type: 'vbox',
  2557. id: 'Options_DictionaryName',
  2558. children: [
  2559. {
  2560. type: 'text',
  2561. id: 'DictionaryName',
  2562. style: 'margin-bottom: 10px',
  2563. label: 'Dictionary Name:',
  2564. labelLayout: 'vertical',
  2565. labelStyle: 'font: 12px/25px arial, sans-serif;',
  2566. 'default': '',
  2567. onLoad: function() {
  2568. nameNode = this;
  2569. var udn = NS.userDictionaryName ? NS.userDictionaryName : appTools.cookie.get('udn') && undefined ? ' ' : this.getValue();
  2570. this.setValue(udn);
  2571. },
  2572. onShow: function() {
  2573. nameNode = this;
  2574. var udn = !appTools.cookie.get('udn') ? this.getValue() : appTools.cookie.get('udn');
  2575. this.setValue(udn);
  2576. this.setLabel(NS.LocalizationComing['DictionaryName']);
  2577. },
  2578. onHide: function() {
  2579. this.reset();
  2580. }
  2581. },
  2582. {
  2583. type: 'hbox',
  2584. id: 'Options_buttons',
  2585. children: [
  2586. {
  2587. type: 'vbox',
  2588. id: 'Options_leftCol_col',
  2589. widths: ['50%', '50%'],
  2590. children: [
  2591. {
  2592. type: 'button',
  2593. id: 'create',
  2594. label: 'Create',
  2595. title: 'Create',
  2596. style: 'width: 100%;',
  2597. onLoad: function() {
  2598. this.getElement().setAttribute("title-cmd", this.id);
  2599. },
  2600. onShow: function() {
  2601. var el = this.getElement().getFirst() || this.getElement();
  2602. el.setText(NS.LocalizationComing['Create']);
  2603. },
  2604. onClick: sendDicOptions
  2605. },
  2606. {
  2607. type: 'button',
  2608. id: 'restore',
  2609. label: 'Restore',
  2610. title: 'Restore',
  2611. style: 'width: 100%;',
  2612. onLoad: function() {
  2613. this.getElement().setAttribute("title-cmd", this.id);
  2614. },
  2615. onShow: function() {
  2616. var el = this.getElement().getFirst() || this.getElement();
  2617. el.setText(NS.LocalizationComing['Restore']);
  2618. },
  2619. onClick: sendDicOptions
  2620. }
  2621. ]
  2622. },
  2623. {
  2624. type: 'vbox',
  2625. id: 'Options_rightCol_col',
  2626. widths: ['50%', '50%'],
  2627. children: [
  2628. {
  2629. type: 'button',
  2630. id: 'rename',
  2631. label: 'Rename',
  2632. title: 'Rename',
  2633. style: 'width: 100%;',
  2634. onLoad: function() {
  2635. this.getElement().setAttribute("title-cmd", this.id);
  2636. },
  2637. onShow: function() {
  2638. var el = this.getElement().getFirst() || this.getElement();
  2639. el.setText(NS.LocalizationComing['Rename']);
  2640. },
  2641. onClick: sendDicOptions
  2642. },
  2643. {
  2644. type: 'button',
  2645. id: 'delete',
  2646. label: 'Remove',
  2647. title: 'Remove',
  2648. style: 'width: 100%;',
  2649. onLoad: function() {
  2650. this.getElement().setAttribute("title-cmd", this.id);
  2651. },
  2652. onShow: function() {
  2653. var el = this.getElement().getFirst() || this.getElement();
  2654. el.setText(NS.LocalizationComing['Remove']);
  2655. },
  2656. onClick: sendDicOptions
  2657. }
  2658. ]
  2659. }
  2660. ]
  2661. }
  2662. ]
  2663. }
  2664. ]
  2665. },
  2666. {
  2667. type: 'hbox',
  2668. id: 'Options_text',
  2669. children: [
  2670. {
  2671. type: 'html',
  2672. style: "text-align: justify;margin-top: 15px;white-space: normal!important; font-size: 12px;color:#777;",
  2673. html: "<div>" + NS.LocalizationComing['OptionsTextIntro'] + "</div>",
  2674. onShow: function() {
  2675. this.getElement().setText(NS.LocalizationComing['OptionsTextIntro']);
  2676. }
  2677. }
  2678. ]
  2679. }
  2680. ]
  2681. }
  2682. ]
  2683. }
  2684. ],
  2685. buttons: [CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton],
  2686. onOk: function() {
  2687. sendAllOptions();
  2688. OptionsTextError.getElement().hide();
  2689. OptionsTextError.getElement().setHtml(' ');
  2690. },
  2691. onLoad: function() {
  2692. dialog = this;
  2693. // appTools.postMessage.init(cameOptions);
  2694. linkOnCheckbox['IgnoreAllCapsWords'] = dialog.getContentElement('OptionsTab', 'IgnoreAllCapsWords');
  2695. linkOnCheckbox['IgnoreWordsNumbers'] = dialog.getContentElement('OptionsTab', 'IgnoreWordsNumbers');
  2696. linkOnCheckbox['IgnoreMixedCaseWords'] = dialog.getContentElement('OptionsTab', 'IgnoreMixedCaseWords');
  2697. linkOnCheckbox['IgnoreDomainNames'] = dialog.getContentElement('OptionsTab', 'IgnoreDomainNames');
  2698. },
  2699. onShow: function() {
  2700. appTools.postMessage.init(cameOptions);
  2701. setHandlerOptions();
  2702. (!parseInt(checkboxState['IgnoreAllCapsWords'], 10)) ? linkOnCheckbox['IgnoreAllCapsWords'].setValue('', false) : linkOnCheckbox['IgnoreAllCapsWords'].setValue('checked', false);
  2703. (!parseInt(checkboxState['IgnoreWordsNumbers'], 10)) ? linkOnCheckbox['IgnoreWordsNumbers'].setValue('', false) : linkOnCheckbox['IgnoreWordsNumbers'].setValue('checked', false);
  2704. (!parseInt(checkboxState['IgnoreMixedCaseWords'], 10)) ? linkOnCheckbox['IgnoreMixedCaseWords'].setValue('', false) : linkOnCheckbox['IgnoreMixedCaseWords'].setValue('checked', false);
  2705. (!parseInt(checkboxState['IgnoreDomainNames'], 10)) ? linkOnCheckbox['IgnoreDomainNames'].setValue('', false) : linkOnCheckbox['IgnoreDomainNames'].setValue('checked', false);
  2706. checkboxState['IgnoreAllCapsWords'] = (!linkOnCheckbox['IgnoreAllCapsWords'].getValue()) ? 0 : 1;
  2707. checkboxState['IgnoreWordsNumbers'] = (!linkOnCheckbox['IgnoreWordsNumbers'].getValue()) ? 0 : 1;
  2708. checkboxState['IgnoreMixedCaseWords'] = (!linkOnCheckbox['IgnoreMixedCaseWords'].getValue()) ? 0 : 1;
  2709. checkboxState['IgnoreDomainNames'] = (!linkOnCheckbox['IgnoreDomainNames'].getValue()) ? 0 : 1;
  2710. linkOnCheckbox['IgnoreAllCapsWords'].getElement().$.lastChild.innerHTML = NS.LocalizationComing['IgnoreAllCapsWords'];
  2711. linkOnCheckbox['IgnoreWordsNumbers'].getElement().$.lastChild.innerHTML = NS.LocalizationComing['IgnoreWordsWithNumbers'];
  2712. linkOnCheckbox['IgnoreMixedCaseWords'].getElement().$.lastChild.innerHTML = NS.LocalizationComing['IgnoreMixedCaseWords'];
  2713. linkOnCheckbox['IgnoreDomainNames'].getElement().$.lastChild.innerHTML = NS.LocalizationComing['IgnoreDomainNames'];
  2714. },
  2715. onHide: function() {
  2716. appTools.postMessage.unbindHandler(cameOptions);
  2717. if(activeElement) {
  2718. try {
  2719. activeElement.focus();
  2720. } catch(e) {}
  2721. }
  2722. }
  2723. };
  2724. });
  2725. // Expand the spell-check frame when dialog resized. (#6829)
  2726. CKEDITOR.dialog.on( 'resize', function( evt ) {
  2727. var data = evt.data,
  2728. dialog = data.dialog,
  2729. currentTabId = dialog._.currentTabId,
  2730. tabID = NS.iframeNumber + '_' + currentTabId,
  2731. iframe = CKEDITOR.document.getById(tabID);
  2732. if ( dialog._.name == 'checkspell' ) {
  2733. if (NS.bnr) {
  2734. iframe && iframe.setSize( 'height', data.height - '310' );
  2735. } else {
  2736. iframe && iframe.setSize( 'height', data.height - '220' );
  2737. }
  2738. // add flag that indicate whether dialog has been resized by user
  2739. if(dialog._.fromResizeEvent && !dialog._.resized) {
  2740. dialog._.resized = true;
  2741. }
  2742. dialog._.fromResizeEvent = true;
  2743. }
  2744. });
  2745. CKEDITOR.on('dialogDefinition', function(dialogDefinitionEvent) {
  2746. if(dialogDefinitionEvent.data.name === 'checkspell') {
  2747. var dialogDefinition = dialogDefinitionEvent.data.definition;
  2748. NS.onLoadOverlay = new overlayBlock({
  2749. opacity: "1",
  2750. background: "#fff",
  2751. target: dialogDefinition.dialog.parts.tabs.getParent().$
  2752. });
  2753. NS.onLoadOverlay.setEnable();
  2754. dialogDefinition.dialog.on('cancel', function(cancelEvent) {
  2755. dialogDefinition.dialog.getParentEditor().config.wsc_onClose.call(this.document.getWindow().getFrame());
  2756. NS.div_overlay.setDisable();
  2757. NS.onLoadOverlay.setDisable();
  2758. return false;
  2759. }, this, null, -1);
  2760. }
  2761. });
  2762. })();