author | Dan |
Fri, 17 Jul 2009 20:23:48 -0400 | |
changeset 1066 | bead71f28f63 |
parent 582 | a38876c0793c |
permissions | -rw-r--r-- |
551 | 1 |
var tinyMCE_GZ = { |
2 |
settings : { |
|
3 |
themes : '', |
|
4 |
plugins : '', |
|
5 |
languages : '', |
|
6 |
disk_cache : true, |
|
7 |
page_name : 'tiny_mce_gzip.php', |
|
8 |
debug : false, |
|
9 |
suffix : '' |
|
10 |
}, |
|
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
551
diff
changeset
|
11 |
|
551 | 12 |
init : function(s, cb, sc) { |
13 |
var t = this, n, i, nl = document.getElementsByTagName('script'); |
|
14 |
||
15 |
for (n in s) |
|
16 |
t.settings[n] = s[n]; |
|
17 |
||
18 |
s = t.settings; |
|
19 |
||
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
551
diff
changeset
|
20 |
t.baseURL = scriptPath + '/includes/clientside/tinymce'; |
551 | 21 |
|
22 |
if (!t.coreLoaded) |
|
23 |
t.loadScripts(1, s.themes, s.plugins, s.languages, cb, sc); |
|
24 |
}, |
|
25 |
||
26 |
loadScripts : function(co, th, pl, la, cb, sc) { |
|
27 |
var t = this, x, w = window, q, c = 0, ti, s = t.settings; |
|
28 |
||
29 |
function get(s) { |
|
30 |
x = 0; |
|
31 |
||
32 |
try { |
|
33 |
x = new ActiveXObject(s); |
|
34 |
} catch (s) { |
|
35 |
} |
|
36 |
||
37 |
return x; |
|
38 |
}; |
|
39 |
||
40 |
// Build query string |
|
41 |
q = 'js=true&diskcache=' + (s.disk_cache ? 'true' : 'false') + '&core=' + (co ? 'true' : 'false') + '&suffix=' + escape(s.suffix) + '&themes=' + escape(th) + '&plugins=' + escape(pl) + '&languages=' + escape(la); |
|
42 |
||
43 |
if (co) |
|
44 |
t.coreLoaded = 1; |
|
45 |
||
46 |
// Send request |
|
47 |
x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Msxml2.XMLHTTP') || get('Microsoft.XMLHTTP'); |
|
48 |
x.overrideMimeType && x.overrideMimeType('text/javascript'); |
|
49 |
x.open('GET', t.baseURL + '/' + s.page_name + '?' + q, !!cb); |
|
50 |
// x.setRequestHeader('Content-Type', 'text/javascript'); |
|
51 |
x.send(''); |
|
52 |
||
53 |
// Handle asyncronous loading |
|
54 |
if (cb) { |
|
55 |
// Wait for response |
|
56 |
ti = w.setInterval(function() { |
|
57 |
if (x.readyState == 4 || c++ > 10000) { |
|
58 |
w.clearInterval(ti); |
|
59 |
||
60 |
if (c < 10000 && x.status == 200) { |
|
61 |
t.loaded = 1; |
|
62 |
t.eval(x.responseText); |
|
63 |
tinymce.dom.Event.domLoaded = true; |
|
64 |
cb.call(sc || t, x); |
|
65 |
} |
|
66 |
||
67 |
ti = x = null; |
|
68 |
} |
|
69 |
}, 10); |
|
70 |
} else |
|
71 |
t.eval(x.responseText); |
|
72 |
}, |
|
73 |
||
74 |
start : function() { |
|
75 |
var t = this, each = tinymce.each, s = t.settings, sl, ln = s.languages.split(','); |
|
76 |
||
77 |
tinymce.suffix = s.suffix; |
|
78 |
||
79 |
// Extend script loader |
|
80 |
tinymce.create('tinymce.compressor.ScriptLoader:tinymce.dom.ScriptLoader', { |
|
81 |
loadScripts : function(sc, cb, s) { |
|
82 |
var ti = this, th = [], pl = [], la = []; |
|
83 |
||
84 |
each(sc, function(o) { |
|
85 |
var u = o.url; |
|
86 |
||
87 |
if ((!ti.lookup[u] || ti.lookup[u].state != 2) && u.indexOf(t.baseURL) === 0) { |
|
88 |
// Collect theme |
|
89 |
if (u.indexOf('editor_template') != -1) { |
|
90 |
th.push(/\/themes\/([^\/]+)/.exec(u)[1]); |
|
91 |
load(u, 1); |
|
92 |
} |
|
93 |
||
94 |
// Collect plugin |
|
95 |
if (u.indexOf('editor_plugin') != -1) { |
|
96 |
pl.push(/\/plugins\/([^\/]+)/.exec(u)[1]); |
|
97 |
load(u, 1); |
|
98 |
} |
|
99 |
||
100 |
// Collect language |
|
101 |
if (u.indexOf('/langs/') != -1) { |
|
102 |
la.push(/\/langs\/([^.]+)/.exec(u)[1]); |
|
103 |
load(u, 1); |
|
104 |
} |
|
105 |
} |
|
106 |
}); |
|
107 |
||
108 |
if (th.length + pl.length + la.length > 0) { |
|
109 |
if (sl.settings.strict_mode) { |
|
110 |
// Async |
|
111 |
t.loadScripts(0, th.join(','), pl.join(','), la.join(','), cb, s); |
|
112 |
return; |
|
113 |
} else |
|
114 |
t.loadScripts(0, th.join(','), pl.join(','), la.join(','), cb, s); |
|
115 |
} |
|
116 |
||
117 |
return ti.parent(sc, cb, s); |
|
118 |
} |
|
119 |
}); |
|
120 |
||
121 |
sl = tinymce.ScriptLoader = new tinymce.compressor.ScriptLoader(); |
|
122 |
||
123 |
function load(u, sp) { |
|
124 |
var o; |
|
125 |
||
126 |
if (!sp) |
|
127 |
u = t.baseURL + u; |
|
128 |
||
129 |
o = {url : u, state : 2}; |
|
130 |
sl.queue.push(o); |
|
131 |
sl.lookup[o.url] = o; |
|
132 |
}; |
|
133 |
||
134 |
// Add core languages |
|
135 |
each (ln, function(c) { |
|
136 |
if (c) |
|
137 |
load('/langs/' + c + '.js'); |
|
138 |
}); |
|
139 |
||
140 |
// Add themes with languages |
|
141 |
each(s.themes.split(','), function(n) { |
|
142 |
if (n) { |
|
143 |
load('/themes/' + n + '/editor_template' + s.suffix + '.js'); |
|
144 |
||
145 |
each (ln, function(c) { |
|
146 |
if (c) |
|
147 |
load('/themes/' + n + '/langs/' + c + '.js'); |
|
148 |
}); |
|
149 |
} |
|
150 |
}); |
|
151 |
||
152 |
// Add plugins with languages |
|
153 |
each(s.plugins.split(','), function(n) { |
|
154 |
if (n) { |
|
155 |
load('/plugins/' + n + '/editor_plugin' + s.suffix + '.js'); |
|
156 |
||
157 |
each (ln, function(c) { |
|
158 |
if (c) |
|
159 |
load('/plugins/' + n + '/langs/' + c + '.js'); |
|
160 |
}); |
|
161 |
} |
|
162 |
}); |
|
163 |
}, |
|
164 |
||
165 |
end : function() { |
|
166 |
}, |
|
167 |
||
168 |
eval : function(co) { |
|
169 |
var w = window; |
|
170 |
||
171 |
// Evaluate script |
|
172 |
if (!w.execScript) { |
|
173 |
if (/Gecko/.test(navigator.userAgent)) |
|
174 |
eval(co, w); // Firefox 3.0 |
|
175 |
else |
|
176 |
eval.call(w, co); |
|
177 |
} else |
|
178 |
w.execScript(co); // IE |
|
179 |
} |
|
180 |
}; |