**/
(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
};