123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- /**
- * DO NOT EDIT THIS FILE.
- * See the following change record for more information,
- * https://www.drupal.org/node/2815083
- * @preserve
- **/
- (function (Drupal, debounce, CKEDITOR, $, displace, AjaxCommands) {
- Drupal.editors.ckeditor = {
- attach: function attach(element, format) {
- this._loadExternalPlugins(format);
- format.editorSettings.drupal = {
- format: format.format
- };
- var label = $('label[for=' + element.getAttribute('id') + ']').html();
- format.editorSettings.title = Drupal.t('Rich Text Editor, !label field', {
- '!label': label
- });
- return !!CKEDITOR.replace(element, format.editorSettings);
- },
- detach: function detach(element, format, trigger) {
- var editor = CKEDITOR.dom.element.get(element).getEditor();
- if (editor) {
- if (trigger === 'serialize') {
- editor.updateElement();
- } else {
- editor.destroy();
- element.removeAttribute('contentEditable');
- }
- }
- return !!editor;
- },
- onChange: function onChange(element, callback) {
- var editor = CKEDITOR.dom.element.get(element).getEditor();
- if (editor) {
- editor.on('change', debounce(function () {
- callback(editor.getData());
- }, 400));
- editor.on('mode', function () {
- var editable = editor.editable();
- if (!editable.isInline()) {
- editor.on('autoGrow', function (evt) {
- var doc = evt.editor.document;
- var scrollable = CKEDITOR.env.quirks ? doc.getBody() : doc.getDocumentElement();
- if (scrollable.$.scrollHeight < scrollable.$.clientHeight) {
- scrollable.setStyle('overflow-y', 'hidden');
- } else {
- scrollable.removeStyle('overflow-y');
- }
- }, null, null, 10000);
- }
- });
- }
- return !!editor;
- },
- attachInlineEditor: function attachInlineEditor(element, format, mainToolbarId, floatedToolbarId) {
- this._loadExternalPlugins(format);
- format.editorSettings.drupal = {
- format: format.format
- };
- var settings = $.extend(true, {}, format.editorSettings);
- if (mainToolbarId) {
- var settingsOverride = {
- extraPlugins: 'sharedspace',
- removePlugins: 'floatingspace,elementspath',
- sharedSpaces: {
- top: mainToolbarId
- }
- };
- var sourceButtonFound = false;
- for (var i = 0; !sourceButtonFound && i < settings.toolbar.length; i++) {
- if (settings.toolbar[i] !== '/') {
- for (var j = 0; !sourceButtonFound && j < settings.toolbar[i].items.length; j++) {
- if (settings.toolbar[i].items[j] === 'Source') {
- sourceButtonFound = true;
- settings.toolbar[i].items[j] = 'Sourcedialog';
- settingsOverride.extraPlugins += ',sourcedialog';
- settingsOverride.removePlugins += ',sourcearea';
- }
- }
- }
- }
- settings.extraPlugins += ',' + settingsOverride.extraPlugins;
- settings.removePlugins += ',' + settingsOverride.removePlugins;
- settings.sharedSpaces = settingsOverride.sharedSpaces;
- }
- element.setAttribute('contentEditable', 'true');
- return !!CKEDITOR.inline(element, settings);
- },
- _loadExternalPlugins: function _loadExternalPlugins(format) {
- var externalPlugins = format.editorSettings.drupalExternalPlugins;
- if (externalPlugins) {
- Object.keys(externalPlugins || {}).forEach(function (pluginName) {
- CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], '');
- });
- delete format.editorSettings.drupalExternalPlugins;
- }
- }
- };
- Drupal.ckeditor = {
- saveCallback: null,
- openDialog: function openDialog(editor, url, existingValues, saveCallback, dialogSettings) {
- var $target = $(editor.container.$);
- if (editor.elementMode === CKEDITOR.ELEMENT_MODE_REPLACE) {
- $target = $target.find('.cke_contents');
- }
- $target.css('position', 'relative').find('.ckeditor-dialog-loading').remove();
- var classes = dialogSettings.dialogClass ? dialogSettings.dialogClass.split(' ') : [];
- classes.push('ui-dialog--narrow');
- dialogSettings.dialogClass = classes.join(' ');
- dialogSettings.autoResize = window.matchMedia('(min-width: 600px)').matches;
- dialogSettings.width = 'auto';
- var $content = $('<div class="ckeditor-dialog-loading"><span style="top: -40px;" class="ckeditor-dialog-loading-link">' + Drupal.t('Loading...') + '</span></div>');
- $content.appendTo($target);
- var ckeditorAjaxDialog = Drupal.ajax({
- dialog: dialogSettings,
- dialogType: 'modal',
- selector: '.ckeditor-dialog-loading-link',
- url: url,
- progress: { type: 'throbber' },
- submit: {
- editor_object: existingValues
- }
- });
- ckeditorAjaxDialog.execute();
- window.setTimeout(function () {
- $content.find('span').animate({ top: '0px' });
- }, 1000);
- Drupal.ckeditor.saveCallback = saveCallback;
- }
- };
- $(window).on('dialogcreate', function (e, dialog, $element, settings) {
- $('.ui-dialog--narrow').css('zIndex', CKEDITOR.config.baseFloatZIndex + 1);
- });
- $(window).on('dialog:beforecreate', function (e, dialog, $element, settings) {
- $('.ckeditor-dialog-loading').animate({ top: '-40px' }, function () {
- $(this).remove();
- });
- });
- $(window).on('editor:dialogsave', function (e, values) {
- if (Drupal.ckeditor.saveCallback) {
- Drupal.ckeditor.saveCallback(values);
- }
- });
- $(window).on('dialog:afterclose', function (e, dialog, $element) {
- if (Drupal.ckeditor.saveCallback) {
- Drupal.ckeditor.saveCallback = null;
- }
- });
- $(document).on('drupalViewportOffsetChange', function () {
- CKEDITOR.config.autoGrow_maxHeight = 0.7 * (window.innerHeight - displace.offsets.top - displace.offsets.bottom);
- });
- function redirectTextareaFragmentToCKEditorInstance() {
- var hash = window.location.hash.substr(1);
- var element = document.getElementById(hash);
- if (element) {
- var editor = CKEDITOR.dom.element.get(element).getEditor();
- if (editor) {
- var id = editor.container.getAttribute('id');
- window.location.replace('#' + id);
- }
- }
- }
- $(window).on('hashchange.ckeditor', redirectTextareaFragmentToCKEditorInstance);
- CKEDITOR.config.autoGrow_onStartup = true;
- CKEDITOR.config.autoGrow_maxHeight = 0.7 * window.innerHeight;
- CKEDITOR.timestamp = drupalSettings.ckeditor.timestamp;
- if (AjaxCommands) {
- AjaxCommands.prototype.ckeditor_add_stylesheet = function (ajax, response, status) {
- var editor = CKEDITOR.instances[response.editor_id];
- if (editor) {
- response.stylesheets.forEach(function (url) {
- editor.document.appendStyleSheet(url);
- });
- }
- };
- }
- })(Drupal, Drupal.debounce, CKEDITOR, jQuery, Drupal.displace, Drupal.AjaxCommands);
|