X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/6839815113720ebc32eba7254471a46a9388c6da..9db0e3facfdcb376b589ea922215bbdb1a3d1787:/modules/documentCanvas/canvas/documentElement.js diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 5ac22fd..ba859fc 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 = []; @@ -161,12 +192,12 @@ $.extend(DocumentNodeElement.prototype, { getWlxmlClass: function() { var klass = this.dom().attr('wlxml-class'); if(klass) - return klass.replace('-', '.'); + return klass.replace(/-/g, '.'); return undefined; }, setWlxmlClass: function(klass) { if(klass) - this.dom().attr('wlxml-class', klass); + this.dom().attr('wlxml-class', klass.replace(/\./g, '-')); else this.dom().removeAttr('wlxml-class'); }, @@ -310,6 +341,8 @@ $.extend(DocumentTextElement.prototype, { succeedingChildren.forEach(function(child) { newElement.append(child); }); + + return {first: parentElement, second: newElement}; }, });