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 cb60b03b2c664de6fd66c8bd7cc5220416858e1e
parent b14dcec47ba019f1259764a25fb5a964ec9ff65b
Author: Ryan Wolf <rwolf@borderstylo.com>
Date:   Thu, 17 Feb 2011 11:38:10 -0800

now .parents really works, for realsies

Diffstat:
Mwindex.js | 11+++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/windex.js b/windex.js @@ -182,8 +182,9 @@ WindexNodes.prototype._parentMatching = function (selector) { WindexNodes.prototype.parents = function (selector) { if (selector) { return this._parentsMatching(selector); } var parents = []; - this.each(function (i, node) { - while (node.parentNode) { + this.forEach(function (node) { + // See: https://developer.mozilla.org/En/DOM/Node.nodeName + while (node.parentNode && node.parentNode.nodeName != '#document') { node = node.parentNode; parents.push(node); } @@ -192,8 +193,9 @@ WindexNodes.prototype.parents = function (selector) { }; WindexNodes.prototype._parentsMatching = function (selector) { - var parents = this.parents().toArray(). - filter(function (node) {return Windex.matchesSelector(node, selector);}); + var parents = this.parents().filter(function (i, n) { + return Windex.matchesSelector(n, selector); + }); return new WindexNodes(parents, selector, parents[0]); }; @@ -231,6 +233,7 @@ WindexNodes.prototype.removeClass = function (className) { WindexNodes.prototype._removeAllClasses = function () { this.forEach(function (node) { node.className = ''; }); + return this; }; // See: http://api.jquery.com/toggleClass/