-
Notifications
You must be signed in to change notification settings - Fork 0
/
bwf.compile.js
54 lines (51 loc) · 1.38 KB
/
bwf.compile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Load all automatically
(function() {
/**
* Load file from an url and returns a string with its content
* @param url: the url to fetch data.
*/
load = function(url) {
var xhr;
if(window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if(window.ActiveXObject) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
} else {
return false;
}
xhr.open('GET', url, false);
if(xhr.overrideMimeType) {
xhr.overrideMimeType('text/plain');
}
xhr.send(null);
if(xhr.status == 200) {
return xhr.responseText;
}
return false;
}
/**
* Compiles the text/bwf scripts and add to page
*/
compile = function() {
var script = document.getElementsByTagName('script');
var i, src = [], elem;
for(i = 0; i < script.length; i++) {
if(script[i].type == 'text/beowulf') {
if(script[i].src) {
src.push(load(script[i].src));
} else {
src.push(script[i].innerHTML);
}
}
}
if(src.length == 0) {
return;
}
// add classes to scope
src.forEach(function(s) {
new Bwf().create(s);
});
}
// compile
compile();
})();