]>
git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/scayt/dialogs/options.js
2 Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
6 CKEDITOR
. dialog
. add ( 'scaytDialog' , function ( editor
) {
7 var scayt_instance
= editor
. scayt
;
9 var aboutTabDefinition
= '<p><img src="' + scayt_instance
. getLogo () + '" /></p>' +
10 '<p>' + scayt_instance
. getLocal ( 'version' ) + scayt_instance
. getVersion () + '</p>' +
11 '<p>' + scayt_instance
. getLocal ( 'text_copyrights' ) + '</p>' ;
13 var doc
= CKEDITOR
. document
;
15 var optionGenerator = function () {
16 var scayt_instance_
= editor
. scayt
,
17 applicationConfig
= scayt_instance
. getApplicationConfig (),
18 optionArrayUiCheckboxes
= [],
19 optionLocalizationList
= {
20 "ignore-all-caps-words" : "label_allCaps" ,
21 "ignore-domain-names" : "label_ignoreDomainNames" ,
22 "ignore-words-with-mixed-cases" : "label_mixedCase" ,
23 "ignore-words-with-numbers" : "label_mixedWithDigits"
26 for ( var option
in applicationConfig
) {
28 var checkboxConfig
= {
32 checkboxConfig
. id
= option
;
33 checkboxConfig
. label
= scayt_instance
. getLocal ( optionLocalizationList
[ option
]);
35 optionArrayUiCheckboxes
. push ( checkboxConfig
);
38 return optionArrayUiCheckboxes
;
41 var languageModelState
= {
42 isChanged : function () {
43 return ( this . newLang
=== null || this . currentLang
=== this . newLang
) ? false : true ;
45 currentLang : scayt_instance
. getLang (),
48 this . currentLang
= scayt_instance
. getLang ();
54 var generateDialogTabs = function ( tabsList
, editor
) {
56 uiTabs
= editor
. config
. scayt_uiTabs
;
61 for ( var i
in uiTabs
) {
62 ( uiTabs
[ i
] == 1 ) && tabs
. push ( tabsList
[ i
]);
65 tabs
. push ( tabsList
[ tabsList
. length
- 1 ]);
73 label : scayt_instance
. getLocal ( 'tab_options' ),
75 // console.log("tab show");
81 children : optionGenerator (),
83 var optionsTab
= this . getChild (),
84 scayt_instance
= editor
. scayt
;
85 for ( var i
= 0 ; i
< this . getChild (). length
; i
++) {
86 this . getChild ()[ i
]. setValue ( scayt_instance
. getApplicationConfig ()[ this . getChild ()[ i
]. id
]);
96 label : scayt_instance
. getLocal ( 'tab_languages' ),
107 style : 'overflow: hidden; white-space: normal;margin-bottom:15px;' ,
108 html : '<div><div style="float:left;width:45%;margin-left:5px;" id="left-col-' + editor
. name
+ '"></div><div style="float:left;width:45%;margin-left:15px;" id="right-col-' + editor
. name
+ '"></div></div>' ,
110 var scayt_instance
= editor
. scayt
;
111 var lang
= scayt_instance
. getLang (),
112 prefix_id
= "scaytLang_" ,
113 radio
= doc
. getById ( prefix_id
+ editor
. name
+ '_' + lang
);
115 radio
.$. checked
= true ;
120 id : 'graytLanguagesHint' ,
121 html : '<div style="margin:5px auto; width:95%;white-space:normal;" id="' + editor
. name
+ 'graytLanguagesHint"><span style="width:10px;height:10px;display: inline-block; background:#02b620;vertical-align:top;margin-top:2px;"></span> - This languages are supported by Grammar As You Type(GRAYT).</div>' ,
123 var graytLanguagesHint
= doc
. getById ( editor
. name
+ 'graytLanguagesHint' );
125 if (! editor
. config
. grayt_autoStartup
) {
126 graytLanguagesHint
.$. style
. display
= 'none' ;
136 label : scayt_instance
. getLocal ( 'tab_dictionaries' ),
140 id : 'rightCol_col__left' ,
144 id : 'dictionaryNote' ,
149 id : 'dictionaryName' ,
150 label : scayt_instance
. getLocal ( 'label_fieldNameDic' ) || 'Dictionary name' ,
151 onShow : function ( data
) {
152 var dialog
= data
. sender
,
153 scayt_instance
= editor
. scayt
;
156 setTimeout ( function () {
157 // clear dictionaryNote field
158 dialog
. getContentElement ( "dictionaries" , "dictionaryNote" ). getElement (). setText ( '' );
160 // restore/clear dictionaryName field
161 if ( scayt_instance
. getUserDictionaryName () != null && scayt_instance
. getUserDictionaryName () != '' ) {
162 dialog
. getContentElement ( "dictionaries" , "dictionaryName" ). setValue ( scayt_instance
. getUserDictionaryName ());
171 style : 'width:auto;' ,
172 widths : [ '50%' , '50%' ],
177 label : scayt_instance
. getLocal ( 'btn_createDic' ),
178 title : scayt_instance
. getLocal ( 'btn_createDic' ),
179 onClick : function () {
180 var dialog
= this . getDialog (),
181 self
= dialogDefinition
,
182 scayt_instance
= editor
. scayt
,
183 name
= dialog
. getContentElement ( "dictionaries" , "dictionaryName" ). getValue ();
185 scayt_instance
. createUserDictionary ( name
, function ( response
) {
186 if (! response
. error
) {
187 self
. toggleDictionaryButtons
. call ( dialog
, true );
189 response
. dialog
= dialog
;
190 response
. command
= "create" ;
191 response
. name
= name
;
192 editor
. fire ( "scaytUserDictionaryAction" , response
);
194 error
. dialog
= dialog
;
195 error
. command
= "create" ;
197 editor
. fire ( "scaytUserDictionaryActionError" , error
);
204 label : scayt_instance
. getLocal ( 'btn_restoreDic' ),
205 title : scayt_instance
. getLocal ( 'btn_restoreDic' ),
206 onClick : function () {
207 var dialog
= this . getDialog (),
208 scayt_instance
= editor
. scayt
,
209 self
= dialogDefinition
,
210 name
= dialog
. getContentElement ( "dictionaries" , "dictionaryName" ). getValue ();
212 scayt_instance
. restoreUserDictionary ( name
, function ( response
) {
213 response
. dialog
= dialog
;
214 if (! response
. error
) {
215 self
. toggleDictionaryButtons
. call ( dialog
, true );
217 response
. command
= "restore" ;
218 response
. name
= name
;
219 editor
. fire ( "scaytUserDictionaryAction" , response
);
221 error
. dialog
= dialog
;
222 error
. command
= "restore" ;
224 editor
. fire ( "scaytUserDictionaryActionError" , error
);
234 style : 'width:auto;' ,
235 widths : [ '50%' , '50%' ],
240 label : scayt_instance
. getLocal ( 'btn_deleteDic' ),
241 title : scayt_instance
. getLocal ( 'btn_deleteDic' ),
242 onClick : function () {
243 var dialog
= this . getDialog (),
244 scayt_instance
= editor
. scayt
,
245 self
= dialogDefinition
,
246 dictionaryNameField
= dialog
. getContentElement ( "dictionaries" , "dictionaryName" ),
247 name
= dictionaryNameField
. getValue ();
249 scayt_instance
. removeUserDictionary ( name
, function ( response
) {
250 dictionaryNameField
. setValue ( "" );
251 if (! response
. error
) {
252 self
. toggleDictionaryButtons
. call ( dialog
, false );
254 response
. dialog
= dialog
;
255 response
. command
= "remove" ;
256 response
. name
= name
;
257 editor
. fire ( "scaytUserDictionaryAction" , response
);
259 error
. dialog
= dialog
;
260 error
. command
= "remove" ;
262 editor
. fire ( "scaytUserDictionaryActionError" , error
);
269 label : scayt_instance
. getLocal ( 'btn_renameDic' ),
270 title : scayt_instance
. getLocal ( 'btn_renameDic' ),
271 onClick : function () {
272 var dialog
= this . getDialog (),
273 scayt_instance
= editor
. scayt
,
274 name
= dialog
. getContentElement ( "dictionaries" , "dictionaryName" ). getValue ();
276 scayt_instance
. renameUserDictionary ( name
, function ( response
) {
277 response
. dialog
= dialog
;
278 response
. command
= "rename" ;
279 response
. name
= name
;
280 editor
. fire ( "scaytUserDictionaryAction" , response
);
282 error
. dialog
= dialog
;
283 error
. command
= "rename" ;
285 editor
. fire ( "scaytUserDictionaryActionError" , error
);
294 html : '<div id="dic_info_editor1" style="margin:5px auto; width:95%;white-space:normal;">' + scayt_instance
. getLocal ( 'text_descriptionDic' ) + '</div>'
302 label : scayt_instance
. getLocal ( 'tab_about' ),
307 style : 'margin: 5px 5px;' ,
308 html : '<div><div id="scayt_about_">' +
315 editor
. on ( "scaytUserDictionaryAction" , function ( event
) {
316 var UILib
= SCAYT
. prototype . UILib
,
317 dialog
= event
. data
. dialog
,
318 dictionaryNote
= dialog
. getContentElement ( "dictionaries" , "dictionaryNote" ). getElement (),
319 scayt_instance
= event
. editor
. scayt
,
322 if ( event
. data
. error
=== undefined ) {
325 messageTemplate
= scayt_instance
. getLocal ( "message_success_" + event
. data
. command
+ "Dic" );
326 messageTemplate
= messageTemplate
. replace ( '%s' , event
. data
. name
);
327 dictionaryNote
. setText ( messageTemplate
);
328 UILib
. css ( dictionaryNote
.$, { color : 'blue' });
332 if ( event
. data
. name
=== '' ) {
334 // empty dictionary name
335 dictionaryNote
. setText ( scayt_instance
. getLocal ( 'message_info_emptyDic' ));
337 messageTemplate
= scayt_instance
. getLocal ( "message_error_" + event
. data
. command
+ "Dic" );
338 messageTemplate
= messageTemplate
. replace ( '%s' , event
. data
. name
);
339 dictionaryNote
. setText ( messageTemplate
);
341 UILib
. css ( dictionaryNote
.$, { color : 'red' });
343 if ( scayt_instance
. getUserDictionaryName () != null && scayt_instance
. getUserDictionaryName () != '' ) {
344 dialog
. getContentElement ( "dictionaries" , "dictionaryName" ). setValue ( scayt_instance
. getUserDictionaryName ());
346 dialog
. getContentElement ( "dictionaries" , "dictionaryName" ). setValue ( "" );
351 editor
. on ( "scaytUserDictionaryActionError" , function ( event
) {
352 var UILib
= SCAYT
. prototype . UILib
,
353 dialog
= event
. data
. dialog
,
354 dictionaryNote
= dialog
. getContentElement ( "dictionaries" , "dictionaryNote" ). getElement (),
355 scayt_instance
= event
. editor
. scayt
,
358 if ( event
. data
. name
=== '' ) {
360 // empty dictionary name
361 dictionaryNote
. setText ( scayt_instance
. getLocal ( 'message_info_emptyDic' ));
363 messageTemplate
= scayt_instance
. getLocal ( "message_error_" + event
. data
. command
+ "Dic" );
364 messageTemplate
= messageTemplate
. replace ( '%s' , event
. data
. name
);
365 dictionaryNote
. setText ( messageTemplate
);
367 UILib
. css ( dictionaryNote
.$, { color : 'red' });
370 if ( scayt_instance
. getUserDictionaryName () != null && scayt_instance
. getUserDictionaryName () != '' ) {
371 dialog
. getContentElement ( "dictionaries" , "dictionaryName" ). setValue ( scayt_instance
. getUserDictionaryName ());
373 dialog
. getContentElement ( "dictionaries" , "dictionaryName" ). setValue ( "" );
378 var plugin
= CKEDITOR
. plugins
. scayt
;
380 var dialogDefinition
= {
381 title : scayt_instance
. getLocal ( 'text_title' ),
382 resizable : CKEDITOR
. DIALOG_RESIZE_BOTH
,
386 if ( editor
. config
. scayt_uiTabs
[ 1 ] == 0 ) {
391 self
= dialogDefinition
,
392 langBoxes
= self
. getLangBoxes
. call ( dialog
);
394 langBoxes
. getParent (). setStyle ( "white-space" , "normal" );
396 //dialog.data = editor.fire( 'scaytDialog', {} );
397 self
. renderLangList ( langBoxes
);
399 var scayt_instance
= editor
. scayt
;
401 this . definition
. minWidth
= this . getSize (). width
;
402 this . resize ( this . definition
. minWidth
, this . definition
. minHeight
);
404 onCancel : function () {
405 languageModelState
. reset ();
408 editor
. unlockSelection ();
411 editor
. fire ( "scaytDialogShown" , this );
413 if ( editor
. config
. scayt_uiTabs
[ 2 ] == 0 ) {
417 var scayt_instance
= editor
. scayt
,
418 self
= dialogDefinition
,
420 dictionaryNameField
= dialog
. getContentElement ( "dictionaries" , "dictionaryName" ),
421 existance
= dialog
. getContentElement ( "dictionaries" , "existDic" ). getElement (). getParent (),
422 notExistance
= dialog
. getContentElement ( "dictionaries" , "notExistDic" ). getElement (). getParent ();
427 if ( scayt_instance
. getUserDictionaryName () != null && scayt_instance
. getUserDictionaryName () != '' ) {
428 dialog
. getContentElement ( "dictionaries" , "dictionaryName" ). setValue ( scayt_instance
. getUserDictionaryName ());
431 dictionaryNameField
. setValue ( "" );
437 self
= dialogDefinition
,
438 scayt_instance
= editor
. scayt
,
439 scaytOptions
= dialog
. getContentElement ( "options" , "scaytOptions" ),
440 changedOptions
= self
. getChangedOption
. call ( dialog
);
442 scayt_instance
. commitOption ({ changedOptions : changedOptions
});
444 toggleDictionaryButtons : function ( exist
) {
445 var existance
= this . getContentElement ( "dictionaries" , "existDic" ). getElement (). getParent (),
446 notExistance
= this . getContentElement ( "dictionaries" , "notExistDic" ). getElement (). getParent ();
457 getChangedOption : function () {
458 var changedOption
= {};
460 if ( editor
. config
. scayt_uiTabs
[ 0 ] == 1 ) {
462 scaytOptions
= dialog
. getContentElement ( "options" , "scaytOptions" ). getChild ();
464 for ( var i
= 0 ; i
< scaytOptions
. length
; i
++) {
465 if ( scaytOptions
[ i
]. isChanged ()) {
466 changedOption
[ scaytOptions
[ i
]. id
] = scaytOptions
[ i
]. getValue ();
471 if ( languageModelState
. isChanged ()) {
472 changedOption
[ languageModelState
. id
] = editor
. config
. scayt_sLang
= languageModelState
. currentLang
= languageModelState
. newLang
;
475 return changedOption
;
477 buildRadioInputs : function ( key
, value
, isSupportedByGrayt
) {
478 var divContainer
= new CKEDITOR
. dom
. element ( 'div' ),
479 doc
= CKEDITOR
. document
,
480 id
= "scaytLang_" + editor
. name
+ '_' + value
,
481 radio
= CKEDITOR
. dom
. element
. createFromHtml ( '<input id="' +
482 id
+ '" type="radio" ' +
483 ' value="' + value
+ '" name="scayt_lang" />' ),
485 radioLabel
= new CKEDITOR
. dom
. element ( 'label' ),
486 scayt_instance
= editor
. scayt
;
488 divContainer
. setStyles ({
489 "white-space" : "normal" ,
490 'position' : 'relative' ,
491 'padding-bottom' : '2px'
494 radio
. on ( 'click' , function ( data
) {
495 languageModelState
. newLang
= data
. sender
. getValue ();
498 radioLabel
. appendText ( key
);
499 radioLabel
. setAttribute ( "for" , id
);
501 if ( isSupportedByGrayt
&& editor
. config
. grayt_autoStartup
) {
502 radioLabel
. setStyles ({
507 divContainer
. append ( radio
);
508 divContainer
. append ( radioLabel
);
510 if ( value
=== scayt_instance
. getLang ()) {
511 radio
. setAttribute ( "checked" , true );
512 radio
. setAttribute ( 'defaultChecked' , 'defaultChecked' );
517 renderLangList : function ( langBoxes
) {
519 leftCol
= langBoxes
. find ( '#left-col-' + editor
. name
). getItem ( 0 ),
520 rightCol
= langBoxes
. find ( '#right-col-' + editor
. name
). getItem ( 0 ),
521 scaytLangList
= scayt_instance
. getScaytLangList (),
522 graytLangList
= scayt_instance
. getGraytLangList (),
526 isSupportedByGrayt
= false ,
529 for ( lang
in scaytLangList
. ltr
) {
530 mergedLangList
[ lang
] = scaytLangList
. ltr
[ lang
];
533 for ( lang
in scaytLangList
. rtl
) {
534 mergedLangList
[ lang
] = scaytLangList
. rtl
[ lang
];
537 // sort alphabetically lang list
538 for ( lang
in mergedLangList
) {
539 sortable
. push ([ lang
, mergedLangList
[ lang
]]);
541 sortable
. sort ( function ( a
, b
) {
545 } else if ( a
[ 1 ] < b
[ 1 ]) {
551 for ( var i
= 0 ; i
< sortable
. length
; i
++) {
552 mergedLangList
[ sortable
[ i
][ 0 ]] = sortable
[ i
][ 1 ];
555 half
= Math
. round ( sortable
. length
/ 2 );
557 for ( lang
in mergedLangList
) {
559 isSupportedByGrayt
= ( lang
in graytLangList
. ltr
) || ( lang
in graytLangList
. rtl
);
560 dialog
. buildRadioInputs ( mergedLangList
[ lang
], lang
, isSupportedByGrayt
). appendTo ( counter
<= half
? leftCol : rightCol
);
563 getLangBoxes : function () {
565 langboxes
= dialog
. getContentElement ( "langs" , "langBox" ). getElement ();
569 contents : generateDialogTabs ( dialogTabs
, editor
)
572 return dialogDefinition
;