/
plugin.js
117 lines (101 loc) · 3.44 KB
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
/**
* @fileOverview Languages plugin.
*/
'use strict';
(function() {
var languagesButtonsGroup = 'languages',
allowedContent = 'span[!lang,!dir]',
requiredContent = 'span[lang,dir]';
CKEDITOR.plugins.add( 'languages', {
requires: 'menubutton',
lang: 'en', // %REMOVE_LINE_CORE%
icons: 'languages', // %REMOVE_LINE_CORE%
hidpi: true, // %REMOVE_LINE_CORE%
init: function( editor ) {
var languagesConfigStrings = ( editor.config.languages || [ 'ar:Arabic:rtl', 'fr:French', 'es:Spanish' ] ),
items = {},
parts,
curLanguageId, // 2-letter lanugage identifier.
i;
// Registers command.
editor.addCommand( 'language', {
allowedContent: allowedContent,
requiredContent: requiredContent,
exec: function( editor, languageId ) {
if ( items[ languageId ] )
editor.applyStyle( items[ languageId ].style );
}
} );
// Parse languagesConfigStrings, and create items entry for each lang.
for ( i = 0; i < languagesConfigStrings.length; i++ ) {
parts = languagesConfigStrings[ i ].split( ':' );
curLanguageId = parts[ 0 ];
items[ curLanguageId ] = {
label: parts[ 1 ],
langId: curLanguageId,
group: languagesButtonsGroup,
order: i,
// Tells if this language is left-to-right oriented (default: true).
ltr: ( String( parts[ 2 ] ).toLowerCase() != 'rtl' ),
// Style property will be assigned after object initialization.
style: null,
onClick: function() {
editor.execCommand( 'language', this.langId );
}
};
// Init style property.
items[ curLanguageId ].style = new CKEDITOR.style( {
element: 'span',
attributes: {
lang: curLanguageId,
dir: items[ curLanguageId ].ltr ? 'ltr' : 'rtl'
}
} );
}
// Initialize group/button.
editor.addMenuGroup( languagesButtonsGroup, 1 );
editor.addMenuItems( items );
editor.ui.add( 'Languages', CKEDITOR.UI_MENUBUTTON, {
label: editor.lang.languages.button,
// MenuButtons do not (yet) has toFeature method, so we cannot do this:
// toFeature: function( editor ) { return editor.getCommand( 'language' ); }
// Set feature's properties directly on button.
allowedContent: allowedContent,
requiredContent: requiredContent,
toolbar: 'bidi,30',
modes: { wysiwyg: 1 },
className: 'cke_button_languages',
onMenu: function() {
var activeItems = {};
for ( var prop in items )
activeItems[ prop ] = CKEDITOR.TRISTATE_ON;
return activeItems;
}
} );
}
} );
}());
/**
* Specifies the list of languages available in the languages plugin. Each entry
* should be a string in the following format:
*
* <languageCode>:<languageLabel>[:<textDirection>]
*
* * _languageCode_: language code used for the lang attribute in ISO 639 format.
* Codes can be found at http://www.loc.gov/standards/iso639-2/php/English_list.php.
* * _languageLabel_: label to show for this language in the list.
* * _textDirection_: (optional) one of following values `rtl` or `ltr`,
* indicating the reading direction for the language text direction. Defaults
* to `ltr`.
*
* For example:
*
* config.languages = [ 'ar:Arabic:rtl', 'fr:French', 'de:Spanish' ];
*
* @cfg {Array} [languages = [ 'ar:Arabic:rtl', 'fr:French', 'de:Spanish' ]]
* @member CKEDITOR.config
*/