From e9aaf1e41c5e695136d06f008c06b287da7d3eda Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 14 Apr 2014 11:26:07 +0200 Subject: [PATCH] wlxml: extending isInside/getParent/is to support tag name --- src/wlxml/wlxml.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index 4e1ddc6..5194c19 100644 --- a/src/wlxml/wlxml.js +++ b/src/wlxml/wlxml.js @@ -12,16 +12,16 @@ define([ var WLXMLDocumentNodeMethods = { - isInside: function(klass) { - var parent = this.getParent(klass); + isInside: function(query) { + var parent = this.getParent(query); return !!parent; }, - getParent: function(klass) { + getParent: function(query) { /* globals Node */ var me = this.nodeType === Node.ELEMENT_NODE ? [this] : [], toret; me.concat(this.parents()).some(function(node) { - if(node.is(klass)) { + if(node.is(query)) { toret = node; return true; } @@ -78,8 +78,12 @@ $.extend(WLXMLElementNode.prototype, WLXMLDocumentNodeMethods, smartxml.ElementN return this.setAttr('class', klass); } }, - is: function(klass) { - return this.getClass().substr(0, klass.length) === klass; + is: function(query) { + if(typeof query === 'string') { + query = {klass: query}; + } + return (_.isUndefined(query.klass) || this.getClass().substr(0, query.klass.length) === query.klass) && + (_.isUndefined(query.tagName) || this.getTagName() === query.tagName); }, getMetaAttributes: function() { var toret = new AttributesList(), -- 2.20.1