Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Expect $(domElement1, domElement2) to return [domElement1] like jQuery. #426

Merged
merged 1 commit into from

3 participants

@johnboxall

Sometimes we anchor Zepto to a particular DOM element to make querying easier eg:

function anchor(context) {
    return function(selector) {
        return Zepto(selector, context)
    }
}

var $ = anchor(domElement)
$('h1')
$(otherDomElement)

Currently passing a DOM element and a context results in an error.

@mislav mislav was assigned
@madrobby madrobby merged commit 62a192c into madrobby:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 2 deletions.
  1. +1 −1  src/zepto.js
  2. +4 −1 test/zepto.html
View
2  src/zepto.js
@@ -78,7 +78,6 @@ var Zepto = (function() {
function $(selector, context){
if (!selector) return Z();
- if (context !== undefined) return $(context).find(selector);
else if (isF(selector)) return $(document).ready(selector);
else if (selector instanceof Z) return selector;
else {
@@ -89,6 +88,7 @@ var Zepto = (function() {
else if (fragmentRE.test(selector))
dom = fragment(selector.trim(), RegExp.$1), selector = null;
else if (selector.nodeType && selector.nodeType == 3) dom = [selector];
+ else if (context !== undefined) return $(context).find(selector);
else dom = $$(document, selector);
return Z(dom, selector);
}
View
5 test/zepto.html
@@ -377,9 +377,12 @@
var zepto = $('p#find1, #find2');
t.assertLength(11, $('span', zepto));
- // DOM Element
+ // Selector with DOM Element Context
var domElement = document.getElementById('find1');
t.assertLength(4, $('span.findme', domElement));
+
+ // DOM Element with DOM Element Context
+ t.assertLength(1, $(domElement, domElement));
},
testDollarWithDocument: function(t){
Something went wrong with that request. Please try again.