From 2d13d45dc8decc699e3d88ca832e3b56a2be1811 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Fri, 23 Oct 2009 01:43:48 +0200 Subject: [PATCH] Remove dependencies to Selector in favor of Prototype.Selector throughout the library. --- src/dom/dom.js | 25 ++++++++++++++----------- src/dom/event.js | 8 ++++++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/dom/dom.js b/src/dom/dom.js index 1301bc7..65182bf 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -518,9 +518,10 @@ Element.Methods = { * Checks if `element` matches the given CSS selector. **/ match: function(element, selector) { + element = $(element); if (Object.isString(selector)) - selector = new Selector(selector); - return selector.match($(element)); + return Prototype.Selector.match(element, selector); + return selector.match(element); }, /** @@ -538,7 +539,7 @@ Element.Methods = { if (arguments.length == 1) return $(element.parentNode); var ancestors = Element.ancestors(element); return Object.isNumber(expression) ? ancestors[expression] : - Selector.findElement(ancestors, expression, index); + Prototype.Selector.filter(ancestors, expression)[index || 0]; }, /** @@ -574,7 +575,7 @@ Element.Methods = { if (!Object.isNumber(index)) index = 0; if (expression) { - return Selector.findElement(element.previousSiblings(), expression, index); + return Prototype.Selector.filter(element.previousSiblings(), expression)[index]; } else { return element.recursivelyCollect("previousSibling", index + 1)[index]; } @@ -596,7 +597,7 @@ Element.Methods = { if (!Object.isNumber(index)) index = 0; if (expression) { - return Selector.findElement(element.nextSiblings(), expression, index); + return Prototype.Selector.filter(element.nextSiblings(), expression)[index]; } else { var maximumLength = Object.isNumber(index) ? index + 1 : 1; return element.recursivelyCollect("nextSibling", index + 1)[index]; @@ -605,15 +606,16 @@ Element.Methods = { /** - * Element.select(@element, selector...) -> [Element...] - * - selector (String): A CSS selector. + * Element.select(@element, expression...) -> [Element...] + * - expression (String): A CSS selector. * * Takes an arbitrary number of CSS selectors and returns an array of * descendants of `element` that match any of them. **/ select: function(element) { - var args = Array.prototype.slice.call(arguments, 1); - return Selector.findChildElements(element, args); + element = $(element); + var expressions = Array.prototype.slice.call(arguments, 1).join(', '); + return Prototype.Selector.select(expressions, element); }, /** @@ -624,8 +626,9 @@ Element.Methods = { * selector(s). **/ adjacent: function(element) { - var args = Array.prototype.slice.call(arguments, 1); - return Selector.findChildElements(element.parentNode, args).without(element); + element = $(element); + var expressions = Array.prototype.slice.call(arguments, 1).join(', '); + return Prototype.Selector.select(expressions, element.parentNode).without(element); }, /** diff --git a/src/dom/event.js b/src/dom/event.js index 7980c52..f94ac87 100644 --- a/src/dom/event.js +++ b/src/dom/event.js @@ -149,8 +149,12 @@ function findElement(event, expression) { var element = Event.element(event); if (!expression) return element; - var elements = [element].concat(element.ancestors()); - return Selector.findElement(elements, expression, 0); + while (element) { + if (Prototype.Selector.match(element, expression)) { + return Element.extend(element); + } + element = element.parentNode + } } /**