Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update array support

  • Loading branch information...
commit a8e8f9648b84ca9d9baf0818a3becaa564c5bca2 1 parent 02b657e
@pyrsmk authored
View
4 README.markdown
@@ -6,7 +6,7 @@ Nut is a concise query selector engine that just allows you to do extremely simp
Notes
-----
-0.2.0: removed array support for the context parameter
+0.2.0: removed array support for the context parameter, you can still pass an array but it will only take the first field
Quickly
-------
@@ -60,7 +60,7 @@ So, all pseudo-classes, attribute selectors and other advanced syntax are not al
Of course, queries can have a context (one node):
// Get nodes from the #foo context
- nut('.bar p',nut('#foo')[0]);
+ nut('.bar p',nut('#foo'));
And that's all you need to know ;)
View
2  benchmark/runner.js
@@ -34,7 +34,7 @@ domReady(function(){
}
})
.add('[nut: .bar from #foo context]',function(){
- nut('.bar',nut('#foo')[0]);
+ nut('.bar',nut('#foo'));
})
// #foo .bar span
View
2  nut-0.2.0.min.js
@@ -1 +1 @@
-window.nut=function(){var e=document,t="firstChild",n="nextSibling",r="getElementsByClassName",i="length",s=function(t,n){var r=e.getElementById(t);return r?[r]:[]},o=function(e,r){var s=r[t],u=[],a;if(s)do s.nodeType==1&&(s.className&&s.className.match("\\b"+e+"\\b")&&u.push(s),(a=o(e,s))[i]&&(u=u.concat(a)));while(s=s[n]);return u},u=function(e,t){return t[r]?t[r](e):o(e,t)},a=function(e,t){return t.getElementsByTagName(e)};return function(t,n){n||(n=e);var r,o,f,l,c=[],h,p,d,v,m,g,y;t=t.split(","),m=-1;while(f=t[++m])t[m]=f.split(/\s+/);h=t[i];while(h){r=[n],p=-1,d=t[--h][i];while(++p<d)if(f=t[h][p]){f.charAt(0)=="#"?(f=f.substr(1),y=s):f.charAt(0)=="."?(f=f.substr(1),y=u):y=a,o=[],v=-1;while(r[++v]){l=y(f,r[v]),m=-1,g=l[i];while(++m<g)o.push(l[m])}r=o}c=c.concat(r)}return c}}();
+window.nut=function(){var e=document,t="firstChild",n="nextSibling",r="getElementsByClassName",i="length",s=function(t,n){var r=e.getElementById(t);return r?[r]:[]},o=function(e,r){var s=r[t],u=[],a;if(s)do s.nodeType==1&&(s.className&&s.className.match("\\b"+e+"\\b")&&u.push(s),(a=o(e,s))[i]&&(u=u.concat(a)));while(s=s[n]);return u},u=function(e,t){return t[r]?t[r](e):o(e,t)},a=function(e,t){return t.getElementsByTagName(e)};return function(t,n){n||(n=e),typeof n=="object"&&n.pop&&(n=n[0]);var r,o,f,l,c=[],h,p,d,v,m,g,y;t=t.split(","),m=-1;while(f=t[++m])t[m]=f.split(/\s+/);h=t[i];while(h){r=[n],p=-1,d=t[--h][i];while(++p<d)if(f=t[h][p]){f.charAt(0)=="#"?(f=f.substr(1),y=s):f.charAt(0)=="."?(f=f.substr(1),y=u):y=a,o=[],v=-1;while(r[++v]){l=y(f,r[v]),m=-1,g=l[i];while(++m<g)o.push(l[m])}r=o}c=c.concat(r)}return c}}();
View
3  src/nut.js
@@ -117,6 +117,9 @@ window.nut=function(){
if(!context){
context=doc;
}
+ if(typeof context=='object' && context.pop){
+ context=context[0];
+ }
// Init vars
var local_contexts,
future_local_contexts,
View
6 unit/runner.js
@@ -16,13 +16,15 @@ domReady(function(){
return true;
};
- test('Acceptable selectors',4,function(){
+ test('Acceptable selectors',5,function(){
// p
ok(verifyNodes(nut('p'),3),'p');
// #foo
ok(verifyNodes(nut('#foo'),1),'#foo');
// .bar from #foo context (node)
- ok(verifyNodes(nut('.bar',nut('#foo')[0]),2),'.bar from #foo context');
+ ok(verifyNodes(nut('.bar',nut('#foo')[0]),2),'.bar from #foo context (node)');
+ // .bar from #foo context (array)
+ ok(verifyNodes(nut('.bar',nut('#foo')),2),'.bar from #foo context (array)');
// #foo .bar span
ok(verifyNodes(nut('#foo .bar span'),2),'#foo .bar span');
});
Please sign in to comment.
Something went wrong with that request. Please try again.