aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2012-04-28 22:18:53 -0700
committerMisko Hevery2012-05-04 15:50:37 -0700
commite40f8d829f10de3d73aa1026591fe014fe54eca9 (patch)
tree6294e221ff5c942f34f095a0ac222463df7bedfe
parent9c0418cf1abd609bf0ffbe71fbdfa75905cf8e0f (diff)
downloadangular.js-e40f8d829f10de3d73aa1026591fe014fe54eca9.tar.bz2
chore(debug): rewrite angular-bootstrap.js to use $script
-rw-r--r--src/angular-bootstrap.js115
1 files changed, 112 insertions, 3 deletions
diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js
index 742e74f2..86b95814 100644
--- a/src/angular-bootstrap.js
+++ b/src/angular-bootstrap.js
@@ -5,7 +5,113 @@
* (c) Dustin Diaz, Jacob Thornton 2011
* License: MIT
*/
-(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});
+(function (name, definition, context) {
+ if (typeof context['module'] != 'undefined' && context['module']['exports']) context['module']['exports'] = definition()
+ else if (typeof context['define'] != 'undefined' && context['define'] == 'function' && context['define']['amd']) define(name, definition)
+ else context[name] = definition()
+})('$script', function () {
+ var doc = document
+ , head = doc.getElementsByTagName('head')[0]
+ , validBase = /^https?:\/\//
+ , list = {}, ids = {}, delay = {}, scriptpath
+ , scripts = {}, s = 'string', f = false
+ , push = 'push', domContentLoaded = 'DOMContentLoaded', readyState = 'readyState'
+ , addEventListener = 'addEventListener', onreadystatechange = 'onreadystatechange'
+
+ function every(ar, fn) {
+ for (var i = 0, j = ar.length; i < j; ++i) if (!fn(ar[i])) return f
+ return 1
+ }
+ function each(ar, fn) {
+ every(ar, function(el) {
+ return !fn(el)
+ })
+ }
+
+ if (!doc[readyState] && doc[addEventListener]) {
+ doc[addEventListener](domContentLoaded, function fn() {
+ doc.removeEventListener(domContentLoaded, fn, f)
+ doc[readyState] = 'complete'
+ }, f)
+ doc[readyState] = 'loading'
+ }
+
+ function $script(paths, idOrDone, optDone) {
+ paths = paths[push] ? paths : [paths]
+ var idOrDoneIsDone = idOrDone && idOrDone.call
+ , done = idOrDoneIsDone ? idOrDone : optDone
+ , id = idOrDoneIsDone ? paths.join('') : idOrDone
+ , queue = paths.length
+ function loopFn(item) {
+ return item.call ? item() : list[item]
+ }
+ function callback() {
+ if (!--queue) {
+ list[id] = 1
+ done && done()
+ for (var dset in delay) {
+ every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = [])
+ }
+ }
+ }
+ setTimeout(function () {
+ each(paths, function (path) {
+ if (scripts[path]) {
+ id && (ids[id] = 1)
+ return scripts[path] == 2 && callback()
+ }
+ scripts[path] = 1
+ id && (ids[id] = 1)
+ create(!validBase.test(path) && scriptpath ? scriptpath + path + '.js' : path, callback)
+ })
+ }, 0)
+ return $script
+ }
+
+ function create(path, fn) {
+ var el = doc.createElement('script')
+ , loaded = f
+ el.onload = el.onerror = el[onreadystatechange] = function () {
+ if ((el[readyState] && !(/^c|loade/.test(el[readyState]))) || loaded) return;
+ el.onload = el[onreadystatechange] = null
+ loaded = 1
+ scripts[path] = 2
+ fn()
+ }
+ el.async = 1
+ el.src = path
+ head.insertBefore(el, head.firstChild)
+ }
+
+ $script.get = create
+
+ $script.order = function (scripts, id, done) {
+ (function callback(s) {
+ s = scripts.shift()
+ if (!scripts.length) $script(s, id, done)
+ else $script(s, callback)
+ }())
+ }
+
+ $script.path = function (p) {
+ scriptpath = p
+ }
+ $script.ready = function (deps, ready, req) {
+ deps = deps[push] ? deps : [deps]
+ var missing = [];
+ !each(deps, function (dep) {
+ list[dep] || missing[push](dep);
+ }) && every(deps, function (dep) {return list[dep]}) ?
+ ready() : !function (key) {
+ delay[key] = delay[key] || []
+ delay[key][push](ready)
+ req && req(missing)
+ }(deps.join('|'))
+ return $script
+ }
+ return $script
+}, this);
+
/**
* @license AngularJS
@@ -20,6 +126,7 @@
match,
globalVars = {},
IGNORE = {
+ innerHeight: true, innerWidth: true,
onkeyup: true, onkeydown: true, onresize: true,
event: true, frames: true, external: true,
sessionStorage: true, clipboardData: true, localStorage: true};
@@ -51,9 +158,11 @@
(function next() {
if (index < scripts.length) {
- var file = scripts[index++];
+ var file = scripts[index++],
+ last = index == scripts.length,
+ name = last ? 'angular' : file;
- $script(file.replace(/\.js$/, ''), function() {
+ $script(file.replace(/\.js$/, ''), name, function() {
angularClobberTest(file);
next();
});