X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/c986f6ebfd3d20bdc75ce00ee09bd2c716e0cb16..e816ae7584e8b11a1e24efb2f743ac744d80485b:/modules/documentCanvas/canvasNode.js diff --git a/modules/documentCanvas/canvasNode.js b/modules/documentCanvas/canvasNode.js index 0bfd358..bb1cee7 100644 --- a/modules/documentCanvas/canvasNode.js +++ b/modules/documentCanvas/canvasNode.js @@ -2,6 +2,9 @@ define(['libs/jquery-1.9.1.min'], function($) { 'use strict'; + +var tagSelector = '[wlxml-tag]'; + var CanvasNode = function(desc) { if(desc instanceof $) { this.dom = desc; @@ -42,7 +45,36 @@ CanvasNode.prototype.setContent = function(content) { } CanvasNode.prototype.isSame = function(other) { - return this.dom.get(0).isSameNode(other.dom.get(0)); + return (other instanceof CanvasNode) && this.dom.get(0).isSameNode(other.dom.get(0)); +} + +CanvasNode.prototype.children = function() { + var list = []; + this.dom.children(tagSelector).each(function() { + list.push(new CanvasNode($(this))); + }); + return $(list); +}; + + +CanvasNode.prototype.parent = function() { + var node = this.dom.parent(tagSelector); + if(node.length) + return new CanvasNode(node); + return null; +}; + +CanvasNode.prototype.parents = function() { + var list = []; + this.dom.parents(tagSelector).each(function() { + list.push(new CanvasNode($(this))); + }); + return $(list); +}; + + +CanvasNode.prototype.isOfClass = function(klass) { + return this.getClass() && this.getClass().substr(0, klass.length) === klass; } return {