-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss-lightbox-tinymce.js
54 lines (51 loc) · 1.93 KB
/
css-lightbox-tinymce.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
jQuery(document).ready(function() {
tinymce.create('tinymce.plugins.csslightbox', {
init: function(editor, url) {
editor.addCommand('css_lightbox_insert_shortcode', function() {
selected = tinyMCE.activeEditor.selection.getContent();
// Only works if user has selected an image url, otherwise abort
if ( ! selected ) {
return;
}
editor.windowManager.open({
title: 'Create a CSS lightbox',
body: [
{type: 'textbox', name: 'id', label: editor.getLang('css-lightbox.id')},
{type: 'textbox', name: 'title', label: editor.getLang('css-lightbox.title')},
{type: 'textbox', name: 'caption', label: editor.getLang('css-lightbox.caption')},
{type: 'textbox', name: 'width', label: editor.getLang('css-lightbox.width')},
{type: 'textbox', name: 'height', label: editor.getLang('css-lightbox.height')},
{type: 'textbox', name: 'alt', label: editor.getLang('css-lightbox.alt')},
{type: 'checkbox', name: 'icon', label: editor.getLang('css-lightbox.icon')}
],
onsubmit: function( e ) {
// Only works if user specifies an ID, otherwise abort
if ( ! e.data.id ) {
return;
}
var new_content = '[css_lightbox id="' + e.data.id + '"';
var atts = [];
atts['title'] = e.data.title;
atts['caption'] = e.data.caption;
atts['width'] = e.data.width;
atts['height'] = e.data.height;
atts['alt'] = e.data.alt;
atts['icon'] = e.data.icon;
for( var index in atts) {
new_content += ' ' + index + '="' + atts[index] + '"';
}
new_content += ']';
editor.insertContent( new_content + selected + '[/css_lightbox]' );
}
});
});
editor.addButton('css_lightbox_button', {
title: 'Create lightbox for image url',
text: 'Lightbox',
icon: false,
cmd: 'css_lightbox_insert_shortcode'
});
}
});
tinymce.PluginManager.add( 'css_lightbox_button', tinymce.plugins.csslightbox );
});