Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit b806b30

Browse files
committed
fix(bootstrap): rewritten to $script
1 parent 43d15f8 commit b806b30

File tree

1 file changed

+61
-58
lines changed

1 file changed

+61
-58
lines changed

src/angular-bootstrap.js

+61-58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
'use strict';
1+
2+
/*!
3+
* $script.js Async loader & dependency manager
4+
* https://github.com/ded/script.js
5+
* (c) Dustin Diaz, Jacob Thornton 2011
6+
* License: MIT
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});
29

310
/**
411
* @license AngularJS
@@ -11,7 +18,11 @@
1118
scripts = document.getElementsByTagName("SCRIPT"),
1219
serverPath,
1320
match,
14-
globalVars = {};
21+
globalVars = {},
22+
IGNORE = {
23+
onkeyup: true, onkeydown: true, onresize: true,
24+
event: true, frames: true, external: true,
25+
sessionStorage: true, clipboardData: true, localStorage: true};
1526

1627
for(var j = 0; j < scripts.length; j++) {
1728
match = (scripts[j].src || "").match(filename);
@@ -20,34 +31,74 @@
2031
}
2132
}
2233

34+
document.write('<link rel="stylesheet" type="text/css" href="' + serverPath + '../css/angular.css"/>');
35+
36+
$script.path(serverPath+'../');
37+
$script('angularFiles', function() {
38+
var index = 0,
39+
scripts = angularFiles.angularSrc;
40+
41+
try { delete window.angularFiles; } catch(e) { window.angularFiles = undefined; }
42+
// initialize the window property cache
43+
for (var prop in window) {
44+
if (IGNORE[prop] || prop.match(/^moz[A-Z]/)) { //skip special variables which keep on changing
45+
continue;
46+
}
47+
try {
48+
globalVars[key(prop)] = window[prop];
49+
} catch(e) {} //ignore properties that throw exception when accessed (common in FF)
50+
}
51+
52+
(function next() {
53+
if (index < scripts.length) {
54+
var file = scripts[index++];
55+
56+
$script(file.replace(/\.js$/, ''), function() {
57+
angularClobberTest(file);
58+
next();
59+
});
60+
} else {
61+
// empty the cache to prevent mem leaks
62+
globalVars = {};
63+
64+
bindJQuery();
65+
publishExternalAPI(window.angular);
66+
67+
angularInit(document, angular.bootstrap);
68+
}
69+
})();
70+
});
71+
2372
function key(prop) {
2473
return "ng-clobber_" + prop;
2574
}
2675

27-
window.angularClobberTest = function(file) {
76+
function angularClobberTest(file) {
2877
var varKey, prop,
29-
clobbered = [];
78+
clobbered = {};
3079

3180
for (prop in window) {
3281
varKey = key(prop);
3382

34-
if (prop === 'event') { //skip special variables which keep on changing
83+
if (IGNORE[prop] || prop.match(/^moz[A-Z]/)) { //skip special variables which keep on changing
3584
continue;
36-
}
37-
else if (!globalVars.hasOwnProperty(varKey)) {
85+
} else if (!globalVars.hasOwnProperty(varKey)) {
3886
//console.log('new global variable found: ', prop);
3987
try {
4088
globalVars[varKey] = window[prop];
4189
} catch(e) {} //ignore properties that throw exception when accessed (common in FF)
4290
} else if (globalVars[varKey] !== window[prop] && !isActuallyNaN(window[prop]) && prop != 'jqLite') {
43-
clobbered.push(prop);
91+
clobbered[prop] = true;
4492
console.error("Global variable clobbered by script " + file + "! Variable name: " + prop);
4593
globalVars[varKey] = window[prop];
4694
}
4795
}
4896
for (varKey in globalVars) {
4997
prop = varKey.substr(11);
50-
if (clobbered.indexOf(prop) == -1 &&
98+
if (prop === 'event' || prop.match(/^moz[A-Z]/)) { //skip special variables which keep on changing
99+
continue;
100+
}
101+
if (!clobbered[prop] &&
51102
prop != 'event' &&
52103
prop != 'jqLite' &&
53104
!isActuallyNaN(globalVars[varKey]) &&
@@ -60,56 +111,8 @@
60111
}
61112

62113
function isActuallyNaN(val) {
63-
return isNaN(val) && (typeof val === 'number');
64-
}
65-
};
66-
67-
window.addScripts = function(scripts) {
68-
delete window.addScripts;
69-
delete window.angularFiles;
70-
71-
var prop, i;
72-
73-
// initialize the window property cache
74-
for (prop in window) {
75-
try {
76-
globalVars[key(prop)] = window[prop];
77-
} catch(e) {} //ignore properties that throw exception when accessed (common in FF)
78-
}
79-
80-
// load the js scripts
81-
for (i in scripts) {
82-
var file = scripts[i].replace(/src\//, '');
83-
document.write('<script type="text/javascript" src="' + serverPath + file + '" ' +
84-
'onload="angularClobberTest(\'' + file + '\')"></script>');
114+
return (typeof val === 'number') && isNaN(val);
85115
}
86116
};
87-
88-
function addCss(file) {
89-
document.write('<link rel="stylesheet" type="text/css" href="' +
90-
serverPath + '../css/' + file + '"/>');
91-
}
92-
93-
addCss('angular.css');
94-
95-
document.write('<script type="text/javascript" src="' + serverPath + '../angularFiles.js' + '" ' +
96-
'onload="addScripts(angularFiles.angularSrc)"></script>');
97-
98-
function onLoadListener() {
99-
// empty the cache to prevent mem leaks
100-
globalVars = {};
101-
102-
bindJQuery();
103-
publishExternalAPI(window.angular);
104-
105-
angularInit(document, angular.bootstrap);
106-
}
107-
108-
if (window.addEventListener) {
109-
window.addEventListener('load', onLoadListener, false);
110-
} else if (window.attachEvent) {
111-
window.attachEvent('onload', onLoadListener);
112-
}
113-
114117
})(window, document);
115118

0 commit comments

Comments
 (0)