Skip to content

Commit 3feab7a

Browse files
author
James Watts
committed
Migration from SourceForge (2010-01-24)
1 parent 1cc0056 commit 3feab7a

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

nano.query.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* nano Query plugin v1.0
3+
* http://nanojs.org/plugins/query
4+
*
5+
* Copyright (c) 2008-2015 James Watts
6+
* https://github.com/jameswatts
7+
*
8+
* This is FREE software, licensed under the GPL
9+
* http://www.gnu.org/licenses/gpl.html
10+
*/
11+
12+
if (nano) {
13+
nano.plugin({
14+
query: function _query(query) {
15+
return nano.query(query, this.node);
16+
}
17+
}, function() {
18+
this.query = function _query(query, node) {
19+
if (typeof Sizzle === 'function') {
20+
var nodes = new Sizzle((typeof query === 'string')? query : '*', (node)? ((node.nano)? node.node : node) : null);
21+
for (var i = 0; i < nodes.length; i++) nodes[i] = nano(nodes[i]);
22+
nodes.val = query;
23+
nodes.add = function _add(obj) {
24+
if (typeof obj === 'string') {
25+
var nodes = new Sizzle((typeof query === 'string')? query : '*');
26+
for (var i = 0; i < nodes.length; i++) this.push(nano(nodes[i]));
27+
} else if (nano.type(obj) === 'array') {
28+
for (var i = 0; i < obj.length; i++) this.nodes.push((obj[i].nano)? obj[i] : nano(obj[i]));
29+
} else {
30+
this.push((obj.nano)? obj : nano(obj));
31+
}
32+
return this;
33+
};
34+
nodes.each = function _each(fn, exit) {
35+
if (typeof fn === 'function') {
36+
var exit = (arguments.length < 2)? null : exit,
37+
i, out;
38+
for (i = 0; i < this.length; i++) {
39+
out = fn.call(this[i], this, i);
40+
if (out === exit) break;
41+
}
42+
}
43+
return this;
44+
};
45+
nodes.first = function _first() {
46+
return (this.length > 0)? this[0] : null;
47+
};
48+
nodes.last = function _last() {
49+
return (this.length > 0)? this[this.length - 1] : null;
50+
};
51+
return nodes;
52+
}
53+
return null;
54+
};
55+
});
56+
}

0 commit comments

Comments
 (0)