xonecas.io
142
St

startsInvasion / files

startsInvasion / libs / node_modules / ender-js / ender.js

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