X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fscayt%2Fdialogs%2Foptions.js;h=3bd9916309a433e6eca07bd8b18693240d84777d;hb=e73319a12b56100b29ef456fd74114fe5519e01c;hp=120adbc4d51fd42b7810724ed8e53d2d349af488;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/plugins/scayt/dialogs/options.js b/_source/plugins/scayt/dialogs/options.js index 120adbc..3bd9916 100644 --- a/_source/plugins/scayt/dialogs/options.js +++ b/_source/plugins/scayt/dialogs/options.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -8,115 +8,153 @@ CKEDITOR.dialog.add( 'scaytcheck', function( editor ) var firstLoad = true, captions, doc = CKEDITOR.document, - tags = [], + editorName = editor.name, + tags = CKEDITOR.plugins.scayt.getUiTabs( editor ), i, contents = [], - userDicActive = false; - var dic_buttons = [ - // [0] contains buttons for creating - "dic_create,dic_restore", - // [1] contains buton for manipulation - "dic_rename,dic_delete" - ]; + userDicActive = 0, + dic_buttons = [ + // [0] contains buttons for creating + "dic_create_" + editorName + ",dic_restore_" + editorName, + // [1] contains buton for manipulation + "dic_rename_" + editorName + ",dic_delete_" + editorName + ], + optionsIds = [ 'mixedCase', 'mixedWithDigits', 'allCaps', 'ignoreDomainNames' ]; + + // common operations + + function getBOMAllOptions() + { + if (typeof document.forms["optionsbar_" + editorName] != "undefined") + return document.forms["optionsbar_" + editorName]["options"]; + return []; + } + function getBOMAllLangs() + { + if (typeof document.forms["languagesbar_" + editorName] != "undefined") + return document.forms["languagesbar_" + editorName]["scayt_lang"]; + return []; + } + + function setCheckedValue( radioObj, newValue ) + { + if ( !radioObj ) + return; + var radioLength = radioObj.length; + if ( radioLength == undefined ) + { + radioObj.checked = radioObj.value == newValue.toString(); + return; + } + for ( var i = 0; i < radioLength; i++ ) + { + radioObj[i].checked = false; + if ( radioObj[i].value == newValue.toString() ) + radioObj[i].checked = true; + } + } + + var lang = editor.lang.scayt; var tags_contents = [ { id : 'options', - label : editor.lang.scayt.optionsTab, + label : lang.optionsTab, elements : [ { type : 'html', id : 'options', - html : '
' + + html : '
' + '
' + '
' + - ' ' + - ' ' + + ' ' + + ' ' + '
' + '
' + - ' ' + - ' ' + + ' ' + + ' ' + '
' + '
' + - ' ' + - ' ' + + ' ' + + ' ' + '
' + '
' + - ' ' + - ' ' + + ' ' + + ' ' + '
' + - '
' + '
' } ] }, { id : 'langs', - label : editor.lang.scayt.languagesTab, + label : lang.languagesTab, elements : [ { type : 'html', id : 'langs', - html : '
' + + html : '
' + '
' + - '
' + - '
' + - '
' + '
' + + '
' + + '
' } ] }, { id : 'dictionaries', - label : editor.lang.scayt.dictionariesTab, + label : lang.dictionariesTab, elements : [ { type : 'html', style: '', - id : 'dic', - html : '
' + - '
' + + id : 'dictionaries', + html : '
' + + '
' + '
' + ' Dictionary name
'+ ' '+ '
'+ - ' '+ + ' '+ '
'+ '
'+ - ' ' + - ' ' + - ' ' + - ' ' + '
' + - '
' + - '
' + '
' + + '
' } ] }, { id : 'about', - label : editor.lang.scayt.aboutTab, + label : lang.aboutTab, elements : [ { type : 'html', id : 'about', - style : 'margin: 10px 40px;', - html : '
' + style : 'margin: 5px 5px;', + html : '
' } ] } ]; + var dialogDefiniton = { - title : editor.lang.scayt.title, - minWidth : 340, - minHeight : 200, + title : lang.title, + minWidth : 360, + minHeight : 220, onShow : function() { var dialog = this; dialog.data = editor.fire( 'scaytDialog', {} ); dialog.options = dialog.data.scayt_control.option(); - dialog.sLang = dialog.data.scayt_control.sLang; + dialog.chosed_lang = dialog.sLang = dialog.data.scayt_control.sLang; if ( !dialog.data || !dialog.data.scayt || !dialog.data.scayt_control ) { @@ -128,15 +166,15 @@ CKEDITOR.dialog.add( 'scaytcheck', function( editor ) var stop = 0; if ( firstLoad ) { - dialog.data.scayt.getCaption( 'en', function( caps ) - { - if ( stop++ > 0 ) // Once only - return; - captions = caps; - init_with_captions.apply( dialog ); - reload.apply( dialog ); - firstLoad = false; - }); + dialog.data.scayt.getCaption( editor.langCode || 'en', function( caps ) + { + if ( stop++ > 0 ) // Once only + return; + captions = caps; + init_with_captions.apply( dialog ); + reload.apply( dialog ); + firstLoad = false; + }); } else reload.apply( dialog ); @@ -145,100 +183,80 @@ CKEDITOR.dialog.add( 'scaytcheck', function( editor ) }, onOk : function() { - var scayt_control = this.data.scayt_control, - o = scayt_control.option(), - c = 0; - - // Set up options if any was set. - for ( var i in this.options ) - { - if (o[i] != this.options[ i ] && c === 0 ) - { - scayt_control.option( this.options ); - c++; - } - } - - // Setup languge if it was changed. + var scayt_control = this.data.scayt_control; + scayt_control.option( this.options ); + // Setup language if it was changed. var csLang = this.chosed_lang; - if ( csLang && this.data.sLang != csLang ) - { - scayt_control.setLang( csLang ); - c++; - } - if ( c > 0 ) - scayt_control.refresh(); + scayt_control.setLang( csLang ); + scayt_control.refresh(); + }, + onCancel: function() + { + var o = getBOMAllOptions(); + for ( var i in o ) + o[i].checked = false; + + setCheckedValue( getBOMAllLangs(), "" ); }, contents : contents - }; + }; var scayt_control = CKEDITOR.plugins.scayt.getScayt( editor ); - if ( scayt_control ) - { - tags = scayt_control.uiTags; - } - for ( i in tags ) { + for ( i = 0; i < tags.length; i++ ) + { if ( tags[ i ] == 1 ) contents[ contents.length ] = tags_contents[ i ]; } if ( tags[2] == 1 ) - userDicActive = true; - - function onDicButtonClick() - { - var dic_name = doc.getById('dic_name').getValue(); - if ( !dic_name ) - { - dic_error_message(" Dictionary name should not be empty. "); - return false; - } - //apply handler - window.dic[ this.getId() ].apply( null, [ this, dic_name, dic_buttons ] ); + userDicActive = 1; - return true; - } var init_with_captions = function() { var dialog = this, lang_list = dialog.data.scayt.getLangList(), - buttons = [ 'dic_create','dic_delete','dic_rename','dic_restore' ], - labels = [ 'mixedCase','mixedWithDigits','allCaps','ignoreDomainNames' ], + buttonCaptions = [ 'dic_create', 'dic_delete', 'dic_rename', 'dic_restore' ], + buttonIds = [], + langList = [], + labels = optionsIds, i; // Add buttons titles - if (userDicActive) + if ( userDicActive ) { - for ( i in buttons ) + for ( i = 0; i < buttonCaptions.length; i++ ) { - var button = buttons[ i ]; - doc.getById( button ).setHtml( '' + captions[ 'button_' + button] +'' ); + buttonIds[ i ] = buttonCaptions[ i ] + "_" + editorName; + doc.getById( buttonIds[ i ] ).setHtml( '' + captions[ 'button_' + buttonCaptions[ i ]] +'' ); } - doc.getById( 'dic_info' ).setHtml( captions[ 'dic_info' ] ); + doc.getById( 'dic_info_' + editorName ).setHtml( captions[ 'dic_info' ] ); } - // Fill options and dictionary labels. - for ( i in labels ) + if ( tags[0] == 1 ) { - var label = 'label_' + labels[ i ], - labelElement = doc.getById( label ); - - if ( 'undefined' != typeof labelElement - && 'undefined' != typeof captions[ label ] - && 'undefined' != typeof dialog.options[labels[ i ]] ) + for ( i in labels ) { - labelElement.setHtml( captions[ label ] ); - var labelParent = labelElement.getParent(); - labelParent.$.style.display = "block"; + var labelCaption = 'label_' + labels[ i ], + labelId = labelCaption + '_' + editorName, + labelElement = doc.getById( labelId ); + + if ( 'undefined' != typeof labelElement + && 'undefined' != typeof captions[ labelCaption ] + && 'undefined' != typeof dialog.options[labels[ i ]] ) + { + labelElement.setHtml( captions[ labelCaption ] ); + var labelParent = labelElement.getParent(); + labelParent.$.style.display = "block"; + } } } - var about = '

' + captions[ 'about_throwt_image' ] + '

'+ - '

' + captions[ 'version' ] + dialog.data.scayt.version.toString() + '

' + - '

' + captions[ 'about_throwt_copy' ] + '

'; + var about = '

' + + '

' + captions[ 'version' ] + window.scayt.getAboutInfo().version.toString() + '

' + + '

' + captions[ 'about_throwt_copy' ] + '

'; - doc.getById( 'scayt_about' ).setHtml( about ); + doc.getById( 'scayt_about_' + editorName ).setHtml( about ); // Create languages tab. var createOption = function( option, list ) @@ -272,107 +290,99 @@ CKEDITOR.dialog.add( 'scaytcheck', function( editor ) }; }; - var langList = []; - for ( i in lang_list.rtl ) - langList[ langList.length ] = createOption( i, lang_list.ltr ); + if ( tags[1] ==1 ) + { + for ( i in lang_list.rtl ) + langList[ langList.length ] = createOption( i, lang_list.ltr ); - for ( i in lang_list.ltr ) - langList[ langList.length ] = createOption( i, lang_list.ltr ); + for ( i in lang_list.ltr ) + langList[ langList.length ] = createOption( i, lang_list.ltr ); - langList.sort( function( lang1, lang2 ) - { - return ( lang2.lang > lang1.lang ) ? -1 : 1 ; - }); + langList.sort( function( lang1, lang2 ) + { + return ( lang2.lang > lang1.lang ) ? -1 : 1 ; + }); - var fieldL = doc.getById( 'scayt_lcol' ), - fieldR = doc.getById( 'scayt_rcol' ); - for ( i=0; i < langList.length; i++ ) - { - var field = ( i < langList.length / 2 ) ? fieldL : fieldR; - field.append( langList[ i ].radio ); + var fieldL = doc.getById( 'scayt_lcol_' + editorName ), + fieldR = doc.getById( 'scayt_rcol_' + editorName ); + for ( i=0; i < langList.length; i++ ) + { + var field = ( i < langList.length / 2 ) ? fieldL : fieldR; + field.append( langList[ i ].radio ); + } } // user dictionary handlers var dic = {}; dic.dic_create = function( el, dic_name , dic_buttons ) - { - // comma separated button's ids include repeats if exists - var all_buttons = dic_buttons[0] + ',' + dic_buttons[1]; + { + // comma separated button's ids include repeats if exists + var all_buttons = dic_buttons[0] + ',' + dic_buttons[1]; - var err_massage = captions["err_dic_create"]; - var suc_massage = captions["succ_dic_create"]; - //console.info("--plugin "); + var err_massage = captions["err_dic_create"]; + var suc_massage = captions["succ_dic_create"]; - window.scayt.createUserDictionary(dic_name, - function(arg) - { - //console.info( "dic_create callback called with args" , arg ); - hide_dic_buttons ( all_buttons ); - display_dic_buttons ( dic_buttons[1] ); - suc_massage = suc_massage.replace("%s" , arg.dname ); - dic_success_message (suc_massage); - }, - function(arg) - { - //console.info( "dic_create errorback called with args" , arg ) - err_massage = err_massage.replace("%s" ,arg.dname ); - dic_error_message ( err_massage + "( "+ (arg.message || "") +")"); - }); + window.scayt.createUserDictionary( dic_name, + function( arg ) + { + hide_dic_buttons ( all_buttons ); + display_dic_buttons ( dic_buttons[1] ); + suc_massage = suc_massage.replace("%s" , arg.dname ); + dic_success_message (suc_massage); + }, + function( arg ) + { + err_massage = err_massage.replace("%s" ,arg.dname ); + dic_error_message ( err_massage + "( "+ (arg.message || "") +")"); + }); - }; + }; dic.dic_rename = function( el, dic_name ) - { - // - // try to rename dictionary - // @TODO: rename dict - //console.info ( captions["err_dic_rename"] ) - var err_massage = captions["err_dic_rename"] || ""; - var suc_massage = captions["succ_dic_rename"] || ""; - window.scayt.renameUserDictionary(dic_name, - function(arg) - { - //console.info( "dic_rename callback called with args" , arg ); - suc_massage = suc_massage.replace("%s" , arg.dname ); - set_dic_name( dic_name ); - dic_success_message ( suc_massage ); - }, - function(arg) - { - //console.info( "dic_rename errorback called with args" , arg ) - err_massage = err_massage.replace("%s" , arg.dname ); - set_dic_name( dic_name ); - dic_error_message( err_massage + "( " + ( arg.message || "" ) + " )" ); - }); - }; + { + // + // try to rename dictionary + var err_massage = captions["err_dic_rename"] || ""; + var suc_massage = captions["succ_dic_rename"] || ""; + window.scayt.renameUserDictionary( dic_name, + function( arg ) + { + suc_massage = suc_massage.replace("%s" , arg.dname ); + set_dic_name( dic_name ); + dic_success_message ( suc_massage ); + }, + function( arg ) + { + err_massage = err_massage.replace("%s" , arg.dname ); + set_dic_name( dic_name ); + dic_error_message( err_massage + "( " + ( arg.message || "" ) + " )" ); + }); + }; - dic.dic_delete = function ( el, dic_name , dic_buttons ) - { - var all_buttons = dic_buttons[0] + ',' + dic_buttons[1]; - var err_massage = captions["err_dic_delete"]; - var suc_massage = captions["succ_dic_delete"]; + dic.dic_delete = function( el, dic_name , dic_buttons ) + { + var all_buttons = dic_buttons[0] + ',' + dic_buttons[1]; + var err_massage = captions["err_dic_delete"]; + var suc_massage = captions["succ_dic_delete"]; - // try to delete dictionary - // @TODO: delete dict - window.scayt.deleteUserDictionary( - function(arg) - { - //console.info( "dic_delete callback " , dic_name ,arg ); - suc_massage = suc_massage.replace("%s" , arg.dname ); - hide_dic_buttons ( all_buttons ); - display_dic_buttons ( dic_buttons[0] ); - set_dic_name( "" ); // empty input field - dic_success_message( suc_massage ); - }, - function(arg) - { - //console.info( " dic_delete errorback called with args" , arg ) - err_massage = err_massage.replace("%s" , arg.dname ); - dic_error_message(err_massage); - }); - }; + // try to delete dictionary + window.scayt.deleteUserDictionary( + function( arg ) + { + suc_massage = suc_massage.replace("%s" , arg.dname ); + hide_dic_buttons ( all_buttons ); + display_dic_buttons ( dic_buttons[0] ); + set_dic_name( "" ); // empty input field + dic_success_message( suc_massage ); + }, + function( arg ) + { + err_massage = err_massage.replace("%s" , arg.dname ); + dic_error_message(err_massage); + }); + }; - dic.dic_restore = dialog.dic_restore || function ( el, dic_name , dic_buttons ) + dic.dic_restore = dialog.dic_restore || function( el, dic_name , dic_buttons ) { // try to restore existing dictionary var all_buttons = dic_buttons[0] + ',' + dic_buttons[1]; @@ -380,29 +390,48 @@ CKEDITOR.dialog.add( 'scaytcheck', function( editor ) var suc_massage = captions["succ_dic_restore"]; window.scayt.restoreUserDictionary(dic_name, - function(arg) - { - //console.info( "dic_restore callback called with args" , arg ); - suc_massage = suc_massage.replace("%s" , arg.dname ); - hide_dic_buttons ( all_buttons ); - display_dic_buttons(dic_buttons[1]); - dic_success_message( suc_massage ); - }, - function(arg) - { - //console.info( " dic_restore errorback called with args" , arg ) - err_massage = err_massage.replace("%s" , arg.dname ); - dic_error_message( err_massage ); - }); + function( arg ) + { + suc_massage = suc_massage.replace("%s" , arg.dname ); + hide_dic_buttons ( all_buttons ); + display_dic_buttons(dic_buttons[1]); + dic_success_message( suc_massage ); + }, + function( arg ) + { + err_massage = err_massage.replace("%s" , arg.dname ); + dic_error_message( err_massage ); + }); }; + function onDicButtonClick( ev ) + { + var dic_name = doc.getById('dic_name_' + editorName).getValue(); + if ( !dic_name ) + { + dic_error_message(" Dictionary name should not be empty. "); + return false; + } + try{ + var el = ev.data.getTarget().getParent(); + var id = /(dic_\w+)_[\w\d]+/.exec(el.getId())[1]; + dic[ id ].apply( null, [ el, dic_name, dic_buttons ] ); + } + catch(err) + { + dic_error_message(" Dictionary error. "); + } + + return true; + } + // ** bind event listeners var arr_buttons = ( dic_buttons[0] + ',' + dic_buttons[1] ).split( ',' ), l; for ( i = 0, l = arr_buttons.length ; i < l ; i += 1 ) { - var dic_button = doc.getById(arr_buttons[i]); + var dic_button = doc.getById(arr_buttons[i]); if ( dic_button ) dic_button.on( 'click', onDicButtonClick, this ); } @@ -411,84 +440,98 @@ CKEDITOR.dialog.add( 'scaytcheck', function( editor ) var reload = function() { var dialog = this; + // for enabled options tab + if ( tags[0] == 1 ){ + var opto = getBOMAllOptions(); - // Animate options. - for ( var i in dialog.options ) - { - var checkbox = doc.getById( i ); - if ( checkbox ) + // Animate options. + for ( var k=0,l = opto.length; k' + m + '' ); - } - function dic_success_message ( m ) - { - doc.getById('dic_message').setHtml('' + m + '') ; - } - function display_dic_buttons ( sIds ) - { - - sIds = String( sIds ); - var aIds = sIds.split(','); - for ( var i=0, l = aIds.length; i < l ; i+=1) - { - doc.getById( aIds[i] ).$.style.display = "inline"; - } - - } - function hide_dic_buttons ( sIds ) - { - sIds = String( sIds ); - var aIds = sIds.split(','); - for ( var i = 0, l = aIds.length; i < l ; i += 1 ) - { - doc.getById( aIds[i] ).$.style.display = "none"; - } - } - function set_dic_name ( dic_name ) - { - doc.getById('dic_name').$.value= dic_name; - } + function dic_error_message( m ) + { + doc.getById('dic_message_' + editorName).setHtml('' + m + '' ); + } + function dic_success_message( m ) + { + doc.getById('dic_message_' + editorName).setHtml('' + m + '') ; + } + function display_dic_buttons( sIds ) + { + sIds = String( sIds ); + var aIds = sIds.split(','); + for ( var i=0, l = aIds.length; i < l ; i+=1) + doc.getById( aIds[i] ).$.style.display = "inline"; + } + function hide_dic_buttons( sIds ) + { + sIds = String( sIds ); + var aIds = sIds.split(','); + for ( var i = 0, l = aIds.length; i < l ; i += 1 ) + doc.getById( aIds[i] ).$.style.display = "none"; + } + function set_dic_name( dic_name ) + { + doc.getById('dic_name_' + editorName).$.value= dic_name; + } return dialogDefiniton; });