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