-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathplugin.js
107 lines (97 loc) · 2.86 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
/**
* @license Copyright © 2013 Stuart Sillitoe <stuart@vericode.co.uk>
* This is open source, can modify it as you wish.
*
* Stuart Sillitoe
* stuartsillitoe.co.uk
*
*/
/**
* List of dicts which define strings to choose from to insert into the editor.
*
* Each insertable string dict is defined by three possible keys:
* 'value': The value to insert.
* 'name': The name for the string to use in the dropdown.
* 'label': The voice label (also used as the tooltip title) for the string.
*
* Only the value to insert is required to define an insertable string, the
* value will be used as the name (and the name as the label) if other keys are
* not provided.
*
* If the value key is *not* defined and the name key is, then a group header
* with the given name will be provided in the dropdown box. This heading is
* not clickable and does not insert, it is for organizational purposes only.
*/
CKEDITOR.config.strinsert_strings = [
{'name': 'Name', 'value': '*|VALUE|*'},
{'name': 'Group 1'},
{'name': 'Another name', 'value': 'totally_different', 'label': 'Good looking'},
];
/**
* String to use as the button label.
*/
CKEDITOR.config.strinsert_button_label = 'Insert';
/**
* String to use as the button title.
*/
CKEDITOR.config.strinsert_button_title = 'Insert content';
/**
* String to use as the button voice label.
*/
CKEDITOR.config.strinsert_button_voice = 'Insert content';
CKEDITOR.plugins.add('strinsert',
{
requires : ['richcombo'],
init : function( editor )
{
var config = editor.config;
// Gets the list of insertable strings from the settings.
var strings = config.strinsert_strings;
// add the menu to the editor
editor.ui.addRichCombo('strinsert',
{
label: config.strinsert_button_label,
title: config.strinsert_button_title,
voiceLabel: config.strinsert_button_voice,
toolbar: 'insert',
className: 'cke_format',
multiSelect:false,
panel:
{
css: [ editor.config.contentsCss, CKEDITOR.skin.getPath('editor') ],
voiceLabel: editor.lang.panelVoiceLabel
},
init: function()
{
var lastgroup = '';
for(var i=0, len=strings.length; i < len; i++)
{
string = strings[i];
// If there is no value, make a group header using the name.
if (!string.value) {
this.startGroup( string.name );
}
// If we have a value, we have a string insert row.
else {
// If no name provided, use the value for the name.
if (!string.name) {
string.name = string.value;
}
// If no label provided, use the name for the label.
if (!string.label) {
string.label = string.name;
}
this.add(string.value, string.name, string.label);
}
}
},
onClick: function( value )
{
editor.focus();
editor.fire( 'saveSnapshot' );
editor.insertHtml(value);
editor.fire( 'saveSnapshot' );
},
});
}
});