windex

jQuery-like that's safe to use in a Firefox Extension
git clone https://wehaveforgeathome.hates.computer/windex.git
Log | Files | Refs | LICENSE

commit 7d0ba03604eb097eaa581c4a30a9561770262d6a
parent cf857678085f3bff0ad88614794427e50d42ee51
Author: Ryan Wolf <rwolf@borderstylo.com>
Date:   Wed, 16 Feb 2011 18:22:00 -0800

implemented .parents

Diffstat:
Mwindex.js | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/windex.js b/windex.js @@ -178,6 +178,25 @@ WindexNodes.prototype._parentMatching = function (selector) { return new WindexNodes(parents, selector, parents[0]); }; +// See: http://api.jquery.com/parents/ +WindexNodes.prototype.parents = function (selector) { + if (selector) { return this._parentsMatching(selector); } + var parents = []; + this.each(function (i, node) { + while (node.parentNode) { + node = node.parentNode; + parents.push(node); + } + }); + return new WindexNodes(parentss); +}; + +WindexNodes.prototype._parentsMatching = function (selector) { + var parents = this.parents().toArray(). + filter(function (node) {return Windex.matchesSelector(node, selector);}); + return new WindexNodes(parents, selector, parents[0]); +}; + // See: http://api.jquery.com/addClass/ WindexNodes.prototype.addClass = function (className) { var classesToAdd = className.split(" ");