Skip to content
Permalink
Browse files

Merge branch 't/13885'

  • Loading branch information...
mlewand committed Nov 6, 2015
2 parents c0e7dee + 87c2d42 commit 68b6b3bceedce83696bf10d16fa59bc2e87aec88
Showing with 148 additions and 18 deletions.
  1. +1 −0 CHANGES.md
  2. +69 −12 plugins/image2/plugin.js
  3. +8 −5 plugins/link/plugin.js
  4. +15 −1 tests/plugins/image2/link.html
  5. +55 −0 tests/plugins/image2/link.js
@@ -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.
@@ -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;
}
};

@@ -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
@@ -272,4 +272,18 @@
<a href="mailto:a?subject=b&amp;body=c"><img alt="x" id="x" src="_assets/foo.png" /></a>
</p>
</textarea>
</body>

<!-- Custom Link Plugin helpers -->

<textarea id="custom-link-getter">
<p>y</p>
<p>
<a href="http://x" target="f"><img alt="x" id="x" src="_assets/foo.png" /></a>
</p>
=>
<p>y</p>
<p>
<a href="custom-href" data-custom="custom"><img alt="x" id="x" src="_assets/foo.png" /></a>
</p>
</textarea>
</body>
@@ -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( '<p><a href="http://x"><img alt="x" id="x" src="_assets/foo.png" /></a></p>', function() {
var widget = getById( bot.editor, 'x' );

objectAssert.areEqual( {
href: 'foo',
bar: 'baz'
}, widget.data.link, 'Custom attributes parser output.' );
} );
}
} );
} )();

0 comments on commit 68b6b3b

Please sign in to comment.
You can’t perform that action at this time.