Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit d1b4764

Browse files
committed
add manual resolve api for further script combination
1 parent 252e49d commit d1b4764

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

js.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$js - asynchronous module definition framework
33
or just simple lightweight javascript dependencies manager
44
5-
@version 4.6
5+
@version 4.7
66
@link http://github.com/redcatphp/js/
77
@author Jo Surikat <jo@surikat.pro>
88
@website http://redcatphp.com
@@ -75,10 +75,7 @@
7575
var relative = u.indexOf('//')<0&&u.substr(0,2)!='./';
7676
return ($js.cdn&&relative?$js.cdn:'')+(u.indexOf('/')!==0?($js.path&&relative&&(!$js.pathDetection||u.indexOf($js.path)!=0)?($js.path+u):u)+($js.pathSuffix&&relative&&(!$js.pathDetection||u.substr(u.length-$js.pathSuffix.length)!=$js.pathSuffix)?$js.pathSuffix:''):u);
7777
};
78-
var createScript = function(u){
79-
var s = d.createElement('script');
80-
d.type = 'text/javascript';
81-
d.body.appendChild(s);
78+
var makeSrcCallback = function(u){
8279
var realcallback = function(){
8380
var shift = $js.modulesStack.shift();
8481
if(shift)
@@ -97,11 +94,30 @@
9794
realcallback();
9895
}
9996
};
97+
return callback;
98+
};
99+
var createScript = function(u){
100+
var callback = makeSrcCallback(u);
101+
var s = d.createElement('script');
102+
d.type = 'text/javascript';
103+
d.body.appendChild(s);
100104
s.onload = callback;
101105
s.onreadystatechange = function(){if(callback&&this.readyState==='loaded'){callback();}}; //old browsers
102106
s.setAttribute('async','async');
103107
s.src = cacheFix(u,$js.dev,$js.min,'js',$js.cdn);
104108
};
109+
var resolve = function(u, c){
110+
if(typeof(c)=='function') c();
111+
u = getSrc(u);
112+
if(!requiring[u]){
113+
requiring[u] = [];
114+
makeSrcCallback(u)();
115+
}
116+
if(handled.indexOf(u)>-1)
117+
handle(u);
118+
else if(required.indexOf(u)>-1)
119+
wait(u);
120+
};
105121
var x = function(u,c){
106122
if(!u){
107123
if(typeof(c)=='function')
@@ -772,6 +788,7 @@
772788
}
773789
};
774790
};
791+
js.resolve = resolve;
775792
return js;
776793
})();
777794

0 commit comments

Comments
 (0)