This repository has been archived by the owner on Feb 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtinymce.gzip.js
188 lines (147 loc) · 3.93 KB
/
tinymce.gzip.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
(function() {
var tinymce, loaded = {}, urls = [], callbacks = [], loading, realInit;
function loadScript(url, callback) {
var elm, head = document.getElementsByTagName('head')[0] || document.body;
// Execute callback when script is loaded
function done() {
elm.parentNode.removeChild(elm);
if (elm) {
elm.onreadystatechange = elm.onload = elm = null;
}
callback();
}
function error() {
// Report the error so it's easier for people to spot loading errors
if (typeof(console) !== "undefined" && console.log) {
console.log("Failed to load: " + url);
}
}
// Create new script element
elm = document.createElement('script');
elm.type = 'text/javascript';
// Use modern onload event when it's available
if ("onload" in elm) {
elm.onload = done;
head.appendChild(elm);
// Add src after appending it to the document seems to work better on IE 10
elm.src = url;
} else {
elm.onreadystatechange = function() {
if (elm.src && /loaded|complete/.test(elm.readyState)) {
done();
}
};
elm.src = url;
head.appendChild(elm);
}
elm.onerror = error;
}
function buildUrl(themes, plugins, languages) {
var url = '';
function getQueryPart(type, items) {
if (items) {
for (var i = items.length - 1; i >= 0; i--) {
if (loaded[type + '_' + items[i]]) {
items.splice(i, 1);
} else {
loaded[type + '_' + items[i]] = true;
}
}
if (items.length) {
return '&' + type + 's=' + items.join(',');
}
}
return '';
}
url += getQueryPart("plugin", plugins);
url += getQueryPart("theme", themes);
url += getQueryPart("language", languages);
if (url) {
if (loaded.core) {
url += '&core=false';
} else {
loaded.core = true;
}
url = tinymce.baseURL + '/tinymce.gzip.php?js=true' + url;
}
return url;
}
function splitValue(value) {
if (typeof(value) == "string") {
return value.split(/[, ]/);
}
var items = [];
if (value) {
for (var i = 0; i < value.length; i++) {
items = items.concat(splitValue(value[i]));
}
}
return items;
}
function loadNext() {
var url = urls.shift();
if (!url) {
for (var i = 0; i < callbacks.length; i++) {
callbacks[i]();
}
callbacks = [];
loading = false;
} else {
loadScript(url, loadNext);
}
}
function init(settings) {
var themes = [], plugins = [], languages = [];
themes.push(settings.theme || 'modern');
var pluginList = splitValue(settings.plugins);
for (var i = 0; i < pluginList.length; i++) {
plugins.push(pluginList[i]);
}
if (settings.language) {
languages.push(settings.language);
}
urls.push(buildUrl(themes, plugins, languages));
callbacks.push(function() {
if (/complete|interactive/.test(document.readyState)) {
window.tinymce.dom.Event.domLoaded = true;
}
if (window.tinymce.init != init) {
realInit = window.tinymce.init;
window.tinymce.init = init;
}
realInit.call(window.tinymce, settings);
});
if (!loading) {
loading = true;
loadNext();
}
}
function getBaseUrl() {
var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
var src = scripts[i].src;
if (src.indexOf('tinymce.gzip.js') != -1) {
return src.substring(0, src.lastIndexOf('/'));
}
}
}
tinymce = {
init: init,
baseURL: getBaseUrl(),
suffix: ".min"
};
window.tinyMCE_GZ = {
init: function(settings, callback) {
urls.push(buildUrl(splitValue(settings.themes), splitValue(settings.plugins), splitValue(settings.languages)));
callbacks.push(function() {
window.tinymce.dom.Event.domLoaded = 1;
callback();
});
if (!loading) {
loading = true;
loadNext();
}
}
};
window.tinymce = window.tinyMCE = tinymce;
})();