diff --git a/CHANGES.md b/CHANGES.md index 1760c4d9f5e..523f8da1d5e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,6 +9,7 @@ Fixed Issues: * [#11490](http://dev.ckeditor.com/ticket/11490): Fixed issue with menubuttons panel showing in source mode. * [#11417](http://dev.ckeditor.com/ticket/11417): The [`widget.doubleclick`](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.widget-event-doubleclick) event is not cancelled anymore after editing has been triggered. * [#11253](http://dev.ckeditor.com/ticket/11253): [IE] Fixed: Clipped upload button in [Enhanced Image](http://ckeditor.com/addon/image2) dialog. +* [#11359](http://dev.ckeditor.com/ticket/11359): Standardized the way anchors are discovered by the [Link](http://ckeditor.com/addon/link) dialog. ## CKEditor 4.3.2 diff --git a/plugins/link/dialogs/link.js b/plugins/link/dialogs/link.js index 4b274f70fef..b02708118a6 100755 --- a/plugins/link/dialogs/link.js +++ b/plugins/link/dialogs/link.js @@ -204,32 +204,7 @@ CKEDITOR.dialog.add( 'link', function( editor ) { } // Find out whether we have any anchors in the editor. - var anchors = retval.anchors = [], - i, count, item; - - // For some browsers we set contenteditable="false" on anchors, making document.anchors not to include them, so we must traverse the links manually (#7893). - if ( CKEDITOR.plugins.link.emptyAnchorFix ) { - var links = editor.document.getElementsByTag( 'a' ); - for ( i = 0, count = links.count(); i < count; i++ ) { - item = links.getItem( i ); - if ( item.data( 'cke-saved-name' ) || item.hasAttribute( 'name' ) ) - anchors.push( { name: item.data( 'cke-saved-name' ) || item.getAttribute( 'name' ), id: item.getAttribute( 'id' ) } ); - } - } else { - var anchorList = new CKEDITOR.dom.nodeList( editor.document.$.anchors ); - for ( i = 0, count = anchorList.count(); i < count; i++ ) { - item = anchorList.getItem( i ); - anchors[ i ] = { name: item.getAttribute( 'name' ), id: item.getAttribute( 'id' ) }; - } - } - - if ( CKEDITOR.plugins.link.fakeAnchor ) { - var imgs = editor.document.getElementsByTag( 'img' ); - for ( i = 0, count = imgs.count(); i < count; i++ ) { - if ( ( item = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, imgs.getItem( i ) ) ) ) - anchors.push( { name: item.getAttribute( 'name' ), id: item.getAttribute( 'id' ) } ); - } - } + retval.anchors = CKEDITOR.plugins.link.getEditorAnchors( editor ); // Record down the selected element in the dialog. this._.selectedElement = element; diff --git a/plugins/link/plugin.js b/plugins/link/plugin.js index ea223a93684..25ffb7d704b 100755 --- a/plugins/link/plugin.js +++ b/plugins/link/plugin.js @@ -263,6 +263,56 @@ CKEDITOR.plugins.link = { return null; }, + /** + * Collects anchors available in the editor (i.e. used by link dialog). + * Note that the scope of search is different for inline (the "global" document) and + * framed editors (the "inner" document). + * + * @since 4.3.3 + * @param {CKEDITOR.editor} editor + * @returns {CKEDITOR.dom.element[]} An array of anchor elements. + */ + getEditorAnchors: function( editor ) { + var editable = editor.editable(), + + // The scope of search for anchors is the entire document for inline editors + // and editor's editable for framed/divarea (#11359). + scope = ( editable.isInline() && !editor.plugins.divarea ) ? editor.document : editable, + + links = scope.getElementsByTag( 'a' ), + anchors = [], + i = 0, + item; + + // Retrieve all anchors within the scope. + while ( ( item = links.getItem( i++ ) ) ) { + if ( item.data( 'cke-saved-name' ) || item.hasAttribute( 'name' ) ) { + anchors.push( { + name: item.data( 'cke-saved-name' ) || item.getAttribute( 'name' ), + id: item.getAttribute( 'id' ) + } ); + } + } + + // Retrieve all "fake anchors" within the scope. + if ( this.fakeAnchor ) { + var imgs = scope.getElementsByTag( 'img' ); + + i = 0; + + while ( ( item = imgs.getItem( i++ ) ) ) { + if ( ( item = this.tryRestoreFakeAnchor( editor, item ) ) ) { + anchors.push( { + name: item.getAttribute( 'name' ), + id: item.getAttribute( 'id' ) + } ); + } + } + } + + return anchors; + }, + /** * Opera and WebKit don't make it possible to select empty anchors. Fake * elements must be used for them.