Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / ckeditor / js / plugins / drupalimage / plugin.js
index b1751c28e0c55080d043afa3dcc62e7eee6850bf..72180faa8eb388c20e65541929a5bbf4e07d78f2 100644 (file)
@@ -6,6 +6,48 @@
 **/
 
 (function ($, Drupal, CKEDITOR) {
+  function getFocusedWidget(editor) {
+    var widget = editor.widgets.focused;
+
+    if (widget && widget.name === 'image') {
+      return widget;
+    }
+
+    return null;
+  }
+
+  function linkCommandIntegrator(editor) {
+    if (!editor.plugins.drupallink) {
+      return;
+    }
+
+    editor.getCommand('drupalunlink').on('exec', function (evt) {
+      var widget = getFocusedWidget(editor);
+
+      if (!widget || !widget.parts.link) {
+        return;
+      }
+
+      widget.setData('link', null);
+
+      this.refresh(editor, editor.elementPath());
+
+      evt.cancel();
+    });
+
+    editor.getCommand('drupalunlink').on('refresh', function (evt) {
+      var widget = getFocusedWidget(editor);
+
+      if (!widget) {
+        return;
+      }
+
+      this.setState(widget.data.link || widget.wrapper.getAscendant('a') ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED);
+
+      evt.cancel();
+    });
+  }
+
   CKEDITOR.plugins.add('drupalimage', {
     requires: 'image2',
     icons: 'drupalimage',
         widgetDefinition.upcast = function (element, data) {
           if (element.name !== 'img') {
             return;
-          } else if (element.attributes['data-cke-realelement']) {
-              return;
-            }
+          }
+
+          if (element.attributes['data-cke-realelement']) {
+            return;
+          }
 
           data['data-entity-type'] = element.attributes['data-entity-type'];
 
     return CKEDITOR.plugins.drupallink.getLinkAttributes;
   };
 
-  function linkCommandIntegrator(editor) {
-    if (!editor.plugins.drupallink) {
-      return;
-    }
-
-    editor.getCommand('drupalunlink').on('exec', function (evt) {
-      var widget = getFocusedWidget(editor);
-
-      if (!widget || !widget.parts.link) {
-        return;
-      }
-
-      widget.setData('link', null);
-
-      this.refresh(editor, editor.elementPath());
-
-      evt.cancel();
-    });
-
-    editor.getCommand('drupalunlink').on('refresh', function (evt) {
-      var widget = getFocusedWidget(editor);
-
-      if (!widget) {
-        return;
-      }
-
-      this.setState(widget.data.link || widget.wrapper.getAscendant('a') ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED);
-
-      evt.cancel();
-    });
-  }
-
-  function getFocusedWidget(editor) {
-    var widget = editor.widgets.focused;
-
-    if (widget && widget.name === 'image') {
-      return widget;
-    }
-
-    return null;
-  }
-
   CKEDITOR.plugins.drupalimage = {
     getFocusedWidget: getFocusedWidget
   };