      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( 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 				_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 		gFCKPluginName = 'wsc';
     82
     83 		LangComparer.setDefaulLangCode( editor.config.defaultLanguage );
     84
     85 		window.doSpell({
     86 			ctrl : textareaId,
     87 			lang : LangComparer.getSPLangCode( editor.langCode ),
     88 			winType : iframeId,		// If not defined app will run on winpopup.
     89
     90 			// Callback binding section.
     91 			onCancel : function()
     92 			{
     93 				dialog.hide();
     94 			},
     95 			onFinish : function( dT )
     96 			{
     97 				editor.focus();
     98 				dialog.getParentEditor().setData( dT.value );
     99 				dialog.hide();
    100 			},
    101
    102 			// Some manipulations with client static pages.
    103 			staticFrame : framesetPath,
    104 			framesetPath : framesetPath,
    105 			iframePath : pluginPath + 'ciframe.html',
    106
    107 			// Styles defining.
    108 			schemaURI : pluginPath + 'wsc.css'
    109 		});
    110
    111 		// Hide user message console (if application was loaded more then after timeout).
    112 		CKEDITOR.document.getById( errorBoxId ).setStyle( 'display', 'none' );
    113 		CKEDITOR.document.getById( iframeId ).setStyle( 'display', 'block' );
    114 	}
    115
    116 	return {
    117 		title : editor.lang.spellCheck.title,
    118 		minWidth : 485,
    119 		minHeight : 380,
    120 		buttons : [ CKEDITOR.dialog.cancelButton ],
    121 		onShow : function()
    122 		{
    123 			var contentArea = this.getContentElement( 'general', 'content' ).getElement();
    124 			contentArea.setHtml( pasteArea );
    125
    126 			if ( typeof( window.doSpell ) != 'function' )
    127 			{
    128 				// Load script.
    129 				CKEDITOR.document.getHead().append(
    130 					CKEDITOR.document.createElement( 'script',
    131 						{
    132 							attributes :
    133 								{
    134 									type : 'text/javascript',
    135 									src : wscCoreUrl
    136 								}
    137 						})
    138 				);
    139 			}
    140
    141 			var sData = editor.getData();											// Get the data to be checked.
    142 			CKEDITOR.document.getById( textareaId ).setValue( sData );
    143
    144 			interval = window.setInterval( burnSpelling( this, errorMsg ), 250 );
    145 		},
    146 		onHide : function()
    147 		{
    148 			window.ooo = undefined;
    149 			window.int_framsetLoaded = undefined;
    150 			window.framesetLoaded = undefined;
    151 			window.is_window_opened = false;
    152 		},
    153 		contents : [
    154 			{
    155 				id : 'general',
    156 				label : editor.lang.spellCheck.title,
    157 				padding : 0,
    158 				elements : [
    159 					{
    160 						type : 'html',
    161 						id : 'content',
    162 						style : 'width:485;height:380px',
    163 						html : '<div></div>'
    164 					}
    165 				]
    166 			}
    167 		]
    168 	};
    169 });
    170