From 73c5dd8f1d4ede0b3fa42b7d6e1b062f88fc47d3 Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Fri, 1 Jun 2012 17:43:34 -0700 Subject: [PATCH] Added ve.dm.Node.getOffset Change-Id: I4fb99040af44c063ad3b6489f2fd895d843fcf0c --- modules/ve2/dm/ve.dm.Node.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/ve2/dm/ve.dm.Node.js b/modules/ve2/dm/ve.dm.Node.js index f37947ee2d..aa307cea8a 100644 --- a/modules/ve2/dm/ve.dm.Node.js +++ b/modules/ve2/dm/ve.dm.Node.js @@ -150,6 +150,18 @@ ve.dm.Node.prototype.adjustLength = function( adjustment ) { this.setLength( this.length + adjustment ); }; +/** + * Gets the offset of this node within the document. + * + * If this node has no parent than the result will always be 0. + * + * @method + * @returns {Integer} Offset of node + */ +ve.dm.Node.prototype.getOffset = function() { + return this.root === this ? 0 : this.root.getOffsetFromNode( this ); +}; + /** * Gets an element attribute value. *