1 /*
  2 Copyright (c) 2003-2009, 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:485px;background-color:#f1f1e3;height:380px"' +
 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( doSpell ) == 'function' )
 50 				initAndSpell( dialog );
 51 			else if ( i++ == 180 )								// Timeout: 180 * 250ms = 45s.
 52 				_cancelOnError( errorMsg );
 53 		}
 54 	};
 55
 56 	function _cancelOnError( m )
 57 	{
 58 		if ( typeof( WSC_Error ) == 'undefined' )
 59 		{
 60 			CKEDITOR.document.getById( iframeId ).setStyle( 'display', 'none' );
 61 			var errorBox = CKEDITOR.document.getById( errorBoxId );
 62 			errorBox.setStyle( 'display', 'block' );
 63 			errorBox.setHtml( m || editor.lang.spellCheck.notAvailable );
 64 		}
 65 	}
 66
 67 	function initAndSpell( dialog )
 68 	{
 69 		//Call from window.setInteval expected at once.
 70 		if ( typeof( interval ) == 'undefined' )
 71 			return null;
 72 		window.clearInterval( interval );
 73
 74 		// Global var is used in FCK specific core.
 75 		gFCKPluginName = 'wsc';
 76
 77 		var sData = editor.getData(),											// Get the data to be checked.
 78 			LangComparer = new _SP_FCK_LangCompare(),							// Language abbr standarts comparer.
 79 			pluginPath = CKEDITOR.getUrl( editor.plugins.wsc.path + 'dialogs/' ),			// Service paths corecting/preparing.
 80 			framesetPath = pluginPath + 'tmpFrameset.html';
 81
 82 		LangComparer.setDefaulLangCode( editor.config.defaultLanguage );
 83
 84 		// Prepare content.
 85 		CKEDITOR.document.getById( textareaId ).setValue( sData );
 86
 87 		// Hide user message console (if application was loaded more then after timeout).
 88 		CKEDITOR.document.getById( errorBoxId ).setStyle( 'display', 'none' );
 89 		CKEDITOR.document.getById( iframeId ).setStyle( 'display', 'block' );
 90
 91 		doSpell({
 92 			ctrl : textareaId,
 93 			lang : LangComparer.getSPLangCode( editor.langCode ),
 94 			winType : iframeId,		// If not defined app will run on winpopup.
 95
 96 			// Callback binding section.
 97 			onCancel : function()
 98 			{
 99 				dialog.hide();
100 			},
101 			onFinish : function( dT )
102 			{
103 				dialog.restoreSelection();
104 				dialog.clearSavedSelection();
105 				dialog.getParentEditor().setData( dT.value );
106 				dialog.hide();
107 			},
108
109 			// Some manipulations with client static pages.
110 			staticFrame : framesetPath,
111 			framesetPath : framesetPath,
112 			iframePath : pluginPath + 'ciframe.html',
113
114 			// Styles defining.
115 			schemaURI : pluginPath + 'wsc.css'
116 		});
117 	};
118
119 	return {
120 		title : editor.lang.spellCheck.title,
121 		minWidth : 540,
122 		minHeight : 480,
123 		buttons : [ CKEDITOR.dialog.cancelButton ],
124 		onShow : function()
125 		{
126 			contentArea = this.getContentElement( 'general', 'content' ).getElement();
127 			contentArea.setHtml( pasteArea );
128
129 			if ( typeof( doSpell ) != 'function' )
130 			{
131 				// Load script.
132 				CKEDITOR.document.getHead().append(
133 					CKEDITOR.document.createElement( 'script',
134 						{
135 							attributes :
136 								{
137 									type : 'text/javascript',
138 									src : wscCoreUrl
139 								}
140 						})
141 				);
142 			}
143 			interval = window.setInterval( burnSpelling( this, errorMsg ), 250 );
144 		},
145 		contents : [
146 			{
147 				id : 'general',
148 				label : editor.lang.spellCheck.title,
149 				elements : [
150 					{
151 						type : 'html',
152 						id : 'content',
153 						style : 'width:500px;height:400px',
154 						html : '<div></div>'
155 					}
156 				]
157 			}
158 		]
159 	};
160 });
161