source: trunk/web/app/plugins/tinymce/jscripts/tiny_mce/plugins/media/js/media.js @ 6

Last change on this file since 6 was 6, checked in by dj3c1t, 12 years ago

mise a jour du trunk

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