/* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.dialog.add( 'scaytcheck', function( editor ) { var firstLoad = true, captions, doc = CKEDITOR.document, tags = [], 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" ]; var tags_contents = [ { id : 'options', label : editor.lang.scayt.optionsTab, elements : [ { type : 'html', id : 'options', html : '
' } ] }, { id : 'langs', label : editor.lang.scayt.languagesTab, elements : [ { type : 'html', id : 'langs', html : '' + captions[ 'about_throwt_image' ] + '
'+ '' + captions[ 'version' ] + dialog.data.scayt.version.toString() + '
' + '' + captions[ 'about_throwt_copy' ] + '
'; doc.getById( 'scayt_about' ).setHtml( about ); // Create languages tab. var createOption = function( option, list ) { var label = doc.createElement( 'label' ); label.setAttribute( 'for', 'cke_option' + option ); label.setHtml( list[ option ] ); if ( dialog.sLang == option ) // Current. dialog.chosed_lang = option; var div = doc.createElement( 'div' ); var radio = CKEDITOR.dom.element.createFromHtml( '' ); radio.on( 'click', function() { this.$.checked = true; dialog.chosed_lang = option; }); div.append( radio ); div.append( label ); return { lang : list[ option ], code : option, radio : div }; }; var langList = []; 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 ); 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 ); } // 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]; var err_massage = captions["err_dic_create"]; var suc_massage = captions["succ_dic_create"]; //console.info("--plugin "); 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 || "") +")"); }); }; 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 || "" ) + " )" ); }); }; 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); }); }; 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]; var err_massage = captions["err_dic_restore"]; 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 ); }); }; // ** 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]); if ( dic_button ) dic_button.on( 'click', onDicButtonClick, this ); } }; var reload = function() { var dialog = this; // Animate options. for ( var i in dialog.options ) { var checkbox = doc.getById( i ); if ( checkbox ) { checkbox.removeAttribute( 'checked' ); if ( dialog.options[ i ] == 1 ) checkbox.setAttribute( 'checked', 'checked' ); // Bind events. Do it only once. if ( firstLoad ) { checkbox.on( 'click', function() { dialog.options[ this.getId() ] = this.$.checked ? 1 : 0 ; } ); } } } // * user dictionary if ( userDicActive ){ window.scayt.getNameUserDictionary( function( o ) { var dic_name = o.dname; if ( dic_name ) { doc.getById( 'dic_name' ).setValue(dic_name); display_dic_buttons( dic_buttons[1] ); } else display_dic_buttons( dic_buttons[0] ); }, function () { doc.getById( 'dic_name' ).setValue(""); }); dic_success_message(""); } }; function dic_error_message ( m ) { doc.getById('dic_message').setHtml('' + 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; } return dialogDefiniton; });