Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced CKEDITOR.dom.nodeList#toArray method #752

Merged
merged 2 commits into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Fixed Issues:
* [#644](https://github.com/ckeditor/ckeditor-dev/issues/644): Fixed: The [`range.extractContents`](http://docs.ckeditor.com/#!/api/CKEDITOR.dom.range-method-extractContents) returns incorrect result when multiple nodes are selected.
* [#684](https://github.com/ckeditor/ckeditor-dev/issues/684): Fixed: The [`elementPath.contains`](http://docs.ckeditor.com/#!/api/CKEDITOR.dom.elementPath-method-contains) incorrectly excludes last element instead of root when `fromTop` parameter is set to true.

Other Changes:

* [#751](https://github.com/ckeditor/ckeditor-dev/issues/751): Added [CKEDITOR.dom.nodeList.toArray](https://docs.ckeditor.com/#!/api/CKEDITOR.dom.nodeList-method-toArray) method which returns array representation of a [nodeList](https://docs.ckeditor.com/#!/api/CKEDITOR.dom.nodeList).

## CKEditor 4.7.1

New Features:
Expand Down
11 changes: 11 additions & 0 deletions core/dom/nodelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,16 @@ CKEDITOR.dom.nodeList.prototype = {

var $node = this.$[ index ];
return $node ? new CKEDITOR.dom.node( $node ) : null;
},

/**
* Returns node list as an array.
*
* @returns {CKEDITOR.dom.node[]}
*/
toArray: function() {
return CKEDITOR.tools.array.map( this.$, function( nativeEl ) {
return new CKEDITOR.dom.node( nativeEl );
} );
}
};
6 changes: 6 additions & 0 deletions tests/core/dom/nodeList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div id="playground">
<span id="el1">foo</span>
<span id="el2">foo</span>
<span id="el3">foo</span>
<span>foo</span>
</div>
27 changes: 27 additions & 0 deletions tests/core/dom/nodeList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* bender-tags: editor,dom */

( function() {
'use strict';

bender.test( {
'test nodeList.toArray()': function() {
var list = CKEDITOR.document.find( '#playground span[id]' ),
ret = list.toArray();

assert.isArray( ret );
assert.areSame( 3, ret.length, 'Array length' );

for ( var i = 0; i < ret.length; i++ ) {
assert.areSame( list.getItem( i ), ret[ i ], 'Item ' + i );
}
},

'test nodeList.toArray() empty list': function() {
var ret = CKEDITOR.document.find( '#nonExistingId__' ).toArray();

assert.isArray( ret );
assert.areSame( 0, ret.length, 'Array length' );
}
} );

} )();