This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
window['$'] = window['ender'] = ender |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,166 +1,66 @@ | ||
/*! | ||
* Ender: open module JavaScript framework (client-lib) | ||
* copyright Dustin Diaz & Jacob Thornton 2011-2012 (@ded @fat) | ||
* http://ender.jit.su | ||
* http://enderjs.com | ||
* License MIT | ||
*/ | ||
(function (context, window, document) { | ||
|
||
// a global object for node.js module compatiblity | ||
// ============================================ | ||
|
||
context['global'] = context | ||
|
||
// Implements simple module system | ||
// loosely based on CommonJS Modules spec v1.1.1 | ||
// ============================================ | ||
|
||
var modules = {} | ||
, old = context['$'] | ||
, oldEnder = context['ender'] | ||
, oldRequire = context['require'] | ||
, oldProvide = context['provide'] | ||
|
||
/** | ||
* @param {string} name | ||
*/ | ||
function require(name) { | ||
// modules can be required from ender's build system, or found on the window | ||
var module = modules['$' + name] || window[name] | ||
if (!module) throw new Error("Ender Error: Requested module '" + name + "' has not been defined.") | ||
return module | ||
} | ||
|
||
/** | ||
* @param {string} name | ||
* @param {*} what | ||
*/ | ||
function provide(name, what) { | ||
return (modules['$' + name] = what) | ||
} | ||
|
||
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 | ||
} | ||
|
||
/** | ||
* @param {*} o is an item to count | ||
* @return {number|boolean} | ||
*/ | ||
function count(o) { | ||
if (typeof o != 'object' || !o || o.nodeType || o === window) | ||
return false | ||
return typeof (o = o.length) == 'number' && o === o ? o : false | ||
} | ||
|
||
/** | ||
* @constructor | ||
* @param {*=} item selector|node|collection|callback|anything | ||
* @param {Object=} root node(s) from which to base selector queries | ||
*/ | ||
function Ender(item, root) { | ||
var i | ||
this.length = 0 // Ensure that instance owns length | ||
|
||
if (typeof item == 'string') | ||
// Start @ strings so the result parlays into the other checks | ||
// The .selector prop only applies to strings | ||
item = ender['_select'](this['selector'] = item, root) | ||
|
||
if (null == item) | ||
return this // Do not wrap null|undefined | ||
|
||
if (typeof item == 'function') | ||
ender['_closure'](item, root) | ||
|
||
// DOM node | scalar | not array-like | ||
else if (false === (i = count(item))) | ||
this[this.length++] = item | ||
|
||
// Array-like - Bitwise ensures integer length: | ||
else for (this.length = i = i > 0 ? i >> 0 : 0; i--;) | ||
this[i] = item[i] | ||
/** | ||
* main Ender return object | ||
* @constructor | ||
* @param {Array|Node|string} s a CSS selector or DOM node(s) | ||
* @param {Array.|Node} r a root node(s) | ||
*/ | ||
function Ender(s, r) { | ||
var elements | ||
, i | ||
|
||
this.selector = s | ||
// string || node || nodelist || window | ||
if (typeof s == 'undefined') { | ||
elements = [] | ||
this.selector = '' | ||
} else if (typeof s == 'string' || s.nodeName || (s.length && 'item' in s) || s == window) { | ||
elements = ender._select(s, r) | ||
} else { | ||
elements = isFinite(s.length) ? s : [s] | ||
} | ||
|
||
/** | ||
* @param {*=} item selector|node|collection|callback|anything | ||
* @param {Object=} root node(s) from which to base selector queries | ||
* @return {Ender} | ||
*/ | ||
function ender(item, root) { | ||
return new Ender(item, root) | ||
} | ||
|
||
ender['_VERSION'] = '0.4.x' | ||
|
||
// Sync the prototypes for jQuery compatibility | ||
ender['fn'] = ender.prototype = Ender.prototype | ||
|
||
Ender.prototype['$'] = ender // handy reference to self | ||
|
||
// dev tools secret sauce | ||
Ender.prototype['splice'] = function () { throw new Error('Not implemented') } | ||
|
||
/** | ||
* @param {function(*, number, Ender)} fn | ||
* @param {Object=} opt_scope | ||
* @return {Ender} | ||
*/ | ||
Ender.prototype['forEach'] = function (fn, opt_scope) { | ||
var i, l | ||
// 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(opt_scope || this[i], this[i], i, this) | ||
// return self for chaining | ||
return this | ||
} | ||
|
||
/** | ||
* @param {Object|Function} o | ||
* @param {boolean=} chain | ||
*/ | ||
ender['ender'] = function (o, chain) { | ||
aug(chain ? Ender.prototype : ender, o) | ||
} | ||
|
||
/** | ||
* @param {string} s | ||
* @param {Node=} r | ||
*/ | ||
ender['_select'] = function (s, r) { | ||
return s ? (r || document).querySelectorAll(s) : [] | ||
} | ||
|
||
/** | ||
* @param {Function} fn | ||
*/ | ||
ender['_closure'] = function (fn) { | ||
fn.call(document, ender) | ||
} | ||
|
||
/** | ||
* @param {(boolean|Function)=} fn optional flag or callback | ||
* To unclaim the global $, use no args. To unclaim *all* ender globals, | ||
* use `true` or a callback that receives (require, provide, ender) | ||
*/ | ||
ender['noConflict'] = function (fn) { | ||
context['$'] = old | ||
if (fn) { | ||
context['provide'] = oldProvide | ||
context['require'] = oldRequire | ||
context['ender'] = oldEnder | ||
typeof fn == 'function' && fn(require, provide, this) | ||
} | ||
return this | ||
} | ||
|
||
if (typeof module !== 'undefined' && module['exports']) module['exports'] = ender | ||
// use subscript notation as extern for Closure compilation | ||
// developers.google.com/closure/compiler/docs/api-tutorial3 | ||
context['ender'] = context['$'] = ender | ||
|
||
}(this, window, document)); | ||
this.length = elements.length | ||
for (i = this.length; i--;) this[i] = elements[i] | ||
} | ||
|
||
/** | ||
* @param {function(el, i, inst)} fn | ||
* @param {Object} opt_scope | ||
* @returns {Ender} | ||
*/ | ||
Ender.prototype['forEach'] = function (fn, opt_scope) { | ||
var i, l | ||
// 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(opt_scope || this[i], this[i], i, this) | ||
// return self for chaining | ||
return this | ||
} | ||
|
||
Ender.prototype.$ = ender // handy reference to self | ||
|
||
|
||
function ender(s, r) { | ||
return new Ender(s, r) | ||
} | ||
|
||
ender.fn = Ender.prototype // for easy compat to jQuery plugins | ||
|
||
ender.ender = function (o, chain) { | ||
var o2 = (chain ? Ender.prototype : ender) | ||
for (var k in o) k != 'noConflict' && k != '_VERSION' && (o2[k] = o[k]) | ||
return o2 | ||
} | ||
|
||
ender._select = function (s, r) { | ||
if (typeof s == 'string') return (r || document).querySelectorAll(s) | ||
if (s.nodeName) return [s] | ||
return s | ||
} | ||
|
||
$ = ender |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters