X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/6839815113720ebc32eba7254471a46a9388c6da..50cc0c32bb9b2322e3f25be4803ad1adbf1d92a6:/modules/documentCanvas/canvas/documentElement.js diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 5ac22fd..0309136 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -52,6 +52,16 @@ $.extend(DocumentElement.prototype, { return null; }, + parents: function() { + var parents = [], + parent = this.parent(); + while(parent) { + parents.push(parent); + parent = parent.parent(); + } + return parents; + }, + sameNode: function(other) { return other && (typeof other === typeof this) && other.dom()[0] === this.dom()[0]; }, @@ -70,6 +80,27 @@ $.extend(DocumentElement.prototype, { markAsCurrent: function() { this.canvas.markAsCurrent(this); + }, + + getVerticallyFirstTextElement: function() { + var toret; + this.children().some(function(child) { + if(!child.isVisible()) + return false; // continue + if(child instanceof DocumentTextElement) { + toret = child; + return true; // break + } else { + toret = child.getVerticallyFirstTextElement(); + if(toret) + return true; // break + } + }); + return toret; + }, + + isVisible: function() { + return this instanceof DocumentTextElement || this.getWlxmlTag() !== 'metadata'; } }); @@ -112,14 +143,14 @@ DocumentNodeElement.prototype = new DocumentElement(); $.extend(DocumentNodeElement.prototype, { append: function(params) { - manipulate(this, params, 'append'); + return manipulate(this, params, 'append'); }, before: function(params) { - manipulate(this, params, 'before'); + return manipulate(this, params, 'before'); }, after: function(params) { - manipulate(this, params, 'after'); + return manipulate(this, params, 'after'); }, children: function() { var toret = []; @@ -310,6 +341,8 @@ $.extend(DocumentTextElement.prototype, { succeedingChildren.forEach(function(child) { newElement.append(child); }); + + return {first: parentElement, second: newElement}; }, });