Skip to content

Commit 97f2a30

Browse files
author
Ted Benson
committed
porting changes
1 parent dce84f0 commit 97f2a30

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

lib/spec/dependency-spec.js

+31-8
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,65 @@ var DependencySpec = function(kind, url, loadedFrom) {
77
this.loaded = false;
88
};
99

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);
1213
if (this.loaded == false) {
1314
if (this.kind == 'css') {
1415
this.loaded = true;
1516
var link = document.createElement('link')
1617
link.setAttribute('rel', 'stylesheet');
1718
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+
}
1931
document.getElementsByTagName('head')[0].appendChild(link);
2032
} else if (this.kind == 'js') {
2133
this.loaded = true;
2234
var script = document.createElement('script')
2335
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+
}
2548
document.getElementsByTagName('head')[0].appendChild(script);
2649
} else if (this.kind == 'cts') {
2750
// Ignore
2851
} 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);
3053
}
3154
} 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);
3356
}
3457
};
3558

3659
DependencySpec.prototype.unload = function() {
3760
if (this.loaded) {
38-
this.url = Util.Net.fixRelativeUrl(this.url, this.loadedFrom);
61+
var url = Util.Net.fixRelativeUrl(this.url, this.loadedFrom);
3962
if (this.kind == 'css') {
4063
var links = document.getElementsByTagName('link');
4164
for (var i = 0; i < links.length; i++) {
4265
var link = links[i];
4366
if (typeof link.attributes != "undefined") {
4467
if (typeof link.attributes["href"] != "undefined") {
45-
if (link.attributes["href"].value == this.url) {
68+
if (link.attributes["href"].value == url) {
4669
link.parentNode.removeChild(link);
4770
this.loaded = false;
4871
}

0 commit comments

Comments
 (0)