yllar
2006-12-16 77c28206a14b5bee3f3091f10cffd531bce5649c
commit | author | age
f0ea59 1 var oldWidth, oldHeight;
S 2 var url = tinyMCE.getParam("media_external_list_url");
3 if (url != null) {
4     // Fix relative
5     if (url.charAt(0) != '/' && url.indexOf('://') == -1)
6         url = tinyMCE.documentBasePath + "/" + url;
7
8     document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></sc'+'ript>');
9 }
10
11 function init() {
12     var pl = "", f, val;
13     var type = "flash", fe, i;
14
15     tinyMCEPopup.resizeToInnerSize();
16     f = document.forms[0]
17
18     fe = tinyMCE.selectedInstance.getFocusElement();
19     if (/mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(tinyMCE.getAttrib(fe, 'class'))) {
20         pl = "x={" + fe.title + "};";
21
22         switch (tinyMCE.getAttrib(fe, 'class')) {
23             case 'mceItemFlash':
24                 type = 'flash';
25                 break;
26
27             case 'mceItemShockWave':
28                 type = 'shockwave';
29                 break;
30
31             case 'mceItemWindowsMedia':
32                 type = 'wmp';
33                 break;
34
35             case 'mceItemQuickTime':
36                 type = 'qt';
37                 break;
38
39             case 'mceItemRealMedia':
40                 type = 'rmp';
41                 break;
42         }
43
44         document.forms[0].insert.value = tinyMCE.getLang('lang_update', 'Insert', true); 
45     }
46
47     document.getElementById('filebrowsercontainer').innerHTML = getBrowserHTML('filebrowser','src','media','media');
48     document.getElementById('qtsrcfilebrowsercontainer').innerHTML = getBrowserHTML('qtsrcfilebrowser','qt_qtsrc','media','media');
49     document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
50
51     var html = getMediaListHTML('filebrowser','src','media','media');
52     if (html == "")
53         document.getElementById("linklistrow").style.display = 'none';
54     else
55         document.getElementById("linklistcontainer").innerHTML = html;
56
57     // Resize some elements
58     if (isVisible('filebrowsercontainer'))
59         document.getElementById('src').style.width = '230px';
60
61     // Setup form
62     if (pl != "") {
63         pl = eval(pl);
64
65         switch (type) {
66             case "flash":
67                 setBool(pl, 'flash', 'play');
68                 setBool(pl, 'flash', 'loop');
69                 setBool(pl, 'flash', 'menu');
70                 setBool(pl, 'flash', 'swliveconnect');
71                 setStr(pl, 'flash', 'quality');
72                 setStr(pl, 'flash', 'scale');
73                 setStr(pl, 'flash', 'salign');
74                 setStr(pl, 'flash', 'wmode');
75                 setStr(pl, 'flash', 'base');
76                 setStr(pl, 'flash', 'flashvars');
77             break;
78
79             case "qt":
80                 setBool(pl, 'qt', 'loop');
81                 setBool(pl, 'qt', 'autoplay');
82                 setBool(pl, 'qt', 'cache');
83                 setBool(pl, 'qt', 'controller');
84                 setBool(pl, 'qt', 'correction');
85                 setBool(pl, 'qt', 'enablejavascript');
86                 setBool(pl, 'qt', 'kioskmode');
87                 setBool(pl, 'qt', 'autohref');
88                 setBool(pl, 'qt', 'playeveryframe');
89                 setBool(pl, 'qt', 'tarsetcache');
90                 setStr(pl, 'qt', 'scale');
91                 setStr(pl, 'qt', 'starttime');
92                 setStr(pl, 'qt', 'endtime');
93                 setStr(pl, 'qt', 'tarset');
94                 setStr(pl, 'qt', 'qtsrcchokespeed');
95                 setStr(pl, 'qt', 'volume');
96                 setStr(pl, 'qt', 'qtsrc');
97             break;
98
99             case "shockwave":
100                 setBool(pl, 'shockwave', 'sound');
101                 setBool(pl, 'shockwave', 'progress');
102                 setBool(pl, 'shockwave', 'autostart');
103                 setBool(pl, 'shockwave', 'swliveconnect');
104                 setStr(pl, 'shockwave', 'swvolume');
105                 setStr(pl, 'shockwave', 'swstretchstyle');
106                 setStr(pl, 'shockwave', 'swstretchhalign');
107                 setStr(pl, 'shockwave', 'swstretchvalign');
108             break;
109
110             case "wmp":
111                 setBool(pl, 'wmp', 'autostart');
112                 setBool(pl, 'wmp', 'enabled');
113                 setBool(pl, 'wmp', 'enablecontextmenu');
114                 setBool(pl, 'wmp', 'fullscreen');
115                 setBool(pl, 'wmp', 'invokeurls');
116                 setBool(pl, 'wmp', 'mute');
117                 setBool(pl, 'wmp', 'stretchtofit');
118                 setBool(pl, 'wmp', 'windowlessvideo');
119                 setStr(pl, 'wmp', 'balance');
120                 setStr(pl, 'wmp', 'baseurl');
121                 setStr(pl, 'wmp', 'captioningid');
122                 setStr(pl, 'wmp', 'currentmarker');
123                 setStr(pl, 'wmp', 'currentposition');
124                 setStr(pl, 'wmp', 'defaultframe');
125                 setStr(pl, 'wmp', 'playcount');
126                 setStr(pl, 'wmp', 'rate');
127                 setStr(pl, 'wmp', 'uimode');
128                 setStr(pl, 'wmp', 'volume');
129             break;
130
131             case "rmp":
132                 setBool(pl, 'rmp', 'autostart');
133                 setBool(pl, 'rmp', 'loop');
134                 setBool(pl, 'rmp', 'autogotourl');
135                 setBool(pl, 'rmp', 'center');
136                 setBool(pl, 'rmp', 'imagestatus');
137                 setBool(pl, 'rmp', 'maintainaspect');
138                 setBool(pl, 'rmp', 'nojava');
139                 setBool(pl, 'rmp', 'prefetch');
140                 setBool(pl, 'rmp', 'shuffle');
141                 setStr(pl, 'rmp', 'console');
142                 setStr(pl, 'rmp', 'controls');
143                 setStr(pl, 'rmp', 'numloop');
144                 setStr(pl, 'rmp', 'scriptcallbacks');
145             break;
146         }
147
148         setStr(pl, null, 'src');
149         setStr(pl, null, 'id');
150         setStr(pl, null, 'name');
151         setStr(pl, null, 'vspace');
152         setStr(pl, null, 'hspace');
153         setStr(pl, null, 'bgcolor');
154         setStr(pl, null, 'align');
155         setStr(pl, null, 'width');
156         setStr(pl, null, 'height');
157
158         if ((val = tinyMCE.getAttrib(fe, "width")) != "")
159             pl.width = f.width.value = val;
160
161         if ((val = tinyMCE.getAttrib(fe, "height")) != "")
162             pl.height = f.height.value = val;
163
164         oldWidth = pl.width ? parseInt(pl.width) : 0;
165         oldHeight = pl.height ? parseInt(pl.height) : 0;
166     } else
167         oldWidth = oldHeight = 0;
168
169     selectByValue(f, 'media_type', type);
170     changedType(type);
171     updateColor('bgcolor_pick', 'bgcolor');
172
173     TinyMCE_EditableSelects.init();
174     generatePreview();
175 }
176
177 function insertMedia() {
178     var fe, f = document.forms[0], h;
179
180     if (!AutoValidator.validate(f)) {
181         alert(tinyMCE.getLang('lang_invalid_data'));
182         return false;
183     }
184
185     f.width.value = f.width.value == "" ? 100 : f.width.value;
186     f.height.value = f.height.value == "" ? 100 : f.height.value;
187
188     fe = tinyMCE.selectedInstance.getFocusElement();
189     if (fe != null && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(tinyMCE.getAttrib(fe, 'class'))) {
190         switch (f.media_type.options[f.media_type.selectedIndex].value) {
191             case "flash":
192                 fe.className = "mceItemFlash";
193                 break;
194
195             case "shockwave":
196                 fe.className = "mceItemShockWave";
197                 break;
198
199             case "qt":
200                 fe.className = "mceItemQuickTime";
201                 break;
202
203             case "wmp":
204                 fe.className = "mceItemWindowsMedia";
205                 break;
206
207             case "rmp":
208                 fe.className = "mceItemRealMedia";
209                 break;
210         }
211
212         if (fe.width != f.width.value || fe.height != f.width.height)
213             tinyMCE.selectedInstance.repaint();
214
215         fe.title = serializeParameters();
216         fe.width = f.width.value;
217         fe.height = f.height.value;
218         fe.style.width = f.width.value + (f.width.value.indexOf('%') == -1 ? 'px' : '');
219         fe.style.height = f.height.value + (f.height.value.indexOf('%') == -1 ? 'px' : '');
220         fe.align = f.align.options[f.align.selectedIndex].value;
221     } else {
222         h = '<img src="' + tinyMCE.getParam("theme_href") + '/images/spacer.gif"' ;
223
224         switch (f.media_type.options[f.media_type.selectedIndex].value) {
225             case "flash":
226                 h += ' class="mceItemFlash"';
227                 break;
228
229             case "shockwave":
230                 h += ' class="mceItemShockWave"';
231                 break;
232
233             case "qt":
234                 h += ' class="mceItemQuickTime"';
235                 break;
236
237             case "wmp":
238                 h += ' class="mceItemWindowsMedia"';
239                 break;
240
241             case "rmp":
242                 h += ' class="mceItemRealMedia"';
243                 break;
244         }
245
246         h += ' title="' + serializeParameters() + '"';
247         h += ' width="' + f.width.value + '"';
248         h += ' height="' + f.height.value + '"';
249         h += ' align="' + f.align.options[f.align.selectedIndex].value + '"';
250
251         h += ' />';
252
253         tinyMCE.selectedInstance.execCommand('mceInsertContent', false, h);
254     }
255
256     tinyMCEPopup.close();
257 }
258
259 function getMediaListHTML() {
260     if (typeof(tinyMCEMediaList) != "undefined" && tinyMCEMediaList.length > 0) {
261         var html = "";
262
263         html += '<select id="linklist" name="linklist" style="width: 250px" onfocus="tinyMCE.addSelectAccessibility(event, this, window);" onchange="this.form.src.value=this.options[this.selectedIndex].value;">';
264         html += '<option value="">---</option>';
265
266         for (var i=0; i<tinyMCEMediaList.length; i++)
267             html += '<option value="' + tinyMCEMediaList[i][1] + '">' + tinyMCEMediaList[i][0] + '</option>';
268
269         html += '</select>';
270
271         return html;
272     }
273
274     return "";
275 }
276
277 function getType(v) {
278     var fo = tinyMCE.getParam("media_types", "flash=swf;shockwave=dcr;qt=mov,qt,mpg,mp3,mp4,mpeg;shockwave=dcr;wmp=avi,wmv,wm,asf,asx,wmx,wvx;rmp=rm,ra,ram").split(';'), i, c, el, x;
279
280     for (i=0; i<fo.length; i++) {
281         c = fo[i].split('=');
282
283         el = c[1].split(',');
284         for (x=0; x<el.length; x++)
285         if (v.indexOf('.' + el[x]) != -1)
286             return c[0];
287     }
288
289     return null;
290 }
291
292 function switchType(v) {
293     var t = getType(v), d = document, f = d.forms[0];
294
295     if (!t)
296         return;
297
298     selectByValue(d.forms[0], 'media_type', t);
299     changedType(t);
300
301     // Update qtsrc also
302     if (t == 'qt' && f.src.value.toLowerCase().indexOf('rtsp://') != -1) {
303         alert(tinyMCE.getLang("lang_media_qt_stream_warn"));
304
305         if (f.qt_qtsrc.value == '')
306             f.qt_qtsrc.value = f.src.value;
307     }
308 }
309
310 function changedType(t) {
311     var d = document;
312
313     d.getElementById('flash_options').style.display = 'none';
314     d.getElementById('qt_options').style.display = 'none';
315     d.getElementById('shockwave_options').style.display = 'none';
316     d.getElementById('wmp_options').style.display = 'none';
317     d.getElementById('rmp_options').style.display = 'none';
318     d.getElementById(t + '_options').style.display = 'block';
319 }
320
321 function serializeParameters() {
322     var d = document, f = d.forms[0], s = '';
323
324     switch (f.media_type.options[f.media_type.selectedIndex].value) {
325         case "flash":
326             s += getBool('flash', 'play', true);
327             s += getBool('flash', 'loop', true);
328             s += getBool('flash', 'menu', true);
329             s += getBool('flash', 'swliveconnect', false);
330             s += getStr('flash', 'quality');
331             s += getStr('flash', 'scale');
332             s += getStr('flash', 'salign');
333             s += getStr('flash', 'wmode');
334             s += getStr('flash', 'base');
335             s += getStr('flash', 'flashvars');
336         break;
337
338         case "qt":
339             s += getBool('qt', 'loop', false);
340             s += getBool('qt', 'autoplay', false);
341             s += getBool('qt', 'cache', false);
342             s += getBool('qt', 'controller', true);
343             s += getBool('qt', 'correction', false, 'none', 'full');
344             s += getBool('qt', 'enablejavascript', false);
345             s += getBool('qt', 'kioskmode', false);
346             s += getBool('qt', 'autohref', false);
347             s += getBool('qt', 'playeveryframe', false);
348             s += getBool('qt', 'targetcache', false);
349             s += getStr('qt', 'scale');
350             s += getStr('qt', 'starttime');
351             s += getStr('qt', 'endtime');
352             s += getStr('qt', 'target');
353             s += getStr('qt', 'qtsrcchokespeed');
354             s += getStr('qt', 'volume');
355             s += getStr('qt', 'qtsrc');
356         break;
357
358         case "shockwave":
359             s += getBool('shockwave', 'sound');
360             s += getBool('shockwave', 'progress');
361             s += getBool('shockwave', 'autostart');
362             s += getBool('shockwave', 'swliveconnect');
363             s += getStr('shockwave', 'swvolume');
364             s += getStr('shockwave', 'swstretchstyle');
365             s += getStr('shockwave', 'swstretchhalign');
366             s += getStr('shockwave', 'swstretchvalign');
367         break;
368
369         case "wmp":
370             s += getBool('wmp', 'autostart', true);
371             s += getBool('wmp', 'enabled', false);
372             s += getBool('wmp', 'enablecontextmenu', true);
373             s += getBool('wmp', 'fullscreen', false);
374             s += getBool('wmp', 'invokeurls', true);
375             s += getBool('wmp', 'mute', false);
376             s += getBool('wmp', 'stretchtofit', false);
377             s += getBool('wmp', 'windowlessvideo', false);
378             s += getStr('wmp', 'balance');
379             s += getStr('wmp', 'baseurl');
380             s += getStr('wmp', 'captioningid');
381             s += getStr('wmp', 'currentmarker');
382             s += getStr('wmp', 'currentposition');
383             s += getStr('wmp', 'defaultframe');
384             s += getStr('wmp', 'playcount');
385             s += getStr('wmp', 'rate');
386             s += getStr('wmp', 'uimode');
387             s += getStr('wmp', 'volume');
388         break;
389
390         case "rmp":
391             s += getBool('rmp', 'autostart', false);
392             s += getBool('rmp', 'loop', false);
393             s += getBool('rmp', 'autogotourl', true);
394             s += getBool('rmp', 'center', false);
395             s += getBool('rmp', 'imagestatus', true);
396             s += getBool('rmp', 'maintainaspect', false);
397             s += getBool('rmp', 'nojava', false);
398             s += getBool('rmp', 'prefetch', false);
399             s += getBool('rmp', 'shuffle', false);
400             s += getStr('rmp', 'console');
401             s += getStr('rmp', 'controls');
402             s += getStr('rmp', 'numloop');
403             s += getStr('rmp', 'scriptcallbacks');
404         break;
405     }
406
407     s += getStr(null, 'id');
408     s += getStr(null, 'name');
409     s += getStr(null, 'src');
410     s += getStr(null, 'align');
411     s += getStr(null, 'bgcolor');
412     s += getInt(null, 'vspace');
413     s += getInt(null, 'hspace');
414     s += getStr(null, 'width');
415     s += getStr(null, 'height');
416
417     s = s.length > 0 ? s.substring(0, s.length - 1) : s;
418
419     return s;
420 }
421
422 function setBool(pl, p, n) {
423     if (typeof(pl[n]) == "undefined")
424         return;
425
426     document.forms[0].elements[p + "_" + n].checked = pl[n];
427 }
428
429 function setStr(pl, p, n) {
430     var f = document.forms[0], e = f.elements[(p != null ? p + "_" : '') + n];
431
432     if (typeof(pl[n]) == "undefined")
433         return;
434
435     if (e.type == "text")
436         e.value = pl[n];
437     else
438         selectByValue(f, (p != null ? p + "_" : '') + n, pl[n]);
439 }
440
441 function getBool(p, n, d, tv, fv) {
442     var v = document.forms[0].elements[p + "_" + n].checked;
443
444     tv = typeof(tv) == 'undefined' ? 'true' : "'" + jsEncode(tv) + "'";
445     fv = typeof(fv) == 'undefined' ? 'false' : "'" + jsEncode(fv) + "'";
446
447     return (v == d) ? '' : n + (v ? ':' + tv + ',' : ':' + fv + ',');
448 }
449
450 function getStr(p, n, d) {
451     var e = document.forms[0].elements[(p != null ? p + "_" : "") + n];
452     var v = e.type == "text" ? e.value : e.options[e.selectedIndex].value;
453
454     return ((n == d || v == '') ? '' : n + ":'" + jsEncode(v) + "',");
455 }
456
457 function getInt(p, n, d) {
458     var e = document.forms[0].elements[(p != null ? p + "_" : "") + n];
459     var v = e.type == "text" ? e.value : e.options[e.selectedIndex].value;
460
461     return ((n == d || v == '') ? '' : n + ":" + v.replace(/[^0-9]+/g, '') + ",");
462 }
463
464 function jsEncode(s) {
465     s = s.replace(new RegExp('\\\\', 'g'), '\\\\');
466     s = s.replace(new RegExp('"', 'g'), '\\"');
467     s = s.replace(new RegExp("'", 'g'), "\\'");
468
469     return s;
470 }
471
472 function generatePreview(c) {
473     var f = document.forms[0], p = document.getElementById('prev'), h = '', cls, pl, n, type, codebase, wp, hp, nw, nh;
474
475     p.innerHTML = '<!-- x --->';
476
477     nw = parseInt(f.width.value);
478     nh = parseInt(f.height.value);
479
480     if (f.width.value != "" && f.height.value != "") {
481         if (f.constrain.checked) {
482             if (c == 'width' && oldWidth != 0) {
483                 wp = nw / oldWidth;
484                 nh = Math.round(wp * nh);
485                 f.height.value = nh;
486             } else if (c == 'height' && oldHeight != 0) {
487                 hp = nh / oldHeight;
488                 nw = Math.round(hp * nw);
489                 f.width.value = nw;
490             }
491         }
492     }
493
494     if (f.width.value != "")
495         oldWidth = nw;
496
497     if (f.height.value != "")
498         oldHeight = nh;
499
500     // After constrain
501     pl = serializeParameters();
502
503     switch (f.media_type.options[f.media_type.selectedIndex].value) {
504         case "flash":
505             cls = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
506             codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
507             type = 'application/x-shockwave-flash';
508             break;
509
510         case "shockwave":
511             cls = 'clsid:166B1BCA-3F9C-11CF-8075-444553540000';
512             codebase = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0';
513             type = 'application/x-director';
514             break;
515
516         case "qt":
517             cls = 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';
518             codebase = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
519             type = 'video/quicktime';
520             break;
521
522         case "wmp":
523             cls = tinyMCE.getParam('media_wmp6_compatible') ? 'clsid:05589FA1-C356-11CE-BF01-00AA0055595A' : 'clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6';
524             codebase = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
525             type = 'application/x-mplayer2';
526             break;
527
528         case "rmp":
529             cls = 'clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA';
530             codebase = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
531             type = 'audio/x-pn-realaudio-plugin';
532             break;
533     }
534
535     if (pl == '') {
536         p.innerHTML = '';
537         return;
538     }
539
540     pl = eval('x={' + pl + '};');
541
542     if (!pl.src) {
543         p.innerHTML = '';
544         return;
545     }
546
547     pl.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], pl.src);
548     pl.width = !pl.width ? 100 : pl.width;
549     pl.height = !pl.height ? 100 : pl.height;
550     pl.id = !pl.id ? 'obj' : pl.id;
551     pl.name = !pl.name ? 'eobj' : pl.name;
552     pl.align = !pl.align ? '' : pl.align;
553
554     h += '<object classid="clsid:' + cls + '" codebase="' + codebase + '" width="' + pl.width + '" height="' + pl.height + '" id="' + pl.id + '" name="' + pl.name + '" align="' + pl.align + '">';
555
556     for (n in pl) {
557         h += '<param name="' + n + '" value="' + pl[n] + '">';
558
559         // Add extra url parameter if it's an absolute URL
560         if (n == 'src' && pl[n].indexOf('://') != -1)
561             h += '<param name="url" value="' + pl[n] + '" />';
562     }
563
564     h += '<embed type="' + type + '" ';
565
566     for (n in pl)
567         h += n + '="' + pl[n] + '" ';
568
569     h += '></embed></object>';
570
571     p.innerHTML = "<!-- x --->" + h;
572 }