Skip to content
Browse files

- deprecating node creation in Ender bridge (Qwery remains untouched)

- Since node creation is no longer supported in the bridge, and relies on Bonzo
  the version is being bumped to major (v 3.0.0)
  Since technically Bonzo is not a dependency of Qwery, this may break integrations that were using qwery
  without Bonzo AND using qwery to create their DOM nodes (eg: $('<p>hello</p>'))
  Therefore anyone upgrading to 3.0.0 and needs node creation, they should add Bonzo as a dependency
  • Loading branch information...
1 parent 00cda9f commit 9cfc26dc9f4332aedfc66b1fc1f6bf43b46cd634 @ded committed Nov 15, 2011
Showing with 362 additions and 270 deletions.
  1. +337 −215 integration/ender.js
  2. +4 −4 integration/ender.min.js
  3. +10 −25 mobile/ender.js
  4. +1 −1 package.json
  5. +10 −25 src/ender.js
View
552 integration/ender.js
@@ -6,155 +6,156 @@
*/
/*!
- * Ender-JS: open module JavaScript framework (client-lib)
+ * Ender: open module JavaScript framework (client-lib)
* copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat)
- * https://ender.no.de
+ * http://ender.no.de
* License MIT
*/
!function (context) {
// a global object for node.js module compatiblity
// ============================================
- context['global'] = context;
+ context['global'] = context
// Implements simple module system
// losely based on CommonJS Modules spec v1.1.1
// ============================================
- var modules = {};
+ var modules = {}
+ , old = context.$
function require (identifier) {
- var module = modules[identifier] || window[identifier];
- if (!module) throw new Error("Requested module '" + identifier + "' has not been defined.");
- return module;
+ // modules can be required from ender's build system, or found on the window
+ var module = modules[identifier] || window[identifier]
+ if (!module) throw new Error("Requested module '" + identifier + "' has not been defined.")
+ return module
}
function provide (name, what) {
- return modules[name] = what;
+ return (modules[name] = what)
}
- context['provide'] = provide;
- context['require'] = require;
-
- // Implements Ender's $ global access object
- // =========================================
+ context['provide'] = provide
+ context['require'] = require
function aug(o, o2) {
- for (var k in o2) {
- k != 'noConflict' && k != '_VERSION' && (o[k] = o2[k]);
- }
- return o;
+ for (var k in o2) k != 'noConflict' && k != '_VERSION' && (o[k] = o2[k])
+ return o
}
function boosh(s, r, els) {
- // string || node || nodelist || window
- if (ender._select && (typeof s == 'string' || s.nodeName || s.length && 'item' in s || s == window)) {
- els = ender._select(s, r);
- els.selector = s;
- } else {
- els = isFinite(s.length) ? s : [s];
- }
- return aug(els, boosh);
+ // string || node || nodelist || window
+ if (typeof s == 'string' || s.nodeName || (s.length && 'item' in s) || s == window) {
+ els = ender._select(s, r)
+ els.selector = s
+ } else els = isFinite(s.length) ? s : [s]
+ return aug(els, boosh)
}
function ender(s, r) {
- return boosh(s, r);
+ return boosh(s, r)
}
aug(ender, {
- _VERSION: '0.2.5',
- ender: function (o, chain) {
- aug(chain ? boosh : ender, o);
- },
- fn: context.$ && context.$.fn || {} // for easy compat to jQuery plugins
- });
+ _VERSION: '0.3.6'
+ , fn: boosh // for easy compat to jQuery plugins
+ , ender: function (o, chain) {
+ aug(chain ? boosh : ender, o)
+ }
+ , _select: function (s, r) {
+ return (r || document).querySelectorAll(s)
+ }
+ })
aug(boosh, {
forEach: function (fn, scope, i) {
// opt out of native forEach so we can intentionally call our own scope
// defaulting to the current item and be able to return self
- for (i = 0, l = this.length; i < l; ++i) {
- i in this && fn.call(scope || this[i], this[i], i, this);
- }
+ for (i = 0, l = this.length; i < l; ++i) i in this && fn.call(scope || this[i], this[i], i, this)
// return self for chaining
- return this;
+ return this
},
$: ender // handy reference to self
- });
+ })
- var old = context.$;
ender.noConflict = function () {
- context.$ = old;
- return this;
- };
+ context.$ = old
+ return this
+ }
- (typeof module !== 'undefined') && module.exports && (module.exports = ender);
+ if (typeof module !== 'undefined' && module.exports) module.exports = ender
// use subscript notation as extern for Closure compilation
- context['ender'] = context['$'] = context['ender'] || ender;
+ context['ender'] = context['$'] = context['ender'] || ender
}(this);
!function () {
var module = { exports: {} }, exports = module.exports;
- !function (context, doc) {
- var fns = [], ol, fn, f = false,
- testEl = doc.documentElement,
- hack = testEl.doScroll,
- domContentLoaded = 'DOMContentLoaded',
- addEventListener = 'addEventListener',
- onreadystatechange = 'onreadystatechange',
- loaded = /^loade|c/.test(doc.readyState);
-
- function flush(i) {
- loaded = 1;
- while (i = fns.shift()) { i() }
+ !function (name, definition) {
+ if (typeof define == 'function') define(definition)
+ else if (typeof module != 'undefined') module.exports = definition()
+ else this[name] = this['domReady'] = definition()
+ }('domready', function (ready) {
+
+ var fns = [], fn, f = false
+ , doc = document
+ , testEl = doc.documentElement
+ , hack = testEl.doScroll
+ , domContentLoaded = 'DOMContentLoaded'
+ , addEventListener = 'addEventListener'
+ , onreadystatechange = 'onreadystatechange'
+ , loaded = /^loade|c/.test(doc.readyState)
+
+ function flush(f) {
+ loaded = 1
+ while (f = fns.shift()) f()
}
+
doc[addEventListener] && doc[addEventListener](domContentLoaded, fn = function () {
- doc.removeEventListener(domContentLoaded, fn, f);
- flush();
- }, f);
+ doc.removeEventListener(domContentLoaded, fn, f)
+ flush()
+ }, f)
- hack && doc.attachEvent(onreadystatechange, (ol = function () {
+ hack && doc.attachEvent(onreadystatechange, (fn = function () {
if (/^c/.test(doc.readyState)) {
- doc.detachEvent(onreadystatechange, ol);
- flush();
+ doc.detachEvent(onreadystatechange, fn)
+ flush()
}
- }));
+ }))
- context['domReady'] = hack ?
+ return (ready = hack ?
function (fn) {
self != top ?
loaded ? fn() : fns.push(fn) :
function () {
try {
- testEl.doScroll('left');
+ testEl.doScroll('left')
} catch (e) {
- return setTimeout(function() { context['domReady'](fn) }, 50);
+ return setTimeout(function() { ready(fn) }, 50)
}
- fn();
+ fn()
}()
} :
function (fn) {
- loaded ? fn() : fns.push(fn);
- };
-
- }(this, document);
-
+ loaded ? fn() : fns.push(fn)
+ })
+ })
provide("domready", module.exports);
!function ($) {
- $.ender({domReady: domReady});
+ var ready = require('domready')
+ $.ender({domReady: ready})
$.ender({
ready: function (f) {
- domReady(f);
- return this;
+ ready(f)
+ return this
}
- }, true);
+ }, true)
}(ender);
}();
@@ -168,35 +169,60 @@
* https://github.com/ded/bonzo
* License MIT
*/
- !function (context, win) {
-
- var doc = context.document
+ !function (name, definition) {
+ if (typeof module != 'undefined') module.exports = definition()
+ else if (typeof define == 'function' && define.amd) define(name, definition)
+ else this[name] = definition()
+ }('bonzo', function() {
+ var context = this
+ , old = context.bonzo
+ , win = window
+ , doc = win.document
, html = doc.documentElement
, parentNode = 'parentNode'
, query = null
, specialAttributes = /^checked|value|selected$/
, specialTags = /select|fieldset|table|tbody|tfoot|td|tr|colgroup/i
- , table = 'table'
- , tagMap = { thead: table, tbody: table, tfoot: table, tr: 'tbody', th: 'tr', td: 'tr', fieldset: 'form', option: 'select' }
+ , table = [ '<table>', '</table>', 1 ]
+ , td = [ '<table><tbody><tr>', '</tr></tbody></table>', 3 ]
+ , option = [ '<select>', '</select>', 1 ]
+ , tagMap = {
+ thead: table, tbody: table, tfoot: table, colgroup: table, caption: table
+ , tr: [ '<table><tbody>', '</tbody></table>', 2 ]
+ , th: td , td: td
+ , col: [ '<table><colgroup>', '</colgroup></table>', 2 ]
+ , fieldset: [ '<form>', '</form>', 1 ]
+ , legend: [ '<form><fieldset>', '</fieldset></form>', 2 ]
+ , option: option
+ , optgroup: option }
, stateAttributes = /^checked|selected$/
, ie = /msie/i.test(navigator.userAgent)
- , uidList = []
+ , uidMap = {}
, uuids = 0
, digit = /^-?[\d\.]+$/
+ , dattr = /^data-(.+)$/
, px = 'px'
- // commonly used methods
, setAttribute = 'setAttribute'
, getAttribute = 'getAttribute'
- , trimReplace = /(^\s*|\s*$)/g
- , unitless = { lineHeight: 1, zoom: 1, zIndex: 1, opacity: 1 }
- , transform = function () {
- var props = ['webkitTransform', 'MozTransform', 'OTransform', 'msTransform', 'Transform'], i
- for (i = 0; i < props.length; i++) {
- if (props[i] in doc.createElement('a').style) {
- return props[i]
- }
+ , byTag = 'getElementsByTagName'
+ , features = function() {
+ var e = doc.createElement('p')
+ e.innerHTML = '<a href="#x">x</a><table style="float:left;"></table>'
+ return {
+ hrefExtended: e[byTag]('a')[0][getAttribute]('href') != '#x' // IE < 8
+ , autoTbody: e[byTag]('tbody').length !== 0 // IE < 8
+ , computedStyle: doc.defaultView && doc.defaultView.getComputedStyle
+ , cssFloat: e[byTag]('table')[0].style.styleFloat ? 'styleFloat' : 'cssFloat'
+ , transform: function () {
+ var props = ['webkitTransform', 'MozTransform', 'OTransform', 'msTransform', 'Transform'], i
+ for (i = 0; i < props.length; i++) {
+ if (props[i] in e.style) return props[i]
+ }
+ }()
}
}()
+ , trimReplace = /(^\s*|\s*$)/g
+ , unitless = { lineHeight: 1, zoom: 1, zIndex: 1, opacity: 1 }
, trim = String.prototype.trim ?
function (s) {
return s.trim()
@@ -206,12 +232,20 @@
}
function classReg(c) {
- return new RegExp("(^|\\s+)" + c + "(\\s+|$)");
+ return new RegExp("(^|\\s+)" + c + "(\\s+|$)")
}
function each(ar, fn, scope) {
+ for (var i = 0, l = ar.length; i < l; i++) fn.call(scope || ar[i], ar[i], i, ar)
+ return ar
+ }
+
+ function deepEach(ar, fn, scope) {
for (var i = 0, l = ar.length; i < l; i++) {
- fn.call(scope || ar[i], ar[i], i, ar);
+ if (isNode(ar[i])) {
+ deepEach(ar[i].childNodes, fn, scope);
+ fn.call(scope || ar[i], ar[i], i, ar);
+ }
}
return ar;
}
@@ -222,36 +256,55 @@
})
}
- function is(node) {
+ function decamelize(s) {
+ return s ? s.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() : s
+ }
+
+ function data(el) {
+ el[getAttribute]('data-node-uid') || el[setAttribute]('data-node-uid', ++uuids)
+ uid = el[getAttribute]('data-node-uid')
+ return uidMap[uid] || (uidMap[uid] = {})
+ }
+
+ function clearData(el) {
+ uid = el[getAttribute]('data-node-uid')
+ uid && (delete uidMap[uid])
+ }
+
+ function dataValue(d) {
+ try {
+ return d === 'true' ? true : d === 'false' ? false : d === 'null' ? null : !isNaN(d) ? parseFloat(d) : d;
+ } catch(e) {}
+ return undefined
+ }
+
+ function isNode(node) {
return node && node.nodeName && node.nodeType == 1
}
- function some(ar, fn, scope) {
- for (var i = 0, j = ar.length; i < j; ++i) {
- if (fn.call(scope, ar[i], i, ar)) {
- return true
- }
- }
+ function some(ar, fn, scope, i) {
+ for (i = 0, j = ar.length; i < j; ++i) if (fn.call(scope, ar[i], i, ar)) return true
return false
}
- var getStyle = doc.defaultView && doc.defaultView.getComputedStyle ?
+ function styleProperty(p) {
+ (p == 'transform' && (p = features.transform)) ||
+ (/^transform-?[Oo]rigin$/.test(p) && (p = features.transform + "Origin")) ||
+ (p == 'float' && (p = features.cssFloat))
+ return p ? camelize(p) : null
+ }
+
+ var getStyle = features.computedStyle ?
function (el, property) {
- property = property == 'transform' ? transform : property
- property = property == 'transform-origin' ? transform + "Origin" : property
var value = null
- if (property == 'float') {
- property = 'cssFloat'
- }
- var computed = doc.defaultView.getComputedStyle(el, '')
- computed && (value = computed[camelize(property)])
+ , computed = doc.defaultView.getComputedStyle(el, '')
+ computed && (value = computed[property])
return el.style[property] || value
- } : (ie && html.currentStyle) ?
+ } :
- function (el, property) {
- property = camelize(property)
- property = property == 'float' ? 'styleFloat' : property
+ (ie && html.currentStyle) ?
+ function (el, property) {
if (property == 'opacity') {
var val = 100
try {
@@ -268,27 +321,31 @@
} :
function (el, property) {
- return el.style[camelize(property)]
- };
+ return el.style[property]
+ }
+ // this insert method is intense
function insert(target, host, fn) {
var i = 0, self = host || this, r = []
- , nodes = query && typeof target == 'string' && target.charAt(0) != '<' ? function (n) {
- return (n = query(target)) && (n.selected = 1) && n
- }() : target
+ // target nodes could be a css selector if it's a string and a selector engine is present
+ // otherwise, just use target
+ , nodes = query && typeof target == 'string' && target.charAt(0) != '<' ? query(target) : target
+ // normalize each node in case it's still a string and we need to create nodes on the fly
each(normalize(nodes), function (t) {
each(self, function (el) {
var n = !el[parentNode] || (el[parentNode] && !el[parentNode][parentNode]) ?
- function () {
- var c = el.cloneNode(true);
- self.$ && self.cloneEvents && self.$(c).cloneEvents(el);
- return c;
- }() :
- el
+ function () {
+ var c = el.cloneNode(true)
+ // check for existence of an event cloner
+ // preferably https://github.com/fat/bean
+ // otherwise Bonzo won't do this for you
+ self.$ && self.cloneEvents && self.$(c).cloneEvents(el)
+ return c
+ }() : el
fn(t, n)
r[i] = n
i++
- });
+ })
}, this)
each(r, function (e, i) {
self[i] = e
@@ -313,11 +370,32 @@
isNaN(delta[0]) && (delta[0] = isRel ? 0 : el.offsetLeft)
isNaN(delta[1]) && (delta[1] = isRel ? 0 : el.offsetTop)
- x !== null && (el.style.left = x - offset.left + delta[0] + px)
- y !== null && (el.style.top = y - offset.top + delta[1] + px)
+ x != null && (el.style.left = x - offset.left + delta[0] + px)
+ y != null && (el.style.top = y - offset.top + delta[1] + px)
}
+ function hasClass(el, c) {
+ return classReg(c).test(el.className)
+ }
+ function addClass(el, c) {
+ el.className = trim(el.className + ' ' + c)
+ }
+ function removeClass(el, c) {
+ el.className = trim(el.className.replace(classReg(c), ' '))
+ }
+
+ // this allows method calling for setting values
+ // example:
+
+ // bonzo(elements).css('color', function (el) {
+ // return el.getAttribute('data-original-color')
+ // })
+
+ function setter(el, v) {
+ return typeof v == 'function' ? v(el) : v
+ }
+
function Bonzo(elements) {
this.length = 0
if (elements) {
@@ -343,6 +421,10 @@
return each(this, fn, scope)
}
+ , deepEach: function (fn, scope) {
+ return deepEach(this, fn, scope)
+ }
+
, map: function (fn, reject) {
var m = [], n, i
for (i = 0; i < this.length; i++) {
@@ -353,28 +435,27 @@
}
, first: function () {
- return bonzo(this[0])
+ return bonzo(this.length ? this[0] : [])
}
, last: function () {
- return bonzo(this[this.length - 1])
+ return bonzo(this.length ? this[this.length - 1] : [])
}
, html: function (h, text) {
var method = text ?
- html.textContent == null ?
+ html.textContent === undefined ?
'innerText' :
'textContent' :
'innerHTML', m;
function append(el) {
- while (el.firstChild) el.removeChild(el.firstChild)
each(normalize(h), function (node) {
el.appendChild(node)
})
}
return typeof h !== 'undefined' ?
- this.each(function (el) {
- (m = el.tagName.match(specialTags)) ?
+ this.empty().each(function (el) {
+ !text && (m = el.tagName.match(specialTags)) ?
append(el, m[0]) :
(el[method] = h)
}) :
@@ -387,33 +468,28 @@
, addClass: function (c) {
return this.each(function (el) {
- this.hasClass(el, c) || (el.className = trim(el.className + ' ' + c))
- }, this)
+ hasClass(el, setter(el, c)) || addClass(el, setter(el, c))
+ })
}
, removeClass: function (c) {
return this.each(function (el) {
- this.hasClass(el, c) && (el.className = trim(el.className.replace(classReg(c), ' ')))
- }, this)
+ hasClass(el, setter(el, c)) && removeClass(el, setter(el, c))
+ })
}
- , hasClass: function (el, c) {
- return typeof c == 'undefined' ?
- some(this, function (i) {
- return classReg(el).test(i.className)
- }) :
- classReg(c).test(el.className)
+ , hasClass: function (c) {
+ return some(this, function (el) {
+ return hasClass(el, c)
+ })
}
, toggleClass: function (c, condition) {
- if (typeof condition !== 'undefined' && !condition) {
- return this
- }
return this.each(function (el) {
- this.hasClass(el, c) ?
- (el.className = trim(el.className.replace(classReg(c), ' '))) :
- (el.className = trim(el.className + ' ' + c))
- }, this)
+ typeof condition !== 'undefined' ?
+ condition ? addClass(el, c) : removeClass(el, c) :
+ hasClass(el, c) ? removeClass(el, c) : addClass(el, c)
+ })
}
, show: function (type) {
@@ -422,7 +498,7 @@
})
}
- , hide: function (elements) {
+ , hide: function () {
return this.each(function (el) {
el.style.display = 'none'
})
@@ -514,19 +590,27 @@
})
}
+ , replaceWith: function(html) {
+ this.deepEach(clearData)
+
+ return this.each(function (el) {
+ el.parentNode.replaceChild(bonzo.create(html)[0], el)
+ })
+ }
+
, css: function (o, v, p) {
// is this a request for just getting a style?
if (v === undefined && typeof o == 'string') {
// repurpose 'v'
- v = this[0];
+ v = this[0]
if (!v) {
return null
}
- if (v == doc || v == win) {
- p = (v == doc) ? bonzo.doc() : bonzo.viewport()
+ if (v === doc || v === win) {
+ p = (v === doc) ? bonzo.doc() : bonzo.viewport()
return o == 'width' ? p.width : o == 'height' ? p.height : ''
}
- return getStyle(v, o)
+ return (o = styleProperty(o)) ? getStyle(v, o) : null
}
var iter = o
if (typeof o == 'string') {
@@ -542,21 +626,13 @@
delete iter.opacity;
}
- if (v = iter['float']) {
- // float is a reserved style word. w3 uses cssFloat, ie uses styleFloat
- ie ? (iter.styleFloat = v) : (iter.cssFloat = v);
- delete iter['float'];
- }
-
function fn(el, p, v) {
for (var k in iter) {
if (iter.hasOwnProperty(k)) {
v = iter[k];
// change "5" to "5px" - unless you're line-height, which is allowed
- (p = camelize(k)) && digit.test(v) && !(p in unitless) && (v += px)
- p = p == 'transform' ? transform : p
- p = p == 'transformOrigin' ? transform + 'Origin' : p
- el.style[p] = v
+ (p = styleProperty(k)) && digit.test(v) && !(p in unitless) && (v += px)
+ el.style[p] = setter(el, v)
}
}
}
@@ -569,6 +645,12 @@
xy(el, x, y)
})
}
+ if (!this[0]) return {
+ top: 0
+ , left: 0
+ , height: 0
+ , width: 0
+ }
var el = this[0]
, width = el.offsetWidth
, height = el.offsetHeight
@@ -587,6 +669,33 @@
}
}
+ , dim: function () {
+ var el = this[0]
+ , orig = !el.offsetWidth && !el.offsetHeight ?
+ // el isn't visible, can't be measured properly, so fix that
+ function (t, s) {
+ s = {
+ position: el.style.position || ''
+ , visibility: el.style.visibility || ''
+ , display: el.style.display || ''
+ }
+ t.first().css({
+ position: 'absolute'
+ , visibility: 'hidden'
+ , display: 'block'
+ })
+ return s
+ }(this) : null
+ , width = el.offsetWidth
+ , height = el.offsetHeight
+
+ orig && this.first().css(orig)
+ return {
+ height: height
+ , width: width
+ }
+ }
+
, attr: function (k, v) {
var el = this[0]
if (typeof k != 'string' && !(k instanceof String)) {
@@ -598,9 +707,10 @@
return typeof v == 'undefined' ?
specialAttributes.test(k) ?
stateAttributes.test(k) && typeof el[k] == 'string' ?
- true : el[k] : el[getAttribute](k) :
+ true : el[k] : (k == 'href' || k =='src') && features.hrefExtended ?
+ el[getAttribute](k, 2) : el[getAttribute](k) :
this.each(function (el) {
- k == 'value' ? (el.value = v) : el[setAttribute](k, v)
+ specialAttributes.test(k) ? (el[k] = setter(el, v)) : el[setAttribute](k, setter(el, v))
})
}
@@ -610,36 +720,40 @@
, removeAttr: function (k) {
return this.each(function (el) {
- el.removeAttribute(k)
+ stateAttributes.test(k) ? (el[k] = false) : el.removeAttribute(k)
})
}
, data: function (k, v) {
- var el = this[0]
+ var el = this[0], uid, o, m
if (typeof v === 'undefined') {
- el[getAttribute]('data-node-uid') || el[setAttribute]('data-node-uid', ++uuids)
- var uid = el[getAttribute]('data-node-uid')
- uidList[uid] || (uidList[uid] = {})
- return uidList[uid][k]
+ o = data(el)
+ if (typeof k === 'undefined') {
+ each(el.attributes, function(a) {
+ (m = (''+a.name).match(dattr)) && (o[camelize(m[1])] = dataValue(a.value))
+ })
+ return o
+ } else {
+ return typeof o[k] === 'undefined' ?
+ (o[k] = dataValue(this.attr('data-' + decamelize(k)))) : o[k]
+ }
} else {
- return this.each(function (el) {
- el[getAttribute]('data-node-uid') || el[setAttribute]('data-node-uid', ++uuids)
- var uid = el[getAttribute]('data-node-uid')
- , o = {}
- o[k] = v
- uidList[uid] = o
- })
+ return this.each(function (el) { data(el)[k] = v })
}
}
, remove: function () {
+ this.deepEach(clearData)
+
return this.each(function (el) {
el[parentNode] && el[parentNode].removeChild(el)
})
}
, empty: function () {
return this.each(function (el) {
+ deepEach(el.childNodes, clearData)
+
while (el.firstChild) {
el.removeChild(el.firstChild)
}
@@ -659,10 +773,18 @@
, scrollLeft: function (x) {
return scroll.call(this, x, null, 'x')
}
+
+ , toggle: function (callback, type) {
+ this.each(function (el) {
+ el.style.display = (el.offsetWidth || el.offsetHeight) ? 'none' : type || ''
+ })
+ callback && callback()
+ return this
+ }
}
function normalize(node) {
- return typeof node == 'string' ? bonzo.create(node) : is(node) ? [node] : node // assume [nodes]
+ return typeof node == 'string' ? bonzo.create(node) : isNode(node) ? [node] : node // assume [nodes]
}
function scroll(x, y, type) {
@@ -703,22 +825,35 @@
}
bonzo.create = function (node) {
- return typeof node == 'string' ?
+ return typeof node == 'string' && node !== '' ?
function () {
- var tag = /^<([^\s>]+)/.exec(node)
- , el = doc.createElement(tag && tagMap[tag[1].toLowerCase()] || 'div'), els = []
- el.innerHTML = node
- var nodes = el.childNodes
- el = el.firstChild
- els.push(el)
- while (el = el.nextSibling) (el.nodeType == 1) && els.push(el)
+ var tag = /^\s*<([^\s>]+)/.exec(node)
+ , el = doc.createElement('div')
+ , els = []
+ , p = tag ? tagMap[tag[1].toLowerCase()] : null
+ , dep = p ? p[2] + 1 : 1
+ , pn = parentNode
+ , tb = features.autoTbody && p && p[0] == '<table>' && !(/<tbody/i).test(node)
+
+ el.innerHTML = p ? (p[0] + node + p[1]) : node
+ while (dep--) el = el.firstChild
+ do {
+ // tbody special case for IE<8, creates tbody on any empty table
+ // we don't want it if we're just after a <thead>, <caption>, etc.
+ if ((!tag || el.nodeType == 1) && (!tb || el.tagName.toLowerCase() != 'tbody')) {
+ els.push(el)
+ }
+ } while (el = el.nextSibling)
+ // IE < 9 gives us a parentNode which messes up insert() check for cloning
+ // `dep` > 1 can also cause problems with the insert() check (must do this last)
+ each(els, function(el) { el[pn] && el[pn].removeChild(el) })
return els
- }() : is(node) ? [node.cloneNode(true)] : []
+ }() : isNode(node) ? [node.cloneNode(true)] : []
}
bonzo.doc = function () {
- var vp = this.viewport()
+ var vp = bonzo.viewport()
return {
width: Math.max(doc.body.scrollWidth, html.scrollWidth, vp.width)
, height: Math.max(doc.body.scrollHeight, html.scrollHeight, vp.height)
@@ -727,9 +862,7 @@
bonzo.firstChild = function (el) {
for (var c = el.childNodes, i = 0, j = (c && c.length) || 0, e; i < j; i++) {
- if (c[i].nodeType === 1) {
- e = c[j = i]
- }
+ if (c[i].nodeType === 1) e = c[j = i]
}
return e
}
@@ -757,15 +890,13 @@
return false
}
- var old = context.bonzo
bonzo.noConflict = function () {
context.bonzo = old
return this
}
- if (typeof module !== 'undefined') module.exports = bonzo; else context['bonzo'] = bonzo
-
- }(this, window)
+ return bonzo
+ })
provide("bonzo", module.exports);
@@ -787,11 +918,7 @@
}
function indexOf(ar, val) {
- for (var i = 0; i < ar.length; i++) {
- if (ar[i] === val) {
- return i
- }
- }
+ for (var i = 0; i < ar.length; i++) if (ar[i] === val) return i
return -1
}
@@ -815,7 +942,7 @@
for (j = 0, k = this.length; j < k; j++) {
p = this[j]
while (p = p.parentNode) {
- if (indexOf(collection, p) !== -1) {
+ if (~indexOf(collection, p)) {
r.push(p)
if (closest) break;
}
@@ -829,11 +956,11 @@
},
first: function () {
- return $(this[0])
+ return $(this.length ? this[0] : this)
},
last: function () {
- return $(this[this.length - 1])
+ return $(this.length ? this[this.length - 1] : [])
},
next: function () {
@@ -864,24 +991,18 @@
var i, l, p, r = []
for (i = 0, l = this.length; i < l; i++) {
p = this[i]
- while (p = p.previousSibling) {
- p.nodeType == 1 && r.push(p)
- }
+ while (p = p.previousSibling) p.nodeType == 1 && r.push(p)
p = this[i]
- while (p = p.nextSibling) {
- p.nodeType == 1 && r.push(p)
- }
+ while (p = p.nextSibling) p.nodeType == 1 && r.push(p)
}
return $(r)
},
children: function () {
var i, el, r = []
for (i = 0, l = this.length; i < l; i++) {
- if (!(el = b.firstChild(this[i]))) {
- continue;
- }
- r.push(el);
+ if (!(el = b.firstChild(this[i]))) continue;
+ r.push(el)
while (el = el.nextSibling) el.nodeType == 1 && r.push(el)
}
return $(uniq(r))
@@ -894,12 +1015,13 @@
width: function (v) {
return dimension(v, this, 'width')
}
- }, true);
+ }, true)
function dimension(v, self, which) {
return v ?
self.css(which, v) :
function (r) {
+ if (!self[0]) return 0
r = parseInt(self.css(which), 10);
return isNaN(r) ? self[0]['offset' + which.replace(/^\w/, function (m) {return m.toUpperCase()})] : r
}()
View
8 integration/ender.min.js
@@ -7,15 +7,15 @@
/*!
- * Ender-JS: open module JavaScript framework (client-lib)
+ * Ender: open module JavaScript framework (client-lib)
* copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat)
- * https://ender.no.de
+ * http://ender.no.de
* License MIT
*/
-!function(a){function g(a,b){return f(a,b)}function f(a,b,c){g._select&&(typeof a=="string"||a.nodeName||a.length&&"item"in a||a==window)?(c=g._select(a,b),c.selector=a):c=isFinite(a.length)?a:[a];return e(c,f)}function e(a,b){for(var c in b)c!="noConflict"&&c!="_VERSION"&&(a[c]=b[c]);return a}function d(a,c){return b[a]=c}function c(a){var c=b[a]||window[a];if(!c)throw new Error("Requested module '"+a+"' has not been defined.");return c}a.global=a;var b={};a.provide=d,a.require=c,e(g,{_VERSION:"0.2.5",ender:function(a,b){e(b?f:g,a)},fn:a.$&&a.$.fn||{}}),e(f,{forEach:function(a,b,c){for(c=0,l=this.length;c<l;++c)c in this&&a.call(b||this[c],this[c],c,this);return this},$:g});var h=a.$;g.noConflict=function(){a.$=h;return this},typeof module!="undefined"&&module.exports&&(module.exports=g),a.ender=a.$=a.ender||g}(this),!function(){var a={exports:{}},b=a.exports;!function(a,b){function m(a){l=1;while(a=c.shift())a()}var c=[],d,e,f=!1,g=b.documentElement,h=g.doScroll,i="DOMContentLoaded",j="addEventListener",k="onreadystatechange",l=/^loade|c/.test(b.readyState);b[j]&&b[j](i,e=function(){b.removeEventListener(i,e,f),m()},f),h&&b.attachEvent(k,d=function(){/^c/.test(b.readyState)&&(b.detachEvent(k,d),m())}),a.domReady=h?function(b){self!=top?l?b():c.push(b):function(){try{g.doScroll("left")}catch(c){return setTimeout(function(){a.domReady(b)},50)}b()}()}:function(a){l?a():c.push(a)}}(this,document),provide("domready",a.exports),!function(a){a.ender({domReady:domReady}),a.ender({ready:function(a){domReady(a);return this}},!0)}(ender)}(),!function(){var a={exports:{}},b=a.exports;
+!function(a){function d(a){var c=b[a]||window[a];if(!c)throw new Error("Requested module '"+a+"' has not been defined.");return c}function e(a,c){return b[a]=c}function f(a,b){for(var c in b)c!="noConflict"&&c!="_VERSION"&&(a[c]=b[c]);return a}function g(a,b,c){return typeof a=="string"||a.nodeName||a.length&&"item"in a||a==window?(c=h._select(a,b),c.selector=a):c=isFinite(a.length)?a:[a],f(c,g)}function h(a,b){return g(a,b)}a.global=a;var b={},c=a.$;a.provide=e,a.require=d,f(h,{_VERSION:"0.3.6",fn:g,ender:function(a,b){f(b?g:h,a)},_select:function(a,b){return(b||document).querySelectorAll(a)}}),f(g,{forEach:function(a,b,c){for(c=0,l=this.length;c<l;++c)c in this&&a.call(b||this[c],this[c],c,this);return this},$:h}),h.noConflict=function(){return a.$=c,this},typeof module!="undefined"&&module.exports&&(module.exports=h),a.ender=a.$=a.ender||h}(this),!function(){var a={exports:{}},b=a.exports;!function(b,c){typeof define=="function"?define(c):typeof a!="undefined"?a.exports=c():this[b]=this.domReady=c()}("domready",function(a){function l(a){k=1;while(a=b.shift())a()}var b=[],c,d=!1,e=document,f=e.documentElement,g=f.doScroll,h="DOMContentLoaded",i="addEventListener",j="onreadystatechange",k=/^loade|c/.test(e.readyState);return e[i]&&e[i](h,c=function(){e.removeEventListener(h,c,d),l()},d),g&&e.attachEvent(j,c=function(){/^c/.test(e.readyState)&&(e.detachEvent(j,c),l())}),a=g?function(c){self!=top?k?c():b.push(c):function(){try{f.doScroll("left")}catch(b){return setTimeout(function(){a(c)},50)}c()}()}:function(a){k?a():b.push(a)}}),provide("domready",a.exports),!function(a){var b=require("domready");a.ender({domReady:b}),a.ender({ready:function(a){return b(a),this}},!0)}(ender)}(),!function(){var a={exports:{}},b=a.exports;
/*!
* Bonzo: DOM Utility (c) Dustin Diaz 2011
* https://github.com/ded/bonzo
* License MIT
*/
-!function(b,c){function K(a,b){return new F(a,b)}function J(){return{x:c.pageXOffset||e.scrollLeft,y:c.pageYOffset||e.scrollTop}}function I(a){return a===c||/^(?:body|html)$/i.test(a.tagName)}function H(a,b,d){var e=this[0];if(a==null&&b==null)return(I(e)?J():{x:e.scrollLeft,y:e.scrollTop})[d];I(e)?c.scrollTo(a,b):(a!=null&&(e.scrollLeft=a),b!=null&&(e.scrollTop=b));return this}function G(a){return typeof a=="string"?K.create(a):A(a)?[a]:a}function F(a){this.length=0;if(a){a=typeof a!="string"&&!a.nodeType&&typeof a.length!="undefined"?a:[a],this.length=a.length;for(var b=0;b<a.length;b++)this[b]=a[b]}}function E(a,b,c){var d=K(a),e=d.css("position"),f=d.offset(),g="relative",h=e==g,i=[parseInt(d.css("left"),10),parseInt(d.css("top"),10)];e=="static"&&(d.css("position",g),e=g),isNaN(i[0])&&(i[0]=h?0:a.offsetLeft),isNaN(i[1])&&(i[1]=h?0:a.offsetTop),b!==null&&(a.style.left=b-f.left+i[0]+q),c!==null&&(a.style.top=c-f.top+i[1]+q)}function D(a,b,c){var d=0,e=b||this,h=[],i=g&&typeof a=="string"&&a.charAt(0)!="<"?function(b){return(b=g(a))&&(b.selected=1)&&b}():a;y(G(i),function(a){y(e,function(b){var g=!b[f]||b[f]&&!b[f][f]?function(){var a=b.cloneNode(!0);e.$&&e.cloneEvents&&e.$(a).cloneEvents(b);return a}():b;c(a,g),h[d]=g,d++})},this),y(h,function(a,b){e[b]=a}),e.length=d;return e}function B(a,b,c){for(var d=0,e=a.length;d<e;++d)if(b.call(c,a[d],d,a))return!0;return!1}function A(a){return a&&a.nodeName&&a.nodeType==1}function z(a){return a.replace(/-(.)/g,function(a,b){return b.toUpperCase()})}function y(a,b,c){for(var d=0,e=a.length;d<e;d++)b.call(c||a[d],a[d],d,a);return a}function x(a){return new RegExp("(^|\\s+)"+a+"(\\s+|$)")}var d=b.document,e=d.documentElement,f="parentNode",g=null,h=/^checked|value|selected$/,i=/select|fieldset|table|tbody|tfoot|td|tr|colgroup/i,j="table",k={thead:j,tbody:j,tfoot:j,tr:"tbody",th:"tr",td:"tr",fieldset:"form",option:"select"},l=/^checked|selected$/,m=/msie/i.test(navigator.userAgent),n=[],o=0,p=/^-?[\d\.]+$/,q="px",r="setAttribute",s="getAttribute",t=/(^\s*|\s*$)/g,u={lineHeight:1,zoom:1,zIndex:1,opacity:1},v=function(){var a=["webkitTransform","MozTransform","OTransform","msTransform","Transform"],b;for(b=0;b<a.length;b++)if(a[b]in d.createElement("a").style)return a[b]}(),w=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(t,"")},C=d.defaultView&&d.defaultView.getComputedStyle?function(a,b){b=b=="transform"?v:b,b=b=="transform-origin"?v+"Origin":b;var c=null;b=="float"&&(b="cssFloat");var e=d.defaultView.getComputedStyle(a,"");e&&(c=e[z(b)]);return a.style[b]||c}:m&&e.currentStyle?function(a,b){b=z(b),b=b=="float"?"styleFloat":b;if(b=="opacity"){var c=100;try{c=a.filters["DXImageTransform.Microsoft.Alpha"].opacity}catch(d){try{c=a.filters("alpha").opacity}catch(e){}}return c/100}var f=a.currentStyle?a.currentStyle[b]:null;return a.style[b]||f}:function(a,b){return a.style[z(b)]};F.prototype={get:function(a){return this[a]},each:function(a,b){return y(this,a,b)},map:function(a,b){var c=[],d,e;for(e=0;e<this.length;e++)d=a.call(this,this[e],e),b?b(d)&&c.push(d):c.push(d);return c},first:function(){return K(this[0])},last:function(){return K(this[this.length-1])},html:function(a,b){function f(b){while(b.firstChild)b.removeChild(b.firstChild);y(G(a),function(a){b.appendChild(a)})}var c=b?e.textContent==null?"innerText":"textContent":"innerHTML",d;return typeof a!="undefined"?this.each(function(b){(d=b.tagName.match(i))?f(b,d[0]):b[c]=a}):this[0]?this[0][c]:""},text:function(a){return this.html(a,1)},addClass:function(a){return this.each(function(b){this.hasClass(b,a)||(b.className=w(b.className+" "+a))},this)},removeClass:function(a){return this.each(function(b){this.hasClass(b,a)&&(b.className=w(b.className.replace(x(a)," ")))},this)},hasClass:function(a,b){return typeof b=="undefined"?B(this,function(b){return x(a).test(b.className)}):x(b).test(a.className)},toggleClass:function(a,b){return typeof b!="undefined"&&!b?this:this.each(function(b){this.hasClass(b,a)?b.className=w(b.className.replace(x(a)," ")):b.className=w(b.className+" "+a)},this)},show:function(a){return this.each(function(b){b.style.display=a||""})},hide:function(a){return this.each(function(a){a.style.display="none"})},append:function(a){return this.each(function(b){y(G(a),function(a){b.appendChild(a)})})},prepend:function(a){return this.each(function(b){var c=b.firstChild;y(G(a),function(a){b.insertBefore(a,c)})})},appendTo:function(a,b){return D.call(this,a,b,function(a,b){a.appendChild(b)})},prependTo:function(a,b){return D.call(this,a,b,function(a,b){a.insertBefore(b,a.firstChild)})},next:function(){return this.related("nextSibling")},previous:function(){return this.related("previousSibling")},related:function(a){return this.map(function(b){b=b[a];while(b&&b.nodeType!==1)b=b[a];return b||0},function(a){return a})},before:function(a){return this.each(function(b){y(K.create(a),function(a){b[f].insertBefore(a,b)})})},after:function(a){return this.each(function(b){y(K.create(a),function(a){b[f].insertBefore(a,b.nextSibling)})})},insertBefore:function(a,b){return D.call(this,a,b,function(a,b){a[f].insertBefore(b,a)})},insertAfter:function(a,b){return D.call(this,a,b,function(a,b){var c=a.nextSibling;c?a[f].insertBefore(b,c):a[f].appendChild(b)})},css:function(a,b,e){function g(a,b,c){for(var d in f)f.hasOwnProperty(d)&&(c=f[d],(b=z(d))&&p.test(c)&&!(b in u)&&(c+=q),b=b=="transform"?v:b,b=b=="transformOrigin"?v+"Origin":b,a.style[b]=c)}if(b===undefined&&typeof a=="string"){b=this[0];if(!b)return null;if(b==d||b==c){e=b==d?K.doc():K.viewport();return a=="width"?e.width:a=="height"?e.height:""}return C(b,a)}var f=a;typeof a=="string"&&(f={},f[a]=b),m&&f.opacity&&(f.filter="alpha(opacity="+f.opacity*100+")",f.zoom=a.zoom||1,delete f.opacity);if(b=f["float"])m?f.styleFloat=b:f.cssFloat=b,delete f["float"];return this.each(g)},offset:function(a,b){if(typeof a=="number"||typeof b=="number")return this.each(function(c){E(c,a,b)});var c=this[0],d=c.offsetWidth,e=c.offsetHeight,f=c.offsetTop,g=c.offsetLeft;while(c=c.offsetParent)f=f+c.offsetTop,g=g+c.offsetLeft;return{top:f,left:g,height:e,width:d}},attr:function(a,b){var c=this[0];if(typeof a=="string"||a instanceof String)return typeof b=="undefined"?h.test(a)?l.test(a)&&typeof c[a]=="string"?!0:c[a]:c[s](a):this.each(function(c){a=="value"?c.value=b:c[r](a,b)});for(var d in a)a.hasOwnProperty(d)&&this.attr(d,a[d]);return this},val:function(a){return typeof a=="string"?this.attr("value",a):this[0].value},removeAttr:function(a){return this.each(function(b){b.removeAttribute(a)})},data:function(a,b){var c=this[0];if(typeof b=="undefined"){c[s]("data-node-uid")||c[r]("data-node-uid",++o);var d=c[s]("data-node-uid");n[d]||(n[d]={});return n[d][a]}return this.each(function(c){c[s]("data-node-uid")||c[r]("data-node-uid",++o);var d=c[s]("data-node-uid"),e={};e[a]=b,n[d]=e})},remove:function(){return this.each(function(a){a[f]&&a[f].removeChild(a)})},empty:function(){return this.each(function(a){while(a.firstChild)a.removeChild(a.firstChild)})},detach:function(){return this.map(function(a){return a[f].removeChild(a)})},scrollTop:function(a){return H.call(this,null,a,"y")},scrollLeft:function(a){return H.call(this,a,null,"x")}},K.setQueryEngine=function(a){g=a,delete K.setQueryEngine},K.aug=function(a,b){for(var c in a)a.hasOwnProperty(c)&&((b||F.prototype)[c]=a[c])},K.create=function(a){return typeof a=="string"?function(){var b=/^<([^\s>]+)/.exec(a),c=d.createElement(b&&k[b[1].toLowerCase()]||"div"),e=[];c.innerHTML=a;var f=c.childNodes;c=c.firstChild,e.push(c);while(c=c.nextSibling)c.nodeType==1&&e.push(c);return e}():A(a)?[a.cloneNode(!0)]:[]},K.doc=function(){var a=this.viewport();return{width:Math.max(d.body.scrollWidth,e.scrollWidth,a.width),height:Math.max(d.body.scrollHeight,e.scrollHeight,a.height)}},K.firstChild=function(a){for(var b=a.childNodes,c=0,d=b&&b.length||0,e;c<d;c++)b[c].nodeType===1&&(e=b[d=c]);return e},K.viewport=function(){return{width:m?e.clientWidth:self.innerWidth,height:m?e.clientHeight:self.innerHeight}},K.isAncestor="compareDocumentPosition"in e?function(a,b){return(a.compareDocumentPosition(b)&16)==16}:"contains"in e?function(a,b){return a!==b&&a.contains(b)}:function(a,b){while(b=b[f])if(b===a)return!0;return!1};var L=b.bonzo;K.noConflict=function(){b.bonzo=L;return this},typeof a!="undefined"?a.exports=K:b.bonzo=K}(this,window),provide("bonzo",a.exports),!function(a){function e(a,b,c){return a?b.css(c,a):function(a){a=parseInt(b.css(c),10);return isNaN(a)?b[0]["offset"+c.replace(/^\w/,function(a){return a.toUpperCase()})]:a}()}function d(a){var b=[],c,d;label:for(c=0;c<a.length;c++){for(d=0;d<b.length;d++)if(b[d]==a[c])continue label;b[b.length]=a[c]}return b}function c(a,b){for(var c=0;c<a.length;c++)if(a[c]===b)return c;return-1}var b=require("bonzo");b.setQueryEngine(a),a.ender(b),a.ender(b(),!0),a.ender({create:function(c){return a(b.create(c))}}),a.id=function(b){return a([document.getElementById(b)])},a.ender({parents:function(b,e){var f=a(b),g,h,i,j=[];for(g=0,h=this.length;g<h;g++){i=this[g];while(i=i.parentNode)if(c(f,i)!==-1){j.push(i);if(e)break}}return a(d(j))},closest:function(a){return this.parents(a,!0)},first:function(){return a(this[0])},last:function(){return a(this[this.length-1])},next:function(){return a(b(this).next())},previous:function(){return a(b(this).previous())},appendTo:function(a){return b(this.selector).appendTo(a,this)},prependTo:function(a){return b(this.selector).prependTo(a,this)},insertAfter:function(a){return b(this.selector).insertAfter(a,this)},insertBefore:function(a){return b(this.selector).insertBefore(a,this)},siblings:function(){var b,c,d,e=[];for(b=0,c=this.length;b<c;b++){d=this[b];while(d=d.previousSibling)d.nodeType==1&&e.push(d);d=this[b];while(d=d.nextSibling)d.nodeType==1&&e.push(d)}return a(e)},children:function(){var c,e,f=[];for(c=0,l=this.length;c<l;c++){if(!(e=b.firstChild(this[c])))continue;f.push(e);while(e=e.nextSibling)e.nodeType==1&&f.push(e)}return a(d(f))},height:function(a){return e(a,this,"height")},width:function(a){return e(a,this,"width")}},!0)}(ender)}()
+!function(b,c){typeof a!="undefined"?a.exports=c():typeof define=="function"&&define.amd?define(b,c):this[b]=c()}("bonzo",function(){function C(a){return new RegExp("(^|\\s+)"+a+"(\\s+|$)")}function D(a,b,c){for(var d=0,e=a.length;d<e;d++)b.call(c||a[d],a[d],d,a);return a}function E(a,b,c){for(var d=0,e=a.length;d<e;d++)K(a[d])&&(E(a[d].childNodes,b,c),b.call(c||a[d],a[d],d,a));return a}function F(a){return a.replace(/-(.)/g,function(a,b){return b.toUpperCase()})}function G(a){return a?a.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase():a}function H(a){return a[w]("data-node-uid")||a[v]("data-node-uid",++r),uid=a[w]("data-node-uid"),q[uid]||(q[uid]={})}function I(a){uid=a[w]("data-node-uid"),uid&&delete q[uid]}function J(a){try{return a==="true"?!0:a==="false"?!1:a==="null"?null:isNaN(a)?a:parseFloat(a)}catch(b){}return undefined}function K(a){return a&&a.nodeName&&a.nodeType==1}function L(a,b,c,d){for(d=0,j=a.length;d<j;++d)if(b.call(c,a[d],d,a))return!0;return!1}function M(a){return a=="transform"&&(a=y.transform)||/^transform-?[Oo]rigin$/.test(a)&&(a=y.transform+"Origin")||a=="float"&&(a=y.cssFloat),a?F(a):null}function O(a,b,c){var d=0,e=b||this,h=[],i=g&&typeof a=="string"&&a.charAt(0)!="<"?g(a):a;return D(V(i),function(a){D(e,function(b){var g=!b[f]||b[f]&&!b[f][f]?function(){var a=b.cloneNode(!0);return e.$&&e.cloneEvents&&e.$(a).cloneEvents(b),a}():b;c(a,g),h[d]=g,d++})},this),D(h,function(a,b){e[b]=a}),e.length=d,e}function P(a,b,c){var d=Z(a),e=d.css("position"),f=d.offset(),g="relative",h=e==g,i=[parseInt(d.css("left"),10),parseInt(d.css("top"),10)];e=="static"&&(d.css("position",g),e=g),isNaN(i[0])&&(i[0]=h?0:a.offsetLeft),isNaN(i[1])&&(i[1]=h?0:a.offsetTop),b!=null&&(a.style.left=b-f.left+i[0]+u),c!=null&&(a.style.top=c-f.top+i[1]+u)}function Q(a,b){return C(b).test(a.className)}function R(a,b){a.className=B(a.className+" "+b)}function S(a,b){a.className=B(a.className.replace(C(b)," "))}function T(a,b){return typeof b=="function"?b(a):b}function U(a){this.length=0;if(a){a=typeof a!="string"&&!a.nodeType&&typeof a.length!="undefined"?a:[a],this.length=a.length;for(var b=0;b<a.length;b++)this[b]=a[b]}}function V(a){return typeof a=="string"?Z.create(a):K(a)?[a]:a}function W(a,b,d){var e=this[0];return a==null&&b==null?(X(e)?Y():{x:e.scrollLeft,y:e.scrollTop})[d]:(X(e)?c.scrollTo(a,b):(a!=null&&(e.scrollLeft=a),b!=null&&(e.scrollTop=b)),this)}function X(a){return a===c||/^(?:body|html)$/i.test(a.tagName)}function Y(){return{x:c.pageXOffset||e.scrollLeft,y:c.pageYOffset||e.scrollTop}}function Z(a,b){return new U(a,b)}var a=this,b=a.bonzo,c=window,d=c.document,e=d.documentElement,f="parentNode",g=null,h=/^checked|value|selected$/,i=/select|fieldset|table|tbody|tfoot|td|tr|colgroup/i,k=["<table>","</table>",1],l=["<table><tbody><tr>","</tr></tbody></table>",3],m=["<select>","</select>",1],n={thead:k,tbody:k,tfoot:k,colgroup:k,caption:k,tr:["<table><tbody>","</tbody></table>",2],th:l,td:l,col:["<table><colgroup>","</colgroup></table>",2],fieldset:["<form>","</form>",1],legend:["<form><fieldset>","</fieldset></form>",2],option:m,optgroup:m},o=/^checked|selected$/,p=/msie/i.test(navigator.userAgent),q={},r=0,s=/^-?[\d\.]+$/,t=/^data-(.+)$/,u="px",v="setAttribute",w="getAttribute",x="getElementsByTagName",y=function(){var a=d.createElement("p");return a.innerHTML='<a href="#x">x</a><table style="float:left;"></table>',{hrefExtended:a[x]("a")[0][w]("href")!="#x",autoTbody:a[x]("tbody").length!==0,computedStyle:d.defaultView&&d.defaultView.getComputedStyle,cssFloat:a[x]("table")[0].style.styleFloat?"styleFloat":"cssFloat",transform:function(){var b=["webkitTransform","MozTransform","OTransform","msTransform","Transform"],c;for(c=0;c<b.length;c++)if(b[c]in a.style)return b[c]}()}}(),z=/(^\s*|\s*$)/g,A={lineHeight:1,zoom:1,zIndex:1,opacity:1},B=String.prototype.trim?function(a){return a.trim()}:function(a){return a.replace(z,"")},N=y.computedStyle?function(a,b){var c=null,e=d.defaultView.getComputedStyle(a,"");return e&&(c=e[b]),a.style[b]||c}:p&&e.currentStyle?function(a,b){if(b=="opacity"){var c=100;try{c=a.filters["DXImageTransform.Microsoft.Alpha"].opacity}catch(d){try{c=a.filters("alpha").opacity}catch(e){}}return c/100}var f=a.currentStyle?a.currentStyle[b]:null;return a.style[b]||f}:function(a,b){return a.style[b]};return U.prototype={get:function(a){return this[a]},each:function(a,b){return D(this,a,b)},deepEach:function(a,b){return E(this,a,b)},map:function(a,b){var c=[],d,e;for(e=0;e<this.length;e++)d=a.call(this,this[e],e),b?b(d)&&c.push(d):c.push(d);return c},first:function(){return Z(this.length?this[0]:[])},last:function(){return Z(this.length?this[this.length-1]:[])},html:function(a,b){function f(b){D(V(a),function(a){b.appendChild(a)})}var c=b?e.textContent===undefined?"innerText":"textContent":"innerHTML",d;return typeof a!="undefined"?this.empty().each(function(e){!b&&(d=e.tagName.match(i))?f(e,d[0]):e[c]=a}):this[0]?this[0][c]:""},text:function(a){return this.html(a,1)},addClass:function(a){return this.each(function(b){Q(b,T(b,a))||R(b,T(b,a))})},removeClass:function(a){return this.each(function(b){Q(b,T(b,a))&&S(b,T(b,a))})},hasClass:function(a){return L(this,function(b){return Q(b,a)})},toggleClass:function(a,b){return this.each(function(c){typeof b!="undefined"?b?R(c,a):S(c,a):Q(c,a)?S(c,a):R(c,a)})},show:function(a){return this.each(function(b){b.style.display=a||""})},hide:function(){return this.each(function(a){a.style.display="none"})},append:function(a){return this.each(function(b){D(V(a),function(a){b.appendChild(a)})})},prepend:function(a){return this.each(function(b){var c=b.firstChild;D(V(a),function(a){b.insertBefore(a,c)})})},appendTo:function(a,b){return O.call(this,a,b,function(a,b){a.appendChild(b)})},prependTo:function(a,b){return O.call(this,a,b,function(a,b){a.insertBefore(b,a.firstChild)})},next:function(){return this.related("nextSibling")},previous:function(){return this.related("previousSibling")},related:function(a){return this.map(function(b){b=b[a];while(b&&b.nodeType!==1)b=b[a];return b||0},function(a){return a})},before:function(a){return this.each(function(b){D(Z.create(a),function(a){b[f].insertBefore(a,b)})})},after:function(a){return this.each(function(b){D(Z.create(a),function(a){b[f].insertBefore(a,b.nextSibling)})})},insertBefore:function(a,b){return O.call(this,a,b,function(a,b){a[f].insertBefore(b,a)})},insertAfter:function(a,b){return O.call(this,a,b,function(a,b){var c=a.nextSibling;c?a[f].insertBefore(b,c):a[f].appendChild(b)})},replaceWith:function(a){return this.deepEach(I),this.each(function(b){b.parentNode.replaceChild(Z.create(a)[0],b)})},css:function(a,b,e){function g(a,b,c){for(var d in f)f.hasOwnProperty(d)&&(c=f[d],(b=M(d))&&s.test(c)&&!(b in A)&&(c+=u),a.style[b]=T(a,c))}if(b===undefined&&typeof a=="string")return b=this[0],b?b===d||b===c?(e=b===d?Z.doc():Z.viewport(),a=="width"?e.width:a=="height"?e.height:""):(a=M(a))?N(b,a):null:null;var f=a;return typeof a=="string"&&(f={},f[a]=b),p&&f.opacity&&(f.filter="alpha(opacity="+f.opacity*100+")",f.zoom=a.zoom||1,delete f.opacity),this.each(g)},offset:function(a,b){if(typeof a=="number"||typeof b=="number")return this.each(function(c){P(c,a,b)});if(!this[0])return{top:0,left:0,height:0,width:0};var c=this[0],d=c.offsetWidth,e=c.offsetHeight,f=c.offsetTop,g=c.offsetLeft;while(c=c.offsetParent)f+=c.offsetTop,g+=c.offsetLeft;return{top:f,left:g,height:e,width:d}},dim:function(){var a=this[0],b=!a.offsetWidth&&!a.offsetHeight?function(b,c){return c={position:a.style.position||"",visibility:a.style.visibility||"",display:a.style.display||""},b.first().css({position:"absolute",visibility:"hidden",display:"block"}),c}(this):null,c=a.offsetWidth,d=a.offsetHeight;return b&&this.first().css(b),{height:d,width:c}},attr:function(a,b){var c=this[0];if(typeof a=="string"||a instanceof String)return typeof b=="undefined"?h.test(a)?o.test(a)&&typeof c[a]=="string"?!0:c[a]:a!="href"&&a!="src"||!y.hrefExtended?c[w](a):c[w](a,2):this.each(function(c){h.test(a)?c[a]=T(c,b):c[v](a,T(c,b))});for(var d in a)a.hasOwnProperty(d)&&this.attr(d,a[d]);return this},val:function(a){return typeof a=="string"?this.attr("value",a):this[0].value},removeAttr:function(a){return this.each(function(b){o.test(a)?b[a]=!1:b.removeAttribute(a)})},data:function(a,b){var c=this[0],d,e,f;return typeof b=="undefined"?(e=H(c),typeof a=="undefined"?(D(c.attributes,function(a){(f=(""+a.name).match(t))&&(e[F(f[1])]=J(a.value))}),e):typeof e[a]=="undefined"?e[a]=J(this.attr("data-"+G(a))):e[a]):this.each(function(c){H(c)[a]=b})},remove:function(){return this.deepEach(I),this.each(function(a){a[f]&&a[f].removeChild(a)})},empty:function(){return this.each(function(a){E(a.childNodes,I);while(a.firstChild)a.removeChild(a.firstChild)})},detach:function(){return this.map(function(a){return a[f].removeChild(a)})},scrollTop:function(a){return W.call(this,null,a,"y")},scrollLeft:function(a){return W.call(this,a,null,"x")},toggle:function(a,b){return this.each(function(a){a.style.display=a.offsetWidth||a.offsetHeight?"none":b||""}),a&&a(),this}},Z.setQueryEngine=function(a){g=a,delete Z.setQueryEngine},Z.aug=function(a,b){for(var c in a)a.hasOwnProperty(c)&&((b||U.prototype)[c]=a[c])},Z.create=function(a){return typeof a=="string"&&a!==""?function(){var b=/^\s*<([^\s>]+)/.exec(a),c=d.createElement("div"),e=[],g=b?n[b[1].toLowerCase()]:null,h=g?g[2]+1:1,i=f,j=y.autoTbody&&g&&g[0]=="<table>"&&!/<tbody/i.test(a);c.innerHTML=g?g[0]+a+g[1]:a;while(h--)c=c.firstChild;do(!b||c.nodeType==1)&&(!j||c.tagName.toLowerCase()!="tbody")&&e.push(c);while(c=c.nextSibling);return D(e,function(a){a[i]&&a[i].removeChild(a)}),e}():K(a)?[a.cloneNode(!0)]:[]},Z.doc=function(){var a=Z.viewport();return{width:Math.max(d.body.scrollWidth,e.scrollWidth,a.width),height:Math.max(d.body.scrollHeight,e.scrollHeight,a.height)}},Z.firstChild=function(a){for(var b=a.childNodes,c=0,d=b&&b.length||0,e;c<d;c++)b[c].nodeType===1&&(e=b[d=c]);return e},Z.viewport=function(){return{width:p?e.clientWidth:self.innerWidth,height:p?e.clientHeight:self.innerHeight}},Z.isAncestor="compareDocumentPosition"in e?function(a,b){return(a.compareDocumentPosition(b)&16)==16}:"contains"in e?function(a,b){return a!==b&&a.contains(b)}:function(a,b){while(b=b[f])if(b===a)return!0;return!1},Z.noConflict=function(){return a.bonzo=b,this},Z}),provide("bonzo",a.exports),!function(a){function c(a,b){for(var c=0;c<a.length;c++)if(a[c]===b)return c;return-1}function d(a){var b=[],c,d;e:for(c=0;c<a.length;c++){for(d=0;d<b.length;d++)if(b[d]==a[c])continue e;b[b.length]=a[c]}return b}function e(a,b,c){return a?b.css(c,a):function(a){return b[0]?(a=parseInt(b.css(c),10),isNaN(a)?b[0]["offset"+c.replace(/^\w/,function(a){return a.toUpperCase()})]:a):0}()}var b=require("bonzo");b.setQueryEngine(a),a.ender(b),a.ender(b(),!0),a.ender({create:function(c){return a(b.create(c))}}),a.id=function(b){return a([document.getElementById(b)])},a.ender({parents:function(b,e){var f=a(b),g,h,i,j=[];for(g=0,h=this.length;g<h;g++){i=this[g];while(i=i.parentNode)if(~c(f,i)){j.push(i);if(e)break}}return a(d(j))},closest:function(a){return this.parents(a,!0)},first:function(){return a(this.length?this[0]:this)},last:function(){return a(this.length?this[this.length-1]:[])},next:function(){return a(b(this).next())},previous:function(){return a(b(this).previous())},appendTo:function(a){return b(this.selector).appendTo(a,this)},prependTo:function(a){return b(this.selector).prependTo(a,this)},insertAfter:function(a){return b(this.selector).insertAfter(a,this)},insertBefore:function(a){return b(this.selector).insertBefore(a,this)},siblings:function(){var b,c,d,e=[];for(b=0,c=this.length;b<c;b++){d=this[b];while(d=d.previousSibling)d.nodeType==1&&e.push(d);d=this[b];while(d=d.nextSibling)d.nodeType==1&&e.push(d)}return a(e)},children:function(){var c,e,f=[];for(c=0,l=this.length;c<l;c++){if(!(e=b.firstChild(this[c])))continue;f.push(e);while(e=e.nextSibling)e.nodeType==1&&f.push(e)}return a(d(f))},height:function(a){return e(a,this,"height")},width:function(a){return e(a,this,"width")}},!0)}(ender)}()
View
35 mobile/ender.js
@@ -1,34 +1,19 @@
!function (doc, $) {
- var q = require('qwery')
- , table = 'table'
- , nodeMap = {
- thead: table
- , tbody: table
- , tfoot: table
- , tr: 'tbody'
- , th: 'tr'
- , td: 'tr'
- , fieldset: 'form'
- , option: 'select'
- }
- function create(node, root) {
- var tag = /^\s*<([^\s>]+)\s*/.exec(node)[1]
- , el = (root || doc).createElement(nodeMap[tag] || 'div'), els = []
+ var q = require('qwery'), b
- el.innerHTML = node
- var nodes = el.childNodes
- el = el.firstChild
- el.nodeType == 1 && els.push(el)
- while (el = el.nextSibling) (el.nodeType == 1) && els.push(el)
- return els
- }
+ $.pseudos = q.pseudos
$._select = function (s, r) {
- return /^\s*</.test(s) ? create(s, r) : q(s, r)
+ // detect if sibling module 'bonzo' is available at run-time
+ // rather than load-time since technically it's not a dependency and
+ // can be loaded in any order
+ // hence the lazy function re-definition
+ $._select = !(b = require('bonzo')) ? q : function (s, r) {
@fat
fat added a note Dec 5, 2011

this makes bonzo a depency of qwery.

As per commonjs spec, if you call require('bonzo') and bonzo is not defined it will throw an exception.

That means currently you can't use qwery with ender, without using bonzo.

@rvagg
Collaborator
rvagg added a note Dec 5, 2011

Hah! I just ran in to this on a new project using Qwery and not Bonzo; borked on a require throw. Good thing I saw this comment because I would have wasted a bit too much time trying to understand it otherwise.

I've put a fix into PR #61, here: https://github.com/ded/qwery/pull/61/files#diff-2

@ded
Owner
ded added a note Dec 6, 2011

this doesn't make bonzo a dependency, it was merely checking if it had it. i really don't think we need all this logic in here when bonzo does it quite well, and much much better

@rvagg
Collaborator
rvagg added a note Dec 6, 2011

I think the point is that because require does a throw when the module you've requested doesn't exist it can't finish the logic you've pout in there; therefore, you either have to have bonzo available or you can't continue; therefore bonzo is a dependency.

@fat
fat added a note Dec 7, 2011

try to ender build qwery and running it - it will throw an exception.

@ded
Owner
ded added a note Dec 8, 2011

@fat i know it will thrown an exception. which made me question whether we should throw an exception, or simply return undefined or null. if we keep the exception throwing (which is fine), then we really should just wrap the require('bonzo') in a try {}catch(){}

@fat
fat added a note Dec 8, 2011

Yeah... it's a tough one... I think semantically "require" should throw an error if can't include something you are requiring.

I'm fine with a try catch, it's only done once, so it's pretty quick and shouldn't be a big deal performance wise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return /^\s*</.test(s) ? b.create(s, r) : q(s, r)
+ }
+ return b && /^\s*</.test(s) ? b.create(s, r) : q(s, r)
}
- $.pseudos = q.pseudos
-
$.ender({
find: function (s) {
var r = [], i, l, j, k, els
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "qwery"
, "description": "blazing fast CSS3 query selector engine"
- , "version": "2.2.8"
+ , "version": "3.0.0"
, "homepage": "https://github.com/ded/qwery"
, "author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)"
, "contributors": ["Jacob Thornton <> (https://github.com/fat)"]
View
35 src/ender.js
@@ -1,34 +1,19 @@
!function (doc, $) {
- var q = require('qwery')
- , table = 'table'
- , nodeMap = {
- thead: table
- , tbody: table
- , tfoot: table
- , tr: 'tbody'
- , th: 'tr'
- , td: 'tr'
- , fieldset: 'form'
- , option: 'select'
- }
- function create(node, root) {
- var tag = /^\s*<([^\s>]+)\s*/.exec(node)[1]
- , el = (root || doc).createElement(nodeMap[tag] || 'div'), els = []
+ var q = require('qwery'), b
- el.innerHTML = node
- var nodes = el.childNodes
- el = el.firstChild
- el.nodeType == 1 && els.push(el)
- while (el = el.nextSibling) (el.nodeType == 1) && els.push(el)
- return els
- }
+ $.pseudos = q.pseudos
$._select = function (s, r) {
- return /^\s*</.test(s) ? create(s, r) : q(s, r)
+ // detect if sibling module 'bonzo' is available at run-time
+ // rather than load-time since technically it's not a dependency and
+ // can be loaded in any order
+ // hence the lazy function re-definition
+ $._select = !(b = require('bonzo')) ? q : function (s, r) {
+ return /^\s*</.test(s) ? b.create(s, r) : q(s, r)
+ }
+ return b && /^\s*</.test(s) ? b.create(s, r) : q(s, r)
}
- $.pseudos = q.pseudos
-
$.ender({
find: function (s) {
var r = [], i, l, j, k, els

0 comments on commit 9cfc26d

Please sign in to comment.
Something went wrong with that request. Please try again.