|
5 | 5 | * (c) Dustin Diaz, Jacob Thornton 2011
|
6 | 6 | * License: MIT
|
7 | 7 | */
|
8 |
| -(function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&define.amd?define(a,b):this[a]=b()})("$script",function(){function q(a,b,c){for(c=0,j=a.length;c<j;++c)if(!b(a[c]))return k;return 1}function r(a,b){q(a,function(a){return!b(a)})}function s(a,b,i){function o(a){return a.call?a():d[a]}function p(){if(!--n){d[m]=1,k&&k();for(var a in f)q(a.split("|"),o)&&!r(f[a],o)&&(f[a]=[])}}a=a[l]?a:[a];var j=b&&b.call,k=j?b:i,m=j?a.join(""):b,n=a.length;return setTimeout(function(){r(a,function(a){if(h[a])return m&&(e[m]=1),h[a]==2&&p();h[a]=1,m&&(e[m]=1),t(!c.test(a)&&g?g+a+".js":a,p)})},0),s}function t(c,d){var e=a.createElement("script"),f=k;e.onload=e.onerror=e[p]=function(){if(e[n]&&!/^c|loade/.test(e[n])||f)return;e.onload=e[p]=null,f=1,h[c]=2,d()},e.async=1,e.src=c,b.insertBefore(e,b.firstChild)}var a=document,b=a.getElementsByTagName("head")[0],c=/^https?:\/\//,d={},e={},f={},g,h={},i="string",k=!1,l="push",m="DOMContentLoaded",n="readyState",o="addEventListener",p="onreadystatechange";return!a[n]&&a[o]&&(a[o](m,function u(){a.removeEventListener(m,u,k),a[n]="complete"},k),a[n]="loading"),s.get=t,s.order=function(a,b,c){(function d(e){e=a.shift(),a.length?s(e,d):s(e,b,c)})()},s.path=function(a){g=a},s.ready=function(a,b,c){a=a[l]?a:[a];var e=[];return!r(a,function(a){d[a]||e[l](a)})&&q(a,function(a){return d[a]})?b():!function(a){f[a]=f[a]||[],f[a][l](b),c&&c(e)}(a.join("|")),s},s}); |
| 8 | +(function (name, definition, context) { |
| 9 | + if (typeof context['module'] != 'undefined' && context['module']['exports']) context['module']['exports'] = definition() |
| 10 | + else if (typeof context['define'] != 'undefined' && context['define'] == 'function' && context['define']['amd']) define(name, definition) |
| 11 | + else context[name] = definition() |
| 12 | +})('$script', function () { |
| 13 | + var doc = document |
| 14 | + , head = doc.getElementsByTagName('head')[0] |
| 15 | + , validBase = /^https?:\/\// |
| 16 | + , list = {}, ids = {}, delay = {}, scriptpath |
| 17 | + , scripts = {}, s = 'string', f = false |
| 18 | + , push = 'push', domContentLoaded = 'DOMContentLoaded', readyState = 'readyState' |
| 19 | + , addEventListener = 'addEventListener', onreadystatechange = 'onreadystatechange' |
| 20 | + |
| 21 | + function every(ar, fn) { |
| 22 | + for (var i = 0, j = ar.length; i < j; ++i) if (!fn(ar[i])) return f |
| 23 | + return 1 |
| 24 | + } |
| 25 | + function each(ar, fn) { |
| 26 | + every(ar, function(el) { |
| 27 | + return !fn(el) |
| 28 | + }) |
| 29 | + } |
| 30 | + |
| 31 | + if (!doc[readyState] && doc[addEventListener]) { |
| 32 | + doc[addEventListener](domContentLoaded, function fn() { |
| 33 | + doc.removeEventListener(domContentLoaded, fn, f) |
| 34 | + doc[readyState] = 'complete' |
| 35 | + }, f) |
| 36 | + doc[readyState] = 'loading' |
| 37 | + } |
| 38 | + |
| 39 | + function $script(paths, idOrDone, optDone) { |
| 40 | + paths = paths[push] ? paths : [paths] |
| 41 | + var idOrDoneIsDone = idOrDone && idOrDone.call |
| 42 | + , done = idOrDoneIsDone ? idOrDone : optDone |
| 43 | + , id = idOrDoneIsDone ? paths.join('') : idOrDone |
| 44 | + , queue = paths.length |
| 45 | + function loopFn(item) { |
| 46 | + return item.call ? item() : list[item] |
| 47 | + } |
| 48 | + function callback() { |
| 49 | + if (!--queue) { |
| 50 | + list[id] = 1 |
| 51 | + done && done() |
| 52 | + for (var dset in delay) { |
| 53 | + every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = []) |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + setTimeout(function () { |
| 58 | + each(paths, function (path) { |
| 59 | + if (scripts[path]) { |
| 60 | + id && (ids[id] = 1) |
| 61 | + return scripts[path] == 2 && callback() |
| 62 | + } |
| 63 | + scripts[path] = 1 |
| 64 | + id && (ids[id] = 1) |
| 65 | + create(!validBase.test(path) && scriptpath ? scriptpath + path + '.js' : path, callback) |
| 66 | + }) |
| 67 | + }, 0) |
| 68 | + return $script |
| 69 | + } |
| 70 | + |
| 71 | + function create(path, fn) { |
| 72 | + var el = doc.createElement('script') |
| 73 | + , loaded = f |
| 74 | + el.onload = el.onerror = el[onreadystatechange] = function () { |
| 75 | + if ((el[readyState] && !(/^c|loade/.test(el[readyState]))) || loaded) return; |
| 76 | + el.onload = el[onreadystatechange] = null |
| 77 | + loaded = 1 |
| 78 | + scripts[path] = 2 |
| 79 | + fn() |
| 80 | + } |
| 81 | + el.async = 1 |
| 82 | + el.src = path |
| 83 | + head.insertBefore(el, head.firstChild) |
| 84 | + } |
| 85 | + |
| 86 | + $script.get = create |
| 87 | + |
| 88 | + $script.order = function (scripts, id, done) { |
| 89 | + (function callback(s) { |
| 90 | + s = scripts.shift() |
| 91 | + if (!scripts.length) $script(s, id, done) |
| 92 | + else $script(s, callback) |
| 93 | + }()) |
| 94 | + } |
| 95 | + |
| 96 | + $script.path = function (p) { |
| 97 | + scriptpath = p |
| 98 | + } |
| 99 | + $script.ready = function (deps, ready, req) { |
| 100 | + deps = deps[push] ? deps : [deps] |
| 101 | + var missing = []; |
| 102 | + !each(deps, function (dep) { |
| 103 | + list[dep] || missing[push](dep); |
| 104 | + }) && every(deps, function (dep) {return list[dep]}) ? |
| 105 | + ready() : !function (key) { |
| 106 | + delay[key] = delay[key] || [] |
| 107 | + delay[key][push](ready) |
| 108 | + req && req(missing) |
| 109 | + }(deps.join('|')) |
| 110 | + return $script |
| 111 | + } |
| 112 | + return $script |
| 113 | +}, this); |
| 114 | + |
9 | 115 |
|
10 | 116 | /**
|
11 | 117 | * @license AngularJS
|
|
20 | 126 | match,
|
21 | 127 | globalVars = {},
|
22 | 128 | IGNORE = {
|
| 129 | + innerHeight: true, innerWidth: true, |
23 | 130 | onkeyup: true, onkeydown: true, onresize: true,
|
24 | 131 | event: true, frames: true, external: true,
|
25 | 132 | sessionStorage: true, clipboardData: true, localStorage: true};
|
|
51 | 158 |
|
52 | 159 | (function next() {
|
53 | 160 | if (index < scripts.length) {
|
54 |
| - var file = scripts[index++]; |
| 161 | + var file = scripts[index++], |
| 162 | + last = index == scripts.length, |
| 163 | + name = last ? 'angular' : file; |
55 | 164 |
|
56 |
| - $script(file.replace(/\.js$/, ''), function() { |
| 165 | + $script(file.replace(/\.js$/, ''), name, function() { |
57 | 166 | angularClobberTest(file);
|
58 | 167 | next();
|
59 | 168 | });
|
|
0 commit comments