Permalink
Browse files

update to match master @1.0.1

  • Loading branch information...
1 parent 53a8bee commit b4956e355e8917ddaba781885571c7e41f5eebba @rvagg committed Nov 1, 2012
View
95 test/integration/ender_noselector.js
@@ -2,7 +2,7 @@
* =============================================================
* Ender: open module JavaScript framework (https://ender.no.de)
* Build: ender build domready bonzo ../.. --output ender_noselector
- * Packages: ender-js@0.4.4 domready@0.2.11 bonzo@1.2.4 traversty@0.0.7
+ * Packages: ender-js@0.4.4 domready@0.2.11 bonzo@1.2.7-1 traversty@1.0.0
* =============================================================
*/
@@ -985,7 +985,11 @@
* @return {Bonzo|number}
*/
, offset: function (opt_x, opt_y) {
- if (typeof opt_x == 'number' || typeof opt_y == 'number') {
+ if (opt_x && typeof opt_x == 'object' && (typeof opt_x.top == 'number' || typeof opt_x.left == 'number')) {
+ return this.each(function (el) {
+ xy(el, opt_x.left, opt_x.top)
+ })
+ } else if (typeof opt_x == 'number' || typeof opt_y == 'number') {
return this.each(function (el) {
xy(el, opt_x, opt_y)
})
@@ -997,19 +1001,13 @@
, width: 0
}
var el = this[0]
+ , de = el.ownerDocument.documentElement
+ , bcr = el.getBoundingClientRect()
+ , scroll = getWindowScroll()
, width = el.offsetWidth
, height = el.offsetHeight
- , top = el.offsetTop
- , left = el.offsetLeft
- while (el = el.offsetParent) {
- top = top + el.offsetTop
- left = left + el.offsetLeft
-
- if (el != doc.body) {
- top -= el.scrollTop
- left -= el.scrollLeft
- }
- }
+ , top = bcr.top + scroll.y - Math.max(0, de && de.clientTop, doc.body.clientTop)
+ , left = bcr.left + scroll.x - Math.max(0, de && de.clientLeft, doc.body.clientLeft)
return {
top: top
@@ -1137,10 +1135,7 @@
*/
, remove: function () {
this.deepEach(clearData)
-
- return this.each(function (el) {
- el[parentNode] && el[parentNode].removeChild(el)
- })
+ return this.detach()
}
@@ -1163,7 +1158,7 @@
*/
, detach: function () {
return this.each(function (el) {
- el[parentNode].removeChild(el)
+ el[parentNode] && el[parentNode].removeChild(el)
})
}
@@ -1492,13 +1487,16 @@
, doc = window.document
, html = doc.documentElement
, toString = Object.prototype.toString
- , slice = Array.prototype.slice
+ , Ap = Array.prototype
+ , slice = Ap.slice
// feature test to find native matchesSelector()
, matchesSelector = (function (el, pfx, name, i, ms) {
while (i < pfx.length)
if (el[ms = pfx[i++] + name]) return ms
}(html, [ 'msM', 'webkitM', 'mozM', 'oM', 'm' ], 'atchesSelector', 0))
+ , Kfalse = function () { return false }
+
, isNumber = function (o) {
return toString.call(o) === '[object Number]'
}
@@ -1614,7 +1612,7 @@
// ignore non-elements, only consider selector-matching elements
// handle both the index and no-index (selector-only) cases
if (isElement(el)
- && (!filterFn || (filterFn === true || filterFn(el, elind)))
+ && (!filterFn || filterFn === true || filterFn(el, elind))
&& selectorMatches(selector, el)
&& (index === null || i-- === 0)) {
// this concat vs push is to make sure we add elements to the result array
@@ -1653,7 +1651,7 @@
? function (el, i) { return slfn.call(el, i) }
: to == 'string' && slfn.length
? function (el) { return selectorMatches(slfn, el) }
- : function () { return false }
+ : Kfalse
}
// fn = !fn
@@ -1742,7 +1740,11 @@
}
, eq: function (index) {
- return traversty((index = eqIndex(this.length, index, 0)) === null ? [] : this[index])
+ return traversty(this.get(index))
+ }
+
+ , get: function (index) {
+ return this[eqIndex(this.length, index, 0)]
}
// a crazy man wrote this, don't try to understand it, see the tests
@@ -1764,15 +1766,6 @@
return traversty(filter(this, inv(filterFn(slfn))))
}
- // same as filter() but return a boolean so quick-return after first successful find
- , is: function (slfn) {
- var i = 0, l = this.length
- , fn = filterFn(slfn)
- for (; i < l; i++)
- if (fn(this[i], i)) return true
- return false
- }
-
// similar to filter() but cares about descendent elements
, has: function (slel) {
return traversty(filter(
@@ -1781,16 +1774,54 @@
? function (el) { return isAncestor(slel, el) }
: typeof slel == 'string' && slel.length
? function (el) { return selectorFind(slel, el).length } //TODO: performance
- : function () { return false }
+ : Kfalse
))
}
+
+ // same as filter() but return a boolean so quick-return after first successful find
+ , is: function (slfn) {
+ var i = 0, l = this.length
+ , fn = filterFn(slfn)
+ for (; i < l; i++)
+ if (fn(this[i], i)) return true
+ return false
+ }
+
+ , toArray: function () { return Ap.slice.call(this) }
+
+ , size: function () { return this.length }
+
+ , each: function (fn, ctx) {
+ var i = 0, l = this.length
+ for (; i < l; i++)
+ fn.call(ctx || this[i], this[i], i, this)
+ return this
+ }
+
+ // quack like a duck (Array)
+ , push: Ap.push
+ , sort: Ap.sort
+ , splice: Ap.splice
}
+
T.prototype.prev = T.prototype.previous
function t(els) {
return new T(isString(els) ? selectorFind(els, doc) : els)
}
+ // extend traversty functionality with custom methods
+ t.aug = function (methods) {
+ var key, method
+ for (key in methods) {
+ method = methods[key]
+ if (typeof method == 'function') {
+ T.prototype[key] = method
+ }
+ }
+ }
+
+
t.setSelectorEngine = function (s) {
// feature testing the selector engine like a boss
var ss, r, a, _selectorMatches, _selectorFind
View
95 test/integration/ender_nwmatcher.js
@@ -2,7 +2,7 @@
* =============================================================
* Ender: open module JavaScript framework (https://ender.no.de)
* Build: ender build domready nwmatcher bonzo ../.. --output ender_nwmatcher
- * Packages: ender-js@0.4.4 domready@0.2.11 nwmatcher@1.2.5 bonzo@1.2.4 traversty@0.0.7
+ * Packages: ender-js@0.4.4 domready@0.2.11 nwmatcher@1.2.5 bonzo@1.2.7-1 traversty@1.0.0
* =============================================================
*/
@@ -1100,7 +1100,11 @@
* @return {Bonzo|number}
*/
, offset: function (opt_x, opt_y) {
- if (typeof opt_x == 'number' || typeof opt_y == 'number') {
+ if (opt_x && typeof opt_x == 'object' && (typeof opt_x.top == 'number' || typeof opt_x.left == 'number')) {
+ return this.each(function (el) {
+ xy(el, opt_x.left, opt_x.top)
+ })
+ } else if (typeof opt_x == 'number' || typeof opt_y == 'number') {
return this.each(function (el) {
xy(el, opt_x, opt_y)
})
@@ -1112,19 +1116,13 @@
, width: 0
}
var el = this[0]
+ , de = el.ownerDocument.documentElement
+ , bcr = el.getBoundingClientRect()
+ , scroll = getWindowScroll()
, width = el.offsetWidth
, height = el.offsetHeight
- , top = el.offsetTop
- , left = el.offsetLeft
- while (el = el.offsetParent) {
- top = top + el.offsetTop
- left = left + el.offsetLeft
-
- if (el != doc.body) {
- top -= el.scrollTop
- left -= el.scrollLeft
- }
- }
+ , top = bcr.top + scroll.y - Math.max(0, de && de.clientTop, doc.body.clientTop)
+ , left = bcr.left + scroll.x - Math.max(0, de && de.clientLeft, doc.body.clientLeft)
return {
top: top
@@ -1252,10 +1250,7 @@
*/
, remove: function () {
this.deepEach(clearData)
-
- return this.each(function (el) {
- el[parentNode] && el[parentNode].removeChild(el)
- })
+ return this.detach()
}
@@ -1278,7 +1273,7 @@
*/
, detach: function () {
return this.each(function (el) {
- el[parentNode].removeChild(el)
+ el[parentNode] && el[parentNode].removeChild(el)
})
}
@@ -1607,13 +1602,16 @@
, doc = window.document
, html = doc.documentElement
, toString = Object.prototype.toString
- , slice = Array.prototype.slice
+ , Ap = Array.prototype
+ , slice = Ap.slice
// feature test to find native matchesSelector()
, matchesSelector = (function (el, pfx, name, i, ms) {
while (i < pfx.length)
if (el[ms = pfx[i++] + name]) return ms
}(html, [ 'msM', 'webkitM', 'mozM', 'oM', 'm' ], 'atchesSelector', 0))
+ , Kfalse = function () { return false }
+
, isNumber = function (o) {
return toString.call(o) === '[object Number]'
}
@@ -1729,7 +1727,7 @@
// ignore non-elements, only consider selector-matching elements
// handle both the index and no-index (selector-only) cases
if (isElement(el)
- && (!filterFn || (filterFn === true || filterFn(el, elind)))
+ && (!filterFn || filterFn === true || filterFn(el, elind))
&& selectorMatches(selector, el)
&& (index === null || i-- === 0)) {
// this concat vs push is to make sure we add elements to the result array
@@ -1768,7 +1766,7 @@
? function (el, i) { return slfn.call(el, i) }
: to == 'string' && slfn.length
? function (el) { return selectorMatches(slfn, el) }
- : function () { return false }
+ : Kfalse
}
// fn = !fn
@@ -1857,7 +1855,11 @@
}
, eq: function (index) {
- return traversty((index = eqIndex(this.length, index, 0)) === null ? [] : this[index])
+ return traversty(this.get(index))
+ }
+
+ , get: function (index) {
+ return this[eqIndex(this.length, index, 0)]
}
// a crazy man wrote this, don't try to understand it, see the tests
@@ -1879,15 +1881,6 @@
return traversty(filter(this, inv(filterFn(slfn))))
}
- // same as filter() but return a boolean so quick-return after first successful find
- , is: function (slfn) {
- var i = 0, l = this.length
- , fn = filterFn(slfn)
- for (; i < l; i++)
- if (fn(this[i], i)) return true
- return false
- }
-
// similar to filter() but cares about descendent elements
, has: function (slel) {
return traversty(filter(
@@ -1896,16 +1889,54 @@
? function (el) { return isAncestor(slel, el) }
: typeof slel == 'string' && slel.length
? function (el) { return selectorFind(slel, el).length } //TODO: performance
- : function () { return false }
+ : Kfalse
))
}
+
+ // same as filter() but return a boolean so quick-return after first successful find
+ , is: function (slfn) {
+ var i = 0, l = this.length
+ , fn = filterFn(slfn)
+ for (; i < l; i++)
+ if (fn(this[i], i)) return true
+ return false
+ }
+
+ , toArray: function () { return Ap.slice.call(this) }
+
+ , size: function () { return this.length }
+
+ , each: function (fn, ctx) {
+ var i = 0, l = this.length
+ for (; i < l; i++)
+ fn.call(ctx || this[i], this[i], i, this)
+ return this
+ }
+
+ // quack like a duck (Array)
+ , push: Ap.push
+ , sort: Ap.sort
+ , splice: Ap.splice
}
+
T.prototype.prev = T.prototype.previous
function t(els) {
return new T(isString(els) ? selectorFind(els, doc) : els)
}
+ // extend traversty functionality with custom methods
+ t.aug = function (methods) {
+ var key, method
+ for (key in methods) {
+ method = methods[key]
+ if (typeof method == 'function') {
+ T.prototype[key] = method
+ }
+ }
+ }
+
+
t.setSelectorEngine = function (s) {
// feature testing the selector engine like a boss
var ss, r, a, _selectorMatches, _selectorFind
View
95 test/integration/ender_qwery.js
@@ -2,7 +2,7 @@
* =============================================================
* Ender: open module JavaScript framework (https://ender.no.de)
* Build: ender build domready qwery bonzo ../.. --output ender_qwery
- * Packages: ender-js@0.4.4 domready@0.2.11 qwery@3.3.11 bonzo@1.2.4 traversty@0.0.7
+ * Packages: ender-js@0.4.4 domready@0.2.11 qwery@3.3.11 bonzo@1.2.7-1 traversty@1.0.0
* =============================================================
*/
@@ -1424,7 +1424,11 @@
* @return {Bonzo|number}
*/
, offset: function (opt_x, opt_y) {
- if (typeof opt_x == 'number' || typeof opt_y == 'number') {
+ if (opt_x && typeof opt_x == 'object' && (typeof opt_x.top == 'number' || typeof opt_x.left == 'number')) {
+ return this.each(function (el) {
+ xy(el, opt_x.left, opt_x.top)
+ })
+ } else if (typeof opt_x == 'number' || typeof opt_y == 'number') {
return this.each(function (el) {
xy(el, opt_x, opt_y)
})
@@ -1436,19 +1440,13 @@
, width: 0
}
var el = this[0]
+ , de = el.ownerDocument.documentElement
+ , bcr = el.getBoundingClientRect()
+ , scroll = getWindowScroll()
, width = el.offsetWidth
, height = el.offsetHeight
- , top = el.offsetTop
- , left = el.offsetLeft
- while (el = el.offsetParent) {
- top = top + el.offsetTop
- left = left + el.offsetLeft
-
- if (el != doc.body) {
- top -= el.scrollTop
- left -= el.scrollLeft
- }
- }
+ , top = bcr.top + scroll.y - Math.max(0, de && de.clientTop, doc.body.clientTop)
+ , left = bcr.left + scroll.x - Math.max(0, de && de.clientLeft, doc.body.clientLeft)
return {
top: top
@@ -1576,10 +1574,7 @@
*/
, remove: function () {
this.deepEach(clearData)
-
- return this.each(function (el) {
- el[parentNode] && el[parentNode].removeChild(el)
- })
+ return this.detach()
}
@@ -1602,7 +1597,7 @@
*/
, detach: function () {
return this.each(function (el) {
- el[parentNode].removeChild(el)
+ el[parentNode] && el[parentNode].removeChild(el)
})
}
@@ -1931,13 +1926,16 @@
, doc = window.document
, html = doc.documentElement
, toString = Object.prototype.toString
- , slice = Array.prototype.slice
+ , Ap = Array.prototype
+ , slice = Ap.slice
// feature test to find native matchesSelector()
, matchesSelector = (function (el, pfx, name, i, ms) {
while (i < pfx.length)
if (el[ms = pfx[i++] + name]) return ms
}(html, [ 'msM', 'webkitM', 'mozM', 'oM', 'm' ], 'atchesSelector', 0))
+ , Kfalse = function () { return false }
+
, isNumber = function (o) {
return toString.call(o) === '[object Number]'
}
@@ -2053,7 +2051,7 @@
// ignore non-elements, only consider selector-matching elements
// handle both the index and no-index (selector-only) cases
if (isElement(el)
- && (!filterFn || (filterFn === true || filterFn(el, elind)))
+ && (!filterFn || filterFn === true || filterFn(el, elind))
&& selectorMatches(selector, el)
&& (index === null || i-- === 0)) {
// this concat vs push is to make sure we add elements to the result array
@@ -2092,7 +2090,7 @@
? function (el, i) { return slfn.call(el, i) }
: to == 'string' && slfn.length
? function (el) { return selectorMatches(slfn, el) }
- : function () { return false }
+ : Kfalse
}
// fn = !fn
@@ -2181,7 +2179,11 @@
}
, eq: function (index) {
- return traversty((index = eqIndex(this.length, index, 0)) === null ? [] : this[index])
+ return traversty(this.get(index))
+ }
+
+ , get: function (index) {
+ return this[eqIndex(this.length, index, 0)]
}
// a crazy man wrote this, don't try to understand it, see the tests
@@ -2203,15 +2205,6 @@
return traversty(filter(this, inv(filterFn(slfn))))
}
- // same as filter() but return a boolean so quick-return after first successful find
- , is: function (slfn) {
- var i = 0, l = this.length
- , fn = filterFn(slfn)
- for (; i < l; i++)
- if (fn(this[i], i)) return true
- return false
- }
-
// similar to filter() but cares about descendent elements
, has: function (slel) {
return traversty(filter(
@@ -2220,16 +2213,54 @@
? function (el) { return isAncestor(slel, el) }
: typeof slel == 'string' && slel.length
? function (el) { return selectorFind(slel, el).length } //TODO: performance
- : function () { return false }
+ : Kfalse
))
}
+
+ // same as filter() but return a boolean so quick-return after first successful find
+ , is: function (slfn) {
+ var i = 0, l = this.length
+ , fn = filterFn(slfn)
+ for (; i < l; i++)
+ if (fn(this[i], i)) return true
+ return false
+ }
+
+ , toArray: function () { return Ap.slice.call(this) }
+
+ , size: function () { return this.length }
+
+ , each: function (fn, ctx) {
+ var i = 0, l = this.length
+ for (; i < l; i++)
+ fn.call(ctx || this[i], this[i], i, this)
+ return this
+ }
+
+ // quack like a duck (Array)
+ , push: Ap.push
+ , sort: Ap.sort
+ , splice: Ap.splice
}
+
T.prototype.prev = T.prototype.previous
function t(els) {
return new T(isString(els) ? selectorFind(els, doc) : els)
}
+ // extend traversty functionality with custom methods
+ t.aug = function (methods) {
+ var key, method
+ for (key in methods) {
+ method = methods[key]
+ if (typeof method == 'function') {
+ T.prototype[key] = method
+ }
+ }
+ }
+
+
t.setSelectorEngine = function (s) {
// feature testing the selector engine like a boss
var ss, r, a, _selectorMatches, _selectorFind
View
95 test/integration/ender_sel.js
@@ -2,7 +2,7 @@
* =============================================================
* Ender: open module JavaScript framework (https://ender.no.de)
* Build: ender build domready sel bonzo ../../ --output ender_sel
- * Packages: ender-js@0.4.4 domready@0.2.11 es5-basic@0.2.1 sel@0.7.5 bonzo@1.2.4 traversty@0.0.7
+ * Packages: ender-js@0.4.4 domready@0.2.11 es5-basic@0.2.1 sel@0.7.5 bonzo@1.2.7-1 traversty@1.0.0
* =============================================================
*/
@@ -2109,7 +2109,11 @@
* @return {Bonzo|number}
*/
, offset: function (opt_x, opt_y) {
- if (typeof opt_x == 'number' || typeof opt_y == 'number') {
+ if (opt_x && typeof opt_x == 'object' && (typeof opt_x.top == 'number' || typeof opt_x.left == 'number')) {
+ return this.each(function (el) {
+ xy(el, opt_x.left, opt_x.top)
+ })
+ } else if (typeof opt_x == 'number' || typeof opt_y == 'number') {
return this.each(function (el) {
xy(el, opt_x, opt_y)
})
@@ -2121,19 +2125,13 @@
, width: 0
}
var el = this[0]
+ , de = el.ownerDocument.documentElement
+ , bcr = el.getBoundingClientRect()
+ , scroll = getWindowScroll()
, width = el.offsetWidth
, height = el.offsetHeight
- , top = el.offsetTop
- , left = el.offsetLeft
- while (el = el.offsetParent) {
- top = top + el.offsetTop
- left = left + el.offsetLeft
-
- if (el != doc.body) {
- top -= el.scrollTop
- left -= el.scrollLeft
- }
- }
+ , top = bcr.top + scroll.y - Math.max(0, de && de.clientTop, doc.body.clientTop)
+ , left = bcr.left + scroll.x - Math.max(0, de && de.clientLeft, doc.body.clientLeft)
return {
top: top
@@ -2261,10 +2259,7 @@
*/
, remove: function () {
this.deepEach(clearData)
-
- return this.each(function (el) {
- el[parentNode] && el[parentNode].removeChild(el)
- })
+ return this.detach()
}
@@ -2287,7 +2282,7 @@
*/
, detach: function () {
return this.each(function (el) {
- el[parentNode].removeChild(el)
+ el[parentNode] && el[parentNode].removeChild(el)
})
}
@@ -2616,13 +2611,16 @@
, doc = window.document
, html = doc.documentElement
, toString = Object.prototype.toString
- , slice = Array.prototype.slice
+ , Ap = Array.prototype
+ , slice = Ap.slice
// feature test to find native matchesSelector()
, matchesSelector = (function (el, pfx, name, i, ms) {
while (i < pfx.length)
if (el[ms = pfx[i++] + name]) return ms
}(html, [ 'msM', 'webkitM', 'mozM', 'oM', 'm' ], 'atchesSelector', 0))
+ , Kfalse = function () { return false }
+
, isNumber = function (o) {
return toString.call(o) === '[object Number]'
}
@@ -2738,7 +2736,7 @@
// ignore non-elements, only consider selector-matching elements
// handle both the index and no-index (selector-only) cases
if (isElement(el)
- && (!filterFn || (filterFn === true || filterFn(el, elind)))
+ && (!filterFn || filterFn === true || filterFn(el, elind))
&& selectorMatches(selector, el)
&& (index === null || i-- === 0)) {
// this concat vs push is to make sure we add elements to the result array
@@ -2777,7 +2775,7 @@
? function (el, i) { return slfn.call(el, i) }
: to == 'string' && slfn.length
? function (el) { return selectorMatches(slfn, el) }
- : function () { return false }
+ : Kfalse
}
// fn = !fn
@@ -2866,7 +2864,11 @@
}
, eq: function (index) {
- return traversty((index = eqIndex(this.length, index, 0)) === null ? [] : this[index])
+ return traversty(this.get(index))
+ }
+
+ , get: function (index) {
+ return this[eqIndex(this.length, index, 0)]
}
// a crazy man wrote this, don't try to understand it, see the tests
@@ -2888,15 +2890,6 @@
return traversty(filter(this, inv(filterFn(slfn))))
}
- // same as filter() but return a boolean so quick-return after first successful find
- , is: function (slfn) {
- var i = 0, l = this.length
- , fn = filterFn(slfn)
- for (; i < l; i++)
- if (fn(this[i], i)) return true
- return false
- }
-
// similar to filter() but cares about descendent elements
, has: function (slel) {
return traversty(filter(
@@ -2905,16 +2898,54 @@
? function (el) { return isAncestor(slel, el) }
: typeof slel == 'string' && slel.length
? function (el) { return selectorFind(slel, el).length } //TODO: performance
- : function () { return false }
+ : Kfalse
))
}
+
+ // same as filter() but return a boolean so quick-return after first successful find
+ , is: function (slfn) {
+ var i = 0, l = this.length
+ , fn = filterFn(slfn)
+ for (; i < l; i++)
+ if (fn(this[i], i)) return true
+ return false
+ }
+
+ , toArray: function () { return Ap.slice.call(this) }
+
+ , size: function () { return this.length }
+
+ , each: function (fn, ctx) {
+ var i = 0, l = this.length
+ for (; i < l; i++)
+ fn.call(ctx || this[i], this[i], i, this)
+ return this
+ }
+
+ // quack like a duck (Array)
+ , push: Ap.push
+ , sort: Ap.sort
+ , splice: Ap.splice
}
+
T.prototype.prev = T.prototype.previous
function t(els) {
return new T(isString(els) ? selectorFind(els, doc) : els)
}
+ // extend traversty functionality with custom methods
+ t.aug = function (methods) {
+ var key, method
+ for (key in methods) {
+ method = methods[key]
+ if (typeof method == 'function') {
+ T.prototype[key] = method
+ }
+ }
+ }
+
+
t.setSelectorEngine = function (s) {
// feature testing the selector engine like a boss
var ss, r, a, _selectorMatches, _selectorFind
View
95 test/integration/ender_sizzle.js
@@ -2,7 +2,7 @@
* =============================================================
* Ender: open module JavaScript framework (https://ender.no.de)
* Build: ender build domready sizzle bonzo ../.. --output ender_sizzle
- * Packages: ender-js@0.4.4 domready@0.2.11 sizzle@1.1.0 bonzo@1.2.4 traversty@0.0.7
+ * Packages: ender-js@0.4.4 domready@0.2.11 sizzle@1.1.0 bonzo@1.2.7-1 traversty@1.0.0
* =============================================================
*/
@@ -2543,7 +2543,11 @@
* @return {Bonzo|number}
*/
, offset: function (opt_x, opt_y) {
- if (typeof opt_x == 'number' || typeof opt_y == 'number') {
+ if (opt_x && typeof opt_x == 'object' && (typeof opt_x.top == 'number' || typeof opt_x.left == 'number')) {
+ return this.each(function (el) {
+ xy(el, opt_x.left, opt_x.top)
+ })
+ } else if (typeof opt_x == 'number' || typeof opt_y == 'number') {
return this.each(function (el) {
xy(el, opt_x, opt_y)
})
@@ -2555,19 +2559,13 @@
, width: 0
}
var el = this[0]
+ , de = el.ownerDocument.documentElement
+ , bcr = el.getBoundingClientRect()
+ , scroll = getWindowScroll()
, width = el.offsetWidth
, height = el.offsetHeight
- , top = el.offsetTop
- , left = el.offsetLeft
- while (el = el.offsetParent) {
- top = top + el.offsetTop
- left = left + el.offsetLeft
-
- if (el != doc.body) {
- top -= el.scrollTop
- left -= el.scrollLeft
- }
- }
+ , top = bcr.top + scroll.y - Math.max(0, de && de.clientTop, doc.body.clientTop)
+ , left = bcr.left + scroll.x - Math.max(0, de && de.clientLeft, doc.body.clientLeft)
return {
top: top
@@ -2695,10 +2693,7 @@
*/
, remove: function () {
this.deepEach(clearData)
-
- return this.each(function (el) {
- el[parentNode] && el[parentNode].removeChild(el)
- })
+ return this.detach()
}
@@ -2721,7 +2716,7 @@
*/
, detach: function () {
return this.each(function (el) {
- el[parentNode].removeChild(el)
+ el[parentNode] && el[parentNode].removeChild(el)
})
}
@@ -3050,13 +3045,16 @@
, doc = window.document
, html = doc.documentElement
, toString = Object.prototype.toString
- , slice = Array.prototype.slice
+ , Ap = Array.prototype
+ , slice = Ap.slice
// feature test to find native matchesSelector()
, matchesSelector = (function (el, pfx, name, i, ms) {
while (i < pfx.length)
if (el[ms = pfx[i++] + name]) return ms
}(html, [ 'msM', 'webkitM', 'mozM', 'oM', 'm' ], 'atchesSelector', 0))
+ , Kfalse = function () { return false }
+
, isNumber = function (o) {
return toString.call(o) === '[object Number]'
}
@@ -3172,7 +3170,7 @@
// ignore non-elements, only consider selector-matching elements
// handle both the index and no-index (selector-only) cases
if (isElement(el)
- && (!filterFn || (filterFn === true || filterFn(el, elind)))
+ && (!filterFn || filterFn === true || filterFn(el, elind))
&& selectorMatches(selector, el)
&& (index === null || i-- === 0)) {
// this concat vs push is to make sure we add elements to the result array
@@ -3211,7 +3209,7 @@
? function (el, i) { return slfn.call(el, i) }
: to == 'string' && slfn.length
? function (el) { return selectorMatches(slfn, el) }
- : function () { return false }
+ : Kfalse
}
// fn = !fn
@@ -3300,7 +3298,11 @@
}
, eq: function (index) {
- return traversty((index = eqIndex(this.length, index, 0)) === null ? [] : this[index])
+ return traversty(this.get(index))
+ }
+
+ , get: function (index) {
+ return this[eqIndex(this.length, index, 0)]
}
// a crazy man wrote this, don't try to understand it, see the tests
@@ -3322,15 +3324,6 @@
return traversty(filter(this, inv(filterFn(slfn))))
}
- // same as filter() but return a boolean so quick-return after first successful find
- , is: function (slfn) {
- var i = 0, l = this.length
- , fn = filterFn(slfn)
- for (; i < l; i++)
- if (fn(this[i], i)) return true
- return false
- }
-
// similar to filter() but cares about descendent elements
, has: function (slel) {
return traversty(filter(
@@ -3339,16 +3332,54 @@
? function (el) { return isAncestor(slel, el) }
: typeof slel == 'string' && slel.length
? function (el) { return selectorFind(slel, el).length } //TODO: performance
- : function () { return false }
+ : Kfalse
))
}
+
+ // same as filter() but return a boolean so quick-return after first successful find
+ , is: function (slfn) {
+ var i = 0, l = this.length
+ , fn = filterFn(slfn)
+ for (; i < l; i++)
+ if (fn(this[i], i)) return true
+ return false
+ }
+
+ , toArray: function () { return Ap.slice.call(this) }
+
+ , size: function () { return this.length }
+
+ , each: function (fn, ctx) {
+ var i = 0, l = this.length
+ for (; i < l; i++)
+ fn.call(ctx || this[i], this[i], i, this)
+ return this
+ }
+
+ // quack like a duck (Array)
+ , push: Ap.push
+ , sort: Ap.sort
+ , splice: Ap.splice
}
+
T.prototype.prev = T.prototype.previous
function t(els) {
return new T(isString(els) ? selectorFind(els, doc) : els)
}
+ // extend traversty functionality with custom methods
+ t.aug = function (methods) {
+ var key, method
+ for (key in methods) {
+ method = methods[key]
+ if (typeof method == 'function') {
+ T.prototype[key] = method
+ }
+ }
+ }
+
+
t.setSelectorEngine = function (s) {
// feature testing the selector engine like a boss
var ss, r, a, _selectorMatches, _selectorFind
View
2 test/integration/traversty_css_zest.html
@@ -62,7 +62,7 @@
<script>
var $ = traversty
- $.setSelectorEngine({ select: zest, is: zest.matches })
+ $.setSelectorEngine(zest)
$('#fixtures > ul')
.down(0).css('color', 'red')
.next('li', 1).css('color', 'green')
View
106 test/vendor/qwery-pseudos.js
@@ -0,0 +1,106 @@
+/*!
+ * @preserve Qwery - A Blazing Fast query selector engine
+ * https://github.com/ded/qwery
+ * copyright Dustin Diaz & Jacob Thornton 2012
+ * MIT License
+ */
+
+!function () {
+ var q, pseudos, i, l, p, r, nodes, m, nthPattern = /\s*((?:\+|\-)?(\d*))n\s*((?:\+|\-)\s*\d+)?\s*/
+ if (typeof module != 'undefined' && typeof 'require' != 'undefined')
+ q = require('qwery')
+ else if (typeof qwery != 'undefined')
+ q = qwery
+ else
+ return
+
+ pseudos = q.pseudos
+
+ function children(node, ofType) {
+ var r = []
+ nodes = node.childNodes
+
+ for (i = 0, l = nodes.length; i < l; i++) {
+ if (nodes[i].nodeType == 1 && (!ofType || nodes[i].nodeName == ofType)) r.push(nodes[i])
+ }
+ return r
+ }
+
+ function checkNthExpr(el, nodes, a, b) {
+ if (!a) return (nodes[b-1] == el)
+ for (i = b, l = nodes.length; ((a > 0) ? (i <= l) : (i >= 1)); i += a) if (el == nodes[i-1]) return true
+ return false
+ }
+
+ function checkNth(el, nodes, val) {
+ if (isFinite(val)) return nodes[val - 1] == el
+ else if (val == 'odd') return checkNthExpr(el, nodes, 2, 1)
+ else if (val == 'even') return checkNthExpr(el, nodes, 2, 0)
+ else if (m = nthPattern.exec(val))
+ return checkNthExpr(el, nodes,
+ (m[2] ? parseInt(m[1], 10) : parseInt(m[1] + '1', 10)), // Check case where coefficient is omitted
+ (m[3] ? parseInt(m[3].replace(/\s*/, ''), 10) : 0)) // Check case where constant is omitted
+
+ return false
+ }
+
+ function text(el, s) {
+ if (el.nodeType === 3 || el.nodeType === 4) return el.nodeValue;
+ if (el.nodeType !== 1 && el.nodeType !== 9) return '';
+ for (s = '', el = el.firstChild; el; el = el.nextSibling) {
+ if (el.nodeType !== 8) s += el.textContent || el.innerText || text(el)
+ }
+ return s
+ }
+
+ // *was* going to be in CSS3, didn't quite make it
+ pseudos.contains = function(el, val) { return text(el).indexOf(val) != -1 }
+
+ pseudos.not = function(el, val) { return !q.is(el, val) }
+
+ pseudos['nth-child'] = function (el, val) {
+ if (!val || !(p = el.parentNode)) return false
+ return checkNth(el, children(p), val)
+ }
+
+ pseudos['nth-last-child'] = function (el, val) {
+ if (!val || !(p = el.parentNode)) return false
+ return checkNth(el, children(p).reverse(), val)
+ }
+
+ pseudos['nth-of-type'] = function (el, val) {
+ if (!val || !(p = el.parentNode)) return false
+ return checkNth(el, children(p, el.nodeName), val)
+ }
+
+ pseudos['nth-last-of-type'] = function (el, val) {
+ if (!val || !(p = el.parentNode)) return false
+ return checkNth(el, children(p, el.nodeName).reverse(), val)
+ }
+
+ pseudos['first-child'] = function (el) { return pseudos['nth-child'](el, 1) }
+ pseudos['last-child'] = function (el) { return pseudos['nth-last-child'](el, 1) }
+ pseudos['first-of-type'] = function (el) { return pseudos['nth-of-type'](el, 1) }
+ pseudos['last-of-type'] = function (el) { return pseudos['nth-last-of-type'](el, 1) }
+
+ pseudos['only-child'] = function (el) {
+ return (p = el.parentNode) && (nodes = children(p)) && (nodes.length == 1) && (el == nodes[0])
+ };
+
+ pseudos['only-of-type'] = function (el) {
+ return (p = el.parentNode) && (nodes = children(p, el.nodeName)) && (nodes.length == 1) && (el == nodes[0])
+ }
+
+ pseudos.target = function (el) {
+ return (el.getAttribute('id') == location.hash.substr(1))
+ }
+
+ pseudos.checked = function (el) { return el.checked }
+
+ pseudos.enabled = function (el) { return !el.disabled }
+
+ pseudos.disabled = function (el) { return el.disabled }
+
+ pseudos.empty = function (el) { return !el.childNodes.length }
+
+}();
View
942 test/vendor/zest.js
@@ -0,0 +1,942 @@
+/**
+ * Zest (https://github.com/chjj/zest)
+ * A css selector engine.
+ * Copyright (c) 2011-2012, Christopher Jeffrey. (MIT Licensed)
+ */
+
+// TODO
+// - Recognize the TR subject selector when parsing.
+// - Pass context to scope.
+// - Add :column pseudo-classes.
+
+;(function() {
+
+/**
+ * Shared
+ */
+
+var window = this
+ , document = this.document
+ , old = this.zest;
+
+/**
+ * Helpers
+ */
+
+var compareDocumentPosition = (function() {
+ if (document.compareDocumentPosition) {
+ return function(a, b) {
+ return a.compareDocumentPosition(b);
+ };
+ }
+ return function(a, b) {
+ var el = a.ownerDocument.getElementsByTagName('*')
+ , i = el.length;
+
+ while (i--) {
+ if (el[i] === a) return 2;
+ if (el[i] === b) return 4;
+ }
+
+ return 1;
+ };
+})();
+
+var order = function(a, b) {
+ return compareDocumentPosition(a, b) & 2 ? 1 : -1;
+};
+
+var next = function(el) {
+ while ((el = el.nextSibling)
+ && el.nodeType !== 1);
+ return el;
+};
+
+var prev = function(el) {
+ while ((el = el.previousSibling)
+ && el.nodeType !== 1);
+ return el;
+};
+
+var child = function(el) {
+ if (el = el.firstChild) {
+ while (el.nodeType !== 1
+ && (el = el.nextSibling));
+ }
+ return el;
+};
+
+var lastChild = function(el) {
+ if (el = el.lastChild) {
+ while (el.nodeType !== 1
+ && (el = el.previousSibling));
+ }
+ return el;
+};
+
+var unquote = function(str) {
+ if (!str) return str;
+ var ch = str[0];
+ return ch === '"' || ch === '\''
+ ? str.slice(1, -1)
+ : str;
+};
+
+var indexOf = (function() {
+ if (Array.prototype.indexOf) {
+ return Array.prototype.indexOf;
+ }
+ return function(obj, item) {
+ var i = this.length;
+ while (i--) {
+ if (this[i] === item) return i;
+ }
+ return -1;
+ };
+})();
+
+var makeInside = function(start, end) {
+ var regex = rules.inside.source
+ .replace(/</g, start)
+ .replace(/>/g, end);
+
+ return new RegExp(regex);
+};
+
+var replace = function(regex, name, val) {
+ regex = regex.source;
+ regex = regex.replace(name, val.source || val);
+ return new RegExp(regex);
+};
+
+var truncateUrl = function(url, num) {
+ return url
+ .replace(/^(?:\w+:\/\/|\/+)/, '')
+ .replace(/(?:\/+|\/*#.*?)$/, '')
+ .split('/', num)
+ .join('/');
+};
+
+/**
+ * Handle `nth` Selectors
+ */
+
+var parseNth = function(param, test) {
+ var param = param.replace(/\s+/g, '')
+ , cap;
+
+ if (param === 'even') {
+ param = '2n+0';
+ } else if (param === 'odd') {
+ param = '2n+1';
+ } else if (!~param.indexOf('n')) {
+ param = '0n' + param;
+ }
+
+ cap = /^([+-])?(\d+)?n([+-])?(\d+)?$/.exec(param);
+
+ return {
+ group: cap[1] === '-'
+ ? -(cap[2] || 1)
+ : +(cap[2] || 1),
+ offset: cap[4]
+ ? (cap[3] === '-' ? -cap[4] : +cap[4])
+ : 0
+ };
+};
+
+var nth = function(param, test, last) {
+ var param = parseNth(param)
+ , group = param.group
+ , offset = param.offset
+ , find = !last ? child : lastChild
+ , advance = !last ? next : prev;
+
+ return function(el) {
+ if (el.parentNode.nodeType !== 1) return;
+
+ var rel = find(el.parentNode)
+ , pos = 0;
+
+ while (rel) {
+ if (test(rel, el)) pos++;
+ if (rel === el) {
+ pos -= offset;
+ return group && pos
+ ? !(pos % group) && (pos < 0 === group < 0)
+ : !pos;
+ }
+ rel = advance(rel);
+ }
+ };
+};
+
+/**
+ * Simple Selectors
+ */
+
+var selectors = {
+ '*': (function() {
+ if (function() {
+ var el = document.createElement('div');
+ el.appendChild(document.createComment(''));
+ return !!el.getElementsByTagName('*')[0];
+ }()) {
+ return function(el) {
+ if (el.nodeType === 1) return true;
+ };
+ }
+ return function() {
+ return true;
+ };
+ })(),
+ 'type': function(type) {
+ type = type.toLowerCase();
+ return function(el) {
+ return el.nodeName.toLowerCase() === type;
+ };
+ },
+ 'attr': function(key, op, val, i) {
+ op = operators[op];
+ return function(el) {
+ var attr;
+ switch (key) {
+ case 'for':
+ attr = el.htmlFor;
+ break;
+ case 'class':
+ attr = el.className;
+ break;
+ case 'href':
+ attr = el.getAttribute('href', 2);
+ break;
+ case 'title':
+ attr = el.getAttribute('title') || null;
+ break;
+ case 'id':
+ if (el.getAttribute) {
+ attr = el.getAttribute('id');
+ break;
+ }
+ default:
+ attr = el[key] != null
+ ? el[key]
+ : el.getAttribute && el.getAttribute(key);
+ break;
+ }
+ if (attr == null) return;
+ attr = attr + '';
+ if (i) {
+ attr = attr.toLowerCase();
+ val = val.toLowerCase();
+ }
+ return op(attr, val);
+ };
+ },
+ ':first-child': function(el) {
+ return !prev(el) && el.parentNode.nodeType === 1;
+ },
+ ':last-child': function(el) {
+ return !next(el) && el.parentNode.nodeType === 1;
+ },
+ ':only-child': function(el) {
+ return !prev(el) && !next(el)
+ && el.parentNode.nodeType === 1;
+ },
+ ':nth-child': function(param, last) {
+ return nth(param, function() {
+ return true;
+ }, last);
+ },
+ ':nth-last-child': function(param) {
+ return selectors[':nth-child'](param, true);
+ },
+ ':root': function(el) {
+ return el.ownerDocument.documentElement === el;
+ },
+ ':empty': function(el) {
+ return !el.firstChild;
+ },
+ ':not': function(sel) {
+ var test = compileGroup(sel);
+ return function(el) {
+ return !test(el);
+ };
+ },
+ ':first-of-type': function(el) {
+ if (el.parentNode.nodeType !== 1) return;
+ var type = el.nodeName;
+ while (el = prev(el)) {
+ if (el.nodeName === type) return;
+ }
+ return true;
+ },
+ ':last-of-type': function(el) {
+ if (el.parentNode.nodeType !== 1) return;
+ var type = el.nodeName;
+ while (el = next(el)) {
+ if (el.nodeName === type) return;
+ }
+ return true;
+ },
+ ':only-of-type': function(el) {
+ return selectors[':first-of-type'](el)
+ && selectors[':last-of-type'](el);
+ },
+ ':nth-of-type': function(param, last) {
+ return nth(param, function(rel, el) {
+ return rel.nodeName === el.nodeName;
+ }, last);
+ },
+ ':nth-last-of-type': function(param) {
+ return selectors[':nth-of-type'](param, true);
+ },
+ ':checked': function(el) {
+ return !!(el.checked || el.selected);
+ },
+ ':indeterminate': function(el) {
+ return !selectors[':checked'](el);
+ },
+ ':enabled': function(el) {
+ return !el.disabled && el.type !== 'hidden';
+ },
+ ':disabled': function(el) {
+ return !!el.disabled;
+ },
+ ':target': function(el) {
+ return el.id === window.location.hash.substring(1);
+ },
+ ':focus': function(el) {
+ return el === el.ownerDocument.activeElement;
+ },
+ ':matches': function(sel) {
+ return compileGroup(sel);
+ },
+ ':nth-match': function(param, last) {
+ var args = param.split(/\s*,\s*/)
+ , arg = args.shift()
+ , test = compileGroup(args.join(','));
+
+ return nth(arg, test, last);
+ },
+ ':nth-last-match': function(param) {
+ return selectors[':nth-match'](param, true);
+ },
+ ':links-here': function(el) {
+ return el + '' === window.location + '';
+ },
+ ':lang': function(param) {
+ return function(el) {
+ while (el) {
+ if (el.lang) return el.lang.indexOf(param) === 0;
+ el = el.parentNode;
+ }
+ };
+ },
+ ':dir': function(param) {
+ return function(el) {
+ while (el) {
+ if (el.dir) return el.dir === param;
+ el = el.parentNode;
+ }
+ };
+ },
+ ':scope': function(el, con) {
+ var context = con || el.ownerDocument;
+ if (context.nodeType === 9) {
+ return el === context.documentElement;
+ }
+ return el === context;
+ },
+ ':any-link': function(el) {
+ return typeof el.href === 'string';
+ },
+ ':local-link': function(el) {
+ if (el.nodeName) {
+ return el.href && el.host === window.location.host;
+ }
+ var param = +el + 1;
+ return function(el) {
+ if (!el.href) return;
+
+ var url = window.location + ''
+ , href = el + '';
+
+ return truncateUrl(url, param) === truncateUrl(href, param);
+ };
+ },
+ ':default': function(el) {
+ return !!el.defaultSelected;
+ },
+ ':valid': function(el) {
+ return el.willValidate || (el.validity && el.validity.valid);
+ },
+ ':invalid': function(el) {
+ return !selectors[':valid'](el);
+ },
+ ':in-range': function(el) {
+ return el.value > el.min && el.value <= el.max;
+ },
+ ':out-of-range': function(el) {
+ return !selectors[':in-range'](el);
+ },
+ ':required': function(el) {
+ return !!el.required;
+ },
+ ':optional': function(el) {
+ return !el.required;
+ },
+ ':read-only': function(el) {
+ if (el.readOnly) return true;
+
+ var attr = el.getAttribute('contenteditable')
+ , prop = el.contentEditable
+ , name = el.nodeName.toLowerCase();
+
+ name = name !== 'input' && name !== 'textarea';
+
+ return (name || el.disabled) && attr == null && prop !== 'true';
+ },
+ ':read-write': function(el) {
+ return !selectors[':read-only'](el);
+ },
+ ':hover': function() {
+ throw new Error(':hover is not supported.');
+ },
+ ':active': function() {
+ throw new Error(':active is not supported.');
+ },
+ ':link': function() {
+ throw new Error(':link is not supported.');
+ },
+ ':visited': function() {
+ throw new Error(':visited is not supported.');
+ },
+ ':column': function() {
+ throw new Error(':column is not supported.');
+ },
+ ':nth-column': function() {
+ throw new Error(':nth-column is not supported.');
+ },
+ ':nth-last-column': function() {
+ throw new Error(':nth-last-column is not supported.');
+ },
+ ':current': function() {
+ throw new Error(':current is not supported.');
+ },
+ ':past': function() {
+ throw new Error(':past is not supported.');
+ },
+ ':future': function() {
+ throw new Error(':future is not supported.');
+ },
+ // Non-standard, for compatibility purposes.
+ ':contains': function(param) {
+ return function(el) {
+ var text = el.innerText || el.textContent || el.value || '';
+ return !!~text.indexOf(param);
+ };
+ },
+ ':has': function(param) {
+ return function(el) {
+ return zest(param, el).length > 0;
+ };
+ }
+ // Potentially add more pseudo selectors for
+ // compatibility with sizzle and most other
+ // selector engines (?).
+};
+
+/**
+ * Attribute Operators
+ */
+
+var operators = {
+ '-': function() {
+ return true;
+ },
+ '=': function(attr, val) {
+ return attr === val;
+ },
+ '*=': function(attr, val) {
+ return attr.indexOf(val) !== -1;
+ },
+ '~=': function(attr, val) {
+ var i = attr.indexOf(val)
+ , f
+ , l;
+
+ if (i === -1) return;
+ f = attr[i - 1];
+ l = attr[i + val.length];
+
+ return (!f || f === ' ') && (!l || l === ' ');
+ },
+ '|=': function(attr, val) {
+ var i = attr.indexOf(val)
+ , l;
+
+ if (i !== 0) return;
+ l = attr[i + val.length];
+
+ return l === '-' || !l;
+ },
+ '^=': function(attr, val) {
+ return attr.indexOf(val) === 0;
+ },
+ '$=': function(attr, val) {
+ return attr.indexOf(val) + val.length === attr.length;
+ },
+ // non-standard
+ '!=': function(attr, val) {
+ return attr !== val;
+ }
+};
+
+/**
+ * Combinator Logic
+ */
+
+var combinators = {
+ ' ': function(test) {
+ return function(el) {
+ while (el = el.parentNode) {
+ if (test(el)) return el;
+ }
+ };
+ },
+ '>': function(test) {
+ return function(el) {
+ return test(el = el.parentNode) && el;
+ };
+ },
+ '+': function(test) {
+ return function(el) {
+ return test(el = prev(el)) && el;
+ };
+ },
+ '~': function(test) {
+ return function(el) {
+ while (el = prev(el)) {
+ if (test(el)) return el;
+ }
+ };
+ },
+ 'noop': function(test) {
+ return function(el) {
+ return test(el) && el;
+ };
+ },
+ 'ref': function(test, name) {
+ var node;
+
+ function ref(el) {
+ var doc = el.ownerDocument
+ , nodes = doc.getElementsByTagName('*')
+ , i = nodes.length;
+
+ while (i--) {
+ node = nodes[i];
+ if (ref.test(el)) {
+ node = null;
+ return true;
+ }
+ }
+
+ node = null;
+ }
+
+ ref.combinator = function(el) {
+ if (!node || !node.getAttribute) return;
+
+ var attr = node.getAttribute(name) || '';
+ if (attr[0] === '#') attr = attr.substring(1);
+
+ if (attr === el.id && test(node)) {
+ return node;
+ }
+ };
+
+ return ref;
+ }
+};
+
+/**
+ * Grammar
+ */
+
+var rules = {
+ qname: /^ *([\w\-]+|\*)/,
+ simple: /^(?:([.#][\w\-]+)|pseudo|attr)/,
+ ref: /^ *\/([\w\-]+)\/ */,
+ combinator: /^(?: +([^ \w*]) +|( )+|([^ \w*]))(?! *$)/,
+ attr: /^\[([\w\-]+)(?:([^\w]?=)(inside))?\]/,
+ pseudo: /^(:[\w\-]+)(?:\((inside)\))?/,
+ inside: /(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|<[^"'>]*>|\\["'>]|[^"'>])*/
+};
+
+rules.inside = replace(rules.inside, '[^"\'>]*', rules.inside);
+rules.attr = replace(rules.attr, 'inside', makeInside('\\[', '\\]'));
+rules.pseudo = replace(rules.pseudo, 'inside', makeInside('\\(', '\\)'));
+rules.simple = replace(rules.simple, 'pseudo', rules.pseudo);
+rules.simple = replace(rules.simple, 'attr', rules.attr);
+
+/**
+ * Compiling
+ */
+
+var compile = function(sel) {
+ var sel = sel.replace(/^\s+|\s+$/g, '')
+ , test
+ , filter = []
+ , buff = []
+ , subject
+ , qname
+ , cap
+ , op
+ , ref;
+
+ while (sel) {
+ if (cap = rules.qname.exec(sel)) {
+ sel = sel.substring(cap[0].length);
+ qname = cap[1];
+ buff.push(tok(qname, true));
+ } else if (cap = rules.simple.exec(sel)) {
+ sel = sel.substring(cap[0].length);
+ qname = '*';
+ buff.push(tok(qname, true));
+ buff.push(tok(cap));
+ } else {
+ throw new Error('Invalid selector.');
+ }
+
+ while (cap = rules.simple.exec(sel)) {
+ sel = sel.substring(cap[0].length);
+ buff.push(tok(cap));
+ }
+
+ if (sel[0] === '!') {
+ sel = sel.substring(1);
+ subject = makeSubject();
+ subject.qname = qname;
+ buff.push(subject.simple);
+ }
+
+ if (cap = rules.ref.exec(sel)) {
+ sel = sel.substring(cap[0].length);
+ ref = combinators.ref(makeSimple(buff), cap[1]);
+ filter.push(ref.combinator);
+ buff = [];
+ continue;
+ }
+
+ if (cap = rules.combinator.exec(sel)) {
+ sel = sel.substring(cap[0].length);
+ op = cap[1] || cap[2] || cap[3];
+ if (op === ',') {
+ filter.push(combinators.noop(makeSimple(buff)));
+ break;
+ }
+ } else {
+ op = 'noop';
+ }
+
+ filter.push(combinators[op](makeSimple(buff)));
+ buff = [];
+ }
+
+ test = makeTest(filter);
+ test.qname = qname;
+ test.sel = sel;
+
+ if (subject) {
+ subject.lname = test.qname;
+
+ subject.test = test;
+ subject.qname = subject.qname;
+ subject.sel = test.sel;
+ test = subject;
+ }
+
+ if (ref) {
+ ref.test = test;
+ ref.qname = test.qname;
+ ref.sel = test.sel;
+ test = ref;
+ }
+
+ return test;
+};
+
+var tok = function(cap, qname) {
+ // qname
+ if (qname) {
+ return cap === '*'
+ ? selectors['*']
+ : selectors.type(cap);
+ }
+
+ // class/id
+ if (cap[1]) {
+ return cap[1][0] === '.'
+ ? selectors.attr('class', '~=', cap[1].substring(1))
+ : selectors.attr('id', '=', cap[1].substring(1));
+ }
+
+ // pseudo-name
+ // inside-pseudo
+ if (cap[2]) {
+ return cap[3]
+ ? selectors[cap[2]](unquote(cap[3]))
+ : selectors[cap[2]];
+ }
+
+ // attr name
+ // attr op
+ // attr value
+ if (cap[4]) {
+ var i;
+ if (cap[6]) {
+ i = cap[6].length;
+ cap[6] = cap[6].replace(/ +i$/, '');
+ i = i > cap[6].length;
+ }
+ return selectors.attr(cap[4], cap[5] || '-', unquote(cap[6]), i);
+ }
+
+ throw new Error('Unknown Selector.');
+};
+
+var makeSimple = function(func) {
+ var l = func.length
+ , i;
+
+ // Potentially make sure
+ // `el` is truthy.
+ if (l < 2) return func[0];
+
+ return function(el) {
+ if (!el) return;
+ for (i = 0; i < l; i++) {
+ if (!func[i](el)) return;
+ }
+ return true;
+ };
+};
+
+var makeTest = function(func) {
+ if (func.length < 2) {
+ return function(el) {
+ return !!func[0](el);
+ };
+ }
+ return function(el) {
+ var i = func.length;
+ while (i--) {
+ if (!(el = func[i](el))) return;
+ }
+ return true;
+ };
+};
+
+var makeSubject = function() {
+ var target;
+
+ function subject(el) {
+ var node = el.ownerDocument
+ , scope = node.getElementsByTagName(subject.lname)
+ , i = scope.length;
+
+ while (i--) {
+ if (subject.test(scope[i]) && target === el) {
+ target = null;
+ return true;
+ }
+ }
+
+ target = null;
+ }
+
+ subject.simple = function(el) {
+ target = el;
+ return true;
+ };
+
+ return subject;
+};
+
+var compileGroup = function(sel) {
+ var test = compile(sel)
+ , tests = [ test ];
+
+ while (test.sel) {
+ test = compile(test.sel);
+ tests.push(test);
+ }
+
+ if (tests.length < 2) return test;
+
+ return function(el) {
+ var l = tests.length
+ , i = 0;
+
+ for (; i < l; i++) {
+ if (tests[i](el)) return true;
+ }
+ };
+};
+
+/**
+ * Selection
+ */
+
+var find = function(sel, node) {
+ var results = []
+ , test = compile(sel)
+ , scope = node.getElementsByTagName(test.qname)
+ , i = 0
+ , el;
+
+ while (el = scope[i++]) {
+ if (test(el)) results.push(el);
+ }
+
+ if (test.sel) {
+ while (test.sel) {
+ test = compile(test.sel);
+ scope = node.getElementsByTagName(test.qname);
+ i = 0;
+ while (el = scope[i++]) {
+ if (test(el) && !~indexOf.call(results, el)) {
+ results.push(el);
+ }
+ }
+ }
+ results.sort(order);
+ }
+
+ return results;
+};
+
+/**
+ * Native
+ */
+
+var select = (function() {
+ var slice = (function() {
+ try {
+ Array.prototype.slice.call(document.getElementsByTagName('*'));
+ return Array.prototype.slice;
+ } catch(e) {
+ e = null;
+ return function() {
+ var a = [], i = 0, l = this.length;
+ for (; i < l; i++) a.push(this[i]);
+ return a;
+ };
+ }
+ })();
+
+ if (document.querySelectorAll) {
+ return function(sel, node) {
+ try {
+ return slice.call(node.querySelectorAll(sel));
+ } catch(e) {
+ return find(sel, node);
+ }
+ };
+ }
+
+ return function(sel, node) {
+ try {
+ if (sel[0] === '#' && /^#[\w\-]+$/.test(sel)) {
+ return [node.getElementById(sel.substring(1))];
+ }
+ if (sel[0] === '.' && /^\.[\w\-]+$/.test(sel)) {
+ sel = node.getElementsByClassName(sel.substring(1));
+ return slice.call(sel);
+ }
+ if (/^[\w\-]+$/.test(sel)) {
+ return slice.call(node.getElementsByTagName(sel));
+ }
+ } catch(e) {
+ ;
+ }
+ return find(sel, node);
+ };
+})();
+
+/**
+ * Zest
+ */
+
+var zest = function(sel, node) {
+ try {
+ sel = select(sel, node || document);
+ } catch(e) {
+ if (window.ZEST_DEBUG) {
+ console.log(e.stack || e + '');
+ }
+ sel = [];
+ }
+ return sel;
+};
+
+/**
+ * Expose
+ */
+
+zest.selectors = selectors;
+zest.operators = operators;
+zest.combinators = combinators;
+zest.compile = compileGroup;
+
+zest.matches = function(el, sel) {
+ return !!compileGroup(sel)(el);
+};
+
+zest.cache = function() {
+ if (compile.raw) return;
+
+ var raw = compile
+ , cache = {};
+
+ compile = function(sel) {
+ return cache[sel]
+ || (cache[sel] = raw(sel));
+ };
+
+ compile.raw = raw;
+ zest._cache = cache;
+};
+
+zest.noCache = function() {
+ if (!compile.raw) return;
+ compile = compile.raw;
+ delete zest._cache;
+};
+
+zest.noConflict = function() {
+ window.zest = old;
+ return zest;
+};
+
+zest.noNative = function() {
+ select = find;
+};
+
+if (typeof module !== 'undefined') {
+ module.exports = zest;
+} else {
+ this.zest = zest;
+}
+
+if (window.ZEST_DEBUG) {
+ zest.noNative();
+} else {
+ zest.cache();
+}
+
+}).call(function() {
+ return this || (typeof window !== 'undefined' ? window : global);
+}());
View
38 traversty.js
@@ -360,22 +360,38 @@
e.innerHTML = '<a/><i/><b/>'
a = e.firstChild
try {
+ // YO! I HEARD YOU LIKED NESTED TERNARY OPERATORS SO I COOKED SOME UP FOR YOU!
+ // (one day I might loop this...)
+
// check to see how we do a matchesSelector
- _selectorMatches =
- isFunction(s.matching) ? function (selector, el) { return s.matching([el], selector).length > 0 } :
- isFunction(s.is) ? function (selector, el) { return s.is(el, selector) } :
- isFunction(s.matchesSelector) ? function (selector, el) { return s.matchesSelector(el, selector) } :
- isFunction(s.match) ? function (selector, el) { return s.match(el, selector) } : null
+ _selectorMatches = isFunction(s.matching)
+ ? function (selector, el) { return s.matching([el], selector).length > 0 }
+ : isFunction(s.is)
+ ? function (selector, el) { return s.is(el, selector) }
+ : isFunction(s.matchesSelector)
+ ? function (selector, el) { return s.matchesSelector(el, selector) }
+ : isFunction(s.match)
+ ? function (selector, el) { return s.match(el, selector) }
+ : isFunction(s.matches)
+ ? function (selector, el) { return s.matches(el, selector) }
+ : null
if (!_selectorMatches) {
// perhaps it's an selector(x).is(y) type selector?
ss = s('a', e)
- _selectorMatches =
- isFunction(ss._is) ? function (selector, el) { return s(el)._is(selector) } : // original .is(), replaced by Enderbridge
- isFunction(ss.matching) ? function (selector, el) { return s(el).matching(selector).length > 0 } :
- isFunction(ss.is) && !ss.is.__ignore ? function (selector, el) { return s(el).is(selector) } :
- isFunction(ss.matchesSelector) ? function (selector, el) { return s(el).matchesSelector(selector) } :
- isFunction(ss.match) ? function (selector, el) { return s(el).match(selector) } : null
+ _selectorMatches = isFunction(ss._is)
+ ? function (selector, el) { return s(el)._is(selector) } // original .is(), replaced by Enderbridge
+ : isFunction(ss.matching)
+ ? function (selector, el) { return s(el).matching(selector).length > 0 }
+ : isFunction(ss.is) && !ss.is.__ignore
+ ? function (selector, el) { return s(el).is(selector) }
+ : isFunction(ss.matchesSelector)
+ ? function (selector, el) { return s(el).matchesSelector(selector) }
+ : isFunction(ss.match)
+ ? function (selector, el) { return s(el).match(selector) }
+ : isFunction(ss.matches)
+ ? function (selector, el) { return s(el).matches(selector) }
+ : null
}
if (!_selectorMatches)
View
2 traversty.min.js
@@ -3,4 +3,4 @@
* (c) Rod Vagg (@rvagg) 2012
* https://github.com/rvagg/traversty
* License: MIT
- */!function(e,t){typeof module!="undefined"?module.exports=t():typeof define=="function"&&define.amd?define(e,t):this[e]=t()}("traversty",function(){var e=this,t=e.traversty,n=window.document,r=n.documentElement,i=Object.prototype.toString,s=Array.prototype,o=s.slice,u=function(e,t,n,r,i){while(r<t.length)if(e[i=t[r++]+n])return i}(r,["msM","webkitM","mozM","oM","m"],"atchesSelector",0),a=function(){return!1},f=function(e){return i.call(e)==="[object Number]"},l=function(e){return i.call(e)==="[object String]"},c=function(e){return i.call(e)==="[object Function]"},h=function(e){return e===void 0},p=function(e){return e&&e.nodeType===1},d=function(e,t){return h(e)&&!f(t)?0:f(e)?e:f(t)?t:null},v=function(e){return l(e)?e:"*"},m=function(e,t){return o.call(t.querySelectorAll(e),0)},g=function(e,t){return e==="*"||t[u](e)},y=m,b=g,w=function(e,t){return function(n,r){if(/,/.test(n)){var i=[],s=-1,o=r.getElementsByTagName("*");while(++s<o.length)p(o[s])&&t(n,o[s])&&i.push(o[s]);return i}return e(n,r)}},E="compareDocumentPosition"in r?function(e,t){return(t.compareDocumentPosition(e)&16)==16}:"contains"in r?function(e,t){return t=t.nodeType===9||t==window?r:t,t!==e&&t.contains(e)}:function(e,t){while(e=e.parentNode)if(e===t)return 1;return 0},S=function(e){var t=[],n=-1,r,i;while(++n<e.length){r=-1,i=!1;while(++r<t.length)if(t[r]===e[n]){i=!0;break}i||t.push(e[n])}return t},x=function(e,t){var n=[],r,i=0,s,o=e.length,u;while(i<o){s=0,u=(r=t(e[i],i++)).length;while(s<u)n.push(r[s++])}return n},T=function(e,t,n,r,i){return r=d(n,r),n=v(n),x(e,function(e,s){var o=r||0,u=[];i||(e=e[t]);while(e&&(r===null||o>=0))p(e)&&(!i||i===!0||i(e,s))&&b(n,e)&&(r===null||o--===0)&&(r===null&&t!=="nextSibling"?u=[e].concat(u):u.push(e)),e=e[t];return u})},N=function(e,t,n){return t<0&&(t=e+t),t<0||t>=e?null:!t&&t!==0?n:t},C=function(e,t){var n=[],r=0,i=e.length;for(;r<i;r++)t(e[r],r)&&n.push(e[r]);return n},k=function(e){var t;return p(e)?function(t){return t===e}:(t=typeof e)=="function"?function(t,n){return e.call(t,n)}:t=="string"&&e.length?function(t){return b(e,t)}:a},L=function(e){return function(){return!e.apply(this,arguments)}},A=function(){function r(e){this.length=0;if(e){e=S(!e.nodeType&&!h(e.length)?e:[e]);var t=this.length=e.length;while(t--)this[t]=e[t]}}function i(e){return new r(l(e)?y(e,n):e)}return r.prototype={down:function(e,t){return t=d(e,t),e=v(e),A(x(this,function(n){var r=y(e,n);return t===null?r:[r[t]]||[]}))},up:function(e,t){return A(T(this,"parentNode",e,t))},parents:function(){return r.prototype.up.apply(this,arguments.length?arguments:["*"])},closest:function(e,t){if(f(e))t=e,e="*";else{if(!l(e))return A([]);f(t)||(t=0)}return A(T(this,"parentNode",e,t,!0))},previous:function(e,t){return A(T(this,"previousSibling",e,t))},next:function(e,t){return A(T(this,"nextSibling",e,t))},siblings:function(e,t){var n=this,r=o.call(this,0),i=0,s=r.length;for(;i<s;i++){r[i]=r[i].parentNode.firstChild;while(!p(r[i]))r[i]=r[i].nextSibling}return h(e)&&(e="*"),A(T(r,"nextSibling",e||"*",t,function(e,t){return e!==n[t]}))},children:function(e,t){return A(T(r.prototype.down.call(this),"nextSibling",e||"*",t,!0))},first:function(){return r.prototype.eq.call(this,0)},last:function(){return r.prototype.eq.call(this,-1)},eq:function(e){return A(this.get(e))},get:function(e){return this[N(this.length,e,0)]},slice:function(e,t){var n=t,r=this.length,i=[];e=N(r,Math.max(-this.length,e),0),n=N(t<0?r:r+1,t,r),t=n===null||n>r?t<0?0:r:n;while(e!==null&&e<t)i.push(this[e++]);return A(i)},filter:function(e){return A(C(this,k(e)))},not:function(e){return A(C(this,L(k(e))))},has:function(e){return A(C(this,p(e)?function(t){return E(e,t)}:typeof e=="string"&&e.length?function(t){return y(e,t).length}:a))},is:function(e){var t=0,n=this.length,r=k(e);for(;t<n;t++)if(r(this[t],t))return!0;return!1},toArray:function(){return s.slice.call(this)},size:function(){return this.length},each:function(e,t){var n=0,r=this.length;for(;n<r;n++)e.call(t||this[n],this[n],n,this);return this},push:s.push,sort:s.sort,splice:s.splice},r.prototype.prev=r.prototype.previous,i.aug=function(e){var t,n;for(t in e)n=e[t],typeof n=="function"&&(r.prototype[t]=n)},i.setSelectorEngine=function(e){var t,r,i,s,o,u=n.createElement("p"),a=e.select||e.sel||e;u.innerHTML="<a/><i/><b/>",i=u.firstChild;try{s=c(e.matching)?function(t,n){return e.matching([n],t).length>0}:c(e.is)?function(t,n){return e.is(n,t)}:c(e.matchesSelector)?function(t,n){return e.matchesSelector(n,t)}:c(e.match)?function(t,n){return e.match(n,t)}:null,s||(t=e("a",u),s=c(t._is)?function(t,n){return e(n)._is(t)}:c(t.matching)?function(t,n){return e(n).matching(t).length>0}:c(t.is)&&!t.is.__ignore?function(t,n){return e(n).is(t)}:c(t.matchesSelector)?function(t,n){return e(n).matchesSelector(t)}:c(t.match)?function(t,n){return e(n).match(t)}:null);if(!s)throw"Traversty: couldn't find selector engine's `matchesSelector`";if(s("x,y",u)||!s("a,p",u))throw"Traversty: couldn't make selector engine's `matchesSelector` work";if((r=a("b,a",u)).length!==2)throw"Traversty: don't know how to use this selector engine";o=r[0]===i?a:w(a,s);if((r=o("b,a",u)).length!==2||r[0]!==i)throw"Traversty: couldn't make selector engine work";b=s,y=o}catch(f){throw l(f)?f:"Traversty: error while figuring out how the selector engine works: "+(f.message||f)}finally{u=null}},i.noConflict=function(){return e.traversty=t,this},i}();return A});