mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 06:24:08 +00:00
* Ported getAnnotationsFromOffset into DocumentFragment
* Wrote unit test for getAnnotationsFromOffset Change-Id: Ie88b15ac6c16838b2d2bf9a2d83ca2952f5df817
This commit is contained in:
parent
89a2b1bc40
commit
d417c571a4
|
@ -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 [];
|
||||||
|
};
|
||||||
|
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
Loading…
Reference in a new issue