mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
44623c9b2a
These have been pointing to the same method for a while now, we can safely remove these obsolete aliases and just use it as generic copy. * Each file touched by my editor had its new line at EOF fixed where absent * Don't copy an otherwise unused empty object (ve.dm.Converter) * Use common ve#copy syntax instead to create a link (ve.dm.Document, ve.dm.example) * Remove redundant conditionals for isArray/copyArray/copyObject (ve.dm.example) Change-Id: If560e658dc1fb59bf01f702c97e3e82a50a8a255
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel DocumentSlice class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* DataModel document slice.
|
|
*
|
|
* @constructor
|
|
* @param {Array} data Balanced sliced data (will be deep copied internally)
|
|
* @param {ve.Range} [range] Original context within data
|
|
*/
|
|
ve.dm.DocumentSlice = function VeDmDocumentSlice( data, range ) {
|
|
// Properties
|
|
this.data = ve.copy( data );
|
|
this.range = range || new ve.Range( 0, data.length );
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Get a deep copy of the sliced data.
|
|
*
|
|
* @method
|
|
* @returns {Array} Document data
|
|
*/
|
|
ve.dm.DocumentSlice.prototype.getData = function () {
|
|
return this.data.slice( this.range.start, this.range.end );
|
|
};
|
|
|
|
/**
|
|
* Get a balanced version of the sliced data.
|
|
*
|
|
* @method
|
|
* @returns {Array} Document data
|
|
*/
|
|
ve.dm.DocumentSlice.prototype.getBalancedData = function () {
|
|
return this.data.slice( 0 );
|
|
};
|
|
|
|
/**
|
|
* Run all elements in this document slice through getClonedElement(). This should be done if
|
|
* you intend to insert the sliced data back into the document as a copy of the original data
|
|
* (e.g. for copy and paste).
|
|
*/
|
|
ve.dm.DocumentSlice.prototype.cloneElements = function () {
|
|
var i, len, node;
|
|
for ( i = 0, len = this.data.length; i < len; i++ ) {
|
|
if ( this.data[i].type && this.data[i].type.charAt( 0 ) !== '/' ) {
|
|
node = ve.dm.nodeFactory.create( this.data[i].type, [], this.data[i] );
|
|
this.data[i] = node.getClonedElement();
|
|
}
|
|
}
|
|
};
|