-
Notifications
You must be signed in to change notification settings - Fork 5
/
plugin.js
72 lines (60 loc) · 2.48 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
tinymce.PluginManager.add('bootstrapaccordion', function(editor, url) {
// Add a button that opens a window
editor.addButton('bootstrapaccordion', {
text: 'Bootstrap Accordion',
icon: false,
onclick: accordionDialog,
stateSelector: 'div.bootstrap-accordion *'
});
function accordionDialog() {
var accordionTitle, accordionContent, accordionIn, current, win;
editor.windowManager.open({
title: 'Accordion',
url: url + '/dialog.html',
width: 600,
height: 400,
buttons: [
{
text: 'Insert',
onclick: function() {
var timestamp = new Date().getTime();
var accordionTitle = win.getContentWindow().document.getElementById('accordion-title').value;
var accordionContent = win.getContentWindow().tinyMCE.activeEditor.getContent({format : 'raw'});
var accordionIn = win.getContentWindow().document.getElementById('accordion-open').value == 'Yes' ? ' in' : '';
var accordion =
'<div class="panel panel-default bootstrap-accordion">' +
'<div class="panel-heading" role="tab" id="heading-' + timestamp + '">' +
'<h4 class="panel-title">' +
'<a role="button" class="bootstrap-accordion-title" data-toggle="collapse" data-parent="#accordion" href="#collapse-' + timestamp + '">' +
accordionTitle +
'</a>' +
'</h4>' +
'</div>' +
'<div id="collapse-' + timestamp + '" class="panel-collapse collapse' + accordionIn + '" role="tabpanel">' +
'<div class="panel-body bootstrap-accordion-content">' +
accordionContent +
'</div>'
'</div>'
'</div>';
if(current.length > 0) {
current.remove();
}
editor.insertContent(accordion);
win.close();
}
},
{text: 'Close', onclick: 'close'}
]
});
// Top most window object
win = editor.windowManager.getWindows()[0];
current = $(editor.selection.getNode()).closest('.bootstrap-accordion');
win.getContentWindow().document.body.onload = function() {
if(current.length > 0) {
win.getContentWindow().document.getElementById('accordion-title').value = current.find('.bootstrap-accordion-title').html();
win.getContentWindow().tinyMCE.activeEditor.setContent(current.find('.bootstrap-accordion-content').html());
win.getContentWindow().document.getElementById('accordion-open').value = (current.find('.panel-collapse.collapse.in').length > 0 ? 'Yes' : 'No');
}
}
}
});