@@ -7,42 +7,65 @@ var DependencySpec = function(kind, url, loadedFrom) {
7
7
this . loaded = false ;
8
8
} ;
9
9
10
- DependencySpec . prototype . load = function ( ) {
11
- this . url = Util . Net . fixRelativeUrl ( this . url , this . loadedFrom ) ;
10
+ DependencySpec . prototype . load = function ( cb ) {
11
+ var self = this ;
12
+ var url = Util . Net . fixRelativeUrl ( this . url , this . loadedFrom ) ;
12
13
if ( this . loaded == false ) {
13
14
if ( this . kind == 'css' ) {
14
15
this . loaded = true ;
15
16
var link = document . createElement ( 'link' )
16
17
link . setAttribute ( 'rel' , 'stylesheet' ) ;
17
18
link . setAttribute ( 'type' , 'text/css' ) ;
18
- link . setAttribute ( 'href' , this . url ) ;
19
+ link . setAttribute ( 'href' , url ) ;
20
+ if ( CTS && CTS . engine && CTS . engine . forrest ) {
21
+ CTS . engine . forrest . dependencyLoading ( self ) ;
22
+ }
23
+ link . onload = function ( ) {
24
+ if ( CTS && CTS . engine && CTS . engine . forrest ) {
25
+ CTS . engine . forrest . dependencyLoaded ( self ) ;
26
+ }
27
+ if ( typeof cb != 'undefined' ) {
28
+ cb ( self ) ;
29
+ }
30
+ }
19
31
document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( link ) ;
20
32
} else if ( this . kind == 'js' ) {
21
33
this . loaded = true ;
22
34
var script = document . createElement ( 'script' )
23
35
script . setAttribute ( 'type' , 'text/javascript' ) ;
24
- script . setAttribute ( 'src' , this . url ) ;
36
+ script . setAttribute ( 'src' , url ) ;
37
+ if ( CTS && CTS . engine && CTS . engine . forrest ) {
38
+ CTS . engine . forrest . dependencyLoading ( self ) ;
39
+ }
40
+ script . onload = function ( ) {
41
+ if ( CTS && CTS . engine && CTS . engine . forrest ) {
42
+ CTS . engine . forrest . dependencyLoaded ( self ) ;
43
+ }
44
+ if ( typeof cb != 'undefined' ) {
45
+ cb ( self ) ;
46
+ }
47
+ }
25
48
document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( script ) ;
26
49
} else if ( this . kind == 'cts' ) {
27
50
// Ignore
28
51
} else {
29
- Util . Log . Error ( "DependencySpec: Unsure how to load: " , this . kind , this . url ) ;
52
+ Util . Log . Error ( "DependencySpec: Unsure how to load: " , this . kind , url ) ;
30
53
}
31
54
} else {
32
- Util . Log . Warn ( "DependencySpec: Not loading already loaded" , this . kind , this . url ) ;
55
+ Util . Log . Warn ( "DependencySpec: Not loading already loaded" , this . kind , url ) ;
33
56
}
34
57
} ;
35
58
36
59
DependencySpec . prototype . unload = function ( ) {
37
60
if ( this . loaded ) {
38
- this . url = Util . Net . fixRelativeUrl ( this . url , this . loadedFrom ) ;
61
+ var url = Util . Net . fixRelativeUrl ( this . url , this . loadedFrom ) ;
39
62
if ( this . kind == 'css' ) {
40
63
var links = document . getElementsByTagName ( 'link' ) ;
41
64
for ( var i = 0 ; i < links . length ; i ++ ) {
42
65
var link = links [ i ] ;
43
66
if ( typeof link . attributes != "undefined" ) {
44
67
if ( typeof link . attributes [ "href" ] != "undefined" ) {
45
- if ( link . attributes [ "href" ] . value == this . url ) {
68
+ if ( link . attributes [ "href" ] . value == url ) {
46
69
link . parentNode . removeChild ( link ) ;
47
70
this . loaded = false ;
48
71
}
0 commit comments