Permalink
Browse files

Allow multiple names for one script. This accommodates the concatenat…

…ion of scripts that provide different dependencies without changing the names referenced by the dependent functions.
  • Loading branch information...
skeltoac committed Dec 1, 2010
1 parent 2ffc66c commit ac48f31d1630c817973a194f2190929d3e7ddf0b
Showing with 32 additions and 6 deletions.
  1. +18 −6 src/head.loader.js
  2. +3 −0 test/ab.js
  3. +11 −0 test/names.html
View
@@ -73,11 +73,21 @@
if (script) return script;
if (typeof url == 'object') {
- for (var key in url) {
- script = { name: key, url: url[key] };
+ if ( url.length > 1 ) {
+ script = { names: [] };
+ for (var key in url) {
+ if ( script.names.length == url.length - 1 )
+ script.url = url[key];
+ else
+ script.names.push(url[key]);
+ }
+ } else {
+ for (var key in url) {
+ script = { names: [ key ], url: url[key] };
+ }
}
} else {
- script = { name: url.substring(url.indexOf("/", 10) + 1, url.indexOf("?")), url: url };
+ script = { names: [ url.substring(url.indexOf("/", 10) + 1, url.indexOf("?")) ], url: url };
}
scripts[script.url] = script;
@@ -176,9 +186,11 @@
//* console.info(" LOADED", script.name);
// waiters for this script
- each(waiters[script.name], function(fn) {
- fn.call();
- });
+ for (var name in script.names) {
+ each(waiters[ script.names[name] ], function(fn) {
+ fn.call();
+ });
+ }
// TODO: do not run until DOM is loaded
var allLoaded = true;
View
@@ -0,0 +1,3 @@
+a=1;
+b=2;
+console.log("loaded ab.js");
View
@@ -0,0 +1,11 @@
+<!doctype html>
+<head>
+<script src="../src/head.loader.js"></script>
+<script>
+head.ready("a", function(){console.log("a ready "+a);});
+head.ready("b", function(){console.log("b ready "+b);});
+head.js(["a", "b", "ab.js"]);
+</script>
+</head>
+<body>
+</body>

0 comments on commit ac48f31

Please sign in to comment.