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