Matt Spendlove wrote:
I understand what the function does, I am just not sure whether the search applies only to the current document or if you can pass in some DOM fragment e.g. the responseXML from an AJAX call..

Gotcha, just misunderstood your question.

The search applies to the current document. If you want it to only apply to a portion of the document you would need to put an identifier on that portion and prepend that identifier to your search criteria.

You might be able to use a DOM fragment but you would have to use the Selector objects directly instead of using the $$() function. So something like:

s = new Selector('.item');
items = s.findElements(dom_fragment);

I have never tested the above code but it seems it should work. The only catch is that using the selector object will only allow you to use the basic selector syntax. You cannot specify element relationships. For example the following would not work:

s = new Selector('#news .item');
news_items = s.findElements(dom_fragment);

If you want to specify relationships and use a dom_fragment you would probably need to do something like this (borrowed from the $$() implementation):

function $$WithFragment(expression, fragment) {
        return expression.strip().split(/\s+/).inject(
                [fragment], function(results, expr) {
                var selector = new Selector(expr);
                return results.map(
                        selector.findElements.bind(selector)).flatten();
        });
})

Of course none of the code is tested but that should give you the general idea.

Eric

_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to