diff --git a/CHANGES.md b/CHANGES.md index c89ee7971e9..ccc287a1f0a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Fixed Issues: * [#13887](https://dev.ckeditor.com/ticket/13887): Fixed: Link target now supports wider ASCII character range. Thanks to [SamZiemer](https://github.com/SamZiemer)! * [#13790](https://dev.ckeditor.com/ticket/13790): Fixed: Allow for the iframe having been removed already. Thanks to [Stefan Rijnhart](https://github.com/StefanRijnhart)! * [#13803](https://dev.ckeditor.com/ticket/13803): Fixed: Allow the editor to be destroyed before being fully initialized. Thanks to [Cyril Fluck](https://github.com/cyril-sf)! +* [#13885](http://dev.ckeditor.com/ticket/13885): Fixed: [Image2](http://ckeditor.com/addon/image2) does no longer require [link](http://ckeditor.com/addon/link) plugin to link an image. * [#13883](http://dev.ckeditor.com/ticket/13883): Fixed: Copying table using context menu strips off styles. * [#13872](http://dev.ckeditor.com/ticket/13872): Fixed: Cut is no longer possible in [read-only](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-property-readOnly) mode. * [#13879](http://dev.ckeditor.com/ticket/13879): Fixed: Preventing [`editor.drop`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-drop) event. diff --git a/plugins/image2/plugin.js b/plugins/image2/plugin.js index ce964b9e8de..179634ba1c5 100644 --- a/plugins/image2/plugin.js +++ b/plugins/image2/plugin.js @@ -1,4 +1,4 @@ -/** +/** * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or http://ckeditor.com/license */ @@ -410,7 +410,7 @@ // Update data.link object with attributes if the link has been discovered. if ( editor.plugins.link && this.parts.link ) { - data.link = CKEDITOR.plugins.link.parseLinkAttributes( editor, this.parts.link ); + data.link = helpers.getLinkAttributesParser()( editor, this.parts.link ); // Get rid of cke_widget_* classes in data. Otherwise // they might appear in link dialog. @@ -492,6 +492,12 @@ }; } + /** + * Set of Image2 plugin helpers. + * + * @class + * @singleton + */ CKEDITOR.plugins.image2 = { stateShifter: function( editor ) { // Tag name used for centering non-captioned widgets. @@ -612,7 +618,7 @@ newEl = wrapInLink( img, shift.newData.link ); // Set and remove all attributes associated with this state. - var attributes = CKEDITOR.plugins.link.getLinkAttributes( editor, newValue ); + var attributes = CKEDITOR.plugins.image2.getLinkAttributesGetter()( editor, newValue ); if ( !CKEDITOR.tools.isEmpty( attributes.set ) ) ( newEl || link ).setAttributes( attributes.set ); @@ -730,10 +736,13 @@ }; }, - // Checks whether current ratio of the image match the natural one. - // by comparing dimensions. - // @param {CKEDITOR.dom.element} image - // @returns {Boolean} + /** + * Checks whether current ratio of the image match the natural one. + * by comparing dimensions. + * + * @param {CKEDITOR.dom.element} image + * @returns {Boolean} + */ checkHasNaturalRatio: function( image ) { var $ = image.$, natural = this.getNatural( image ); @@ -746,11 +755,14 @@ Math.round( $.clientHeight / natural.height * natural.width ) == $.clientWidth; }, - // Returns natural dimensions of the image. For modern browsers - // it uses natural(Width|Height) for old ones (IE8), creates - // a new image and reads dimensions. - // @param {CKEDITOR.dom.element} image - // @returns {Object} + /** + * Returns natural dimensions of the image. For modern browsers + * it uses natural(Width|Height) for old ones (IE8), creates + * a new image and reads dimensions. + * + * @param {CKEDITOR.dom.element} image + * @returns {Object} + */ getNatural: function( image ) { var dimensions; @@ -770,6 +782,51 @@ } return dimensions; + }, + + /** + * Returns an attributes getter function. Default getter comes from the Link Plugin + * and is documented by {@link CKEDITOR.plugins.link#getLinkAttributes}. + * + * **Note:** It is possible to override this method and use a custom getter e.g. + * in the absence of the Link Plugin. + * + * **Note:** If a custom getter is used, a data model format it produces + * must be compatible with {@link CKEDITOR.plugins.link#getLinkAttributes}. + * + * **Note:** A custom getter must understand data model format produced by + * {@link #getLinkAttributesParser} to work correctly. + * + * @returns {Function} A function that gets (composes) link attributes. + * @since 4.5.5 + */ + getLinkAttributesGetter: function() { + // #13885 + return CKEDITOR.plugins.link.getLinkAttributes; + }, + + /** + * Returns an attributes parser function. Default parser comes from the Link Plugin + * and is documented by {@link CKEDITOR.plugins.link#parseLinkAttributes}. + * + * **Note:** It is possible to override this method and use a custom parser e.g. + * in the absence of the Link Plugin. + * + * **Note:** If a custom parser is used, a data model format produced by the parser + * must be compatible with {@link #getLinkAttributesGetter}. + * + * **Note:** If a custom parser is used, it should be compatible with + * {@link CKEDITOR.plugins.link#parseLinkAttributes} data model format. Otherwise + * Link Plugin dialog may not be populated correctly with parsed data. However + * as long as Image2 is **not** used with Link Plugin dialog, any custom data model + * will work, being stored as an internal property of Image2 widget's data only. + * + * @returns {Function} A function that parses attributes. + * @since 4.5.5 + */ + getLinkAttributesParser: function() { + // #13885 + return CKEDITOR.plugins.link.parseLinkAttributes; } }; diff --git a/plugins/link/plugin.js b/plugins/link/plugin.js index d89648b2d60..d0ac2ae2885 100755 --- a/plugins/link/plugin.js +++ b/plugins/link/plugin.js @@ -417,8 +417,11 @@ /** * Parses attributes of the link element and returns an object representing - * the current state (data) of the link. This data format is accepted e.g. by - * the Link dialog window and {@link #getLinkAttributes}. + * the current state (data) of the link. This data format is a plain object accepted + * e.g. by the Link dialog window and {@link #getLinkAttributes}. + * + * **Note:** Data model format produced by the parser must be compatible with the Link + * Plugin dialog because it is passed directly to {@link CKEDITOR.dialog#setupContent}. * * @since 4.4 * @param {CKEDITOR.editor} editor @@ -546,9 +549,9 @@ }, /** - * Converts link data into an object which consists of attributes to be set - * (with their values) and an array of attributes to be removed. This method - * can be used to synthesise or to update any link element with the given data. + * Converts link data produced by {@link #parseLinkAttributes} into an object which consists + * of attributes to be set (with their values) and an array of attributes to be removed. + * This method can be used to compose or to update any link element with the given data. * * @since 4.4 * @param {CKEDITOR.editor} editor diff --git a/tests/plugins/image2/link.html b/tests/plugins/image2/link.html index 70e35a6183a..9dccbf90d1f 100644 --- a/tests/plugins/image2/link.html +++ b/tests/plugins/image2/link.html @@ -272,4 +272,18 @@ x

- \ No newline at end of file + + + + + diff --git a/tests/plugins/image2/link.js b/tests/plugins/image2/link.js index a28284acce3..f4105319ab6 100644 --- a/tests/plugins/image2/link.js +++ b/tests/plugins/image2/link.js @@ -783,6 +783,61 @@ assert.areSame( 'right', widget.data.align ); assert.isFalse( widget.parts.image.hasClass( 'align-right' ) ); } ); + }, + + // #13885 + 'test custom link attributes getter': function() { + CKEDITOR.plugins.image2.getLinkAttributesGetter = function() { + return function() { + return { + set: { + 'data-cke-saved-href': 'custom-href', + 'data-custom': 'custom' + }, + removed: [ 'target' ] + }; + }; + }; + + this.setWidgetData( 'custom-link-getter', { + link: { + type: 'url', + url: { + protocol: 'ftp://', + url: 'y' + }, + target: { + type: null + }, + advanced: { + advId: 'foo', + advLangDir: 'rtl' + } + } + }, inlineStructureWithLink, [ 2, 2 ] ); + }, + + // #13885 + 'test custom link attributes parser': function() { + var bot = this.editorBot; + + CKEDITOR.plugins.image2.getLinkAttributesParser = function() { + return function() { + return { + href: 'foo', + bar: 'baz' + }; + }; + }; + + bot.setData( '

x

', function() { + var widget = getById( bot.editor, 'x' ); + + objectAssert.areEqual( { + href: 'foo', + bar: 'baz' + }, widget.data.link, 'Custom attributes parser output.' ); + } ); } } ); } )();