-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
71 lines (65 loc) · 2.31 KB
/
code.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function code(){
//Replacing document.getElementById with $
function $(x){
if (typeof x == "string") return document.getElementById(x);
return x;
}
function interface() {
var container = $('container');
container.innerHTML="<div id=\"placeHolder\">Welcome! This is Ken\'s toolbox. Useful or not, this is fun!</div>";
}
// Load JS files on demand with loadJS
function loadJS(obj, callback) {
var arr = obj,
timeout,
str = typeof obj === 'string';
function add() {
var script = document.createElement("script");
header = document.getElementsByTagName("head")[0];
script.src = str ? obj : arr[0];
script.type = "text/javascript";
if (str) {
if (script.readyState) {
script.onreadystatechange = function() {
if (script.readyState === 'loaded' || script.readyState === 'complete') {
script.onreadystatechange = null;
callback && callback();
}
};
} else {
script.onload = function() {
callback && callback();
};
}
} else {
if (arr.length >= 1) {
if (script.readyState) {
script.onreadystatechange = function() {
if (script.readyState === 'loaded' || script.readyState === 'complete') {
script.onreadystatechange = null;
arr.shift();
timeout = setTimeout(add, 1);
}
};
} else {
script.onload = function() {
arr.shift();
timeout = setTimeout(add, 1);
};
}
} else {
clearTimeout(timeout);
callback && callback();
}
}
header.appendChild(script);
}
add();
}
interface();
$('container').children[0].onclick = function(){loadJS('./module/cool18.js');};
$('button_cool18').onclick = function(){loadJS('./module/cool18.js');};
}
window.onload = function(){
code();
};