xonecas.io
142
St

startsInvasion / files

startsInvasion / libs / node_modules / bean / ender.js

2.2 KB
1/*!
2  * Ender: open module JavaScript framework
3  * copyright Dustin Diaz & Jacob Thornton 2011 (@ded @fat)
4  * https://ender.no.de
5  * License MIT 
6  * Module's individual licenses still apply
7  * Build: ender build ../bean
8  */
9
10!function (context) {
11
12  // Implements simple module system
13  // losely based on CommonJS Modules spec v1.1.1
14  // ============================================
15
16  var modules = {};
17
18  function require (identifier) {
19    var module = modules[identifier];
20    if (!module) throw new Error("Requested module has not been defined.");
21    return module;
22  }
23
24  function provide (name, what) {
25    return modules[name] = what;
26  }
27
28  context['provide'] = provide;
29  context['require'] = require;
30
31  // Implements Ender's $ global access object
32  // =========================================
33
34  function aug(o, o2) {
35    for (var k in o2) {
36      k != 'noConflict' && k != '_VERSION' && (o[k] = o2[k]);
37    }
38    return o;
39  }
40
41  function boosh(s, r, els) {
42                          // string || node || nodelist || window
43    if (ender._select && (typeof s == 'string' || s.nodeName || s.length && 'item' in s || s == window)) {
44      els = ender._select(s, r);
45      els.selector = s;
46    } else {
47      els = isFinite(s.length) ? s : [s];
48    }
49    return aug(els, boosh);
50  }
51
52  function ender(s, r) {
53    return boosh(s, r);
54  }
55
56  aug(ender, {
57    _VERSION: '0.2.5',
58    ender: function (o, chain) {
59      aug(chain ? boosh : ender, o);
60    },
61    fn: context.$ && context.$.fn || {} // for easy compat to jQuery plugins
62  });
63
64  aug(boosh, {
65    forEach: function (fn, scope, i) {
66      // opt out of native forEach so we can intentionally call our own scope
67      // defaulting to the current item and be able to return self
68      for (i = 0, l = this.length; i < l; ++i) {
69        i in this && fn.call(scope || this[i], this[i], i, this);
70      }
71      // return self for chaining
72      return this;
73    },
74    $: ender // handy reference to self
75  });
76
77  var old = context.$;
78  ender.noConflict = function () {
79    context.$ = old;
80    return this;
81  };
82
83  (typeof module !== 'undefined') && module.exports && (module.exports = ender);
84  // use subscript notation as extern for Closure compilation
85  context['ender'] = context['$'] = ender;
86
87}(this);