aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMisko Hevery2012-04-20 13:28:58 -0700
committerMisko Hevery2012-04-20 17:04:21 -0700
commitb806b308614668c2590996a72b26b3529e909ebd (patch)
tree9dc6a43ef40fd37d2a50eb3a73e481c4b2e8270e /src
parent43d15f830f9d419c41c41f0682e47e86839e3917 (diff)
downloadangular.js-b806b308614668c2590996a72b26b3529e909ebd.tar.bz2
fix(bootstrap): rewritten to $script
Diffstat (limited to 'src')
-rw-r--r--src/angular-bootstrap.js119
1 files changed, 61 insertions, 58 deletions
diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js
index 50211416..742e74f2 100644
--- a/src/angular-bootstrap.js
+++ b/src/angular-bootstrap.js
@@ -1,4 +1,11 @@
-'use strict';
+
+/*!
+ * $script.js Async loader & dependency manager
+ * https://github.com/ded/script.js
+ * (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});
/**
* @license AngularJS
@@ -11,7 +18,11 @@
scripts = document.getElementsByTagName("SCRIPT"),
serverPath,
match,
- globalVars = {};
+ globalVars = {},
+ IGNORE = {
+ onkeyup: true, onkeydown: true, onresize: true,
+ event: true, frames: true, external: true,
+ sessionStorage: true, clipboardData: true, localStorage: true};
for(var j = 0; j < scripts.length; j++) {
match = (scripts[j].src || "").match(filename);
@@ -20,34 +31,74 @@
}
}
+ document.write('<link rel="stylesheet" type="text/css" href="' + serverPath + '../css/angular.css"/>');
+
+ $script.path(serverPath+'../');
+ $script('angularFiles', function() {
+ var index = 0,
+ scripts = angularFiles.angularSrc;
+
+ try { delete window.angularFiles; } catch(e) { window.angularFiles = undefined; }
+ // initialize the window property cache
+ for (var prop in window) {
+ if (IGNORE[prop] || prop.match(/^moz[A-Z]/)) { //skip special variables which keep on changing
+ continue;
+ }
+ try {
+ globalVars[key(prop)] = window[prop];
+ } catch(e) {} //ignore properties that throw exception when accessed (common in FF)
+ }
+
+ (function next() {
+ if (index < scripts.length) {
+ var file = scripts[index++];
+
+ $script(file.replace(/\.js$/, ''), function() {
+ angularClobberTest(file);
+ next();
+ });
+ } else {
+ // empty the cache to prevent mem leaks
+ globalVars = {};
+
+ bindJQuery();
+ publishExternalAPI(window.angular);
+
+ angularInit(document, angular.bootstrap);
+ }
+ })();
+ });
+
function key(prop) {
return "ng-clobber_" + prop;
}
- window.angularClobberTest = function(file) {
+ function angularClobberTest(file) {
var varKey, prop,
- clobbered = [];
+ clobbered = {};
for (prop in window) {
varKey = key(prop);
- if (prop === 'event') { //skip special variables which keep on changing
+ if (IGNORE[prop] || prop.match(/^moz[A-Z]/)) { //skip special variables which keep on changing
continue;
- }
- else if (!globalVars.hasOwnProperty(varKey)) {
+ } else if (!globalVars.hasOwnProperty(varKey)) {
//console.log('new global variable found: ', prop);
try {
globalVars[varKey] = window[prop];
} catch(e) {} //ignore properties that throw exception when accessed (common in FF)
} else if (globalVars[varKey] !== window[prop] && !isActuallyNaN(window[prop]) && prop != 'jqLite') {
- clobbered.push(prop);
+ clobbered[prop] = true;
console.error("Global variable clobbered by script " + file + "! Variable name: " + prop);
globalVars[varKey] = window[prop];
}
}
for (varKey in globalVars) {
prop = varKey.substr(11);
- if (clobbered.indexOf(prop) == -1 &&
+ if (prop === 'event' || prop.match(/^moz[A-Z]/)) { //skip special variables which keep on changing
+ continue;
+ }
+ if (!clobbered[prop] &&
prop != 'event' &&
prop != 'jqLite' &&
!isActuallyNaN(globalVars[varKey]) &&
@@ -60,56 +111,8 @@
}
function isActuallyNaN(val) {
- return isNaN(val) && (typeof val === 'number');
- }
- };
-
- window.addScripts = function(scripts) {
- delete window.addScripts;
- delete window.angularFiles;
-
- var prop, i;
-
- // initialize the window property cache
- for (prop in window) {
- try {
- globalVars[key(prop)] = window[prop];
- } catch(e) {} //ignore properties that throw exception when accessed (common in FF)
- }
-
- // load the js scripts
- for (i in scripts) {
- var file = scripts[i].replace(/src\//, '');
- document.write('<script type="text/javascript" src="' + serverPath + file + '" ' +
- 'onload="angularClobberTest(\'' + file + '\')"></script>');
+ return (typeof val === 'number') && isNaN(val);
}
};
-
- function addCss(file) {
- document.write('<link rel="stylesheet" type="text/css" href="' +
- serverPath + '../css/' + file + '"/>');
- }
-
- addCss('angular.css');
-
- document.write('<script type="text/javascript" src="' + serverPath + '../angularFiles.js' + '" ' +
- 'onload="addScripts(angularFiles.angularSrc)"></script>');
-
- function onLoadListener() {
- // empty the cache to prevent mem leaks
- globalVars = {};
-
- bindJQuery();
- publishExternalAPI(window.angular);
-
- angularInit(document, angular.bootstrap);
- }
-
- if (window.addEventListener) {
- window.addEventListener('load', onLoadListener, false);
- } else if (window.attachEvent) {
- window.attachEvent('onload', onLoadListener);
- }
-
})(window, document);