Permalink
Browse files

added client-side .ready()

  • Loading branch information...
1 parent 41f41b0 commit 2ef69339294827e21de4afe665435df64c25ea42 @khrome khrome committed Jun 10, 2013
Showing with 19 additions and 1 deletion.
  1. +1 −1 package.json
  2. +18 −0 protolus-resource.js
View
@@ -1,7 +1,7 @@
{
"name": "protolus-resource",
"homepage": "https://github.com/Protolus/protolus-resource",
- "version": "0.0.9-alpha",
+ "version": "0.0.10-alpha",
"main": "protolus-resource.js",
"description": "a CommonJS based server-side resource delivery mechanism with client side shim",
"keywords": [
View
@@ -21,7 +21,9 @@ var Client = function(options){
Protolus.packages = ['mootools-core','protolus'];
Protolus.loaded = {};
Protolus.scripts = {};
+ Protolus.waiting = [];
}
+
};
Client.require = function(moduleName, callback){
a = {};
@@ -55,6 +57,19 @@ Client.require = function(moduleName, callback){
};
}
};
+Client.ready = function(callback){
+ if(callback === true){
+ var waiting = Protolus.waiting;
+ Protolus.waiting = [];
+ waiting.forEach(function(cb){
+ cb();
+ });
+ Protolus.loadComplete = true;
+ return;
+ }
+ if(Protolus.loadComplete) callback();
+ Protolus.waiting.push(callback);
+}
Client.register = function(name, source){
if(!Protolus.loaded) Protolus();
if(name && source){
@@ -85,6 +100,7 @@ var Resource = new Class({
'var Protolus = '+(Client.toString())+';',
'Protolus.require = '+(Client.require.toString())+';',
'Protolus.register = '+(Client.register.toString())+';',
+ 'Protolus.ready = '+(Client.ready.toString())+';',
'window.onload = Protolus;'
].join("\n")]);
}else callback([]);
@@ -295,6 +311,7 @@ Resource.head = function(options, callback){ //get head
tags.push('<'+tagInfo.name+' '+assembleAttrs(tagInfo.attrs, tagInfo.target, '/'+type+compact+dependencies+'/'+resList.join('.'))+'></'+tagInfo.name+'>');
});
}
+ tags.push('<script>Protolus.ready(true);</script>');
if(callback) callback(tags);
}
};
@@ -334,6 +351,7 @@ Resource.handle = function(request, response, passthru){
'var Protolus = '+(Client.toString())+';',
'Protolus.require = '+(Client.require.toString())+';',
'Protolus.register = '+(Client.register.toString())+';',
+ 'Protolus.ready = '+(Client.ready.toString())+';',
'window.onload = Protolus;'
].join("\n"));
wasResourceRequest = true;

0 comments on commit 2ef6933

Please sign in to comment.