* Ported getAnnotationsFromOffset into DocumentFragment

* Wrote unit test for getAnnotationsFromOffset

Change-Id: Ie88b15ac6c16838b2d2bf9a2d83ca2952f5df817
This commit is contained in:
Rob Moen 2012-05-09 16:31:56 -07:00
parent 89a2b1bc40
commit d417c571a4
2 changed files with 30 additions and 0 deletions

View file

@ -180,3 +180,21 @@ ve.dm.DocumentFragment.prototype.getDataFromNode = function( node ) {
} }
return null; return null;
}; };
/**
* Gets a list of annotations that a given offset is covered by.
*
* @method
* @param {Integer} offset Offset to get annotations for
* @returns {Object[]} A copy of all annotation objects offset is covered by
*/
ve.dm.DocumentFragment.prototype.getAnnotationsFromOffset = function( offset, byref ) {
if ( ve.isArray( this.data[offset] ) ) {
if ( byref === true ) {
return this.data[offset].slice( 1 );
} else {
return ve.copyArray( this.data[offset].slice( 1 ) );
}
}
return [];
};

View file

@ -113,3 +113,15 @@ test( 'getDataFromNode', 3, function() {
'leaf without children' 'leaf without children'
); );
} ); } );
test( 'getAnnotationsFromOffset', 2, function() {
var fragment = new ve.dm.DocumentFragment( ve.dm.example.data ),
data = fragment.getData(),
annotations;
for ( var i = 0; i < data.length; i++ ) {
annotations = fragment.getAnnotationsFromOffset( i );
if (typeof annotations[0] === 'object') {
ok( annotations, 'annotations at offset ' + i );
}
}
} );