diff --git a/core/modules/ckeditor/js/plugins/drupalimage/plugin.js b/core/modules/ckeditor/js/plugins/drupalimage/plugin.js index 28705c1..be44125 100644 --- a/core/modules/ckeditor/js/plugins/drupalimage/plugin.js +++ b/core/modules/ckeditor/js/plugins/drupalimage/plugin.js @@ -57,25 +57,6 @@ CKEDITOR.plugins.add('drupalimage', { } } } - - // Set image alignment. - if (returnValues['alignment'] !== existingValues['alignment']) { - // Set a new alignment. - if (returnValues['alignment']) { - var alignCommand = editor.getCommand('justify' + returnValues['alignment']); - if (alignCommand.state === CKEDITOR.TRISTATE_OFF) { - alignCommand.exec(); - } - } - // Remove alignment. - else if (existingValues['alignment']) { - var alignCommand = editor.getCommand('justify' + existingValues['alignment']); - if (alignCommand.state === CKEDITOR.TRISTATE_ON) { - alignCommand.exec(); - } - } - } - } }; var modalSettings = { @@ -108,51 +89,6 @@ CKEDITOR.plugins.add('drupalimage', { } }); } - }, - afterInit: function (editor) { - // Customize the behavior of the alignment commands. (#7430) - setupAlignCommand('left'); - setupAlignCommand('right'); - setupAlignCommand('center'); - setupAlignCommand('block'); - - function setupAlignCommand (value) { - var command = editor.getCommand('justify' + value); - if (command) { - command.on( 'exec', function(evt) { - var img = getSelectedImage(editor), align; - if (img) { - // Remove the state of the previous alignment button. - previousAlignment = getImageAlignment(img); - if (previousAlignment) { - var previousCommand = editor.getCommand('justify' + previousAlignment); - if ( previousCommand.state === CKEDITOR.TRISTATE_ON) { - previousCommand.setState(CKEDITOR.TRISTATE_OFF); - } - } - // Set alignment and activate the current alignment button. - if (setImageAlignment(img, value)) { - command.setState(CKEDITOR.TRISTATE_ON); - } - evt.cancel(); - } - }); - - command.on('refresh', function(evt) { - var img = getSelectedImage(editor), align; - if (img) { - align = getImageAlignment(img); - - this.setState( - (align == value) ? CKEDITOR.TRISTATE_ON : - (CKEDITOR.config.drupalimage_justifyClasses || value == 'right' || value == 'left' ) ? CKEDITOR.TRISTATE_OFF : - CKEDITOR.TRISTATE_DISABLED); - - evt.cancel(); - } - }); - } - } } }); @@ -173,97 +109,4 @@ function getSelectedImage (editor, element) { } } -/** - * Given an image element, get the alignment based on precedence of display. - * - * Matching browsers, this order is: - * 1) inline style - * 2) class style - * 3) align attribute - * - * @return string|false - * A string "left", "center", "right", or "block". Or false if the image is - * not aligned at all. - */ -function getImageAlignment (element) { - var align = element.getStyle('float'); - if (align == 'inherit' || align == 'none') { - align = false; - } - - if (!align && CKEDITOR.config.drupalimage_justifyClasses) { - var justifyClasses = CKEDITOR.config.drupalimage_justifyClasses; - var justifyNames = ['left', 'center', 'right', 'block']; - for (var classPosition = 0; classPosition < 4; classPosition++) { - if (element.hasClass(justifyClasses[classPosition])) { - align = justifyNames[classPosition]; - } - } - } - - if (!align) { - align = element.getAttribute('align'); - } - - return align; -} - -/** - * Set an image alignment using classes if available, inline style otherwise. - * - * @param img - * CKEditor element for the image. - * @param value - * One of the following string values: "left", "center", "right", or "block". - * @return boolean - * Returns true if the alignment has been changed, false otherwise. - */ -function setImageAlignment (img, value) { - align = getImageAlignment(img); - if (CKEDITOR.config.drupalimage_justifyClasses) { - var justifyClasses = CKEDITOR.config.drupalimage_justifyClasses; - var justifyNames = [ 'left', 'center', 'right', 'block' ]; - var justifyOldPosition = CKEDITOR.tools.indexOf( justifyNames, align ); - var justifyOldClassName = justifyOldPosition === -1 ? null : justifyClasses[justifyOldPosition]; - var justifyNewPosition = CKEDITOR.tools.indexOf( justifyNames, value ); - var justifyNewClassName = justifyNewPosition === -1 ? null : justifyClasses[justifyNewPosition]; - } - - // If this image is already aligned, remove existing alignment. - if (align) { - img.removeStyle('float'); - img.removeAttribute('align'); - if (justifyOldClassName) { - img.removeClass(justifyOldClassName); - } - } - - // If changing the alignment to a new value, set the new style. - if (value && align !== value) { - if (justifyNewClassName) { - img.addClass(justifyNewClassName); - } - else { - img.setStyle('float', value); - } - } - - return align !== value; -} - })(jQuery, Drupal, drupalSettings); - -/** - * List of classes to use for aligning images. Each class will be used when - * an image is selected and the normal justify toolbar buttons are clicked. The - * array of classes should contain 4 members, in the following order: left, - * center, right, justify. If the list of classes is null, CSS style attributes - * will be used instead. - * - * @type Array - * @default true - * @example - * // Disable the list of classes and use styles instead. - * config.drupalimage_justifyClasses = null; - */ -CKEDITOR.config.drupalimage_justifyClasses = [ 'align-left', 'align-center', 'align-right', 'full-width' ];