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', {
22 return !!CKEDITOR.replace(element, format.editorSettings);
24 detach: function detach(element, format, trigger) {
25 var editor = CKEDITOR.dom.element.get(element).getEditor();
27 if (trigger === 'serialize') {
28 editor.updateElement();
31 element.removeAttribute('contentEditable');
36 onChange: function onChange(element, callback) {
37 var editor = CKEDITOR.dom.element.get(element).getEditor();
39 editor.on('change', debounce(function () {
40 callback(editor.getData());
43 editor.on('mode', function () {
44 var editable = editor.editable();
45 if (!editable.isInline()) {
46 editor.on('autoGrow', function (evt) {
47 var doc = evt.editor.document;
48 var scrollable = CKEDITOR.env.quirks ? doc.getBody() : doc.getDocumentElement();
50 if (scrollable.$.scrollHeight < scrollable.$.clientHeight) {
51 scrollable.setStyle('overflow-y', 'hidden');
53 scrollable.removeStyle('overflow-y');
55 }, null, null, 10000);
61 attachInlineEditor: function attachInlineEditor(element, format, mainToolbarId, floatedToolbarId) {
62 this._loadExternalPlugins(format);
64 format.editorSettings.drupal = {
68 var settings = $.extend(true, {}, format.editorSettings);
71 var settingsOverride = {
72 extraPlugins: 'sharedspace',
73 removePlugins: 'floatingspace,elementspath',
79 var sourceButtonFound = false;
80 for (var i = 0; !sourceButtonFound && i < settings.toolbar.length; i++) {
81 if (settings.toolbar[i] !== '/') {
82 for (var j = 0; !sourceButtonFound && j < settings.toolbar[i].items.length; j++) {
83 if (settings.toolbar[i].items[j] === 'Source') {
84 sourceButtonFound = true;
86 settings.toolbar[i].items[j] = 'Sourcedialog';
87 settingsOverride.extraPlugins += ',sourcedialog';
88 settingsOverride.removePlugins += ',sourcearea';
94 settings.extraPlugins += ',' + settingsOverride.extraPlugins;
95 settings.removePlugins += ',' + settingsOverride.removePlugins;
96 settings.sharedSpaces = settingsOverride.sharedSpaces;
99 element.setAttribute('contentEditable', 'true');
101 return !!CKEDITOR.inline(element, settings);
103 _loadExternalPlugins: function _loadExternalPlugins(format) {
104 var externalPlugins = format.editorSettings.drupalExternalPlugins;
106 if (externalPlugins) {
107 Object.keys(externalPlugins || {}).forEach(function (pluginName) {
108 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 = window.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 window.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);