Skip to content

Commit

Permalink
Merge branch 't/13351'
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Jun 10, 2015
2 parents 0e4f412 + 8f4afe1 commit 7e5367f
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 251 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -23,6 +23,7 @@ Fixed Issues:
* [#9086](http://dev.ckeditor.com/ticket/9086): Fixed: Invalid ARIA property used on paste area `<iframe>`.
* [#13164](http://dev.ckeditor.com/ticket/13164): Fixed: Error when inserting a hidden field.
* [#13155](http://dev.ckeditor.com/ticket/13155): Fixed: Incorrect [Line Utilities](http://ckeditor.com/addon/lineutils) positioning when `<body>` has a margin.
* [#13351](http://dev.ckeditor.com/ticket/13351): Fixed: Link lost when editing linked image with the link tab disabled. Also, fixed a bug when inserting an image into fully selected link would throw an error.

Other Changes:

Expand Down
2 changes: 2 additions & 0 deletions core/dom/range.js
Expand Up @@ -2533,6 +2533,7 @@ CKEDITOR.dom.range = function( root ) {

if ( !isRootAscendantOrSelf ) {
window.console && console.log && console.log( 'Element', startContainer, 'is not a descendant of root', this.root ); // jshint ignore:line
throw new Error( 1 );
}
// %REMOVE_END%
this.startContainer = startContainer;
Expand All @@ -2551,6 +2552,7 @@ CKEDITOR.dom.range = function( root ) {

if ( !isRootAscendantOrSelf ) {
window.console && console.log && console.log( 'Element', endContainer, 'is not a descendant of root', this.root ); // jshint ignore:line
throw new Error( 2 );
}
// %REMOVE_END%
this.endContainer = endContainer;
Expand Down
40 changes: 28 additions & 12 deletions plugins/image/dialogs/image.js
Expand Up @@ -296,16 +296,23 @@
this.linkElement = link;
this.linkEditMode = true;

// If there is an existing link, by default keep it (true).
// It will be removed if certain conditions are met and Link tab is enabled. (#13351)
this.addLink = true;

// Look for Image element.
var linkChildren = link.getChildren();
if ( linkChildren.count() == 1 ) {
var childTagName = linkChildren.getItem( 0 ).getName();
if ( childTagName == 'img' || childTagName == 'input' ) {
this.imageElement = linkChildren.getItem( 0 );
if ( this.imageElement.getName() == 'img' )
this.imageEditMode = 'img';
else if ( this.imageElement.getName() == 'input' )
this.imageEditMode = 'input';
var childTag = linkChildren.getItem( 0 );

if ( childTag.type == CKEDITOR.NODE_ELEMENT ) {
if ( childTag.is( 'img' ) || childTag.is( 'input' ) ) {
this.imageElement = linkChildren.getItem( 0 );
if ( this.imageElement.is( 'img' ) )
this.imageEditMode = 'img';
else if ( this.imageElement.is( 'input' ) )
this.imageEditMode = 'input';
}
}
}
// Fill out all fields.
Expand Down Expand Up @@ -333,8 +340,6 @@

// Fill out all fields.
this.setupContent( IMAGE, this.imageElement );
} else {
this.imageElement = editor.document.createElement( 'img' );
}

// Refresh LockRatio button
Expand Down Expand Up @@ -402,12 +407,21 @@
// Insert a new Image.
if ( !this.imageEditMode ) {
if ( this.addLink ) {
//Insert a new Link.
if ( !this.linkEditMode ) {
// Insert a new link.
editor.insertElement( this.linkElement );
this.linkElement.append( this.imageElement, false );
} else //Link already exists, image not.
editor.insertElement( this.imageElement );
} else {
// We already have a link in editor.
if ( this.linkElement.equals( editor.getSelection().getSelectedElement() ) ) {
// If the link is selected outside, replace it's content rather than the link itself. ([<a>foo</a>])
this.linkElement.setHtml( '' );
this.linkElement.append( this.imageElement, false );
} else {
// Only inside of the link is selected, so replace it with image. (<a>[foo]</a>, <a>[f]oo</a>)
editor.insertElement( this.imageElement );
}
}
} else {
editor.insertElement( this.imageElement );
}
Expand Down Expand Up @@ -978,6 +992,8 @@

if ( this.getValue() || !editor.config.image_removeLinkByEmptyURL )
this.getDialog().addLink = true;
else
this.getDialog().addLink = false;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/image/image.html
@@ -1 +1 @@
<textarea id="test_create_link_editor"></textarea>
<textarea id="test_create_link_editor"></textarea>

0 comments on commit 7e5367f

Please sign in to comment.