Permalink
Browse files

return boolean from $().is() via ender bridge

  • Loading branch information...
1 parent 7f94ea9 commit d75a4be9ef2be8b60a1f2e6c166da772d3e3daa2 @rvagg committed Oct 27, 2012
View
@@ -13,14 +13,24 @@
} catch (ex) { } // ignore exception, we may have an ender build with no selector engine
integrated = true
}
- fn = function (self, selector, index) { return $(t(self)[meth](selector, index)) }
+ fn = meth == 'is'
+ ? function (self, slfn) {
+ return t(self)[meth](slfn) // boolean
+ }
+ : function (self, selector, index) {
+ return $(t(self)[meth](selector, index)) // collection
+ }
return fn(self, selector, index)
}
return function (selector, index) { return fn(this, selector, index) }
}
, methods = 'up down next previous prev parents closest siblings children first last eq slice filter not is has'.split(' ')
, b = {}, i = methods.length
+ // does this build have an .is()? if so, shift it to _is() for traversty to use and
+ // allow us to integrate a new is(), wrapped around it
+ if ($.fn.is) $.fn._is = $.fn.is
while (--i >= 0) b[methods[i]] = integrate(methods[i])
$.ender(b, true)
+ $.fn.is.__ignore = true
}(ender))
@@ -46,8 +46,8 @@ var own = Object.prototype.hasOwnProperty
// we also don't want to run native tests in older browsers that don't support it
if (__matchesSelector) engineTest(null, 'Native')
engineTest(Q, 'Qwery')
-engineTest(Sizzle, 'Sizzle')
-engineTest(NW.Dom, 'NW')
+//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
@@ -750,23 +750,23 @@ this.filterTests = {
, 'is()': {
'is() on empty collection': function () {
- refute(T([]).is())
+ assert(T([]).is() === false)
}
, 'is() on multi collection': function () {
- refute(T(Q('#fixtures > ul > li')).is())
+ assert(T(Q('#fixtures > ul > li')).is() === false)
}
, 'is(fn=false) on multi collection': function () {
- refute(T(Q('#fixtures > ul > li')).is(function () { return false }))
+ assert(T(Q('#fixtures > ul > li')).is(function () { return false }) === false)
}
, 'is(fn=true) on multi collection': function () {
- assert(T(Q('#fixtures > ul > li')).is(function () { return true }))
+ assert(T(Q('#fixtures > ul > li')).is(function () { return true }) === true)
}
, 'is(fn=true) on empty collection': function () {
- refute(T([]).is(function () { return true }))
+ assert(T([]).is(function () { return true }) === false)
}
, 'is(fn) `this` and arguments check': function () {
@@ -784,21 +784,21 @@ this.filterTests = {
}
, 'is(nonmatch selector) on multi collection': function () {
- refute(T(Q('#fixtures > ul > li')).is('ul'))
+ assert(T(Q('#fixtures > ul > li')).is('ul') === false)
}
, 'is(selector) on multi collection': function () {
- assert(T(Q('#fixtures > ul > li')).is('li'))
+ assert(T(Q('#fixtures > ul > li')).is('li') === true)
}
, 'is(nonmatch element) on multi collection': function () {
- refute(T(Q('#fixtures > ul > li')).is(Q('#fixtures')[0]))
+ assert(T(Q('#fixtures > ul > li')).is(Q('#fixtures')[0]) === false)
}
, 'is(element) on multi collection': function () {
- assert(T(Q('#fixtures > ul > li')).is(Q('#fixtures > ul > li')[0]))
- assert(T(Q('#fixtures > ul > li')).is(Q('#fixtures > ul > li')[2]))
- assert(T(Q('#fixtures > ul > li')).is(Q('#fixtures > ul > li')[6]))
+ assert(T(Q('#fixtures > ul > li')).is(Q('#fixtures > ul > li')[0]) === true)
+ assert(T(Q('#fixtures > ul > li')).is(Q('#fixtures > ul > li')[2]) === true)
+ assert(T(Q('#fixtures > ul > li')).is(Q('#fixtures > ul > li')[6]) === true)
}
}
}
@@ -20,7 +20,7 @@
.up('ul').eq(-1).css('borderLeft', 'solid 5px orange')
.closest('#fixtures').down('li').slice(-10,-9).css('fontSize', '25px')
- if ($('li').is('.c')) $.create('<div>INTEGRATION TEST ALL DONE!</div>').prependTo('#fixtures')
+ if ($('li').is('.c') === true) $.create('<div>INTEGRATION TEST ALL DONE!</div>').prependTo('#fixtures')
})
</script>
</head>
@@ -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.3 traversty@0.0.7
+ * Packages: ender-js@0.4.4 domready@0.2.11 bonzo@1.2.4 traversty@0.0.7
* =============================================================
*/
@@ -1026,7 +1026,8 @@
, dim: function () {
if (!this.length) return { height: 0, width: 0 }
var el = this[0]
- , orig = !el.offsetWidth && !el.offsetHeight ?
+ , de = el.nodeType == 9 && el.documentElement // document
+ , orig = !de && !!el.style && !el.offsetWidth && !el.offsetHeight ?
// el isn't visible, can't be measured properly, so fix that
function (t) {
var s = {
@@ -1041,8 +1042,12 @@
})
return s
}(this) : null
- , width = el.offsetWidth
- , height = el.offsetHeight
+ , width = de
+ ? Math.max(el.body.scrollWidth, el.body.offsetWidth, de.scrollWidth, de.offsetWidth, de.clientWidth)
+ : el.offsetWidth
+ , height = de
+ ? Math.max(el.body.scrollHeight, el.body.offsetHeight, de.scrollWidth, de.offsetWidth, de.clientHeight)
+ : el.offsetHeight
orig && this.first().css(orig)
return {
@@ -1780,6 +1785,7 @@
))
}
}
+ T.prototype.prev = T.prototype.previous
function t(els) {
return new T(isString(els) ? selectorFind(els, doc) : els)
@@ -1805,10 +1811,11 @@
// perhaps it's an selector(x).is(y) type selector?
ss = s('a', e)
_selectorMatches =
- isFunction(ss.matching) ? function (selector, el) { return s(el).matching(selector).length > 0 } :
- isFunction(ss.is) ? 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
+ 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
}
if (!_selectorMatches)
@@ -1864,15 +1871,25 @@
} catch (ex) { } // ignore exception, we may have an ender build with no selector engine
integrated = true
}
- fn = function (self, selector, index) { return $(t(self)[meth](selector, index)) }
+ fn = meth == 'is'
+ ? function (self, slfn) {
+ return t(self)[meth](slfn) // boolean
+ }
+ : function (self, selector, index) {
+ return $(t(self)[meth](selector, index)) // collection
+ }
return fn(self, selector, index)
}
return function (selector, index) { return fn(this, selector, index) }
}
- , methods = 'up down next previous parents closest siblings children first last eq slice filter not is has'.split(' ')
+ , methods = 'up down next previous prev parents closest siblings children first last eq slice filter not is has'.split(' ')
, b = {}, i = methods.length
+ // does this build have an .is()? if so, shift it to _is() for traversty to use and
+ // allow us to integrate a new is(), wrapped around it
+ if ($.fn.is) $.fn._is = $.fn.is
while (--i >= 0) b[methods[i]] = integrate(methods[i])
$.ender(b, true)
+ $.fn.is.__ignore = true
}(ender))
}());
@@ -20,7 +20,7 @@
.up('ul').eq(-1).css('borderLeft', 'solid 5px orange')
.closest('#fixtures').down('li').slice(-10,-9).css('fontSize', '25px')
- if ($('li').is('.c')) $('<div>INTEGRATION TEST ALL DONE!</div>').prependTo('#fixtures')
+ if ($('li').is('.c') === true) $('<div>INTEGRATION TEST ALL DONE!</div>').prependTo('#fixtures')
})
</script>
</head>
@@ -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.3 traversty@0.0.7
+ * Packages: ender-js@0.4.4 domready@0.2.11 nwmatcher@1.2.5 bonzo@1.2.4 traversty@0.0.7
* =============================================================
*/
@@ -1141,7 +1141,8 @@
, dim: function () {
if (!this.length) return { height: 0, width: 0 }
var el = this[0]
- , orig = !el.offsetWidth && !el.offsetHeight ?
+ , de = el.nodeType == 9 && el.documentElement // document
+ , orig = !de && !!el.style && !el.offsetWidth && !el.offsetHeight ?
// el isn't visible, can't be measured properly, so fix that
function (t) {
var s = {
@@ -1156,8 +1157,12 @@
})
return s
}(this) : null
- , width = el.offsetWidth
- , height = el.offsetHeight
+ , width = de
+ ? Math.max(el.body.scrollWidth, el.body.offsetWidth, de.scrollWidth, de.offsetWidth, de.clientWidth)
+ : el.offsetWidth
+ , height = de
+ ? Math.max(el.body.scrollHeight, el.body.offsetHeight, de.scrollWidth, de.offsetWidth, de.clientHeight)
+ : el.offsetHeight
orig && this.first().css(orig)
return {
@@ -1895,6 +1900,7 @@
))
}
}
+ T.prototype.prev = T.prototype.previous
function t(els) {
return new T(isString(els) ? selectorFind(els, doc) : els)
@@ -1920,10 +1926,11 @@
// perhaps it's an selector(x).is(y) type selector?
ss = s('a', e)
_selectorMatches =
- isFunction(ss.matching) ? function (selector, el) { return s(el).matching(selector).length > 0 } :
- isFunction(ss.is) ? 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
+ 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
}
if (!_selectorMatches)
@@ -1979,15 +1986,25 @@
} catch (ex) { } // ignore exception, we may have an ender build with no selector engine
integrated = true
}
- fn = function (self, selector, index) { return $(t(self)[meth](selector, index)) }
+ fn = meth == 'is'
+ ? function (self, slfn) {
+ return t(self)[meth](slfn) // boolean
+ }
+ : function (self, selector, index) {
+ return $(t(self)[meth](selector, index)) // collection
+ }
return fn(self, selector, index)
}
return function (selector, index) { return fn(this, selector, index) }
}
- , methods = 'up down next previous parents closest siblings children first last eq slice filter not is has'.split(' ')
+ , methods = 'up down next previous prev parents closest siblings children first last eq slice filter not is has'.split(' ')
, b = {}, i = methods.length
+ // does this build have an .is()? if so, shift it to _is() for traversty to use and
+ // allow us to integrate a new is(), wrapped around it
+ if ($.fn.is) $.fn._is = $.fn.is
while (--i >= 0) b[methods[i]] = integrate(methods[i])
$.ender(b, true)
+ $.fn.is.__ignore = true
}(ender))
}());
@@ -20,7 +20,7 @@
.up('ul').eq(-1).css('borderLeft', 'solid 5px orange')
.closest('#fixtures').down('li').slice(-10,-9).css('fontSize', '25px')
- if ($('li').is('.c')) $('<div>INTEGRATION TEST ALL DONE!</div>').prependTo('#fixtures')
+ if ($('li').is('.c') === true) $('<div>INTEGRATION TEST ALL DONE!</div>').prependTo('#fixtures')
})
</script>
</head>
@@ -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.3 traversty@0.0.7
+ * Packages: ender-js@0.4.4 domready@0.2.11 qwery@3.3.11 bonzo@1.2.4 traversty@0.0.7
* =============================================================
*/
@@ -1465,7 +1465,8 @@
, dim: function () {
if (!this.length) return { height: 0, width: 0 }
var el = this[0]
- , orig = !el.offsetWidth && !el.offsetHeight ?
+ , de = el.nodeType == 9 && el.documentElement // document
+ , orig = !de && !!el.style && !el.offsetWidth && !el.offsetHeight ?
// el isn't visible, can't be measured properly, so fix that
function (t) {
var s = {
@@ -1480,8 +1481,12 @@
})
return s
}(this) : null
- , width = el.offsetWidth
- , height = el.offsetHeight
+ , width = de
+ ? Math.max(el.body.scrollWidth, el.body.offsetWidth, de.scrollWidth, de.offsetWidth, de.clientWidth)
+ : el.offsetWidth
+ , height = de
+ ? Math.max(el.body.scrollHeight, el.body.offsetHeight, de.scrollWidth, de.offsetWidth, de.clientHeight)
+ : el.offsetHeight
orig && this.first().css(orig)
return {
@@ -2219,6 +2224,7 @@
))
}
}
+ T.prototype.prev = T.prototype.previous
function t(els) {
return new T(isString(els) ? selectorFind(els, doc) : els)
@@ -2244,10 +2250,11 @@
// perhaps it's an selector(x).is(y) type selector?
ss = s('a', e)
_selectorMatches =
- isFunction(ss.matching) ? function (selector, el) { return s(el).matching(selector).length > 0 } :
- isFunction(ss.is) ? 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
+ 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
}
if (!_selectorMatches)
@@ -2303,15 +2310,25 @@
} catch (ex) { } // ignore exception, we may have an ender build with no selector engine
integrated = true
}
- fn = function (self, selector, index) { return $(t(self)[meth](selector, index)) }
+ fn = meth == 'is'
+ ? function (self, slfn) {
+ return t(self)[meth](slfn) // boolean
+ }
+ : function (self, selector, index) {
+ return $(t(self)[meth](selector, index)) // collection
+ }
return fn(self, selector, index)
}
return function (selector, index) { return fn(this, selector, index) }
}
- , methods = 'up down next previous parents closest siblings children first last eq slice filter not is has'.split(' ')
+ , methods = 'up down next previous prev parents closest siblings children first last eq slice filter not is has'.split(' ')
, b = {}, i = methods.length
+ // does this build have an .is()? if so, shift it to _is() for traversty to use and
+ // allow us to integrate a new is(), wrapped around it
+ if ($.fn.is) $.fn._is = $.fn.is
while (--i >= 0) b[methods[i]] = integrate(methods[i])
$.ender(b, true)
+ $.fn.is.__ignore = true
}(ender))
}());
@@ -20,7 +20,7 @@
.up('ul').eq(-1).css('borderLeft', 'solid 5px orange')
.closest('#fixtures').down('li').slice(-10,-9).css('fontSize', '25px')
- if ($('li').is('.c')) $('<div>INTEGRATION TEST ALL DONE!</div>').prependTo('#fixtures')
+ if ($('li').is('.c') === true) $('<div>INTEGRATION TEST ALL DONE!</div>').prependTo('#fixtures')
})
</script>
</head>
Oops, something went wrong.

0 comments on commit d75a4be

Please sign in to comment.