X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/7f5e612121a78074e505ad6cf593671ca60e889c..b53d709d888332da35d991ef449ddfc60633273f:/src/wlxml/wlxml.js diff --git a/src/wlxml/wlxml.js b/src/wlxml/wlxml.js index 4e1ddc6..bbd6233 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; } @@ -58,7 +58,9 @@ var installObject = function(instance, klass) { }); instance.object = Object.create(_.extend({}, methods, transformations)); _.keys(methods).concat(_.keys(transformations)).forEach(function(key) { - instance.object[key] = _.bind(instance.object[key], instance); + if(_.isFunction(instance.object[key])) { + instance.object[key] = _.bind(instance.object[key], instance); + } }); }; @@ -72,14 +74,21 @@ $.extend(WLXMLElementNode.prototype, WLXMLDocumentNodeMethods, smartxml.ElementN getClass: function() { return this.getAttr('class') || ''; }, + getClassHierarchy: function() { + return getClassLists(this.getClass()); + }, setClass: function(klass) { if(klass !== this.klass) { installObject(this, klass); 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(), @@ -380,7 +389,8 @@ return { return this.WLXMLDocumentFromXML(xml).root; }, - WLXMLDocument: WLXMLDocument + WLXMLDocument: WLXMLDocument, + getClassHierarchy: getClassLists }; }); \ No newline at end of file