2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function (Drupal, debounce, CKEDITOR, $, displace, AjaxCommands) {
9 Drupal.editors.ckeditor = {
10 attach: function attach(element, format) {
11 this._loadExternalPlugins(format);
13 format.editorSettings.drupal = {
17 var label = $('label[for=' + element.getAttribute('id') + ']').html();
18 format.editorSettings.title = Drupal.t('Rich Text Editor, !label field', { '!label': label });
20 return !!CKEDITOR.replace(element, format.editorSettings);
22 detach: function detach(element, format, trigger) {
23 var editor = CKEDITOR.dom.element.get(element).getEditor();
25 if (trigger === 'serialize') {
26 editor.updateElement();
29 element.removeAttribute('contentEditable');
34 onChange: function onChange(element, callback) {
35 var editor = CKEDITOR.dom.element.get(element).getEditor();
37 editor.on('change', debounce(function () {
38 callback(editor.getData());
41 editor.on('mode', function () {
42 var editable = editor.editable();
43 if (!editable.isInline()) {
44 editor.on('autoGrow', function (evt) {
45 var doc = evt.editor.document;
46 var scrollable = CKEDITOR.env.quirks ? doc.getBody() : doc.getDocumentElement();
48 if (scrollable.$.scrollHeight < scrollable.$.clientHeight) {
49 scrollable.setStyle('overflow-y', 'hidden');
51 scrollable.removeStyle('overflow-y');
53 }, null, null, 10000);
59 attachInlineEditor: function attachInlineEditor(element, format, mainToolbarId, floatedToolbarId) {
60 this._loadExternalPlugins(format);
62 format.editorSettings.drupal = {
66 var settings = $.extend(true, {}, format.editorSettings);
69 var settingsOverride = {
70 extraPlugins: 'sharedspace',
71 removePlugins: 'floatingspace,elementspath',
77 var sourceButtonFound = false;
78 for (var i = 0; !sourceButtonFound && i < settings.toolbar.length; i++) {
79 if (settings.toolbar[i] !== '/') {
80 for (var j = 0; !sourceButtonFound && j < settings.toolbar[i].items.length; j++) {
81 if (settings.toolbar[i].items[j] === 'Source') {
82 sourceButtonFound = true;
84 settings.toolbar[i].items[j] = 'Sourcedialog';
85 settingsOverride.extraPlugins += ',sourcedialog';
86 settingsOverride.removePlugins += ',sourcearea';
92 settings.extraPlugins += ',' + settingsOverride.extraPlugins;
93 settings.removePlugins += ',' + settingsOverride.removePlugins;
94 settings.sharedSpaces = settingsOverride.sharedSpaces;
97 element.setAttribute('contentEditable', 'true');
99 return !!CKEDITOR.inline(element, settings);
101 _loadExternalPlugins: function _loadExternalPlugins(format) {
102 var externalPlugins = format.editorSettings.drupalExternalPlugins;
104 if (externalPlugins) {
105 for (var pluginName in externalPlugins) {
106 if (externalPlugins.hasOwnProperty(pluginName)) {
107 CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], '');
110 delete format.editorSettings.drupalExternalPlugins;
118 openDialog: function openDialog(editor, url, existingValues, saveCallback, dialogSettings) {
119 var $target = $(editor.container.$);
120 if (editor.elementMode === CKEDITOR.ELEMENT_MODE_REPLACE) {
121 $target = $target.find('.cke_contents');
124 $target.css('position', 'relative').find('.ckeditor-dialog-loading').remove();
126 var classes = dialogSettings.dialogClass ? dialogSettings.dialogClass.split(' ') : [];
127 classes.push('ui-dialog--narrow');
128 dialogSettings.dialogClass = classes.join(' ');
129 dialogSettings.autoResize = window.matchMedia('(min-width: 600px)').matches;
130 dialogSettings.width = 'auto';
132 var $content = $('<div class="ckeditor-dialog-loading"><span style="top: -40px;" class="ckeditor-dialog-loading-link">' + Drupal.t('Loading...') + '</span></div>');
133 $content.appendTo($target);
135 var ckeditorAjaxDialog = Drupal.ajax({
136 dialog: dialogSettings,
138 selector: '.ckeditor-dialog-loading-link',
140 progress: { type: 'throbber' },
142 editor_object: existingValues
145 ckeditorAjaxDialog.execute();
147 window.setTimeout(function () {
148 $content.find('span').animate({ top: '0px' });
151 Drupal.ckeditor.saveCallback = saveCallback;
155 $(window).on('dialogcreate', function (e, dialog, $element, settings) {
156 $('.ui-dialog--narrow').css('zIndex', CKEDITOR.config.baseFloatZIndex + 1);
159 $(window).on('dialog:beforecreate', function (e, dialog, $element, settings) {
160 $('.ckeditor-dialog-loading').animate({ top: '-40px' }, function () {
165 $(window).on('editor:dialogsave', function (e, values) {
166 if (Drupal.ckeditor.saveCallback) {
167 Drupal.ckeditor.saveCallback(values);
171 $(window).on('dialog:afterclose', function (e, dialog, $element) {
172 if (Drupal.ckeditor.saveCallback) {
173 Drupal.ckeditor.saveCallback = null;
177 $(document).on('drupalViewportOffsetChange', function () {
178 CKEDITOR.config.autoGrow_maxHeight = 0.7 * (window.innerHeight - displace.offsets.top - displace.offsets.bottom);
181 function redirectTextareaFragmentToCKEditorInstance() {
182 var hash = location.hash.substr(1);
183 var element = document.getElementById(hash);
185 var editor = CKEDITOR.dom.element.get(element).getEditor();
187 var id = editor.container.getAttribute('id');
188 location.replace('#' + id);
192 $(window).on('hashchange.ckeditor', redirectTextareaFragmentToCKEditorInstance);
194 CKEDITOR.config.autoGrow_onStartup = true;
196 CKEDITOR.timestamp = drupalSettings.ckeditor.timestamp;
199 AjaxCommands.prototype.ckeditor_add_stylesheet = function (ajax, response, status) {
200 var editor = CKEDITOR.instances[response.editor_id];
203 response.stylesheets.forEach(function (url) {
204 editor.document.appendStyleSheet(url);
209 })(Drupal, Drupal.debounce, CKEDITOR, jQuery, Drupal.displace, Drupal.AjaxCommands);