wlxml: helper functions related to context root
[fnpeditor.git] / src / wlxml / wlxml.js
index cb43f07..ef70d3d 100644 (file)
@@ -44,6 +44,19 @@ var WLXMLDocumentNodeMethods =  {
             }
         }.bind(this));
         return toret;
+    },
+    getContextRoot: function() {
+        var contextRoot;
+        [this].concat(this.parents()).some(function(n) {
+            if(n.isContextRoot()) {
+                contextRoot = n;
+                return true;
+            }
+        });
+        return contextRoot;
+    },
+    hasSameContextRoot: function(other) {
+        return this.getContextRoot().sameNode(other.getContextRoot());
     }
 };
 
@@ -106,6 +119,16 @@ $.extend(WLXMLElementNode.prototype, WLXMLDocumentNodeMethods, smartxml.ElementN
             return child.is(query);
         }.bind(this));
     },
+    find: function(query) {
+        var doc = this.document;
+        return this._$.find('*')
+            .map(function() {
+                return doc.createDocumentNode(this);
+            })
+            .filter(function() {
+                return this.is(query);
+            });
+    },
 
     _getXMLDOMToDump: function() {
         var DOM = this._$.clone(true, true),
@@ -173,7 +196,6 @@ var WLXMLDocumentNode = function() {
 };
 WLXMLDocumentNode.prototype = Object.create(smartxml.DocumentNode.prototype);
 
-
 var WLXMLTextNode = function() {
     smartxml.TextNode.apply(this, arguments);
 };