|
4 | 4 | * (c) Dustin Diaz 2014 | License MIT |
5 | 5 | */ |
6 | 6 |
|
7 | | -(function (name, context, definition) { |
| 7 | +(function (name, definition) { |
8 | 8 | if (typeof module != 'undefined' && module.exports) module.exports = definition() |
9 | 9 | else if (typeof define == 'function' && define.amd) define(definition) |
10 | | - else context[name] = definition() |
11 | | -})('$script', this, function () { |
| 10 | + else this[name] = definition() |
| 11 | +})('$script', function () { |
12 | 12 | var doc = document |
13 | 13 | , head = doc.getElementsByTagName('head')[0] |
14 | | - , validBase = /^https?:\/\// |
15 | 14 | , s = 'string' |
16 | 15 | , f = false |
17 | 16 | , push = 'push' |
18 | 17 | , readyState = 'readyState' |
19 | 18 | , onreadystatechange = 'onreadystatechange' |
20 | | - , scriptpath |
21 | 19 | , list = {} |
22 | 20 | , ids = {} |
23 | 21 | , delay = {} |
24 | 22 | , scripts = {} |
| 23 | + , scriptpath |
25 | 24 |
|
26 | 25 | function every(ar, fn) { |
27 | 26 | for (var i = 0, j = ar.length; i < j; ++i) if (!fn(ar[i])) return f |
|
60 | 59 | } |
61 | 60 | scripts[path] = 1 |
62 | 61 | id && (ids[id] = 1) |
63 | | - create(!validBase.test(path) && scriptpath ? scriptpath + path + '.js' : path, callback) |
| 62 | + create(!/^https?:\/\//.test(path) && scriptpath ? scriptpath + path + '.js' : path, callback) |
64 | 63 | }) |
65 | 64 | }, 0) |
66 | 65 | return $script |
|
86 | 85 | $script.order = function (scripts, id, done) { |
87 | 86 | (function callback(s) { |
88 | 87 | s = scripts.shift() |
89 | | - if (!scripts.length) $script(s, id, done) |
90 | | - else $script(s, callback) |
| 88 | + !scripts.length ? $script(s, id, done) : $script(s, callback) |
91 | 89 | }()) |
92 | 90 | } |
93 | 91 |
|
|
0 commit comments