X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fckeditor%2Fjs%2Fplugins%2Fdrupalimagecaption%2Fplugin.js;h=7cd215a70589c674a9afa4badca054a250350e97;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=d1d666c5b945a65c87a11afbb8a349d7745f6f64;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website
diff --git a/web/core/modules/ckeditor/js/plugins/drupalimagecaption/plugin.js b/web/core/modules/ckeditor/js/plugins/drupalimagecaption/plugin.js
index d1d666c5b..7cd215a70 100644
--- a/web/core/modules/ckeditor/js/plugins/drupalimagecaption/plugin.js
+++ b/web/core/modules/ckeditor/js/plugins/drupalimagecaption/plugin.js
@@ -1,46 +1,44 @@
/**
- * @file
- * Drupal Image Caption plugin.
- *
- * This alters the existing CKEditor image2 widget plugin, which is already
- * altered by the Drupal Image plugin, to:
- * - allow for the data-caption and data-align attributes to be set
- * - mimic the upcasting behavior of the caption_filter filter.
- *
- * @ignore
- */
+* DO NOT EDIT THIS FILE.
+* See the following change record for more information,
+* https://www.drupal.org/node/2815083
+* @preserve
+**/
(function (CKEDITOR) {
+ function findElementByName(element, name) {
+ if (element.name === name) {
+ return element;
+ }
+
+ var found = null;
+ element.forEach(function (el) {
+ if (el.name === name) {
+ found = el;
- 'use strict';
+ return false;
+ }
+ }, CKEDITOR.NODE_ELEMENT);
+ return found;
+ }
CKEDITOR.plugins.add('drupalimagecaption', {
requires: 'drupalimage',
- beforeInit: function (editor) {
- // Disable default placeholder text that comes with CKEditor's image2
- // plugin: it has an inferior UX (it requires the user to manually delete
- // the place holder text).
+ beforeInit: function beforeInit(editor) {
editor.lang.image2.captionPlaceholder = '';
- // Drupal.t() will not work inside CKEditor plugins because CKEditor loads
- // the JavaScript file instead of Drupal. Pull translated strings from the
- // plugin settings that are translated server-side.
var placeholderText = editor.config.drupalImageCaption_captionPlaceholderText;
- // Override the image2 widget definition to handle the additional
- // data-align and data-caption attributes.
editor.on('widgetDefinition', function (event) {
var widgetDefinition = event.data;
if (widgetDefinition.name !== 'image') {
return;
}
- // Only perform the downcasting/upcasting for to the enabled filters.
var captionFilterEnabled = editor.config.drupalImageCaption_captionFilterEnabled;
var alignFilterEnabled = editor.config.drupalImageCaption_alignFilterEnabled;
- // Override default features definitions for drupalimagecaption.
CKEDITOR.tools.extend(widgetDefinition.features, {
caption: {
requiredContent: 'img[data-caption]'
@@ -50,10 +48,6 @@
}
}, true);
- // Extend requiredContent & allowedContent.
- // CKEDITOR.style is an immutable object: we cannot modify its
- // definition to extend requiredContent. Hence we get the definition,
- // modify it, and pass it to a new CKEDITOR.style instance.
var requiredContent = widgetDefinition.requiredContent.getDefinition();
requiredContent.attributes['data-align'] = '';
requiredContent.attributes['data-caption'] = '';
@@ -61,15 +55,8 @@
widgetDefinition.allowedContent.img.attributes['!data-align'] = true;
widgetDefinition.allowedContent.img.attributes['!data-caption'] = true;
- // Override allowedContent setting for the 'caption' nested editable.
- // This must match what caption_filter enforces.
- // @see \Drupal\filter\Plugin\Filter\FilterCaption::process()
- // @see \Drupal\Component\Utility\Xss::filter()
widgetDefinition.editables.caption.allowedContent = 'a[!href]; em strong cite code br';
- // Override downcast(): ensure we *only* output , but also ensure
- // we include the data-entity-type, data-entity-uuid, data-align and
- // data-caption attributes.
var originalDowncast = widgetDefinition.downcast;
widgetDefinition.downcast = function (element) {
var img = findElementByName(element, 'img');
@@ -80,8 +67,6 @@
var attrs = img.attributes;
if (captionFilterEnabled) {
- // If image contains a non-empty caption, serialize caption to the
- // data-caption attribute.
if (captionHtml) {
attrs['data-caption'] = captionHtml;
}
@@ -92,28 +77,20 @@
}
}
- // If img is wrapped with a link, we want to return that link.
if (img.parent.name === 'a') {
return img.parent;
}
- else {
- return img;
- }
+
+ return img;
};
- // We want to upcast elements to a DOM structure required by the
- // image2 widget. Depending on a case it may be:
- // - just an tag (non-captioned, not-centered image),
- // - tag in a paragraph (non-captioned, centered image),
- // -