JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fbc2f7798ef3d38c6a1c3781134d93979dac961e
[ckeditor.git] / _source / plugins / wsc / dialogs / wsc.js
1 /*\r
2 Copyright (c) 2003-2009, 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 {\r
8         var number = CKEDITOR.tools.getNextNumber(),\r
9                 iframeId = 'cke_frame_' + number,\r
10                 textareaId = 'cke_data_' + number,\r
11                 errorBoxId = 'cke_error_' + number,\r
12                 interval,\r
13                 protocol = document.location.protocol || 'http:',\r
14                 errorMsg = editor.lang.spellCheck.notAvailable;\r
15 \r
16         var pasteArea = '<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:485px;background-color:#f1f1e3;height:380px"' +\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 +\r
34                         '//loader.spellchecker.net/sproxy_fck/sproxy.php'\r
35                         + '?plugin=fck2'\r
36                         + '&customerid=' + editor.config.wsc_customerId\r
37                         + '&cmd=script&doc=wsc&schema=22'\r
38                 );\r
39 \r
40         if ( editor.config.wsc_customLoaderScript )\r
41                 errorMsg += '<p style="color:#000;font-size:11px;font-weight: normal;text-align:center;padding-top:10px">' +\r
42                         editor.lang.spellCheck.errorLoading.replace( /%s/g, editor.config.wsc_customLoaderScript ) + '</p>';\r
43 \r
44         function burnSpelling( dialog, errorMsg )\r
45         {\r
46                 var i = 0;\r
47                 return function ()\r
48                 {\r
49                         if ( typeof( window.doSpell ) == 'function' )\r
50                         {\r
51                                 //Call from window.setInteval expected at once.\r
52                                 if ( typeof( interval ) != 'undefined' )\r
53                                         window.clearInterval( interval );\r
54 \r
55                                 initAndSpell( dialog );\r
56                         }\r
57                         else if ( i++ == 180 )                                                          // Timeout: 180 * 250ms = 45s.\r
58                                 window._cancelOnError( errorMsg );\r
59                 };\r
60         }\r
61 \r
62         window._cancelOnError = function( m )\r
63         {\r
64                 if ( typeof( window.WSC_Error ) == 'undefined' )\r
65                 {\r
66                         CKEDITOR.document.getById( iframeId ).setStyle( 'display', 'none' );\r
67                         var errorBox = CKEDITOR.document.getById( errorBoxId );\r
68                         errorBox.setStyle( 'display', 'block' );\r
69                         errorBox.setHtml( m || editor.lang.spellCheck.notAvailable );\r
70                 }\r
71         };\r
72 \r
73         function initAndSpell( dialog )\r
74         {\r
75                 var LangComparer = new window._SP_FCK_LangCompare(),                                                    // Language abbr standarts comparer.\r
76                         pluginPath = CKEDITOR.getUrl( editor.plugins.wsc.path + 'dialogs/' ),                   // Service paths corecting/preparing.\r
77                         framesetPath = pluginPath + 'tmpFrameset.html';\r
78 \r
79                 // global var is used in FCK specific core\r
80                 // change on equal var used in fckplugin.js\r
81                 window.gFCKPluginName = 'wsc';\r
82 \r
83                 LangComparer.setDefaulLangCode( editor.config.defaultLanguage );\r
84 \r
85                 window.doSpell({\r
86                         ctrl : textareaId,\r
87                         lang : LangComparer.getSPLangCode( editor.langCode ),\r
88                         winType : iframeId,             // If not defined app will run on winpopup.\r
89 \r
90                         // Callback binding section.\r
91                         onCancel : function()\r
92                         {\r
93                                 dialog.hide();\r
94                         },\r
95                         onFinish : function( dT )\r
96                         {\r
97                                 editor.focus();\r
98                                 dialog.getParentEditor().setData( dT.value );\r
99                                 dialog.hide();\r
100                         },\r
101 \r
102                         // Some manipulations with client static pages.\r
103                         staticFrame : framesetPath,\r
104                         framesetPath : framesetPath,\r
105                         iframePath : pluginPath + 'ciframe.html',\r
106 \r
107                         // Styles defining.\r
108                         schemaURI : pluginPath + 'wsc.css'\r
109                 });\r
110 \r
111                 // Hide user message console (if application was loaded more then after timeout).\r
112                 CKEDITOR.document.getById( errorBoxId ).setStyle( 'display', 'none' );\r
113                 CKEDITOR.document.getById( iframeId ).setStyle( 'display', 'block' );\r
114         }\r
115 \r
116         return {\r
117                 title : editor.lang.spellCheck.title,\r
118                 minWidth : 485,\r
119                 minHeight : 380,\r
120                 buttons : [ CKEDITOR.dialog.cancelButton ],\r
121                 onShow : function()\r
122                 {\r
123                         var contentArea = this.getContentElement( 'general', 'content' ).getElement();\r
124                         contentArea.setHtml( pasteArea );\r
125 \r
126                         if ( typeof( window.doSpell ) != 'function' )\r
127                         {\r
128                                 // Load script.\r
129                                 CKEDITOR.document.getHead().append(\r
130                                         CKEDITOR.document.createElement( 'script',\r
131                                                 {\r
132                                                         attributes :\r
133                                                                 {\r
134                                                                         type : 'text/javascript',\r
135                                                                         src : wscCoreUrl\r
136                                                                 }\r
137                                                 })\r
138                                 );\r
139                         }\r
140 \r
141                         var sData = editor.getData();                                                                                   // Get the data to be checked.\r
142                         CKEDITOR.document.getById( textareaId ).setValue( sData );\r
143 \r
144                         interval = window.setInterval( burnSpelling( this, errorMsg ), 250 );\r
145                 },\r
146                 onHide : function()\r
147                 {\r
148                         window.ooo = undefined;\r
149                         window.int_framsetLoaded = undefined;\r
150                         window.framesetLoaded = undefined;\r
151                         window.is_window_opened = false;\r
152                 },\r
153                 contents : [\r
154                         {\r
155                                 id : 'general',\r
156                                 label : editor.lang.spellCheck.title,\r
157                                 padding : 0,\r
158                                 elements : [\r
159                                         {\r
160                                                 type : 'html',\r
161                                                 id : 'content',\r
162                                                 style : 'width:485;height:380px',\r
163                                                 html : '<div></div>'\r
164                                         }\r
165                                 ]\r
166                         }\r
167                 ]\r
168         };\r
169 });\r