mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 06:46:26 +00:00
c3340e273c
This ensures that attributes and properties that are supposed to be stripped on copypaste are actually stripped. Bug: 49307 Change-Id: I8c90f4a0b33acba6eea3180cc077f8dc440e6e7b
56 lines
1.5 KiB
JavaScript
56 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.copyArray( 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();
|
|
}
|
|
}
|
|
}; |