-
Notifications
You must be signed in to change notification settings - Fork 1
/
bookmark-tool-loader.js
executable file
·57 lines (51 loc) · 1.25 KB
/
bookmark-tool-loader.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
(function() {
// loadFile('jQuery URL', 'js', function() {
// loadFile('Your Plugin', 'js', function() {
// // initialize
// });
// });
/**
* Load File
* @param {string} file file url
* @param {string} type file type (css or js)
* @param {function} handle file loaded callback
*/
function loadFile (file, type, handle) {
var head = document.getElementsByTagName('head')[0],
res;
// avoid load more times
if ( !window.loadedFiles ) {
window.loadedFiles = [];
}
for (var i = 0; i < window.loadedFiles.length; i++) {
if( file === window.loadedFiles[i] )
return;
}
window.loadedFiles.push(file);
// load res
if ( type === 'js' ) {
res = document.createElement('script');
res.src = file;
}else if ( type === 'css' ) {
res = document.createElement('link');
res.rel = 'stylesheet';
res.type = 'text/css';
res.href = file;
}
head.appendChild(res);
// callback
if (handle) {
if ( type === 'js' && document.all ) {
res.onreadystatechange = function() {
if ( res.readyState === 'loaded' || res.readyState === 'complete' ) {
handle();
}
};
} else {
res.onload = function() {
handle();
};
}
}
}
})();