]>
Commit | Line | Data |
---|---|---|
7adcb81e IB |
1 | /**\r |
2 | * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.\r | |
3 | * For licensing, see LICENSE.html or http://ckeditor.com/license\r | |
4 | */\r | |
5 | \r | |
6 | CKEDITOR.dialog.add( 'checkspell', function( editor ) {\r | |
7 | var number = CKEDITOR.tools.getNextNumber(),\r | |
8 | iframeId = 'cke_frame_' + number,\r | |
9 | textareaId = 'cke_data_' + number,\r | |
10 | errorBoxId = 'cke_error_' + number,\r | |
11 | interval,\r | |
12 | protocol = document.location.protocol || 'http:',\r | |
13 | errorMsg = editor.lang.wsc.notAvailable;\r | |
14 | \r | |
15 | var pasteArea =\r | |
16 | '<textarea' +\r | |
17 | ' style="display: none"' +\r | |
18 | ' id="' + textareaId + '"' +\r | |
19 | ' rows="10"' +\r | |
20 | ' cols="40">' +\r | |
21 | ' </textarea><div' +\r | |
22 | ' id="' + errorBoxId + '"' +\r | |
23 | ' style="display:none;color:red;font-size:16px;font-weight:bold;padding-top:160px;text-align:center;z-index:11;">' +\r | |
24 | '</div><iframe' +\r | |
25 | ' src=""' +\r | |
26 | ' style="width:100%;background-color:#f1f1e3;"' +\r | |
27 | ' frameborder="0"' +\r | |
28 | ' name="' + iframeId + '"' +\r | |
29 | ' id="' + iframeId + '"' +\r | |
30 | ' allowtransparency="1">' +\r | |
31 | '</iframe>';\r | |
32 | \r | |
33 | var wscCoreUrl = editor.config.wsc_customLoaderScript || ( protocol + '//loader.webspellchecker.net/sproxy_fck/sproxy.php' + '?plugin=fck2'\r | |
34 | + '&customerid=' + editor.config.wsc_customerId\r | |
35 | + '&cmd=script&doc=wsc&schema=22'\r | |
36 | );\r | |
37 | \r | |
38 | if ( editor.config.wsc_customLoaderScript ) {\r | |
39 | errorMsg += '<p style="color:#000;font-size:11px;font-weight: normal;text-align:center;padding-top:10px">' +\r | |
40 | editor.lang.wsc.errorLoading.replace( /%s/g, editor.config.wsc_customLoaderScript ) + '</p>';\r | |
41 | }\r | |
42 | \r | |
43 | function burnSpelling( dialog, errorMsg ) {\r | |
44 | var i = 0;\r | |
45 | return function() {\r | |
46 | if ( typeof( window.doSpell ) == 'function' ) {\r | |
47 | //Call from window.setInteval expected at once.\r | |
48 | if ( typeof( interval ) != 'undefined' )\r | |
49 | window.clearInterval( interval );\r | |
50 | \r | |
51 | initAndSpell( dialog );\r | |
52 | } else if ( i++ == 180 ) // Timeout: 180 * 250ms = 45s.\r | |
53 | window._cancelOnError( errorMsg );\r | |
54 | };\r | |
55 | }\r | |
56 | \r | |
57 | window._cancelOnError = function( m ) {\r | |
58 | if ( typeof( window.WSC_Error ) == 'undefined' ) {\r | |
59 | CKEDITOR.document.getById( iframeId ).setStyle( 'display', 'none' );\r | |
60 | var errorBox = CKEDITOR.document.getById( errorBoxId );\r | |
61 | errorBox.setStyle( 'display', 'block' );\r | |
62 | errorBox.setHtml( m || editor.lang.wsc.notAvailable );\r | |
63 | }\r | |
64 | };\r | |
65 | \r | |
66 | function initAndSpell( dialog ) {\r | |
67 | var LangComparer = new window._SP_FCK_LangCompare(),\r | |
68 | // Language abbr standarts comparer.\r | |
69 | pluginPath = CKEDITOR.getUrl( editor.plugins.wsc.path + 'dialogs/' ),\r | |
70 | // Service paths corecting/preparing.\r | |
71 | framesetPath = pluginPath + 'tmpFrameset.html';\r | |
72 | \r | |
73 | // global var is used in FCK specific core\r | |
74 | // change on equal var used in fckplugin.js\r | |
75 | window.gFCKPluginName = 'wsc';\r | |
76 | \r | |
77 | LangComparer.setDefaulLangCode( editor.config.defaultLanguage );\r | |
78 | \r | |
79 | window.doSpell({\r | |
80 | ctrl: textareaId,\r | |
81 | \r | |
82 | lang: editor.config.wsc_lang || LangComparer.getSPLangCode( editor.langCode ),\r | |
83 | intLang: editor.config.wsc_uiLang || LangComparer.getSPLangCode( editor.langCode ),\r | |
84 | winType: iframeId, // If not defined app will run on winpopup.\r | |
85 | \r | |
86 | // Callback binding section.\r | |
87 | onCancel: function() {\r | |
88 | dialog.hide();\r | |
89 | },\r | |
90 | onFinish: function( dT ) {\r | |
91 | editor.focus();\r | |
92 | dialog.getParentEditor().setData( dT.value );\r | |
93 | dialog.hide();\r | |
94 | },\r | |
95 | \r | |
96 | // Some manipulations with client static pages.\r | |
97 | staticFrame: framesetPath,\r | |
98 | framesetPath: framesetPath,\r | |
99 | iframePath: pluginPath + 'ciframe.html',\r | |
100 | \r | |
101 | // Styles defining.\r | |
102 | schemaURI: pluginPath + 'wsc.css',\r | |
103 | \r | |
104 | userDictionaryName: editor.config.wsc_userDictionaryName,\r | |
105 | customDictionaryName: editor.config.wsc_customDictionaryIds && editor.config.wsc_customDictionaryIds.split( "," ),\r | |
106 | domainName: editor.config.wsc_domainName\r | |
107 | \r | |
108 | });\r | |
109 | \r | |
110 | // Hide user message console (if application was loaded more then after timeout).\r | |
111 | CKEDITOR.document.getById( errorBoxId ).setStyle( 'display', 'none' );\r | |
112 | CKEDITOR.document.getById( iframeId ).setStyle( 'display', 'block' );\r | |
113 | }\r | |
114 | \r | |
115 | return {\r | |
116 | title: editor.config.wsc_dialogTitle || editor.lang.wsc.title,\r | |
117 | minWidth: 485,\r | |
118 | minHeight: 380,\r | |
119 | buttons: [ CKEDITOR.dialog.cancelButton ],\r | |
120 | onShow: function() {\r | |
121 | var contentArea = this.getContentElement( 'general', 'content' ).getElement();\r | |
122 | contentArea.setHtml( pasteArea );\r | |
123 | contentArea.getChild( 2 ).setStyle( 'height', this._.contentSize.height + 'px' );\r | |
124 | \r | |
125 | if ( typeof( window.doSpell ) != 'function' ) {\r | |
126 | // Load script.\r | |
127 | CKEDITOR.document.getHead().append( CKEDITOR.document.createElement( 'script', {\r | |
128 | attributes: {\r | |
129 | type: 'text/javascript',\r | |
130 | src: wscCoreUrl\r | |
131 | }\r | |
132 | }));\r | |
133 | }\r | |
134 | \r | |
135 | var sData = editor.getData(); // Get the data to be checked.\r | |
136 | \r | |
137 | CKEDITOR.document.getById( textareaId ).setValue( sData );\r | |
138 | \r | |
139 | interval = window.setInterval( burnSpelling( this, errorMsg ), 250 );\r | |
140 | },\r | |
141 | onHide: function() {\r | |
142 | window.ooo = undefined;\r | |
143 | window.int_framsetLoaded = undefined;\r | |
144 | window.framesetLoaded = undefined;\r | |
145 | window.is_window_opened = false;\r | |
146 | },\r | |
147 | contents: [\r | |
148 | {\r | |
149 | id: 'general',\r | |
150 | label: editor.config.wsc_dialogTitle || editor.lang.wsc.title,\r | |
151 | padding: 0,\r | |
152 | elements: [\r | |
153 | {\r | |
154 | type: 'html',\r | |
155 | id: 'content',\r | |
156 | html: ''\r | |
157 | }\r | |
158 | ]\r | |
159 | }\r | |
160 | ]\r | |
161 | };\r | |
162 | });\r | |
163 | \r | |
164 | // Expand the spell-check frame when dialog resized. (#6829)\r | |
165 | CKEDITOR.dialog.on( 'resize', function( evt ) {\r | |
166 | var data = evt.data,\r | |
167 | dialog = data.dialog;\r | |
168 | \r | |
169 | if ( dialog._.name == 'checkspell' ) {\r | |
170 | var content = dialog.getContentElement( 'general', 'content' ).getElement(),\r | |
171 | iframe = content && content.getChild( 2 );\r | |
172 | \r | |
173 | iframe && iframe.setSize( 'height', data.height );\r | |
174 | iframe && iframe.setSize( 'width', data.width );\r | |
175 | }\r | |
176 | });\r |