Skip to content

Commit

Permalink
$.select() and $.first()
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jan 2, 2012
1 parent cf0eed4 commit 61092e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
20 changes: 18 additions & 2 deletions lib/ender/bridge.js
Expand Up @@ -62,8 +62,11 @@
}

$.ender({
// boolean, does at least one element in the collection match the given selector
is: is
, match: is
// find all elements that are children of the elements in this collection matching
// the given selector
, find: function (s) {
var r = [], i, l, j, k, els
for (i = 0, l = this.length; i < l; i++) {
Expand All @@ -72,13 +75,26 @@
}
return $(uniq(r))
}
, and: function (s) {
var plus = $(s)
// add additional elements to this collection matching the given selector
, and: function (s, r) {
var plus = $(s, r)
for (var i = this.length, j = 0, l = this.length + plus.length; i < l; i++, j++) {
this[i] = plus[j]
}
return this
}
}, true)

$.ender({
// allow for NW.Dom.select(selector, root, callback), for speedy code such as
// $.select("div", null, function ( e ) { e.style.backgroundColor = "#ffe"; });
select: function () {
return $(nw.select.apply(null, arguments))
}
// like querySelector(), return only the first match, document-order
, first: function (selector, root) {
return $(nw.select(selector, root, function() { return false }))
}
})

}(document, ender)
20 changes: 18 additions & 2 deletions test/ender/ender.js
Expand Up @@ -1778,8 +1778,11 @@
}

$.ender({
// boolean, does at least one element in the collection match the given selector
is: is
, match: is
// find all elements that are children of the elements in this collection matching
// the given selector
, find: function (s) {
var r = [], i, l, j, k, els
for (i = 0, l = this.length; i < l; i++) {
Expand All @@ -1788,15 +1791,28 @@
}
return $(uniq(r))
}
, and: function (s) {
var plus = $(s)
// add additional elements to this collection matching the given selector
, and: function (s, r) {
var plus = $(s, r)
for (var i = this.length, j = 0, l = this.length + plus.length; i < l; i++, j++) {
this[i] = plus[j]
}
return this
}
}, true)

$.ender({
// allow for NW.Dom.select(selector, root, callback), for speedy code such as
// $.select("div", null, function ( e ) { e.style.backgroundColor = "#ffe"; });
select: function () {
return $(nw.select.apply(null, arguments))
}
// like querySelector(), return only the first match, document-order
, first: function (selector, root) {
return $(nw.select(selector, root, function() { return false }))
}
})

}(document, ender)


Expand Down

0 comments on commit 61092e9

Please sign in to comment.