-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin.js
executable file
·326 lines (247 loc) · 12 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// Init default alert classes
CKEDITOR.config.widgetbootstrapAlert_alertTypes = {
'alert': 'Alert',
'info': 'Info',
'warning': 'Warning',
'success': 'Success'
};
CKEDITOR.plugins.add( 'widgetbootstrap', {
requires: 'widget',
icons: 'widgetbootstrapLeftCol,widgetbootstrapRightCol,widgetbootstrapTwoCol,widgetbootstrapThreeCol,widgetbootstrapAlert',
/*defaults : {
name: 'accordion',
count: 3,
activePanel: 1,
multiExpand: false
},*/
init: function( editor ) {
// Configurable settings
//var allowedWidget = editor.config.widgetbootstrap_allowedWidget != undefined ? editor.config.widgetbootstrap_allowedFull :
// 'p h2 h3 h4 h5 h6 span br ul ol li strong em img[!src,alt,width,height]';
var allowedFull = editor.config.widgetbootstrap_allowedFull != undefined ? editor.config.widgetbootstrap_allowedFull :
'p a div span h2 h3 h4 h5 h6 section article iframe object embed strong b i em cite pre blockquote small sub sup code ul ol li dl dt dd table thead tbody th tr td img caption mediawrapper br[href,src,target,width,height,colspan,span,alt,name,title,class,id,data-options]{text-align,float,margin}(*);'
//var allowedText = editor.config.widgetbootstrap_allowedText != undefined ? editor.config.widgetbootstrap_allowedFull :
// 'p span br ul ol li strong em';
allowedWidget = allowedFull;
//allowedText = allowedWidget;
var showButtons = editor.config.widgetbootstrapShowButtons != undefined ? editor.config.widgetbootstrapShowButtons : true;
// Define the widgets
editor.widgets.add( 'widgetbootstrapLeftCol', {
button: showButtons ? 'Add left column box' : undefined,
template:
'<div class="row two-col-left">' +
'<div class="col-md-3 col-sidebar"><p><img src="http://placehold.it/300x250&text=Image" /></p></div>' +
'<div class="col-md-9 col-main"><p>Content</p></div>' +
'</div>',
editables: {
col1: {
selector: '.col-sidebar',
allowedContent: allowedWidget
},
col2: {
selector: '.col-main',
allowedContent: allowedWidget
}
},
allowedContent: allowedFull,
upcast: function( element ) {
return element.name == 'div' && element.hasClass( 'two-col-right-left' );
}
} );
editor.widgets.add( 'widgetbootstrapRightCol', {
button: showButtons ? 'Add right column box' : undefined,
template:
'<div class="row two-col-right">' +
'<div class="col-md-9 col-main"><p>Content</p></div>' +
'<div class="col-md-3 col-sidebar"><p><img src="http://placehold.it/300x250&text=Image" /></p></div>' +
'</div>',
editables: {
col1: {
selector: '.col-sidebar',
allowedContent: allowedWidget
},
col2: {
selector: '.col-main',
allowedContent: allowedWidget
}
},
allowedContent: allowedFull,
upcast: function( element ) {
return element.name == 'div' && element.hasClass( 'two-col-right' );
}
} );
editor.widgets.add( 'widgetbootstrapTwoCol', {
button: showButtons ? 'Add two column box' : undefined,
template:
'<div class="row two-col">' +
'<div class="col-md-6 col-1"><p><img src="http://placehold.it/500x280&text=Image" /></p><p>Content</p></div>' +
'<div class="col-md-6 col-2"><p><img src="http://placehold.it/500x280&text=Image" /></p><p>Content</p></div>' +
'</div>',
editables: {
col1: {
selector: '.col-1',
allowedContent: allowedWidget
},
col2: {
selector: '.col-2',
allowedContent: allowedWidget
}
},
allowedContent: allowedFull,
upcast: function( element ) {
return element.name == 'div' && element.hasClass( 'two-col' );
}
} );
editor.widgets.add( 'widgetbootstrapThreeCol', {
button: showButtons ? 'Add three column box' : undefined,
template:
'<div class="row three-col">' +
'<div class="col-md-4 col-1"><p><img src="http://placehold.it/400x225&text=Image" /></p><p>Text below</p></div>' +
'<div class="col-md-4 col-2"><p><img src="http://placehold.it/400x225&text=Image" /></p><p>Text below</p></div>' +
'<div class="col-md-4 col-3"><p><img src="http://placehold.it/400x225&text=Image" /></p><p>Text below</p></div>' +
'</div>',
editables: {
col1: {
selector: '.col-1',
allowedContent: allowedWidget
},
col2: {
selector: '.col-2',
allowedContent: allowedWidget
},
col3: {
selector: '.col-3',
allowedContent: allowedWidget
}
},
allowedContent: allowedFull,
upcast: function( element ) {
return element.name == 'div' && element.hasClass( 'three-col' );
}
} );
editor.addCommand( 'openwidgetbootstrapAlert', new CKEDITOR.dialogCommand( 'widgetbootstrapAlert' ) );
// Add foundation alert button
// Textare decodes html entities
//var textarea = new CKEDITOR.dom.element( 'textarea' );
editor.widgets.add( 'widgetbootstrapAlert', {
button: showButtons ? 'Add alert box' : undefined,
dialog: 'widgetbootstrapAlert',
template: '<div class="alert-box"><div class="alert-text">Some Text</span></div>',
editables: {
alertBox: {
selector: '.alert-text',
allowedContent: allowedWidget
},
},
allowedContent: allowedFull,
data: function() {
var newData = this.data,
oldData = this.oldData;
/*if( newData.alertText ) {
this.element.getChild( 0 ).setHtml( CKEDITOR.tools.htmlEncode( newData.alertText ) );
}*/
if ( oldData && newData.type != oldData.type )
this.element.removeClass(oldData.type);
if ( newData.type )
this.element.addClass(newData.type);
// Save oldData.
this.oldData = CKEDITOR.tools.copy( newData );
},
upcast: function( el, data ) {
if (el.name != 'div' || !el.hasClass( 'alert-box' ))
return;
var childrenArray = el.children,
alertText;
if ( childrenArray.length !== 1 || !( alertText = childrenArray[ 0 ] ).hasClass('alert-text'))
return;
// Acceptable alert types
var alertTypes = CKEDITOR.config.widgetbootstrapAlert_alertTypes;
// Check alert types
for(var i = 0; i < el.classes.length; i++) {
if(el.classes[i] != 'alert-box') {
for ( alertName in alertTypes ) {
if(el.classes[i] == alertName) {
data.type = alertName;
}
}
}
}
// Use textarea to decode HTML entities (#11926).
//textarea.setHtml( alertText.getHtml() );
//data.alertText = textarea.getValue();
return el;
},
downcast: function( el ) {
return el;
}
} );
// Alert dialog
CKEDITOR.dialog.add( 'widgetbootstrapAlert', this.path + 'dialogs/widgetbootstrapAlert.js' );
/*CKEDITOR.dialog.add( 'widgetbootstrapAccordion', this.path + 'dialogs/widgetbootstrapAccordion.js' );
editor.widgets.add( 'widgetbootstrapAccordion', {
button: showButtons ? 'Add accordion box' : undefined,
template:
'<dl class="accordion" data-accordion><div class="col-1"></div></dl>',
allowedContent: allowedFull,
dialog: 'widgetbootstrapAccordion',
upcast: function( element ) {
return element.name == 'div' && element.hasClass( 'accordion' );
},
/*init: function() {
var width = this.element.getStyle( 'width' );
if ( width )
this.setData( 'width', width );
if ( this.element.hasClass( 'align-left' ) )
this.setData( 'align', 'left' );
if ( this.element.hasClass( 'align-right' ) )
this.setData( 'align', 'right' );
if ( this.element.hasClass( 'align-center' ) )
this.setData( 'align', 'center' );
},
data: function() {
var name = this.data.name != undefined ? this.data.name : 'accordion';
var count = this.data.count != undefined ? this.data.count : 0;
//@todo: var prevCount = this.data.prevCount != undefined ? this.data.prevCount :
// Add rows
if (this.data.prevCount == undefined || this.data.prevCount < count) {
for (var i=this.data.prevCount != undefined ? this.data.prevCount : 1; i<=count; i++) {
var active = this.data.activePanel == i ? ' active' : '';
var template =
'<dd class="accordion-navigation">' +
'<a href="#'+ name+i +'"><div class="accordion-header-'+i+'">Heading '+i+'</div></a>' +
'<div id="panel'+ name+i +'" class="content content-'+i+active+'">' +
'' +
'</div>'
'</dd>'
var newPanel = CKEDITOR.dom.element.createFromHtml( template );
this.element.append(newPanel);
}
// For some reason, the initEditable call needs to come in a separate for loop
// the html code added wasn't in the DOM yet
for (var i=this.data.prevCount != undefined ? this.data.prevCount : 1; i<=count; i++) {
this.initEditable( 'heading'+i, {
selector: '.accordion-header-'+i
} );
this.initEditable( 'content'+i, {
selector: '.content-'+i
} );
}
}
// Remove rows
if (this.data.prevCount != undefined && this.data.prevCount > count) {
// @todo
}
this.data.prevCount = i;
}
} );*/
// Append the widget's styles when in the CKEditor edit page,
// added for better user experience.
// Assign or append the widget's styles depending on the existing setup.
if (typeof editor.config.contentsCss == 'object') {
editor.config.contentsCss.push(CKEDITOR.getUrl(this.path + 'contents.css'));
}
else {
editor.config.contentsCss = [editor.config.contentsCss, CKEDITOR.getUrl(this.path + 'contents.css')];
}
}
} );