Integrating new canvas api into rest of the modules
[fnpeditor.git] / modules / documentCanvas / canvasNode.js
index 0bfd358..2b108a1 100644 (file)
@@ -2,6 +2,9 @@ define(['libs/jquery-1.9.1.min'], function($) {
 \r
 'use strict';\r
 \r
+\r
+var tagSelector = '[wlxml-tag]';\r
+\r
 var CanvasNode = function(desc) {\r
     if(desc instanceof $) {\r
         this.dom = desc;\r
@@ -42,9 +45,34 @@ CanvasNode.prototype.setContent = function(content) {
 }\r
 \r
 CanvasNode.prototype.isSame = function(other) {\r
-    return this.dom.get(0).isSameNode(other.dom.get(0));\r
+    return (other instanceof CanvasNode) && this.dom.get(0).isSameNode(other.dom.get(0));\r
 }\r
 \r
+CanvasNode.prototype.children = function() {\r
+    var list = [];\r
+    this.dom.children(tagSelector).each(function() {\r
+        list.push(new CanvasNode($(this)));\r
+    });\r
+    return $(list);\r
+};\r
+\r
+\r
+CanvasNode.prototype.parent = function() {\r
+    var node = this.dom.parent(tagSelector);\r
+    if(node.length)\r
+        return new CanvasNode(node);\r
+    return null;\r
+};\r
+\r
+CanvasNode.prototype.parents = function() {\r
+    var list = [];\r
+    this.dom.parents(tagSelector).each(function() {\r
+        list.push(new CanvasNode($(this)));\r
+    });\r
+    return $(list);\r
+};\r
+\r
+\r
 return {\r
     create: function(desc) {\r
         return new CanvasNode(desc);\r