-
Notifications
You must be signed in to change notification settings - Fork 7
/
plugin.js
91 lines (78 loc) · 4.06 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
/**
* Reference docs for how to build a CKEditor plugin:
* http://docs.ckeditor.com/#!/guide/plugin_sdk_sample_1
*/
CKEDITOR.plugins.add('bootstrapTabs', {
lang: 'en,ru',
requires: 'dialog',
icons: 'bootstrapTabs',
init: function( editor ) {
// Plugin logic goes here...
// Create the command for the plugin.
editor.addCommand('bootstrapTabs', new CKEDITOR.dialogCommand('bootstrapTabsDialog', {
allowedContent: 'div ul li a[role,href,id,aria-*,data-number-of-tabs,data-tab-set-title,data-toggle](bootstrap-tabs,nav,nav-tabs,tab-link,active,tab-content,tab-pane,tab-pane-content)'
}));
// Add the button for the plugin.
editor.ui.addButton('BootstrapTabs', {
label: editor.lang.bootstrapTabs.buttonLabel,
command: 'bootstrapTabs', // The command that was created by addCommand, above.
toolbar: 'insert' // Defines the toolbar group. Can also specify an index for ordering: 'insert,30' or 'insert,100', or 'insert,0'.
});
CKEDITOR.dialog.add('bootstrapTabsDialog', this.path + 'dialogs/bootstrapTabs.js');
// Context menu support in CKEditor is implemented by the Context Menu plugin.
// The context menu implementation should be placed inside the init function in the plugin file,
// following the command and button definitions.
// The if check here is a "best practice".
// If for some reason the Context Menu plugin will be removed or not available,
// the menu registration should not take place (otherwise an exception is thrown).
// http://docs.ckeditor.com/#!/guide/plugin_sdk_sample_2
if ( editor.contextMenu ) {
editor.addMenuGroup( 'bootstrapTabsGroup' );
editor.addMenuItem( 'bootstrapTabsItem', {
label: editor.lang.bootstrapTabs.contextMenuLabel,
icon: this.path + 'icons/bootstrapTabs.png',
command: 'bootstrapTabs',
group: 'bootstrapTabsGroup'
});
editor.contextMenu.addListener( function(element) {
// If an ascendant of the element has the nav-tabs or tab-content class,
// enable the context menu (a button with off state for the tab)
ascendant = element.getAscendant( function(element) {
// NOTE: The first part of this condition determinds if we've reached the '#document' for the page.
// If we've reached the document ascendant, then calling hasClass() will cause an error, breaking the contextMenu.
// http://docs.ckeditor.com/#!/api/CKEDITOR.dom.document
return !( element instanceof CKEDITOR.dom.document ) &&
( element.hasClass('nav-tabs') || element.hasClass('tab-content') );
});
if ( ascendant ) {
return { bootstrapTabsItem: CKEDITOR.TRISTATE_OFF };
}
});
}
// Register a doubleclick event handler
// When an element is double-clicked, the bootstrapTabsDialog
// will be displayed for elements that are descendents part of a tab set.
editor.on('doubleclick', function (event) {
var element = event.data.element;
// If an ascendant of the element has the nav-tabs or tab-content class,
// enable the context menu (a button with off state for the tab)
ascendant = element.getAscendant( function(element) {
// QUESTION: How to prevent linkDialog from displaying on doubleclick in a nav-tab?
// In the case of of a[role="tab"], the link dialog is not displayed, but the bootstrapTabsDialog
// is not displayed as preferred.
// NOTE: The first part of this condition determinds if we've reached the '#document' for the page.
// If we've reached the document ascendant, then calling hasClass() will cause an error, breaking the contextMenu.
// http://docs.ckeditor.com/#!/api/CKEDITOR.dom.document
return !( element instanceof CKEDITOR.dom.document ) &&
(
( element.name == 'a' && element.attributes.role == 'tab') ||
element.hasClass('nav-tabs') ||
element.hasClass('tab-content')
);
});
if ( ascendant ) {
event.data.dialog = 'bootstrapTabsDialog';
}
});
}
});