Skip to content

Commit 05f125f

Browse files
committed
Merge branch 't/11359'
2 parents 8fb204a + d3bf6c9 commit 05f125f

File tree

3 files changed

+52
-26
lines changed

3 files changed

+52
-26
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Fixed Issues:
99
* [#11490](http://dev.ckeditor.com/ticket/11490): Fixed issue with menubuttons panel showing in source mode.
1010
* [#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.
1111
* [#11253](http://dev.ckeditor.com/ticket/11253): [IE] Fixed: Clipped upload button in [Enhanced Image](http://ckeditor.com/addon/image2) dialog.
12+
* [#11359](http://dev.ckeditor.com/ticket/11359): Standardized the way anchors are discovered by the [Link](http://ckeditor.com/addon/link) dialog.
1213

1314
## CKEditor 4.3.2
1415

plugins/link/dialogs/link.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -204,32 +204,7 @@ CKEDITOR.dialog.add( 'link', function( editor ) {
204204
}
205205

206206
// Find out whether we have any anchors in the editor.
207-
var anchors = retval.anchors = [],
208-
i, count, item;
209-
210-
// For some browsers we set contenteditable="false" on anchors, making document.anchors not to include them, so we must traverse the links manually (#7893).
211-
if ( CKEDITOR.plugins.link.emptyAnchorFix ) {
212-
var links = editor.document.getElementsByTag( 'a' );
213-
for ( i = 0, count = links.count(); i < count; i++ ) {
214-
item = links.getItem( i );
215-
if ( item.data( 'cke-saved-name' ) || item.hasAttribute( 'name' ) )
216-
anchors.push( { name: item.data( 'cke-saved-name' ) || item.getAttribute( 'name' ), id: item.getAttribute( 'id' ) } );
217-
}
218-
} else {
219-
var anchorList = new CKEDITOR.dom.nodeList( editor.document.$.anchors );
220-
for ( i = 0, count = anchorList.count(); i < count; i++ ) {
221-
item = anchorList.getItem( i );
222-
anchors[ i ] = { name: item.getAttribute( 'name' ), id: item.getAttribute( 'id' ) };
223-
}
224-
}
225-
226-
if ( CKEDITOR.plugins.link.fakeAnchor ) {
227-
var imgs = editor.document.getElementsByTag( 'img' );
228-
for ( i = 0, count = imgs.count(); i < count; i++ ) {
229-
if ( ( item = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, imgs.getItem( i ) ) ) )
230-
anchors.push( { name: item.getAttribute( 'name' ), id: item.getAttribute( 'id' ) } );
231-
}
232-
}
207+
retval.anchors = CKEDITOR.plugins.link.getEditorAnchors( editor );
233208

234209
// Record down the selected element in the dialog.
235210
this._.selectedElement = element;

plugins/link/plugin.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,56 @@ CKEDITOR.plugins.link = {
263263
return null;
264264
},
265265

266+
/**
267+
* Collects anchors available in the editor (i.e. used by link dialog).
268+
* Note that the scope of search is different for inline (the "global" document) and
269+
* framed editors (the "inner" document).
270+
*
271+
* @since 4.3.3
272+
* @param {CKEDITOR.editor} editor
273+
* @returns {CKEDITOR.dom.element[]} An array of anchor elements.
274+
*/
275+
getEditorAnchors: function( editor ) {
276+
var editable = editor.editable(),
277+
278+
// The scope of search for anchors is the entire document for inline editors
279+
// and editor's editable for framed/divarea (#11359).
280+
scope = ( editable.isInline() && !editor.plugins.divarea ) ? editor.document : editable,
281+
282+
links = scope.getElementsByTag( 'a' ),
283+
anchors = [],
284+
i = 0,
285+
item;
286+
287+
// Retrieve all anchors within the scope.
288+
while ( ( item = links.getItem( i++ ) ) ) {
289+
if ( item.data( 'cke-saved-name' ) || item.hasAttribute( 'name' ) ) {
290+
anchors.push( {
291+
name: item.data( 'cke-saved-name' ) || item.getAttribute( 'name' ),
292+
id: item.getAttribute( 'id' )
293+
} );
294+
}
295+
}
296+
297+
// Retrieve all "fake anchors" within the scope.
298+
if ( this.fakeAnchor ) {
299+
var imgs = scope.getElementsByTag( 'img' );
300+
301+
i = 0;
302+
303+
while ( ( item = imgs.getItem( i++ ) ) ) {
304+
if ( ( item = this.tryRestoreFakeAnchor( editor, item ) ) ) {
305+
anchors.push( {
306+
name: item.getAttribute( 'name' ),
307+
id: item.getAttribute( 'id' )
308+
} );
309+
}
310+
}
311+
}
312+
313+
return anchors;
314+
},
315+
266316
/**
267317
* Opera and WebKit don't make it possible to select empty anchors. Fake
268318
* elements must be used for them.

0 commit comments

Comments
 (0)