2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Can define centre and project information in administrative menu

Able to edit questionnaires RS text and name
Can disable/enable questionnaires for viewing in admin interface
RS text entered via new CKEditor including ability to insert tokens/template replace text
Added setting table and associated getter/setter functions (currently only used for centre information but could add more)
This commit is contained in:
azammitdcarf
2011-01-18 03:32:21 +00:00
parent ca02adf4c2
commit e5615b708a
628 changed files with 117476 additions and 21 deletions

View File

@@ -0,0 +1,534 @@
/*
Copyright (c) 2003-2010, 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 = 0,
dic_buttons = [
// [0] contains buttons for creating
"dic_create,dic_restore",
// [1] contains buton for manipulation
"dic_rename,dic_delete"
],
optionsIds = [ 'mixedCase', 'mixedWithDigits', 'allCaps', 'ignoreDomainNames' ];
// common operations
function getBOMAllOptions()
{
return document.forms.optionsbar["options"];
}
function getBOMAllLangs()
{
return document.forms.languagesbar["scayt_lang"];
}
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 : lang.optionsTab,
elements : [
{
type : 'html',
id : 'options',
html : '<form name="optionsbar"><div class="inner_options">' +
' <div class="messagebox"></div>' +
' <div style="display:none;">' +
' <input type="checkbox" name="options" id="allCaps" />' +
' <label for="allCaps" id="label_allCaps"></label>' +
' </div>' +
' <div style="display:none;">' +
' <input name="options" type="checkbox" id="ignoreDomainNames" />' +
' <label for="ignoreDomainNames" id="label_ignoreDomainNames"></label>' +
' </div>' +
' <div style="display:none;">' +
' <input name="options" type="checkbox" id="mixedCase" />' +
' <label for="mixedCase" id="label_mixedCase"></label>' +
' </div>' +
' <div style="display:none;">' +
' <input name="options" type="checkbox" id="mixedWithDigits" />' +
' <label for="mixedWithDigits" id="label_mixedWithDigits"></label>' +
' </div>' +
'</div></form>'
}
]
},
{
id : 'langs',
label : lang.languagesTab,
elements : [
{
type : 'html',
id : 'langs',
html : '<form name="languagesbar"><div class="inner_langs">' +
' <div class="messagebox"></div> ' +
' <div style="float:left;width:45%;margin-left:5px;" id="scayt_lcol" ></div>' +
' <div style="float:left;width:45%;margin-left:15px;" id="scayt_rcol"></div>' +
'</div></form>'
}
]
},
{
id : 'dictionaries',
label : lang.dictionariesTab,
elements : [
{
type : 'html',
style: '',
id : 'dictionaries',
html : '<form name="dictionarybar"><div class="inner_dictionary" style="text-align:left; white-space:normal; width:320px; overflow: hidden;">' +
' <div style="margin:5px auto; width:80%;white-space:normal; overflow:hidden;" id="dic_message"> </div>' +
' <div style="margin:5px auto; width:80%;white-space:normal;"> ' +
' <span class="cke_dialog_ui_labeled_label" >Dictionary name</span><br>'+
' <span class="cke_dialog_ui_labeled_content" >'+
' <div class="cke_dialog_ui_input_text">'+
' <input id="dic_name" type="text" class="cke_dialog_ui_input_text"/>'+
' </div></span></div>'+
' <div style="margin:5px auto; width:80%;white-space:normal;">'+
' <a style="display:none;" class="cke_dialog_ui_button" href="javascript:void(0)" id="dic_create">'+
' </a>' +
' <a style="display:none;" class="cke_dialog_ui_button" href="javascript:void(0)" id="dic_delete">'+
' </a>' +
' <a style="display:none;" class="cke_dialog_ui_button" href="javascript:void(0)" id="dic_rename">'+
' </a>' +
' <a style="display:none;" class="cke_dialog_ui_button" href="javascript:void(0)" id="dic_restore">'+
' </a>' +
' </div>' +
' <div style="margin:5px auto; width:95%;white-space:normal;" id="dic_info"></div>' +
'</div></form>'
}
]
},
{
id : 'about',
label : lang.aboutTab,
elements : [
{
type : 'html',
id : 'about',
style : 'margin: 5px 5px;',
html : '<div id="scayt_about"></div>'
}
]
}
];
var dialogDefiniton = {
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;
if ( !dialog.data || !dialog.data.scayt || !dialog.data.scayt_control )
{
alert( 'Error loading application service' );
dialog.hide();
return;
}
var stop = 0;
if ( firstLoad )
{
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 );
dialog.selectPage( dialog.data.tab );
},
onOk : function()
{
var scayt_control = this.data.scayt_control;
scayt_control.option( this.options );
// Setup languge if it was changed.
var csLang = this.chosed_lang;
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 );
tags = CKEDITOR.plugins.scayt.uiTabs;
for ( i in tags )
{
if ( tags[ i ] == 1 )
contents[ contents.length ] = tags_contents[ i ];
}
if ( tags[2] == 1 )
userDicActive = 1;
var init_with_captions = function()
{
var dialog = this,
lang_list = dialog.data.scayt.getLangList(),
buttons = [ 'dic_create', 'dic_delete', 'dic_rename', 'dic_restore' ],
labels = optionsIds,
i;
// Add buttons titles
if ( userDicActive )
{
for ( i = 0; i < buttons.length; i++ )
{
var button = buttons[ i ];
doc.getById( button ).setHtml( '<span class="cke_dialog_ui_button">' + captions[ 'button_' + button] +'</span>' );
}
doc.getById( 'dic_info' ).setHtml( captions[ 'dic_info' ] );
}
// Fill options and dictionary labels.
if ( tags[0] == 1 )
{
for ( i in labels )
{
var label = 'label_' + labels[ i ],
labelElement = doc.getById( label );
if ( 'undefined' != typeof labelElement
&& 'undefined' != typeof captions[ label ]
&& 'undefined' != typeof dialog.options[labels[ i ]] )
{
labelElement.setHtml( captions[ label ] );
var labelParent = labelElement.getParent();
labelParent.$.style.display = "block";
}
}
}
var about = '<p><img src="' + window.scayt.getAboutInfo().logoURL + '" /></p>' +
'<p>' + captions[ 'version' ] + window.scayt.getAboutInfo().version.toString() + '</p>' +
'<p>' + captions[ 'about_throwt_copy' ] + '</p>';
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( '<input id="cke_option' +
option + '" type="radio" ' +
( dialog.sLang == option ? 'checked="checked"' : '' ) +
' value="' + option + '" name="scayt_lang" />' );
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 = [];
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 );
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"];
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
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"];
// 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 )
{
// 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 )
{
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').getValue();
if ( !dic_name )
{
dic_error_message(" Dictionary name should not be empty. ");
return false;
}
try{
var el = id = ev.data.getTarget().getParent();
var id = el.getId();
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]);
if ( dic_button )
dic_button.on( 'click', onDicButtonClick, this );
}
};
var reload = function()
{
var dialog = this;
// for enabled options tab
if ( tags[0] == 1 ){
var opto = getBOMAllOptions();
// Animate options.
for ( var k=0,l = opto.length; k<l;k++ )
{
var i = opto[k].id;
var checkbox = doc.getById( i );
if ( checkbox )
{
opto[k].checked = false;
//alert (opto[k].removeAttribute)
if ( dialog.options[ i ] == 1 )
{
opto[k].checked = true;
}
// Bind events. Do it only once.
if ( firstLoad )
{
checkbox.on( 'click', function()
{
dialog.options[ this.getId() ] = this.$.checked ? 1 : 0 ;
});
}
}
}
}
//for enabled languages tab
if ( tags[1] == 1 )
{
var domLang = doc.getById("cke_option" + dialog.sLang);
setCheckedValue( domLang.$,dialog.sLang );
}
// * user dictionary
if ( userDicActive )
{
window.scayt.getNameUserDictionary(
function( o )
{
var dic_name = o.dname;
hide_dic_buttons( dic_buttons[0] + ',' + dic_buttons[1] );
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('<span style="color:red;">' + m + '</span>' );
}
function dic_success_message( m )
{
doc.getById('dic_message').setHtml('<span style="color:blue;">' + m + '</span>') ;
}
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;
});

View File

@@ -0,0 +1,71 @@
a
{
text-decoration:none;
padding: 2px 4px 4px 6px;
display : block;
border-width: 1px;
border-style: solid;
margin : 0px;
}
a.cke_scayt_toogle:hover,
a.cke_scayt_toogle:focus,
a.cke_scayt_toogle:active
{
border-color: #316ac5;
background-color: #dff1ff;
color : #000;
cursor: pointer;
margin : 0px;
}
a.cke_scayt_toogle {
color : #316ac5;
border-color: #fff;
}
.scayt_enabled a.cke_scayt_item {
color : #316ac5;
border-color: #fff;
margin : 0px;
}
.scayt_disabled a.cke_scayt_item {
color : gray;
border-color : #fff;
}
.scayt_enabled a.cke_scayt_item:hover,
.scayt_enabled a.cke_scayt_item:focus,
.scayt_enabled a.cke_scayt_item:active
{
border-color: #316ac5;
background-color: #dff1ff;
color : #000;
cursor: pointer;
}
.scayt_disabled a.cke_scayt_item:hover,
.scayt_disabled a.cke_scayt_item:focus,
.scayt_disabled a.cke_scayt_item:active
{
border-color: gray;
background-color: #dff1ff;
color : gray;
cursor: no-drop;
}
.cke_scayt_set_on, .cke_scayt_set_off
{
display: none;
}
.scayt_enabled .cke_scayt_set_on
{
display: none;
}
.scayt_disabled .cke_scayt_set_on
{
display: inline;
}
.scayt_disabled .cke_scayt_set_off
{
display: none;
}
.scayt_enabled .cke_scayt_set_off
{
display: inline;
}

View File

@@ -0,0 +1,947 @@
/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
/**
* @fileOverview Spell Check As You Type (SCAYT).
* Button name : Scayt.
*/
(function()
{
var commandName = 'scaytcheck',
openPage = '';
// Checks if a value exists in an array
function in_array( needle, haystack )
{
var found = 0,
key;
for ( key in haystack )
{
if ( haystack[ key ] == needle )
{
found = 1;
break;
}
}
return found;
}
var onEngineLoad = function()
{
var editor = this;
var createInstance = function() // Create new instance every time Document is created.
{
var config = editor.config;
// Initialise Scayt instance.
var oParams = {};
// Get the iframe.
oParams.srcNodeRef = editor.document.getWindow().$.frameElement;
// syntax : AppName.AppVersion@AppRevision
oParams.assocApp = 'CKEDITOR.' + CKEDITOR.version + '@' + CKEDITOR.revision;
oParams.customerid = config.scayt_customerid || '1:WvF0D4-UtPqN1-43nkD4-NKvUm2-daQqk3-LmNiI-z7Ysb4-mwry24-T8YrS3-Q2tpq2';
oParams.customDictionaryIds = config.scayt_customDictionaryIds || '';
oParams.userDictionaryName = config.scayt_userDictionaryName || '';
oParams.sLang = config.scayt_sLang || 'en_US';
// Introduce SCAYT onLoad callback. (#5632)
oParams.onLoad = function()
{
// Draw down word marker to avoid being covered by background-color style.(#5466)
if ( !( CKEDITOR.env.ie && CKEDITOR.env.version < 8 ) )
this.addStyle( this.selectorCss(), 'padding-bottom: 2px !important;' );
// Call scayt_control.focus when SCAYT loaded
// and only if editor has focus and scayt control creates at first time (#5720)
if ( editor.focusManager.hasFocus && !plugin.isControlRestored( editor ) )
this.focus();
};
oParams.onBeforeChange = function()
{
if ( plugin.getScayt( editor ) && !editor.checkDirty() )
setTimeout( function(){ editor.resetDirty(); }, 0 );
};
var scayt_custom_params = window.scayt_custom_params;
if ( typeof scayt_custom_params == 'object' )
{
for ( var k in scayt_custom_params )
oParams[ k ] = scayt_custom_params[ k ];
}
// needs for restoring a specific scayt control settings
if ( plugin.getControlId( editor ) )
oParams.id = plugin.getControlId( editor );
var scayt_control = new window.scayt( oParams );
scayt_control.afterMarkupRemove.push( function( node )
{
( new CKEDITOR.dom.element( node, scayt_control.document ) ).mergeSiblings();
} );
// Copy config.
var lastInstance = plugin.instances[ editor.name ];
if ( lastInstance )
{
scayt_control.sLang = lastInstance.sLang;
scayt_control.option( lastInstance.option() );
scayt_control.paused = lastInstance.paused;
}
plugin.instances[ editor.name ] = scayt_control;
//window.scayt.uiTags
var menuGroup = 'scaytButton';
var uiTabs = window.scayt.uiTags;
var fTabs = [];
for ( var i = 0, l=4; i < l; i++ )
fTabs.push( uiTabs[i] && plugin.uiTabs[i] );
plugin.uiTabs = fTabs;
try {
scayt_control.setDisabled( plugin.isPaused( editor ) === false );
} catch (e) {}
editor.fire( 'showScaytState' );
};
editor.on( 'contentDom', createInstance );
editor.on( 'contentDomUnload', function()
{
// Remove scripts.
var scripts = CKEDITOR.document.getElementsByTag( 'script' ),
scaytIdRegex = /^dojoIoScript(\d+)$/i,
scaytSrcRegex = /^https?:\/\/svc\.spellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;
for ( var i=0; i < scripts.count(); i++ )
{
var script = scripts.getItem( i ),
id = script.getId(),
src = script.getAttribute( 'src' );
if ( id && src && id.match( scaytIdRegex ) && src.match( scaytSrcRegex ))
script.remove();
}
});
editor.on( 'beforeCommandExec', function( ev ) // Disable SCAYT before Source command execution.
{
if ( ( ev.data.name == 'source' || ev.data.name == 'newpage' ) && editor.mode == 'wysiwyg' )
{
var scayt_instance = plugin.getScayt( editor );
if ( scayt_instance )
{
plugin.setPaused( editor, !scayt_instance.disabled );
// store a control id for restore a specific scayt control settings
plugin.setControlId( editor, scayt_instance.id );
scayt_instance.destroy( true );
delete plugin.instances[ editor.name ];
}
}
// Catch on source mode switch off (#5720)
else if ( ev.data.name == 'source' && editor.mode == 'source' )
plugin.markControlRestore( editor );
});
editor.on( 'afterCommandExec', function( ev )
{
if ( !plugin.isScaytEnabled( editor ) )
return;
if ( editor.mode == 'wysiwyg' && ( ev.data.name == 'undo' || ev.data.name == 'redo' ) )
window.setTimeout( function() { plugin.getScayt( editor ).refresh(); }, 10 );
});
editor.on( 'destroy', function( ev )
{
var editor = ev.editor,
scayt_instance = plugin.getScayt( editor );
// SCAYT instance might already get destroyed by mode switch (#5744).
if ( !scayt_instance )
return;
delete plugin.instances[ editor.name ];
// store a control id for restore a specific scayt control settings
plugin.setControlId( editor, scayt_instance.id );
scayt_instance.destroy( true );
});
// Listen to data manipulation to reflect scayt markup.
editor.on( 'afterSetData', function()
{
if ( plugin.isScaytEnabled( editor ) ) {
window.setTimeout( function()
{
var instance = plugin.getScayt( editor );
instance && instance.refresh();
}, 10 );
}
});
// Reload spell-checking for current word after insertion completed.
editor.on( 'insertElement', function()
{
var scayt_instance = plugin.getScayt( editor );
if ( plugin.isScaytEnabled( editor ) )
{
// Unlock the selection before reload, SCAYT will take
// care selection update.
if ( CKEDITOR.env.ie )
editor.getSelection().unlock( true );
// Return focus to the editor and refresh SCAYT markup (#5573).
window.setTimeout( function()
{
scayt_instance.focus();
scayt_instance.refresh();
}, 10 );
}
}, this, null, 50 );
editor.on( 'insertHtml', function()
{
var scayt_instance = plugin.getScayt( editor );
if ( plugin.isScaytEnabled( editor ) )
{
// Unlock the selection before reload, SCAYT will take
// care selection update.
if ( CKEDITOR.env.ie )
editor.getSelection().unlock( true );
// Return focus to the editor (#5573)
// Refresh SCAYT markup
window.setTimeout( function()
{
scayt_instance.focus();
scayt_instance.refresh();
}, 10 );
}
}, this, null, 50 );
editor.on( 'scaytDialog', function( ev ) // Communication with dialog.
{
ev.data.djConfig = window.djConfig;
ev.data.scayt_control = plugin.getScayt( editor );
ev.data.tab = openPage;
ev.data.scayt = window.scayt;
});
var dataProcessor = editor.dataProcessor,
htmlFilter = dataProcessor && dataProcessor.htmlFilter;
if ( htmlFilter )
{
htmlFilter.addRules(
{
elements :
{
span : function( element )
{
if ( element.attributes[ 'data-scayt_word' ]
&& element.attributes[ 'data-scaytid' ] )
{
delete element.name; // Write children, but don't write this node.
return element;
}
}
}
}
);
}
// Override Image.equals method avoid CK snapshot module to add SCAYT markup to snapshots. (#5546)
var undoImagePrototype = CKEDITOR.plugins.undo.Image.prototype;
undoImagePrototype.equals = CKEDITOR.tools.override( undoImagePrototype.equals, function( org )
{
return function( otherImage )
{
var thisContents = this.contents,
otherContents = otherImage.contents;
var scayt_instance = plugin.getScayt( this.editor );
// Making the comparison based on content without SCAYT word markers.
if ( scayt_instance && plugin.isScaytReady( this.editor ) )
{
// scayt::reset might return value undefined. (#5742)
this.contents = scayt_instance.reset( thisContents ) || '';
otherImage.contents = scayt_instance.reset( otherContents ) || '';
}
var retval = org.apply( this, arguments );
this.contents = thisContents;
otherImage.contents = otherContents;
return retval;
};
});
if ( editor.document )
createInstance();
};
CKEDITOR.plugins.scayt =
{
engineLoaded : false,
instances : {},
// Data storage for SCAYT control, based on editor instances
controlInfo : {},
setControlInfo : function( editor, o )
{
if ( editor && editor.name && typeof ( this.controlInfo[ editor.name ] ) != 'object' )
this.controlInfo[ editor.name ] = {};
for ( var infoOpt in o )
this.controlInfo[ editor.name ][ infoOpt ] = o[ infoOpt ];
},
isControlRestored : function( editor )
{
if ( editor &&
editor.name &&
this.controlInfo[ editor.name ] )
{
return this.controlInfo[ editor.name ].restored ;
}
return false;
},
markControlRestore : function( editor )
{
this.setControlInfo( editor, { restored:true } );
},
setControlId: function( editor, id )
{
this.setControlInfo( editor, { id:id } );
},
getControlId: function( editor )
{
if ( editor &&
editor.name &&
this.controlInfo[ editor.name ] &&
this.controlInfo[ editor.name ].id )
{
return this.controlInfo[ editor.name ].id;
}
return null;
},
setPaused: function( editor , bool )
{
this.setControlInfo( editor, { paused:bool } );
},
isPaused: function( editor )
{
if ( editor &&
editor.name &&
this.controlInfo[editor.name] )
{
return this.controlInfo[editor.name].paused;
}
return undefined;
},
getScayt : function( editor )
{
return this.instances[ editor.name ];
},
isScaytReady : function( editor )
{
return this.engineLoaded === true &&
'undefined' !== typeof window.scayt && this.getScayt( editor );
},
isScaytEnabled : function( editor )
{
var scayt_instance = this.getScayt( editor );
return ( scayt_instance ) ? scayt_instance.disabled === false : false;
},
loadEngine : function( editor )
{
// SCAYT doesn't work with Firefox2, Opera and AIR.
if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 || CKEDITOR.env.opera || CKEDITOR.env.air )
return editor.fire( 'showScaytState' );
if ( this.engineLoaded === true )
return onEngineLoad.apply( editor ); // Add new instance.
else if ( this.engineLoaded == -1 ) // We are waiting.
return CKEDITOR.on( 'scaytReady', function(){ onEngineLoad.apply( editor ); } ); // Use function(){} to avoid rejection as duplicate.
CKEDITOR.on( 'scaytReady', onEngineLoad, editor );
CKEDITOR.on( 'scaytReady', function()
{
this.engineLoaded = true;
},
this,
null,
0
); // First to run.
this.engineLoaded = -1; // Loading in progress.
// compose scayt url
var protocol = document.location.protocol;
// Default to 'http' for unknown.
protocol = protocol.search( /https?:/) != -1? protocol : 'http:';
var baseUrl = 'svc.spellchecker.net/scayt26/loader__base.js';
var scaytUrl = editor.config.scayt_srcUrl || ( protocol + '//' + baseUrl );
var scaytConfigBaseUrl = plugin.parseUrl( scaytUrl ).path + '/';
if( window.scayt == undefined )
{
CKEDITOR._djScaytConfig =
{
baseUrl: scaytConfigBaseUrl,
addOnLoad:
[
function()
{
CKEDITOR.fireOnce( 'scaytReady' );
}
],
isDebug: false
};
// Append javascript code.
CKEDITOR.document.getHead().append(
CKEDITOR.document.createElement( 'script',
{
attributes :
{
type : 'text/javascript',
async : 'true',
src : scaytUrl
}
})
);
}
else
CKEDITOR.fireOnce( 'scaytReady' );
return null;
},
parseUrl : function ( data )
{
var match;
if ( data.match && ( match = data.match(/(.*)[\/\\](.*?\.\w+)$/) ) )
return { path: match[1], file: match[2] };
else
return data;
}
};
var plugin = CKEDITOR.plugins.scayt;
// Context menu constructing.
var addButtonCommand = function( editor, buttonName, buttonLabel, commandName, command, menugroup, menuOrder )
{
editor.addCommand( commandName, command );
// If the "menu" plugin is loaded, register the menu item.
editor.addMenuItem( commandName,
{
label : buttonLabel,
command : commandName,
group : menugroup,
order : menuOrder
});
};
var commandDefinition =
{
preserveState : true,
editorFocus : false,
canUndo : false,
exec: function( editor )
{
if ( plugin.isScaytReady( editor ) )
{
var isEnabled = plugin.isScaytEnabled( editor );
this.setState( isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_ON );
var scayt_control = plugin.getScayt( editor );
// the place where the status of editor focus should be restored
// after there will be ability to store its state before SCAYT button click
// if (storedFocusState is focused )
// scayt_control.focus();
//
// now focus is set certainly
scayt_control.focus();
scayt_control.setDisabled( isEnabled );
}
else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 ) // Load first time
{
this.setState( CKEDITOR.TRISTATE_DISABLED );
plugin.loadEngine( editor );
}
}
};
// Add scayt plugin.
CKEDITOR.plugins.add( 'scayt',
{
requires : [ 'menubutton' ],
beforeInit : function( editor )
{
var items_order = editor.config.scayt_contextMenuItemsOrder
|| 'suggest|moresuggest|control',
items_order_str = "";
items_order = items_order.split( '|' );
if ( items_order && items_order.length )
{
for ( var pos = 0 ; pos < items_order.length ; pos++ )
items_order_str += 'scayt_' + items_order[ pos ] + ( items_order.length != parseInt( pos, 10 ) + 1 ? ',' : '' );
}
// Put it on top of all context menu items (#5717)
editor.config.menu_groups = items_order_str + ',' + editor.config.menu_groups;
},
init : function( editor )
{
var moreSuggestions = {},
mainSuggestions = {};
// Scayt command.
var command = editor.addCommand( commandName, commandDefinition );
// Add Options dialog.
CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) );
// read ui tags
var confuiTabs = editor.config.scayt_uiTabs || '1,1,1';
var uiTabs =[];
// string to array convert
confuiTabs = confuiTabs.split( ',' );
// check array length ! always must be 3 filled with 1 or 0
for ( var i=0, l=3; i < l; i++ )
{
var flag = parseInt( confuiTabs[i] || '1', 10 );
uiTabs.push( flag );
}
var menuGroup = 'scaytButton';
editor.addMenuGroup( menuGroup );
// combine menu items to render
var uiMuneItems = {};
var lang = editor.lang.scayt;
// always added
uiMuneItems.scaytToggle =
{
label : lang.enable,
command : commandName,
group : menuGroup
};
if ( uiTabs[0] == 1 )
uiMuneItems.scaytOptions =
{
label : lang.options,
group : menuGroup,
onClick : function()
{
openPage = 'options';
editor.openDialog( commandName );
}
};
if ( uiTabs[1] == 1 )
uiMuneItems.scaytLangs =
{
label : lang.langs,
group : menuGroup,
onClick : function()
{
openPage = 'langs';
editor.openDialog( commandName );
}
};
if ( uiTabs[2] == 1 )
uiMuneItems.scaytDict =
{
label : lang.dictionariesTab,
group : menuGroup,
onClick : function()
{
openPage = 'dictionaries';
editor.openDialog( commandName );
}
};
// always added
uiMuneItems.scaytAbout =
{
label : editor.lang.scayt.about,
group : menuGroup,
onClick : function()
{
openPage = 'about';
editor.openDialog( commandName );
}
};
uiTabs[3] = 1; // about us tab is always on
plugin.uiTabs = uiTabs;
editor.addMenuItems( uiMuneItems );
editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON,
{
label : lang.title,
title : CKEDITOR.env.opera ? lang.opera_title : lang.title,
className : 'cke_button_scayt',
modes : { wysiwyg : 1 },
onRender: function()
{
command.on( 'state', function()
{
this.setState( command.state );
},
this);
},
onMenu : function()
{
var isEnabled = plugin.isScaytEnabled( editor );
editor.getMenuItem( 'scaytToggle' ).label = lang[ isEnabled ? 'disable' : 'enable' ];
return {
scaytToggle : CKEDITOR.TRISTATE_OFF,
scaytOptions : isEnabled && plugin.uiTabs[0] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
scaytLangs : isEnabled && plugin.uiTabs[1] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
scaytDict : isEnabled && plugin.uiTabs[2] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
scaytAbout : isEnabled && plugin.uiTabs[3] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED
};
}
});
// If the "contextmenu" plugin is loaded, register the listeners.
if ( editor.contextMenu && editor.addMenuItems )
{
editor.contextMenu.addListener( function( element, selection )
{
if ( !plugin.isScaytEnabled( editor )
|| selection.getCommonAncestor().isReadOnly() )
return null;
var scayt_control = plugin.getScayt( editor ),
node = scayt_control.getScaytNode();
if ( !node )
return null;
var word = scayt_control.getWord( node );
if ( !word )
return null;
var sLang = scayt_control.getLang(),
_r = {},
items_suggestion = window.scayt.getSuggestion( word, sLang );
if ( !items_suggestion || !items_suggestion.length )
return null;
// Remove unused commands and menuitems
for ( i in moreSuggestions )
{
delete editor._.menuItems[ i ];
delete editor._.commands[ i ];
}
for ( i in mainSuggestions )
{
delete editor._.menuItems[ i ];
delete editor._.commands[ i ];
}
moreSuggestions = {}; // Reset items.
mainSuggestions = {};
var moreSuggestionsUnable = editor.config.scayt_moreSuggestions || 'on';
var moreSuggestionsUnableAdded = false;
var maxSuggestions = editor.config.scayt_maxSuggestions;
( typeof maxSuggestions != 'number' ) && ( maxSuggestions = 5 );
!maxSuggestions && ( maxSuggestions = items_suggestion.length );
var contextCommands = editor.config.scayt_contextCommands || 'all';
contextCommands = contextCommands.split( '|' );
for ( var i = 0, l = items_suggestion.length; i < l; i += 1 )
{
var commandName = 'scayt_suggestion_' + items_suggestion[i].replace( ' ', '_' );
var exec = ( function( el, s )
{
return {
exec: function()
{
scayt_control.replace( el, s );
}
};
})( node, items_suggestion[i] );
if ( i < maxSuggestions )
{
addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
commandName, exec, 'scayt_suggest', i + 1 );
_r[ commandName ] = CKEDITOR.TRISTATE_OFF;
mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
}
else if ( moreSuggestionsUnable == 'on' )
{
addButtonCommand( editor, 'button_' + commandName, items_suggestion[i],
commandName, exec, 'scayt_moresuggest', i + 1 );
moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
moreSuggestionsUnableAdded = true;
}
}
if ( moreSuggestionsUnableAdded )
{
// Register the More suggestions group;
editor.addMenuItem( 'scayt_moresuggest',
{
label : lang.moreSuggestions,
group : 'scayt_moresuggest',
order : 10,
getItems : function()
{
return moreSuggestions;
}
});
mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;
}
if ( in_array( 'all', contextCommands ) || in_array( 'ignore', contextCommands) )
{
var ignore_command = {
exec: function(){
scayt_control.ignore( node );
}
};
addButtonCommand( editor, 'ignore', lang.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 1 );
mainSuggestions[ 'scayt_ignore' ] = CKEDITOR.TRISTATE_OFF;
}
if ( in_array( 'all', contextCommands ) || in_array( 'ignoreall', contextCommands ) )
{
var ignore_all_command = {
exec: function(){
scayt_control.ignoreAll( node );
}
};
addButtonCommand(editor, 'ignore_all', lang.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 2);
mainSuggestions['scayt_ignore_all'] = CKEDITOR.TRISTATE_OFF;
}
if ( in_array( 'all', contextCommands ) || in_array( 'add', contextCommands ) )
{
var addword_command = {
exec: function(){
window.scayt.addWordToUserDictionary( node );
}
};
addButtonCommand(editor, 'add_word', lang.addWord, 'scayt_add_word', addword_command, 'scayt_control', 3);
mainSuggestions['scayt_add_word'] = CKEDITOR.TRISTATE_OFF;
}
if ( scayt_control.fireOnContextMenu )
scayt_control.fireOnContextMenu( editor );
return mainSuggestions;
});
}
var showInitialState = function()
{
editor.removeListener( 'showScaytState', showInitialState );
if ( !CKEDITOR.env.opera && !CKEDITOR.env.air )
command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
else
command.setState( CKEDITOR.TRISTATE_DISABLED );
};
editor.on( 'showScaytState', showInitialState );
if ( CKEDITOR.env.opera || CKEDITOR.env.air )
{
editor.on( 'instanceReady', function()
{
showInitialState();
});
}
// Start plugin
if ( editor.config.scayt_autoStartup )
{
editor.on( 'instanceReady', function()
{
plugin.loadEngine( editor );
});
}
},
afterInit : function( editor )
{
// Prevent word marker line from displaying in elements path and been removed when cleaning format. (#3570) (#4125)
var elementsPathFilters,
scaytFilter = function( element )
{
if ( element.hasAttribute( 'data-scaytid' ) )
return false;
};
if ( editor._.elementsPath && ( elementsPathFilters = editor._.elementsPath.filters ) )
elementsPathFilters.push( scaytFilter );
editor.addRemoveFormatFilter && editor.addRemoveFormatFilter( scaytFilter );
}
});
})();
/**
* If enabled (true), turns on SCAYT automatically after loading the editor.
* @name CKEDITOR.config.scayt_autoStartup
* @type Boolean
* @default false
* @example
* config.scayt_autoStartup = true;
*/
/**
* Defines the number of SCAYT suggestions to show in the main context menu.
* The possible values are:
* <ul>
* <li>0 (zero): All suggestions are displayed in the main context menu.</li>
* <li>Positive number: The maximum number of suggestions to shown in context
* menu. Other entries will be shown in "More Suggestions" sub-menu.</li>
* <li>Negative number: No suggestions are shown in the main context menu. All
* entries will be listed in the "Suggestions" sub-menu.</li>
* </ul>
* @name CKEDITOR.config.scayt_maxSuggestions
* @type Number
* @default 5
* @example
* // Display only three suggestions in the main context menu.
* config.scayt_maxSuggestions = 3;
* @example
* // Do not show the suggestions directly.
* config.scayt_maxSuggestions = -1;
*/
/**
* Sets the customer ID for SCAYT. Required for migration from free version
* with banner to paid version.
* @name CKEDITOR.config.scayt_customerid
* @type String
* @default ''
* @example
* // Load SCAYT using my customer ID.
* config.scayt_customerid = 'your-encrypted-customer-id';
*/
/**
* Enables/disables the "More Suggestions" sub-menu in the context menu.
* The possible values are "on" or "off".
* @name CKEDITOR.config.scayt_moreSuggestions
* @type String
* @default 'on'
* @example
* // Disables the "More Suggestions" sub-menu.
* config.scayt_moreSuggestions = 'off';
*/
/**
* Customizes the display of SCAYT context menu commands ("Add Word", "Ignore"
* and "Ignore All"). It must be a string with one or more of the following
* words separated by a pipe ("|"):
* <ul>
* <li>"off": disables all options.</li>
* <li>"all": enables all options.</li>
* <li>"ignore": enables the "Ignore" option.</li>
* <li>"ignoreall": enables the "Ignore All" option.</li>
* <li>"add": enables the "Add Word" option.</li>
* </ul>
* @name CKEDITOR.config.scayt_contextCommands
* @type String
* @default 'all'
* @example
* // Show only "Add Word" and "Ignore All" in the context menu.
* config.scayt_contextCommands = 'add|ignoreall';
*/
/**
* Sets the default spellchecking language for SCAYT.
* @name CKEDITOR.config.scayt_sLang
* @type String
* @default 'en_US'
* @example
* // Sets SCAYT to German.
* config.scayt_sLang = 'de_DE';
*/
/**
* Sets the visibility of the SCAYT tabs in the settings dialog and toolbar
* button. The value must contain a "1" (enabled) or "0" (disabled) number for
* each of the following entries, in this precise order, separated by a
* comma (","): "Options", "Languages" and "Dictionary".
* @name CKEDITOR.config.scayt_uiTabs
* @type String
* @default '1,1,1'
* @example
* // Hide the "Languages" tab.
* config.scayt_uiTabs = '1,0,1';
*/
/**
* Set the URL to SCAYT core. Required to switch to licensed version of SCAYT application.
* Further details at http://wiki.spellchecker.net/doku.php?id=3rd:wysiwyg:fckeditor:wscckf3l .
* @name CKEDITOR.config.scayt_srcUrl
* @type String
* @default ''
* @example
* config.scayt_srcUrl = "http://my-host/spellcheck/lf/scayt/scayt.js";
*/
/**
* Links SCAYT to custom dictionaries. It's a string containing dictionary ids
* separared by commas (","). Available only for licensed version.
* Further details at http://wiki.spellchecker.net/doku.php?id=custom_dictionary_support .
* @name CKEDITOR.config.scayt_customDictionaryIds
* @type String
* @default ''
* @example
* config.scayt_customDictionaryIds = '3021,3456,3478"';
*/
/**
* Makes it possible to activate a custom dictionary on SCAYT. The user
* dictionary name must be used. Available only for licensed version.
* @name CKEDITOR.config.scayt_userDictionaryName
* @type String
* @default ''
* @example
* config.scayt_userDictionaryName = 'MyDictionary';
*/
/**
* Define order of placing of SCAYT context menu items by groups.
* It must be a string with one or more of the following
* words separated by a pipe ("|"):
* <ul>
* <li>'suggest' - main suggestion word list,</li>
* <li>'moresuggest' - more suggestions word list,</li>
* <li>'control' - SCAYT commands, such as 'Ignore' and 'Add Word'</li>
* </ul>
*
* @name CKEDITOR.config.scayt_contextMenuItemsOrder
* @type String
* @default 'suggest|moresuggest|control'
* @example
* config.scayt_contextMenuItemsOrder = 'moresuggest|control|suggest';
*/