Chris@0
|
1 /**
|
Chris@0
|
2 * DO NOT EDIT THIS FILE.
|
Chris@0
|
3 * See the following change record for more information,
|
Chris@0
|
4 * https://www.drupal.org/node/2815083
|
Chris@0
|
5 * @preserve
|
Chris@0
|
6 **/
|
Chris@0
|
7
|
Chris@0
|
8 (function ($, Drupal, drupalSettings, _) {
|
Chris@0
|
9 Drupal.ckeditor = Drupal.ckeditor || {};
|
Chris@0
|
10
|
Chris@0
|
11 Drupal.behaviors.ckeditorAdmin = {
|
Chris@0
|
12 attach: function attach(context) {
|
Chris@0
|
13 var $configurationForm = $(context).find('.ckeditor-toolbar-configuration').once('ckeditor-configuration');
|
Chris@0
|
14 if ($configurationForm.length) {
|
Chris@0
|
15 var $textarea = $configurationForm.find('.js-form-item-editor-settings-toolbar-button-groups').hide().find('textarea');
|
Chris@0
|
16
|
Chris@0
|
17 $configurationForm.append(drupalSettings.ckeditor.toolbarAdmin);
|
Chris@0
|
18
|
Chris@14
|
19 Drupal.ckeditor.models.Model = new Drupal.ckeditor.Model({
|
Chris@0
|
20 $textarea: $textarea,
|
Chris@0
|
21 activeEditorConfig: JSON.parse($textarea.val()),
|
Chris@0
|
22 hiddenEditorConfig: drupalSettings.ckeditor.hiddenCKEditorConfig
|
Chris@0
|
23 });
|
Chris@0
|
24
|
Chris@0
|
25 var viewDefaults = {
|
Chris@14
|
26 model: Drupal.ckeditor.models.Model,
|
Chris@0
|
27 el: $('.ckeditor-toolbar-configuration')
|
Chris@0
|
28 };
|
Chris@0
|
29 Drupal.ckeditor.views = {
|
Chris@0
|
30 controller: new Drupal.ckeditor.ControllerView(viewDefaults),
|
Chris@0
|
31 visualView: new Drupal.ckeditor.VisualView(viewDefaults),
|
Chris@0
|
32 keyboardView: new Drupal.ckeditor.KeyboardView(viewDefaults),
|
Chris@0
|
33 auralView: new Drupal.ckeditor.AuralView(viewDefaults)
|
Chris@0
|
34 };
|
Chris@0
|
35 }
|
Chris@0
|
36 },
|
Chris@0
|
37 detach: function detach(context, settings, trigger) {
|
Chris@0
|
38 if (trigger !== 'unload') {
|
Chris@0
|
39 return;
|
Chris@0
|
40 }
|
Chris@0
|
41
|
Chris@0
|
42 var $configurationForm = $(context).find('.ckeditor-toolbar-configuration').findOnce('ckeditor-configuration');
|
Chris@0
|
43 if ($configurationForm.length && Drupal.ckeditor.models && Drupal.ckeditor.models.Model) {
|
Chris@0
|
44 var config = Drupal.ckeditor.models.Model.toJSON().activeEditorConfig;
|
Chris@0
|
45 var buttons = Drupal.ckeditor.views.controller.getButtonList(config);
|
Chris@0
|
46 var $activeToolbar = $('.ckeditor-toolbar-configuration').find('.ckeditor-toolbar-active');
|
Chris@0
|
47 for (var i = 0; i < buttons.length; i++) {
|
Chris@0
|
48 $activeToolbar.trigger('CKEditorToolbarChanged', ['removed', buttons[i]]);
|
Chris@0
|
49 }
|
Chris@0
|
50 }
|
Chris@0
|
51 }
|
Chris@0
|
52 };
|
Chris@0
|
53
|
Chris@0
|
54 Drupal.ckeditor = {
|
Chris@0
|
55 views: {},
|
Chris@0
|
56
|
Chris@0
|
57 models: {},
|
Chris@0
|
58
|
Chris@0
|
59 registerButtonMove: function registerButtonMove(view, $button, callback) {
|
Chris@0
|
60 var $group = $button.closest('.ckeditor-toolbar-group');
|
Chris@0
|
61
|
Chris@0
|
62 if ($group.hasClass('placeholder')) {
|
Chris@0
|
63 if (view.isProcessing) {
|
Chris@0
|
64 return;
|
Chris@0
|
65 }
|
Chris@0
|
66 view.isProcessing = true;
|
Chris@0
|
67
|
Chris@0
|
68 Drupal.ckeditor.openGroupNameDialog(view, $group, callback);
|
Chris@0
|
69 } else {
|
Chris@0
|
70 view.model.set('isDirty', true);
|
Chris@0
|
71 callback(true);
|
Chris@0
|
72 }
|
Chris@0
|
73 },
|
Chris@0
|
74 registerGroupMove: function registerGroupMove(view, $group) {
|
Chris@0
|
75 var $row = $group.closest('.ckeditor-row');
|
Chris@0
|
76 if ($row.hasClass('placeholder')) {
|
Chris@0
|
77 $row.removeClass('placeholder');
|
Chris@0
|
78 }
|
Chris@0
|
79
|
Chris@0
|
80 $row.parent().children().each(function () {
|
Chris@0
|
81 $row = $(this);
|
Chris@0
|
82 if ($row.find('.ckeditor-toolbar-group').not('.placeholder').length === 0) {
|
Chris@0
|
83 $row.addClass('placeholder');
|
Chris@0
|
84 }
|
Chris@0
|
85 });
|
Chris@0
|
86 view.model.set('isDirty', true);
|
Chris@0
|
87 },
|
Chris@0
|
88 openGroupNameDialog: function openGroupNameDialog(view, $group, callback) {
|
Chris@0
|
89 callback = callback || function () {};
|
Chris@0
|
90
|
Chris@0
|
91 function validateForm(form) {
|
Chris@0
|
92 if (form.elements[0].value.length === 0) {
|
Chris@0
|
93 var $form = $(form);
|
Chris@0
|
94 if (!$form.hasClass('errors')) {
|
Chris@0
|
95 $form.addClass('errors').find('input').addClass('error').attr('aria-invalid', 'true');
|
Chris@0
|
96 $('<div class="description" >' + Drupal.t('Please provide a name for the button group.') + '</div>').insertAfter(form.elements[0]);
|
Chris@0
|
97 }
|
Chris@0
|
98 return true;
|
Chris@0
|
99 }
|
Chris@0
|
100 return false;
|
Chris@0
|
101 }
|
Chris@0
|
102
|
Chris@0
|
103 function closeDialog(action, form) {
|
Chris@0
|
104 function shutdown() {
|
Chris@0
|
105 dialog.close(action);
|
Chris@0
|
106
|
Chris@0
|
107 delete view.isProcessing;
|
Chris@0
|
108 }
|
Chris@0
|
109
|
Chris@0
|
110 function namePlaceholderGroup($group, name) {
|
Chris@0
|
111 if ($group.hasClass('placeholder')) {
|
Chris@0
|
112 var groupID = 'ckeditor-toolbar-group-aria-label-for-' + Drupal.checkPlain(name.toLowerCase().replace(/\s/g, '-'));
|
Chris@0
|
113 $group.removeAttr('aria-label').attr('data-drupal-ckeditor-type', 'group').attr('tabindex', 0).children('.ckeditor-toolbar-group-name').attr('id', groupID).end().children('.ckeditor-toolbar-group-buttons').attr('aria-labelledby', groupID);
|
Chris@0
|
114 }
|
Chris@0
|
115
|
Chris@0
|
116 $group.attr('data-drupal-ckeditor-toolbar-group-name', name).children('.ckeditor-toolbar-group-name').text(name);
|
Chris@0
|
117 }
|
Chris@0
|
118
|
Chris@0
|
119 if (action === 'cancel') {
|
Chris@0
|
120 shutdown();
|
Chris@0
|
121 callback(false, $group);
|
Chris@0
|
122 return;
|
Chris@0
|
123 }
|
Chris@0
|
124
|
Chris@0
|
125 if (form && validateForm(form)) {
|
Chris@0
|
126 return;
|
Chris@0
|
127 }
|
Chris@0
|
128
|
Chris@0
|
129 if (action === 'apply') {
|
Chris@0
|
130 shutdown();
|
Chris@0
|
131
|
Chris@0
|
132 namePlaceholderGroup($group, Drupal.checkPlain(form.elements[0].value));
|
Chris@0
|
133
|
Chris@0
|
134 $group.closest('.ckeditor-row.placeholder').addBack().removeClass('placeholder');
|
Chris@0
|
135
|
Chris@0
|
136 callback(true, $group);
|
Chris@0
|
137
|
Chris@0
|
138 view.model.set('isDirty', true);
|
Chris@0
|
139 }
|
Chris@0
|
140 }
|
Chris@0
|
141
|
Chris@0
|
142 var $ckeditorButtonGroupNameForm = $(Drupal.theme('ckeditorButtonGroupNameForm'));
|
Chris@0
|
143 var dialog = Drupal.dialog($ckeditorButtonGroupNameForm.get(0), {
|
Chris@0
|
144 title: Drupal.t('Button group name'),
|
Chris@0
|
145 dialogClass: 'ckeditor-name-toolbar-group',
|
Chris@0
|
146 resizable: false,
|
Chris@0
|
147 buttons: [{
|
Chris@0
|
148 text: Drupal.t('Apply'),
|
Chris@0
|
149 click: function click() {
|
Chris@0
|
150 closeDialog('apply', this);
|
Chris@0
|
151 },
|
Chris@0
|
152
|
Chris@0
|
153 primary: true
|
Chris@0
|
154 }, {
|
Chris@0
|
155 text: Drupal.t('Cancel'),
|
Chris@0
|
156 click: function click() {
|
Chris@0
|
157 closeDialog('cancel');
|
Chris@0
|
158 }
|
Chris@0
|
159 }],
|
Chris@0
|
160 open: function open() {
|
Chris@0
|
161 var form = this;
|
Chris@0
|
162 var $form = $(this);
|
Chris@0
|
163 var $widget = $form.parent();
|
Chris@0
|
164 $widget.find('.ui-dialog-titlebar-close').remove();
|
Chris@0
|
165
|
Chris@0
|
166 $widget.on('keypress.ckeditor', 'input, button', function (event) {
|
Chris@0
|
167 if (event.keyCode === 13) {
|
Chris@0
|
168 var $target = $(event.currentTarget);
|
Chris@0
|
169 var data = $target.data('ui-button');
|
Chris@0
|
170 var action = 'apply';
|
Chris@0
|
171
|
Chris@0
|
172 if (data && data.options && data.options.label) {
|
Chris@0
|
173 action = data.options.label.toLowerCase();
|
Chris@0
|
174 }
|
Chris@0
|
175 closeDialog(action, form);
|
Chris@0
|
176 event.stopPropagation();
|
Chris@0
|
177 event.stopImmediatePropagation();
|
Chris@0
|
178 event.preventDefault();
|
Chris@0
|
179 }
|
Chris@0
|
180 });
|
Chris@0
|
181
|
Chris@0
|
182 var text = Drupal.t('Editing the name of the new button group in a dialog.');
|
Chris@0
|
183 if (typeof $group.attr('data-drupal-ckeditor-toolbar-group-name') !== 'undefined') {
|
Chris@0
|
184 text = Drupal.t('Editing the name of the "@groupName" button group in a dialog.', {
|
Chris@0
|
185 '@groupName': $group.attr('data-drupal-ckeditor-toolbar-group-name')
|
Chris@0
|
186 });
|
Chris@0
|
187 }
|
Chris@0
|
188 Drupal.announce(text);
|
Chris@0
|
189 },
|
Chris@0
|
190 close: function close(event) {
|
Chris@0
|
191 $(event.target).remove();
|
Chris@0
|
192 }
|
Chris@0
|
193 });
|
Chris@0
|
194
|
Chris@0
|
195 dialog.showModal();
|
Chris@0
|
196
|
Chris@0
|
197 $(document.querySelector('.ckeditor-name-toolbar-group').querySelector('input')).attr('value', $group.attr('data-drupal-ckeditor-toolbar-group-name')).trigger('focus');
|
Chris@0
|
198 }
|
Chris@0
|
199 };
|
Chris@0
|
200
|
Chris@0
|
201 Drupal.behaviors.ckeditorAdminButtonPluginSettings = {
|
Chris@0
|
202 attach: function attach(context) {
|
Chris@0
|
203 var $context = $(context);
|
Chris@0
|
204 var $ckeditorPluginSettings = $context.find('#ckeditor-plugin-settings').once('ckeditor-plugin-settings');
|
Chris@0
|
205 if ($ckeditorPluginSettings.length) {
|
Chris@0
|
206 $ckeditorPluginSettings.find('[data-ckeditor-buttons]').each(function () {
|
Chris@0
|
207 var $this = $(this);
|
Chris@0
|
208 if ($this.data('verticalTab')) {
|
Chris@0
|
209 $this.data('verticalTab').tabHide();
|
Chris@0
|
210 } else {
|
Chris@0
|
211 $this.hide();
|
Chris@0
|
212 }
|
Chris@0
|
213 $this.data('ckeditorButtonPluginSettingsActiveButtons', []);
|
Chris@0
|
214 });
|
Chris@0
|
215
|
Chris@0
|
216 $context.find('.ckeditor-toolbar-active').off('CKEditorToolbarChanged.ckeditorAdminPluginSettings').on('CKEditorToolbarChanged.ckeditorAdminPluginSettings', function (event, action, button) {
|
Chris@0
|
217 var $pluginSettings = $ckeditorPluginSettings.find('[data-ckeditor-buttons~=' + button + ']');
|
Chris@0
|
218
|
Chris@0
|
219 if ($pluginSettings.length === 0) {
|
Chris@0
|
220 return;
|
Chris@0
|
221 }
|
Chris@0
|
222
|
Chris@0
|
223 var verticalTab = $pluginSettings.data('verticalTab');
|
Chris@0
|
224 var activeButtons = $pluginSettings.data('ckeditorButtonPluginSettingsActiveButtons');
|
Chris@0
|
225 if (action === 'added') {
|
Chris@0
|
226 activeButtons.push(button);
|
Chris@0
|
227
|
Chris@0
|
228 if (verticalTab) {
|
Chris@0
|
229 verticalTab.tabShow();
|
Chris@0
|
230 } else {
|
Chris@0
|
231 $pluginSettings.show();
|
Chris@0
|
232 }
|
Chris@0
|
233 } else {
|
Chris@0
|
234 activeButtons.splice(activeButtons.indexOf(button), 1);
|
Chris@0
|
235
|
Chris@0
|
236 if (activeButtons.length === 0) {
|
Chris@0
|
237 if (verticalTab) {
|
Chris@0
|
238 verticalTab.tabHide();
|
Chris@0
|
239 } else {
|
Chris@0
|
240 $pluginSettings.hide();
|
Chris@0
|
241 }
|
Chris@0
|
242 }
|
Chris@0
|
243 }
|
Chris@0
|
244 $pluginSettings.data('ckeditorButtonPluginSettingsActiveButtons', activeButtons);
|
Chris@0
|
245 });
|
Chris@0
|
246 }
|
Chris@0
|
247 }
|
Chris@0
|
248 };
|
Chris@0
|
249
|
Chris@0
|
250 Drupal.theme.ckeditorRow = function () {
|
Chris@0
|
251 return '<li class="ckeditor-row placeholder" role="group"><ul class="ckeditor-toolbar-groups clearfix"></ul></li>';
|
Chris@0
|
252 };
|
Chris@0
|
253
|
Chris@0
|
254 Drupal.theme.ckeditorToolbarGroup = function () {
|
Chris@0
|
255 var group = '';
|
Chris@0
|
256 group += '<li class="ckeditor-toolbar-group placeholder" role="presentation" aria-label="' + Drupal.t('Place a button to create a new button group.') + '">';
|
Chris@0
|
257 group += '<h3 class="ckeditor-toolbar-group-name">' + Drupal.t('New group') + '</h3>';
|
Chris@0
|
258 group += '<ul class="ckeditor-buttons ckeditor-toolbar-group-buttons" role="toolbar" data-drupal-ckeditor-button-sorting="target"></ul>';
|
Chris@0
|
259 group += '</li>';
|
Chris@0
|
260 return group;
|
Chris@0
|
261 };
|
Chris@0
|
262
|
Chris@0
|
263 Drupal.theme.ckeditorButtonGroupNameForm = function () {
|
Chris@0
|
264 return '<form><input name="group-name" required="required"></form>';
|
Chris@0
|
265 };
|
Chris@0
|
266
|
Chris@0
|
267 Drupal.theme.ckeditorButtonGroupNamesToggle = function () {
|
Chris@0
|
268 return '<button class="link ckeditor-groupnames-toggle" aria-pressed="false"></button>';
|
Chris@0
|
269 };
|
Chris@0
|
270
|
Chris@0
|
271 Drupal.theme.ckeditorNewButtonGroup = function () {
|
Chris@0
|
272 return '<li class="ckeditor-add-new-group"><button aria-label="' + Drupal.t('Add a CKEditor button group to the end of this row.') + '">' + Drupal.t('Add group') + '</button></li>';
|
Chris@0
|
273 };
|
Chris@0
|
274 })(jQuery, Drupal, drupalSettings, _); |