2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.dialog.add( 'scaytcheck', function( editor )
\r
8 var firstLoad = true,
\r
10 doc = CKEDITOR.document,
\r
16 // [0] contains buttons for creating
\r
17 "dic_create,dic_restore",
\r
18 // [1] contains buton for manipulation
\r
19 "dic_rename,dic_delete"
\r
21 optionsIds = [ 'mixedCase', 'mixedWithDigits', 'allCaps', 'ignoreDomainNames' ];
\r
23 // common operations
\r
25 function getBOMAllOptions()
\r
27 return document.forms.optionsbar["options"];
\r
29 function getBOMAllLangs()
\r
31 return document.forms.languagesbar["scayt_lang"];
\r
34 function setCheckedValue( radioObj, newValue )
\r
38 var radioLength = radioObj.length;
\r
39 if ( radioLength == undefined )
\r
41 radioObj.checked = radioObj.value == newValue.toString();
\r
44 for ( var i = 0; i < radioLength; i++ )
\r
46 radioObj[i].checked = false;
\r
47 if ( radioObj[i].value == newValue.toString() )
\r
48 radioObj[i].checked = true;
\r
52 var lang = editor.lang.scayt;
\r
53 var tags_contents = [
\r
56 label : lang.optionsTab,
\r
61 html : '<form name="optionsbar"><div class="inner_options">' +
\r
62 ' <div class="messagebox"></div>' +
\r
63 ' <div style="display:none;">' +
\r
64 ' <input type="checkbox" name="options" id="allCaps" />' +
\r
65 ' <label for="allCaps" id="label_allCaps"></label>' +
\r
67 ' <div style="display:none;">' +
\r
68 ' <input name="options" type="checkbox" id="ignoreDomainNames" />' +
\r
69 ' <label for="ignoreDomainNames" id="label_ignoreDomainNames"></label>' +
\r
71 ' <div style="display:none;">' +
\r
72 ' <input name="options" type="checkbox" id="mixedCase" />' +
\r
73 ' <label for="mixedCase" id="label_mixedCase"></label>' +
\r
75 ' <div style="display:none;">' +
\r
76 ' <input name="options" type="checkbox" id="mixedWithDigits" />' +
\r
77 ' <label for="mixedWithDigits" id="label_mixedWithDigits"></label>' +
\r
85 label : lang.languagesTab,
\r
90 html : '<form name="languagesbar"><div class="inner_langs">' +
\r
91 ' <div class="messagebox"></div> ' +
\r
92 ' <div style="float:left;width:45%;margin-left:5px;" id="scayt_lcol" ></div>' +
\r
93 ' <div style="float:left;width:45%;margin-left:15px;" id="scayt_rcol"></div>' +
\r
99 id : 'dictionaries',
\r
100 label : lang.dictionariesTab,
\r
105 id : 'dictionaries',
\r
106 html : '<form name="dictionarybar"><div class="inner_dictionary" style="text-align:left; white-space:normal; width:320px; overflow: hidden;">' +
\r
107 ' <div style="margin:5px auto; width:80%;white-space:normal; overflow:hidden;" id="dic_message"> </div>' +
\r
108 ' <div style="margin:5px auto; width:80%;white-space:normal;"> ' +
\r
109 ' <span class="cke_dialog_ui_labeled_label" >Dictionary name</span><br>'+
\r
110 ' <span class="cke_dialog_ui_labeled_content" >'+
\r
111 ' <div class="cke_dialog_ui_input_text">'+
\r
112 ' <input id="dic_name" type="text" class="cke_dialog_ui_input_text"/>'+
\r
113 ' </div></span></div>'+
\r
114 ' <div style="margin:5px auto; width:80%;white-space:normal;">'+
\r
115 ' <a style="display:none;" class="cke_dialog_ui_button" href="javascript:void(0)" id="dic_create">'+
\r
117 ' <a style="display:none;" class="cke_dialog_ui_button" href="javascript:void(0)" id="dic_delete">'+
\r
119 ' <a style="display:none;" class="cke_dialog_ui_button" href="javascript:void(0)" id="dic_rename">'+
\r
121 ' <a style="display:none;" class="cke_dialog_ui_button" href="javascript:void(0)" id="dic_restore">'+
\r
124 ' <div style="margin:5px auto; width:95%;white-space:normal;" id="dic_info"></div>' +
\r
131 label : lang.aboutTab,
\r
136 style : 'margin: 5px 5px;',
\r
137 html : '<div id="scayt_about"></div>'
\r
143 var dialogDefiniton = {
\r
144 title : lang.title,
\r
147 onShow : function()
\r
150 dialog.data = editor.fire( 'scaytDialog', {} );
\r
151 dialog.options = dialog.data.scayt_control.option();
\r
152 dialog.sLang = dialog.data.scayt_control.sLang;
\r
154 if ( !dialog.data || !dialog.data.scayt || !dialog.data.scayt_control )
\r
156 alert( 'Error loading application service' );
\r
164 dialog.data.scayt.getCaption( editor.langCode || 'en', function( caps )
\r
166 if ( stop++ > 0 ) // Once only
\r
169 init_with_captions.apply( dialog );
\r
170 reload.apply( dialog );
\r
175 reload.apply( dialog );
\r
177 dialog.selectPage( dialog.data.tab );
\r
181 var scayt_control = this.data.scayt_control;
\r
182 scayt_control.option( this.options );
\r
183 // Setup languge if it was changed.
\r
184 var csLang = this.chosed_lang;
\r
185 scayt_control.setLang( csLang );
\r
186 scayt_control.refresh();
\r
188 onCancel: function()
\r
190 var o = getBOMAllOptions();
\r
192 o[i].checked = false;
\r
194 setCheckedValue( getBOMAllLangs(), "" );
\r
196 contents : contents
\r
199 var scayt_control = CKEDITOR.plugins.scayt.getScayt( editor );
\r
201 tags = CKEDITOR.plugins.scayt.uiTabs;
\r
205 if ( tags[ i ] == 1 )
\r
206 contents[ contents.length ] = tags_contents[ i ];
\r
208 if ( tags[2] == 1 )
\r
212 var init_with_captions = function()
\r
215 lang_list = dialog.data.scayt.getLangList(),
\r
216 buttons = [ 'dic_create', 'dic_delete', 'dic_rename', 'dic_restore' ],
\r
217 labels = optionsIds,
\r
220 // Add buttons titles
\r
221 if ( userDicActive )
\r
223 for ( i = 0; i < buttons.length; i++ )
\r
225 var button = buttons[ i ];
\r
226 doc.getById( button ).setHtml( '<span class="cke_dialog_ui_button">' + captions[ 'button_' + button] +'</span>' );
\r
228 doc.getById( 'dic_info' ).setHtml( captions[ 'dic_info' ] );
\r
232 // Fill options and dictionary labels.
\r
233 if ( tags[0] == 1 )
\r
235 for ( i in labels )
\r
237 var label = 'label_' + labels[ i ],
\r
238 labelElement = doc.getById( label );
\r
240 if ( 'undefined' != typeof labelElement
\r
241 && 'undefined' != typeof captions[ label ]
\r
242 && 'undefined' != typeof dialog.options[labels[ i ]] )
\r
244 labelElement.setHtml( captions[ label ] );
\r
245 var labelParent = labelElement.getParent();
\r
246 labelParent.$.style.display = "block";
\r
251 var about = '<p><img src="' + window.scayt.getAboutInfo().logoURL + '" /></p>' +
\r
252 '<p>' + captions[ 'version' ] + window.scayt.getAboutInfo().version.toString() + '</p>' +
\r
253 '<p>' + captions[ 'about_throwt_copy' ] + '</p>';
\r
255 doc.getById( 'scayt_about' ).setHtml( about );
\r
257 // Create languages tab.
\r
258 var createOption = function( option, list )
\r
260 var label = doc.createElement( 'label' );
\r
261 label.setAttribute( 'for', 'cke_option' + option );
\r
262 label.setHtml( list[ option ] );
\r
264 if ( dialog.sLang == option ) // Current.
\r
265 dialog.chosed_lang = option;
\r
267 var div = doc.createElement( 'div' );
\r
268 var radio = CKEDITOR.dom.element.createFromHtml( '<input id="cke_option' +
\r
269 option + '" type="radio" ' +
\r
270 ( dialog.sLang == option ? 'checked="checked"' : '' ) +
\r
271 ' value="' + option + '" name="scayt_lang" />' );
\r
273 radio.on( 'click', function()
\r
275 this.$.checked = true;
\r
276 dialog.chosed_lang = option;
\r
279 div.append( radio );
\r
280 div.append( label );
\r
283 lang : list[ option ],
\r
292 for ( i in lang_list.rtl )
\r
293 langList[ langList.length ] = createOption( i, lang_list.ltr );
\r
295 for ( i in lang_list.ltr )
\r
296 langList[ langList.length ] = createOption( i, lang_list.ltr );
\r
298 langList.sort( function( lang1, lang2 )
\r
300 return ( lang2.lang > lang1.lang ) ? -1 : 1 ;
\r
303 var fieldL = doc.getById( 'scayt_lcol' ),
\r
304 fieldR = doc.getById( 'scayt_rcol' );
\r
305 for ( i=0; i < langList.length; i++ )
\r
307 var field = ( i < langList.length / 2 ) ? fieldL : fieldR;
\r
308 field.append( langList[ i ].radio );
\r
312 // user dictionary handlers
\r
314 dic.dic_create = function( el, dic_name , dic_buttons )
\r
316 // comma separated button's ids include repeats if exists
\r
317 var all_buttons = dic_buttons[0] + ',' + dic_buttons[1];
\r
319 var err_massage = captions["err_dic_create"];
\r
320 var suc_massage = captions["succ_dic_create"];
\r
322 window.scayt.createUserDictionary( dic_name,
\r
325 hide_dic_buttons ( all_buttons );
\r
326 display_dic_buttons ( dic_buttons[1] );
\r
327 suc_massage = suc_massage.replace("%s" , arg.dname );
\r
328 dic_success_message (suc_massage);
\r
332 err_massage = err_massage.replace("%s" ,arg.dname );
\r
333 dic_error_message ( err_massage + "( "+ (arg.message || "") +")");
\r
338 dic.dic_rename = function( el, dic_name )
\r
341 // try to rename dictionary
\r
342 var err_massage = captions["err_dic_rename"] || "";
\r
343 var suc_massage = captions["succ_dic_rename"] || "";
\r
344 window.scayt.renameUserDictionary( dic_name,
\r
347 suc_massage = suc_massage.replace("%s" , arg.dname );
\r
348 set_dic_name( dic_name );
\r
349 dic_success_message ( suc_massage );
\r
353 err_massage = err_massage.replace("%s" , arg.dname );
\r
354 set_dic_name( dic_name );
\r
355 dic_error_message( err_massage + "( " + ( arg.message || "" ) + " )" );
\r
359 dic.dic_delete = function( el, dic_name , dic_buttons )
\r
361 var all_buttons = dic_buttons[0] + ',' + dic_buttons[1];
\r
362 var err_massage = captions["err_dic_delete"];
\r
363 var suc_massage = captions["succ_dic_delete"];
\r
365 // try to delete dictionary
\r
366 window.scayt.deleteUserDictionary(
\r
369 suc_massage = suc_massage.replace("%s" , arg.dname );
\r
370 hide_dic_buttons ( all_buttons );
\r
371 display_dic_buttons ( dic_buttons[0] );
\r
372 set_dic_name( "" ); // empty input field
\r
373 dic_success_message( suc_massage );
\r
377 err_massage = err_massage.replace("%s" , arg.dname );
\r
378 dic_error_message(err_massage);
\r
382 dic.dic_restore = dialog.dic_restore || function( el, dic_name , dic_buttons )
\r
384 // try to restore existing dictionary
\r
385 var all_buttons = dic_buttons[0] + ',' + dic_buttons[1];
\r
386 var err_massage = captions["err_dic_restore"];
\r
387 var suc_massage = captions["succ_dic_restore"];
\r
389 window.scayt.restoreUserDictionary(dic_name,
\r
392 suc_massage = suc_massage.replace("%s" , arg.dname );
\r
393 hide_dic_buttons ( all_buttons );
\r
394 display_dic_buttons(dic_buttons[1]);
\r
395 dic_success_message( suc_massage );
\r
399 err_massage = err_massage.replace("%s" , arg.dname );
\r
400 dic_error_message( err_massage );
\r
404 function onDicButtonClick( ev )
\r
406 var dic_name = doc.getById('dic_name').getValue();
\r
409 dic_error_message(" Dictionary name should not be empty. ");
\r
413 var el = id = ev.data.getTarget().getParent();
\r
414 var id = el.getId();
\r
415 dic[ id ].apply( null, [ el, dic_name, dic_buttons ] );
\r
419 dic_error_message(" Dictionary error. ");
\r
425 // ** bind event listeners
\r
426 var arr_buttons = ( dic_buttons[0] + ',' + dic_buttons[1] ).split( ',' ),
\r
429 for ( i = 0, l = arr_buttons.length ; i < l ; i += 1 )
\r
431 var dic_button = doc.getById(arr_buttons[i]);
\r
433 dic_button.on( 'click', onDicButtonClick, this );
\r
437 var reload = function()
\r
440 // for enabled options tab
\r
441 if ( tags[0] == 1 ){
\r
442 var opto = getBOMAllOptions();
\r
444 // Animate options.
\r
445 for ( var k=0,l = opto.length; k<l;k++ )
\r
448 var i = opto[k].id;
\r
449 var checkbox = doc.getById( i );
\r
453 opto[k].checked = false;
\r
454 //alert (opto[k].removeAttribute)
\r
455 if ( dialog.options[ i ] == 1 )
\r
457 opto[k].checked = true;
\r
461 // Bind events. Do it only once.
\r
464 checkbox.on( 'click', function()
\r
466 dialog.options[ this.getId() ] = this.$.checked ? 1 : 0 ;
\r
473 //for enabled languages tab
\r
474 if ( tags[1] == 1 )
\r
476 var domLang = doc.getById("cke_option" + dialog.sLang);
\r
477 setCheckedValue( domLang.$,dialog.sLang );
\r
480 // * user dictionary
\r
481 if ( userDicActive )
\r
483 window.scayt.getNameUserDictionary(
\r
486 var dic_name = o.dname;
\r
487 hide_dic_buttons( dic_buttons[0] + ',' + dic_buttons[1] );
\r
490 doc.getById( 'dic_name' ).setValue(dic_name);
\r
491 display_dic_buttons( dic_buttons[1] );
\r
494 display_dic_buttons( dic_buttons[0] );
\r
499 doc.getById( 'dic_name' ).setValue("");
\r
501 dic_success_message("");
\r
506 function dic_error_message( m )
\r
508 doc.getById('dic_message').setHtml('<span style="color:red;">' + m + '</span>' );
\r
510 function dic_success_message( m )
\r
512 doc.getById('dic_message').setHtml('<span style="color:blue;">' + m + '</span>') ;
\r
514 function display_dic_buttons( sIds )
\r
516 sIds = String( sIds );
\r
517 var aIds = sIds.split(',');
\r
518 for ( var i=0, l = aIds.length; i < l ; i+=1)
\r
519 doc.getById( aIds[i] ).$.style.display = "inline";
\r
521 function hide_dic_buttons( sIds )
\r
523 sIds = String( sIds );
\r
524 var aIds = sIds.split(',');
\r
525 for ( var i = 0, l = aIds.length; i < l ; i += 1 )
\r
526 doc.getById( aIds[i] ).$.style.display = "none";
\r
528 function set_dic_name( dic_name )
\r
530 doc.getById('dic_name').$.value= dic_name;
\r
533 return dialogDefiniton;
\r