forked from szabyg/vie-annotation-bookmarklet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.js
executable file
·102 lines (91 loc) · 3.83 KB
/
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
(function(){
// Load the script from url and when it's ready loading run the callback.
function loadScript(url, callback) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = url;
// Attach handlers for all browsers
var done = false;
script.onload = script.onreadystatechange = function()
{
if( !done && ( !this.readyState
|| this.readyState == "loaded"
|| this.readyState == "complete") )
{
done = true;
// Continue your code
callback();
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
head.removeChild( script );
}
};
head.appendChild(script);
}
// Load a list of scripts *one after the other* and run cb
var loadScripts = function(scripts, cb) {
var script, _i, _len, _results;
if(scripts.length) {
script = scripts.shift();
loadScript(script, function(){
loadScripts(scripts.slice(0), cb);
});
} else {
console.info("all scripts loaded.");
if (cb) cb();
}
};
var loadStyles = function(csss) {
var css, _i, _len, _results;
for (_i = 0, _len = csss.length; _i < _len; _i++) {
css = csss[_i];
var e = document.createElement('link');
e.setAttribute('rel','stylesheet');
e.setAttribute('href', css);document.head.appendChild(e);
}
};
function noCache(){
return Math.random().toString().substring(2);
}
var appRoot = window.bookmarkletConfig.appRoot;
// Loading style definitions
loadStyles([
appRoot + "annotate.css",
appRoot + "annotate.js/lib/jquery/jquery-ui.min.css",
appRoot + "annotate.js/lib/Smoothness/jquery.ui.all.css",
appRoot + "vie-widgets/jquery.anythingslider/anythingslider.css",
appRoot + "vie-widgets/jquery.anythingslider/theme-polished.css",
appRoot + "vie-widgets/jquery.fancybox/jquery.fancybox-1.3.4.css",
appRoot + "vie-widgets/widgets.css"
]);
// Loading the scripts
loadScripts([
appRoot + "annotate.js/lib/jquery/jquery-1.7.1.js",
appRoot + "annotate.js/lib/jquery-ui.1.9m5.js",
appRoot + "annotate.js/lib/underscore-min.js",
appRoot + "annotate.js/lib/backbone-min.js",
appRoot + "annotate.js/lib/hallo/hallo.js",
appRoot + "annotate.js/lib/hallo/format.js",
// TODO switch back as soon https://github.com/bergie/VIE/pull/91 is approved
// appRoot + "annotate.js/lib/jquery.rdfquery.debug.js",
appRoot + "jquery.rdfquery.debug.js?",
appRoot + "annotate.js/lib/vie/vie-latest.debug.js?" + noCache(),
appRoot + "annotate.js/lib/annotate.js?",
appRoot + "vie-widgets/vie.widget.image_search.js?",
appRoot + "vie-widgets/schemaOrg/schema.json?",
appRoot + "vie-widgets/schemaOrg/wrapper.js?",
appRoot + "vie-widgets/jquery.anythingslider/jquery.anythingslider.min.js?",
// appRoot + "vie-widgets/jquery.anythingslider/jquery.anythingslider.video.js?",
// appRoot + "vie-widgets/jquery.anythingslider/swfobject.js?",
appRoot + "vie-widgets/jquery.fancybox/jquery.fancybox-1.3.4.pack.js?",
appRoot + "vie-widgets/jquery.fancybox/jquery.mousewheel-3.0.4.pack.js?",
appRoot + "vie-widgets/jquery.fancybox/jquery.easing-1.3.pack.js?",
appRoot + "activate.js?",
appRoot + "imagesearch.js?"
]);
// Show spinner
var e = document.createElement("div");
e.setAttribute("class", "loadingDiv");
e.innerHTML = "<img src='" + appRoot + "spinner.gif'/>";
document.body.appendChild(e);
})();