0
|
1 |
/**
|
|
2 |
* $Id: editor_plugin_src.js 1222 2009-09-03 17:26:47Z spocke $
|
|
3 |
*
|
|
4 |
* @author Moxiecode
|
|
5 |
* @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
|
|
6 |
*/
|
|
7 |
|
|
8 |
(function() {
|
|
9 |
var each = tinymce.each;
|
|
10 |
|
|
11 |
tinymce.create('tinymce.plugins.MediaPlugin', {
|
|
12 |
init : function(ed, url) {
|
|
13 |
var t = this;
|
|
14 |
|
|
15 |
t.editor = ed;
|
|
16 |
t.url = url;
|
|
17 |
|
|
18 |
function isMediaElm(n) {
|
|
19 |
return /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className);
|
|
20 |
};
|
|
21 |
|
|
22 |
ed.onPreInit.add(function() {
|
|
23 |
// Force in _value parameter this extra parameter is required for older Opera versions
|
|
24 |
ed.serializer.addRules('param[name|value|_mce_value]');
|
|
25 |
});
|
|
26 |
|
|
27 |
// Register commands
|
|
28 |
ed.addCommand('mceMedia', function() {
|
|
29 |
ed.windowManager.open({
|
|
30 |
file : url + '/media.htm',
|
|
31 |
width : 430 + parseInt(ed.getLang('media.delta_width', 0)),
|
|
32 |
height : 470 + parseInt(ed.getLang('media.delta_height', 0)),
|
|
33 |
inline : 1
|
|
34 |
}, {
|
|
35 |
plugin_url : url
|
|
36 |
});
|
|
37 |
});
|
|
38 |
|
|
39 |
// Register buttons
|
|
40 |
ed.addButton('media', {title : 'media.desc', cmd : 'mceMedia'});
|
|
41 |
|
|
42 |
ed.onNodeChange.add(function(ed, cm, n) {
|
|
43 |
cm.setActive('media', n.nodeName == 'IMG' && isMediaElm(n));
|
|
44 |
});
|
|
45 |
|
|
46 |
ed.onInit.add(function() {
|
|
47 |
var lo = {
|
|
48 |
mceItemFlash : 'flash',
|
|
49 |
mceItemShockWave : 'shockwave',
|
|
50 |
mceItemWindowsMedia : 'windowsmedia',
|
|
51 |
mceItemQuickTime : 'quicktime',
|
|
52 |
mceItemRealMedia : 'realmedia'
|
|
53 |
};
|
|
54 |
|
|
55 |
ed.selection.onSetContent.add(function() {
|
|
56 |
t._spansToImgs(ed.getBody());
|
|
57 |
});
|
|
58 |
|
|
59 |
ed.selection.onBeforeSetContent.add(t._objectsToSpans, t);
|
|
60 |
|
|
61 |
if (ed.settings.content_css !== false)
|
|
62 |
ed.dom.loadCSS(url + "/css/content.css");
|
|
63 |
|
|
64 |
if (ed.theme && ed.theme.onResolveName) {
|
|
65 |
ed.theme.onResolveName.add(function(th, o) {
|
|
66 |
if (o.name == 'img') {
|
|
67 |
each(lo, function(v, k) {
|
|
68 |
if (ed.dom.hasClass(o.node, k)) {
|
|
69 |
o.name = v;
|
|
70 |
o.title = ed.dom.getAttrib(o.node, 'title');
|
|
71 |
return false;
|
|
72 |
}
|
|
73 |
});
|
|
74 |
}
|
|
75 |
});
|
|
76 |
}
|
|
77 |
|
|
78 |
if (ed && ed.plugins.contextmenu) {
|
|
79 |
ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
|
|
80 |
if (e.nodeName == 'IMG' && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(e.className)) {
|
|
81 |
m.add({title : 'media.edit', icon : 'media', cmd : 'mceMedia'});
|
|
82 |
}
|
|
83 |
});
|
|
84 |
}
|
|
85 |
});
|
|
86 |
|
|
87 |
ed.onBeforeSetContent.add(t._objectsToSpans, t);
|
|
88 |
|
|
89 |
ed.onSetContent.add(function() {
|
|
90 |
t._spansToImgs(ed.getBody());
|
|
91 |
});
|
|
92 |
|
|
93 |
ed.onPreProcess.add(function(ed, o) {
|
|
94 |
var dom = ed.dom;
|
|
95 |
|
|
96 |
if (o.set) {
|
|
97 |
t._spansToImgs(o.node);
|
|
98 |
|
|
99 |
each(dom.select('IMG', o.node), function(n) {
|
|
100 |
var p;
|
|
101 |
|
|
102 |
if (isMediaElm(n)) {
|
|
103 |
p = t._parse(n.title);
|
|
104 |
dom.setAttrib(n, 'width', dom.getAttrib(n, 'width', p.width || 100));
|
|
105 |
dom.setAttrib(n, 'height', dom.getAttrib(n, 'height', p.height || 100));
|
|
106 |
}
|
|
107 |
});
|
|
108 |
}
|
|
109 |
|
|
110 |
if (o.get) {
|
|
111 |
each(dom.select('IMG', o.node), function(n) {
|
|
112 |
var ci, cb, mt;
|
|
113 |
|
|
114 |
if (ed.getParam('media_use_script')) {
|
|
115 |
if (isMediaElm(n))
|
|
116 |
n.className = n.className.replace(/mceItem/g, 'mceTemp');
|
|
117 |
|
|
118 |
return;
|
|
119 |
}
|
|
120 |
|
|
121 |
switch (n.className) {
|
|
122 |
case 'mceItemFlash':
|
|
123 |
ci = 'd27cdb6e-ae6d-11cf-96b8-444553540000';
|
|
124 |
cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
|
|
125 |
mt = 'application/x-shockwave-flash';
|
|
126 |
break;
|
|
127 |
|
|
128 |
case 'mceItemShockWave':
|
|
129 |
ci = '166b1bca-3f9c-11cf-8075-444553540000';
|
|
130 |
cb = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0';
|
|
131 |
mt = 'application/x-director';
|
|
132 |
break;
|
|
133 |
|
|
134 |
case 'mceItemWindowsMedia':
|
|
135 |
ci = ed.getParam('media_wmp6_compatible') ? '05589fa1-c356-11ce-bf01-00aa0055595a' : '6bf52a52-394a-11d3-b153-00c04f79faa6';
|
|
136 |
cb = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
|
|
137 |
mt = 'application/x-mplayer2';
|
|
138 |
break;
|
|
139 |
|
|
140 |
case 'mceItemQuickTime':
|
|
141 |
ci = '02bf25d5-8c17-4b23-bc80-d3488abddc6b';
|
|
142 |
cb = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
|
|
143 |
mt = 'video/quicktime';
|
|
144 |
break;
|
|
145 |
|
|
146 |
case 'mceItemRealMedia':
|
|
147 |
ci = 'cfcdaa03-8be4-11cf-b84b-0020afbbccfa';
|
|
148 |
cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
|
|
149 |
mt = 'audio/x-pn-realaudio-plugin';
|
|
150 |
break;
|
|
151 |
}
|
|
152 |
|
|
153 |
if (ci) {
|
|
154 |
dom.replace(t._buildObj({
|
|
155 |
classid : ci,
|
|
156 |
codebase : cb,
|
|
157 |
type : mt
|
|
158 |
}, n), n);
|
|
159 |
}
|
|
160 |
});
|
|
161 |
}
|
|
162 |
});
|
|
163 |
|
|
164 |
ed.onPostProcess.add(function(ed, o) {
|
|
165 |
o.content = o.content.replace(/_mce_value=/g, 'value=');
|
|
166 |
});
|
|
167 |
|
|
168 |
function getAttr(s, n) {
|
|
169 |
n = new RegExp(n + '=\"([^\"]+)\"', 'g').exec(s);
|
|
170 |
|
|
171 |
return n ? ed.dom.decode(n[1]) : '';
|
|
172 |
};
|
|
173 |
|
|
174 |
ed.onPostProcess.add(function(ed, o) {
|
|
175 |
if (ed.getParam('media_use_script')) {
|
|
176 |
o.content = o.content.replace(/<img[^>]+>/g, function(im) {
|
|
177 |
var cl = getAttr(im, 'class');
|
|
178 |
|
|
179 |
if (/^(mceTempFlash|mceTempShockWave|mceTempWindowsMedia|mceTempQuickTime|mceTempRealMedia)$/.test(cl)) {
|
|
180 |
at = t._parse(getAttr(im, 'title'));
|
|
181 |
at.width = getAttr(im, 'width');
|
|
182 |
at.height = getAttr(im, 'height');
|
|
183 |
im = '<script type="text/javascript">write' + cl.substring(7) + '({' + t._serialize(at) + '});</script>';
|
|
184 |
}
|
|
185 |
|
|
186 |
return im;
|
|
187 |
});
|
|
188 |
}
|
|
189 |
});
|
|
190 |
},
|
|
191 |
|
|
192 |
getInfo : function() {
|
|
193 |
return {
|
|
194 |
longname : 'Media',
|
|
195 |
author : 'Moxiecode Systems AB',
|
|
196 |
authorurl : 'http://tinymce.moxiecode.com',
|
|
197 |
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media',
|
|
198 |
version : tinymce.majorVersion + "." + tinymce.minorVersion
|
|
199 |
};
|
|
200 |
},
|
|
201 |
|
|
202 |
// Private methods
|
|
203 |
_objectsToSpans : function(ed, o) {
|
|
204 |
var t = this, h = o.content;
|
|
205 |
|
|
206 |
h = h.replace(/<script[^>]*>\s*write(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)\(\{([^\)]*)\}\);\s*<\/script>/gi, function(a, b, c) {
|
|
207 |
var o = t._parse(c);
|
|
208 |
|
|
209 |
return '<img class="mceItem' + b + '" title="' + ed.dom.encode(c) + '" src="' + t.url + '/img/trans.gif" width="' + o.width + '" height="' + o.height + '" />'
|
|
210 |
});
|
|
211 |
|
|
212 |
h = h.replace(/<object([^>]*)>/gi, '<span class="mceItemObject" $1>');
|
|
213 |
h = h.replace(/<embed([^>]*)\/?>/gi, '<span class="mceItemEmbed" $1></span>');
|
|
214 |
h = h.replace(/<embed([^>]*)>/gi, '<span class="mceItemEmbed" $1>');
|
|
215 |
h = h.replace(/<\/(object)([^>]*)>/gi, '</span>');
|
|
216 |
h = h.replace(/<\/embed>/gi, '');
|
|
217 |
h = h.replace(/<param([^>]*)>/gi, function(a, b) {return '<span ' + b.replace(/value=/gi, '_mce_value=') + ' class="mceItemParam"></span>'});
|
|
218 |
h = h.replace(/\/ class=\"mceItemParam\"><\/span>/gi, 'class="mceItemParam"></span>');
|
|
219 |
|
|
220 |
o.content = h;
|
|
221 |
},
|
|
222 |
|
|
223 |
_buildObj : function(o, n) {
|
|
224 |
var ob, ed = this.editor, dom = ed.dom, p = this._parse(n.title), stc;
|
|
225 |
|
|
226 |
stc = ed.getParam('media_strict', true) && o.type == 'application/x-shockwave-flash';
|
|
227 |
|
|
228 |
p.width = o.width = dom.getAttrib(n, 'width') || 100;
|
|
229 |
p.height = o.height = dom.getAttrib(n, 'height') || 100;
|
|
230 |
|
|
231 |
if (p.src)
|
|
232 |
p.src = ed.convertURL(p.src, 'src', n);
|
|
233 |
|
|
234 |
if (stc) {
|
|
235 |
ob = dom.create('span', {
|
|
236 |
id : p.id,
|
|
237 |
mce_name : 'object',
|
|
238 |
type : 'application/x-shockwave-flash',
|
|
239 |
data : p.src,
|
|
240 |
style : dom.getAttrib(n, 'style'),
|
|
241 |
width : o.width,
|
|
242 |
height : o.height
|
|
243 |
});
|
|
244 |
} else {
|
|
245 |
ob = dom.create('span', {
|
|
246 |
id : p.id,
|
|
247 |
mce_name : 'object',
|
|
248 |
classid : "clsid:" + o.classid,
|
|
249 |
style : dom.getAttrib(n, 'style'),
|
|
250 |
codebase : o.codebase,
|
|
251 |
width : o.width,
|
|
252 |
height : o.height
|
|
253 |
});
|
|
254 |
}
|
|
255 |
|
|
256 |
each (p, function(v, k) {
|
|
257 |
if (!/^(width|height|codebase|classid|id|_cx|_cy)$/.test(k)) {
|
|
258 |
// Use url instead of src in IE for Windows media
|
|
259 |
if (o.type == 'application/x-mplayer2' && k == 'src' && !p.url)
|
|
260 |
k = 'url';
|
|
261 |
|
|
262 |
if (v)
|
|
263 |
dom.add(ob, 'span', {mce_name : 'param', name : k, '_mce_value' : v});
|
|
264 |
}
|
|
265 |
});
|
|
266 |
|
|
267 |
if (!stc)
|
|
268 |
dom.add(ob, 'span', tinymce.extend({mce_name : 'embed', type : o.type, style : dom.getAttrib(n, 'style')}, p));
|
|
269 |
|
|
270 |
return ob;
|
|
271 |
},
|
|
272 |
|
|
273 |
_spansToImgs : function(p) {
|
|
274 |
var t = this, dom = t.editor.dom, im, ci;
|
|
275 |
|
|
276 |
each(dom.select('span', p), function(n) {
|
|
277 |
// Convert object into image
|
|
278 |
if (dom.getAttrib(n, 'class') == 'mceItemObject') {
|
|
279 |
ci = dom.getAttrib(n, "classid").toLowerCase().replace(/\s+/g, '');
|
|
280 |
|
|
281 |
switch (ci) {
|
|
282 |
case 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000':
|
|
283 |
dom.replace(t._createImg('mceItemFlash', n), n);
|
|
284 |
break;
|
|
285 |
|
|
286 |
case 'clsid:166b1bca-3f9c-11cf-8075-444553540000':
|
|
287 |
dom.replace(t._createImg('mceItemShockWave', n), n);
|
|
288 |
break;
|
|
289 |
|
|
290 |
case 'clsid:6bf52a52-394a-11d3-b153-00c04f79faa6':
|
|
291 |
case 'clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95':
|
|
292 |
case 'clsid:05589fa1-c356-11ce-bf01-00aa0055595a':
|
|
293 |
dom.replace(t._createImg('mceItemWindowsMedia', n), n);
|
|
294 |
break;
|
|
295 |
|
|
296 |
case 'clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b':
|
|
297 |
dom.replace(t._createImg('mceItemQuickTime', n), n);
|
|
298 |
break;
|
|
299 |
|
|
300 |
case 'clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa':
|
|
301 |
dom.replace(t._createImg('mceItemRealMedia', n), n);
|
|
302 |
break;
|
|
303 |
|
|
304 |
default:
|
|
305 |
dom.replace(t._createImg('mceItemFlash', n), n);
|
|
306 |
}
|
|
307 |
|
|
308 |
return;
|
|
309 |
}
|
|
310 |
|
|
311 |
// Convert embed into image
|
|
312 |
if (dom.getAttrib(n, 'class') == 'mceItemEmbed') {
|
|
313 |
switch (dom.getAttrib(n, 'type')) {
|
|
314 |
case 'application/x-shockwave-flash':
|
|
315 |
dom.replace(t._createImg('mceItemFlash', n), n);
|
|
316 |
break;
|
|
317 |
|
|
318 |
case 'application/x-director':
|
|
319 |
dom.replace(t._createImg('mceItemShockWave', n), n);
|
|
320 |
break;
|
|
321 |
|
|
322 |
case 'application/x-mplayer2':
|
|
323 |
dom.replace(t._createImg('mceItemWindowsMedia', n), n);
|
|
324 |
break;
|
|
325 |
|
|
326 |
case 'video/quicktime':
|
|
327 |
dom.replace(t._createImg('mceItemQuickTime', n), n);
|
|
328 |
break;
|
|
329 |
|
|
330 |
case 'audio/x-pn-realaudio-plugin':
|
|
331 |
dom.replace(t._createImg('mceItemRealMedia', n), n);
|
|
332 |
break;
|
|
333 |
|
|
334 |
default:
|
|
335 |
dom.replace(t._createImg('mceItemFlash', n), n);
|
|
336 |
}
|
|
337 |
}
|
|
338 |
});
|
|
339 |
},
|
|
340 |
|
|
341 |
_createImg : function(cl, n) {
|
|
342 |
var im, dom = this.editor.dom, pa = {}, ti = '', args;
|
|
343 |
|
|
344 |
args = ['id', 'name', 'width', 'height', 'bgcolor', 'align', 'flashvars', 'src', 'wmode', 'allowfullscreen', 'quality', 'data'];
|
|
345 |
|
|
346 |
// Create image
|
|
347 |
im = dom.create('img', {
|
|
348 |
src : this.url + '/img/trans.gif',
|
|
349 |
width : dom.getAttrib(n, 'width') || 100,
|
|
350 |
height : dom.getAttrib(n, 'height') || 100,
|
|
351 |
style : dom.getAttrib(n, 'style'),
|
|
352 |
'class' : cl
|
|
353 |
});
|
|
354 |
|
|
355 |
// Setup base parameters
|
|
356 |
each(args, function(na) {
|
|
357 |
var v = dom.getAttrib(n, na);
|
|
358 |
|
|
359 |
if (v)
|
|
360 |
pa[na] = v;
|
|
361 |
});
|
|
362 |
|
|
363 |
// Add optional parameters
|
|
364 |
each(dom.select('span', n), function(n) {
|
|
365 |
if (dom.hasClass(n, 'mceItemParam'))
|
|
366 |
pa[dom.getAttrib(n, 'name')] = dom.getAttrib(n, '_mce_value');
|
|
367 |
});
|
|
368 |
|
|
369 |
// Use src not movie
|
|
370 |
if (pa.movie) {
|
|
371 |
pa.src = pa.movie;
|
|
372 |
delete pa.movie;
|
|
373 |
}
|
|
374 |
|
|
375 |
// No src try data
|
|
376 |
if (!pa.src) {
|
|
377 |
pa.src = pa.data;
|
|
378 |
delete pa.data;
|
|
379 |
}
|
|
380 |
|
|
381 |
// Merge with embed args
|
|
382 |
n = dom.select('.mceItemEmbed', n)[0];
|
|
383 |
if (n) {
|
|
384 |
each(args, function(na) {
|
|
385 |
var v = dom.getAttrib(n, na);
|
|
386 |
|
|
387 |
if (v && !pa[na])
|
|
388 |
pa[na] = v;
|
|
389 |
});
|
|
390 |
}
|
|
391 |
|
|
392 |
delete pa.width;
|
|
393 |
delete pa.height;
|
|
394 |
|
|
395 |
im.title = this._serialize(pa);
|
|
396 |
|
|
397 |
return im;
|
|
398 |
},
|
|
399 |
|
|
400 |
_parse : function(s) {
|
|
401 |
return tinymce.util.JSON.parse('{' + s + '}');
|
|
402 |
},
|
|
403 |
|
|
404 |
_serialize : function(o) {
|
|
405 |
return tinymce.util.JSON.serialize(o).replace(/[{}]/g, '');
|
|
406 |
}
|
|
407 |
});
|
|
408 |
|
|
409 |
// Register plugin
|
|
410 |
tinymce.PluginManager.add('media', tinymce.plugins.MediaPlugin);
|
|
411 |
})(); |