Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix for ender-js@0.4.* compat, published 0.0.7

  • Loading branch information...
commit bd33785d3333bee72ee141bebc5f101d0be94de2 1 parent cf6b683
@rvagg authored
View
2  build.js
@@ -16,7 +16,6 @@ var jshintOptions = {
, 'sub': true
, 'white': false
, 'indent': 2
- , 'whitespace': true
, 'asi': true
, 'laxbreak': true
, 'eqeqeq': true
@@ -24,6 +23,7 @@ var jshintOptions = {
, 'browser': true
, 'node': true
, 'laxcomma': true
+ , 'strict': false
}
require('smoosh')
.config({
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "traversty"
, "description": "Library agnostic utility for traversing the DOM"
- , "version": "0.0.6"
+ , "version": "0.0.7"
, "homepage": "https://github.com/rvagg/traversty"
, "author": "Rod Vagg <rod@vagg.org> @rvagg"
, "keywords": ["ender", "dom", "nodes"]
View
8 src/traversty.js
@@ -92,8 +92,12 @@
}
, collect = function (els, fn) {
- var ret = [], i = 0, l = els.length
- while (i < l) ret = ret.concat(fn(els[i++]))
+ var ret = [], res, i = 0, j, l = els.length, l2
+ while (i < l) {
+ j = 0
+ l2 = (res = fn(els[i++])).length
+ while (j < l2) ret.push(res[j++])
+ }
return ret
}
View
5 test/core-test.js
@@ -28,7 +28,7 @@ buster.testCase('traversty', {
}
, 'traversty() can be passed selector strings': function () {
- var el, t
+ var t
if (__matchesSelector) { // defined in setup.js
// T("#fixtures") has #fixtures element (only)
@@ -39,7 +39,8 @@ buster.testCase('traversty', {
assert.equals((t = T('#fixtures,div#flat')).length, 2)
assert.same(t[0], Q('#fixtures')[0])
assert.same(t[1], Q('div#flat')[0])
- }
+ } else
+ assert(true) // needed for buster
}
}
)
View
5 test/engines-test.js
@@ -36,11 +36,10 @@ var own = Object.prototype.hasOwnProperty
// native must be first so we start off without T.setSelectorEngine() being called
// we also don't want to run native tests in older browsers that don't support it
-if (!!__matchesSelector)
- engineTest(null, 'Native')
+if (__matchesSelector) engineTest(null, 'Native')
engineTest(Q, 'Qwery')
engineTest(Sizzle, 'Sizzle')
engineTest(NW.Dom, 'NW')
// Sel must be last because it requires es5-basic which extends natives and we don't
// want that impacting any other tests in unexpected ways
-engineTest(sel, 'Sel', function() { loadES5Basic() })
+engineTest(sel, 'Sel', function() { loadES5Basic() })
View
12 test/setup.js
@@ -1,12 +1,12 @@
/*global qwery:true, traversty:true, assert: true, buster:true*/
var Q = qwery.noConflict()
-var T = traversty.noConflict()
-var __matchesSelector = (function (el, pfx, name, i, ms) {
- while (i < pfx.length)
- if (el[ms = pfx[i++] + name]) return ms
- if (el[name = 'm' + name.substring(1)]) return name
-}(document.documentElement, [ 'ms', 'webkit', 'moz', 'o' ], 'MatchesSelector', 0))
+ , T = traversty.noConflict()
+ , __matchesSelector = (function (el, pfx, name, i, ms) {
+ while (i < pfx.length)
+ if (el[ms = pfx[i++] + name]) return ms
+ return false
+ }(document.documentElement, [ 'msM', 'webkitM', 'mozM', 'oM', 'm' ], 'atchesSelector', 0))
assert.equals.message += ": ${2}";
assert.same.message += ": ${2}";
View
8 traversty.js
@@ -98,8 +98,12 @@
}
, collect = function (els, fn) {
- var ret = [], i = 0, l = els.length
- while (i < l) ret = ret.concat(fn(els[i++]))
+ var ret = [], res, i = 0, j, l = els.length, l2
+ while (i < l) {
+ j = 0
+ l2 = (res = fn(els[i++])).length
+ while (j < l2) ret.push(res[j++])
+ }
return ret
}
View
2  traversty.min.js
@@ -3,4 +3,4 @@
* https://github.com/rvagg/traversty
* License: MIT
*/
-!function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&define.amd?define(a,b):this[a]=b()}("traversty",function(){var a=this,b=a.traversty,c=window.document,d=c.documentElement,e=Object.prototype.toString,f=Array.prototype.slice,g=function(a,b,c,d,e){while(d<b.length)if(a[e=b[d++]+c])return e}(d,["msM","webkitM","mozM","oM","m"],"atchesSelector",0),h=function(a){return e.call(a)==="[object Number]"},i=function(a){return e.call(a)==="[object String]"},j=function(a){return e.call(a)==="[object Function]"},k=function(a){return a===void 0},l=function(a){return a&&a.nodeType===1},m=function(a,b){return k(a)&&!h(b)?0:h(a)?a:h(b)?b:null},n=function(a){return i(a)?a:"*"},o=function(a,b){return f.call(b.querySelectorAll(a),0)},p=function(a,b){return a==="*"||b[g](a)},q=o,r=p,s=function(a,b){return function(c,d){if(/,/.test(c)){var e=[],f=-1,g=d.getElementsByTagName("*");while(++f<g.length)l(g[f])&&b(c,g[f])&&e.push(g[f]);return e}return a(c,d)}},t=function(a){var b=[],c=-1,d,e;while(++c<a.length){d=-1,e=!1;while(++d<b.length)if(b[d]===a[c]){e=!0;break}e||b.push(a[c])}return b},u=function(a,b){var c=[],d=0,e=a.length;while(d<e)c=c.concat(b(a[d++]));return c},v=function(a,b,c,d){return d=m(c,d),c=n(c),u(a,function(a){var e=d||0,f=[];while(a&&(d===null||e>=0))a=a[b],l(a)&&r(c,a)&&(d===null||e--===0)&&(d===null&&b!=="nextSibling"?f=[a].concat(f):f.push(a));return f})},w=function(){function d(a){this.length=0;if(a){a=t(!a.nodeType&&!k(a.length)?a:[a]);var b=this.length=a.length;while(b--)this[b]=a[b]}}function e(a){return new d(i(a)?q(a,c):a)}return d.prototype={down:function(a,b){return b=m(a,b),a=n(a),w(u(this,function(c){var d=q(a,c);return b===null?d:[d[b]]||[]}))},up:function(a,b){return w(v(this,"parentNode",a,b))},previous:function(a,b){return w(v(this,"previousSibling",a,b))},next:function(a,b){return w(v(this,"nextSibling",a,b))}},e.setSelectorEngine=function(a){var b,d,e,f,g,h=c.createElement("p"),k=a.select||a.sel||a;h.innerHTML="<a/><i/><b/>",e=h.firstChild;try{f=j(a.matching)?function(b,c){return a.matching([c],b).length>0}:j(a.is)?function(b,c){return a.is(c,b)}:j(a.matchesSelector)?function(b,c){return a.matchesSelector(c,b)}:j(a.match)?function(b,c){return a.match(c,b)}:null,f||(b=a("a",h),f=j(b.matching)?function(b,c){return a(c).matching(b).length>0}:j(b.is)?function(b,c){return a(c).is(b)}:j(b.matchesSelector)?function(b,c){return a(c).matchesSelector(b)}:j(b.match)?function(b,c){return a(c).match(b)}:null);if(!f)throw"Traversty: couldn't find selector engine's `matchesSelector`";if(f("x,y",h)||!f("a,p",h))throw"Traversty: couldn't make selector engine's `matchesSelector` work";if((d=k("b,a",h)).length!==2)throw"Traversty: don't know how to use this selector engine";g=d[0]===e?k:s(k,f);if((d=g("b,a",h)).length!==2||d[0]!==e)throw"Traversty: couldn't make selector engine work";r=f,q=g}catch(l){throw i(l)?l:"Traversty: error while figuring out how the selector engine works: "+(l.message||l)}finally{h=null}},e.noConflict=function(){return a.traversty=b,this},e}();return w})
+!function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&define.amd?define(a,b):this[a]=b()}("traversty",function(){var a=this,b=a.traversty,c=window.document,d=c.documentElement,e=Object.prototype.toString,f=Array.prototype.slice,g=function(a,b,c,d,e){while(d<b.length)if(a[e=b[d++]+c])return e}(d,["msM","webkitM","mozM","oM","m"],"atchesSelector",0),h=function(a){return e.call(a)==="[object Number]"},i=function(a){return e.call(a)==="[object String]"},j=function(a){return e.call(a)==="[object Function]"},k=function(a){return a===void 0},l=function(a){return a&&a.nodeType===1},m=function(a,b){return k(a)&&!h(b)?0:h(a)?a:h(b)?b:null},n=function(a){return i(a)?a:"*"},o=function(a,b){return f.call(b.querySelectorAll(a),0)},p=function(a,b){return a==="*"||b[g](a)},q=o,r=p,s=function(a,b){return function(c,d){if(/,/.test(c)){var e=[],f=-1,g=d.getElementsByTagName("*");while(++f<g.length)l(g[f])&&b(c,g[f])&&e.push(g[f]);return e}return a(c,d)}},t=function(a){var b=[],c=-1,d,e;while(++c<a.length){d=-1,e=!1;while(++d<b.length)if(b[d]===a[c]){e=!0;break}e||b.push(a[c])}return b},u=function(a,b){var c=[],d,e=0,f,g=a.length,h;while(e<g){f=0,h=(d=b(a[e++])).length;while(f<h)c.push(d[f++])}return c},v=function(a,b,c,d){return d=m(c,d),c=n(c),u(a,function(a){var e=d||0,f=[];while(a&&(d===null||e>=0))a=a[b],l(a)&&r(c,a)&&(d===null||e--===0)&&(d===null&&b!=="nextSibling"?f=[a].concat(f):f.push(a));return f})},w=function(){function d(a){this.length=0;if(a){a=t(!a.nodeType&&!k(a.length)?a:[a]);var b=this.length=a.length;while(b--)this[b]=a[b]}}function e(a){return new d(i(a)?q(a,c):a)}return d.prototype={down:function(a,b){return b=m(a,b),a=n(a),w(u(this,function(c){var d=q(a,c);return b===null?d:[d[b]]||[]}))},up:function(a,b){return w(v(this,"parentNode",a,b))},previous:function(a,b){return w(v(this,"previousSibling",a,b))},next:function(a,b){return w(v(this,"nextSibling",a,b))}},e.setSelectorEngine=function(a){var b,d,e,f,g,h=c.createElement("p"),k=a.select||a.sel||a;h.innerHTML="<a/><i/><b/>",e=h.firstChild;try{f=j(a.matching)?function(b,c){return a.matching([c],b).length>0}:j(a.is)?function(b,c){return a.is(c,b)}:j(a.matchesSelector)?function(b,c){return a.matchesSelector(c,b)}:j(a.match)?function(b,c){return a.match(c,b)}:null,f||(b=a("a",h),f=j(b.matching)?function(b,c){return a(c).matching(b).length>0}:j(b.is)?function(b,c){return a(c).is(b)}:j(b.matchesSelector)?function(b,c){return a(c).matchesSelector(b)}:j(b.match)?function(b,c){return a(c).match(b)}:null);if(!f)throw"Traversty: couldn't find selector engine's `matchesSelector`";if(f("x,y",h)||!f("a,p",h))throw"Traversty: couldn't make selector engine's `matchesSelector` work";if((d=k("b,a",h)).length!==2)throw"Traversty: don't know how to use this selector engine";g=d[0]===e?k:s(k,f);if((d=g("b,a",h)).length!==2||d[0]!==e)throw"Traversty: couldn't make selector engine work";r=f,q=g}catch(l){throw i(l)?l:"Traversty: error while figuring out how the selector engine works: "+(l.message||l)}finally{h=null}},e.noConflict=function(){return a.traversty=b,this},e}();return w})
Please sign in to comment.
Something went wrong with that request. Please try again.