-
Notifications
You must be signed in to change notification settings - Fork 4
/
Viper-all.js
132 lines (114 loc) · 5.01 KB
/
Viper-all.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* +--------------------------------------------------------------------+
* | This Squiz Viper file is Copyright (c) Squiz Australia Pty Ltd |
* | ABN 53 131 581 247 |
* +--------------------------------------------------------------------+
* | IMPORTANT: Your use of this Software is subject to the terms of |
* | the Licence provided in the file licence.txt. If you cannot find |
* | this file please contact Squiz (www.squiz.com.au) so we may |
* | provide you a copy. |
* +--------------------------------------------------------------------+
*
*/
(function() {
var scripts = document.getElementsByTagName('script');
var path = null;
// Loop through all the script tags that exist in the document and find the one
// that has included this file.
var scriptsLen = scripts.length;
for (var i = 0; i < scriptsLen; i++) {
if (scripts[i].src) {
if (scripts[i].src.match(/Viper-all\.js.*/)) {
path = scripts[i].src.replace(/Viper-all\.js.*/,'');
break;
}
}
}
var _loadScript = function(path, scriptName, callback, scriptNameAsPath) {
var script = document.createElement('script');
if (navigator.appName == 'Microsoft Internet Explorer') {
var rv = -1;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(navigator.userAgent) != null) {
rv = parseFloat(RegExp.$1);
}
if (rv <= 8.0) {
script.onreadystatechange = function() {
if (/^(loaded|complete)$/.test(this.readyState) === true) {
callback.call(window);
}
};
}
}//end if
script.onload = function() {
callback.call(window);
};
if (scriptNameAsPath === true) {
script.src = path + scriptName + '/' + scriptName + '.js';
} else {
script.src = path + scriptName;
}
if (window.ViperVersion) {
script.src += '?v=' + ViperVersion;
}
if (document.head) {
document.head.appendChild(script);
} else {
document.getElementsByTagName('head')[0].appendChild(script);
}
};
var _loadScripts = function(path, scripts, callback, scriptNameAsPath) {
if (scripts.length === 0) {
callback.call(window);
return;
}
var script = scripts.shift();
_loadScript(path, script, function() {
_loadScripts(path, scripts, callback, scriptNameAsPath);
}, scriptNameAsPath);
};
// Viper core files.
var jsFiles = 'Viper.js|Util.js|Translation.js|Tools.js|Selection.js|DOMRange.js|IERange.js|MozRange.js|PluginManager.js|HistoryManager.js|KeyboardHandler.js';
jsFiles = jsFiles.split('|');
_loadScripts(path + 'Lib/', jsFiles, function() {
var plugins = 'ViperCopyPastePlugin|ViperToolbarPlugin|ViperInlineToolbarPlugin|ViperCoreStylesPlugin|ViperFormatPlugin|ViperListPlugin|ViperHistoryPlugin|ViperTableEditorPlugin|ViperLinkPlugin|ViperAccessibilityPlugin|ViperSourceViewPlugin|ViperImagePlugin|ViperSearchReplacePlugin|ViperLangToolsPlugin|ViperCharMapPlugin|ViperCursorAssistPlugin|ViperReplacementPlugin';
plugins = plugins.split('|');
_loadScripts(path + 'Plugins/', plugins.concat([]), function() {
if (window.ViperReadyCallback) {
window.ViperReadyCallback.call(window);
} else {
var maxTry = 10;
var interval = setInterval(function() {
maxTry--;
if (window.ViperReadyCallback) {
window.ViperReadyCallback.call(window);
clearInterval(interval);
} else if (maxTry === 0) {
clearInterval(interval);
}
}, 500);
}
}, true);
var coreCSS = 'viper|viper_moz'.split('|');
for (var j = 0; j < coreCSS.length; j++) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.media = 'screen';
link.href = path + 'Css/' + coreCSS[j] + '.css';
if (window.ViperVersion) {
link.href += '?v=' + window.ViperVersion;
}
document.getElementsByTagName('head')[0].appendChild(link);
}
for (var j = 0; j < plugins.length; j++) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.media = 'screen';
link.href = path + 'Plugins/' + plugins[j] + '/' + plugins[j] + '.css';
if (window.ViperVersion) {
link.href += '?v=' + window.ViperVersion;
}
document.getElementsByTagName('head')[0].appendChild(link);
}
});
}) ();