Browse code

Re-add TinyMCE 2.0.1 to the site settings list - TinyMCE directoy names changed - installer submission settings layout dirty fix

Clarissa Walker authored on 2026/07/27 11:20:38
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,464 +0,0 @@
1
-(function() {
2
-	var url;
3
-
4
-	if (url = tinyMCEPopup.getParam("media_external_list_url"))
5
-		document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
6
-
7
-	function get(id) {
8
-		return document.getElementById(id);
9
-	}
10
-
11
-	function clone(obj) {
12
-		var i, len, copy, attr;
13
-
14
-		if (null == obj || "object" != typeof obj)
15
-			return obj;
16
-
17
-		// Handle Array
18
-		if ('length' in obj) {
19
-			copy = [];
20
-
21
-			for (i = 0, len = obj.length; i < len; ++i) {
22
-				copy[i] = clone(obj[i]);
23
-			}
24
-
25
-			return copy;
26
-		}
27
-
28
-		// Handle Object
29
-		copy = {};
30
-		for (attr in obj) {
31
-			if (obj.hasOwnProperty(attr))
32
-				copy[attr] = clone(obj[attr]);
33
-		}
34
-
35
-		return copy;
36
-	}
37
-
38
-	function getVal(id) {
39
-		var elm = get(id);
40
-
41
-		if (elm.nodeName == "SELECT")
42
-			return elm.options[elm.selectedIndex].value;
43
-
44
-		if (elm.type == "checkbox")
45
-			return elm.checked;
46
-
47
-		return elm.value;
48
-	}
49
-
50
-	function setVal(id, value, name) {
51
-		if (typeof(value) != 'undefined' && value != null) {
52
-			var elm = get(id);
53
-
54
-			if (elm.nodeName == "SELECT")
55
-				selectByValue(document.forms[0], id, value);
56
-			else if (elm.type == "checkbox") {
57
-				if (typeof(value) == 'string') {
58
-					value = value.toLowerCase();
59
-					value = (!name && value === 'true') || (name && value === name.toLowerCase());
60
-				}
61
-				elm.checked = !!value;
62
-			} else
63
-				elm.value = value;
64
-		}
65
-	}
66
-
67
-	window.Media = {
68
-		init : function() {
69
-			var html, editor, self = this;
70
-
71
-			self.editor = editor = tinyMCEPopup.editor;
72
-
73
-			// Setup file browsers and color pickers
74
-			get('filebrowsercontainer').innerHTML = getBrowserHTML('filebrowser','src','media','media');
75
-			get('qtsrcfilebrowsercontainer').innerHTML = getBrowserHTML('qtsrcfilebrowser','quicktime_qtsrc','media','media');
76
-			get('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
77
-			get('video_altsource1_filebrowser').innerHTML = getBrowserHTML('video_filebrowser_altsource1','video_altsource1','media','media');
78
-			get('video_altsource2_filebrowser').innerHTML = getBrowserHTML('video_filebrowser_altsource2','video_altsource2','media','media');
79
-			get('audio_altsource1_filebrowser').innerHTML = getBrowserHTML('audio_filebrowser_altsource1','audio_altsource1','media','media');
80
-			get('audio_altsource2_filebrowser').innerHTML = getBrowserHTML('audio_filebrowser_altsource2','audio_altsource2','media','media');
81
-			get('video_poster_filebrowser').innerHTML = getBrowserHTML('filebrowser_poster','video_poster','media','image');
82
-
83
-			html = self.getMediaListHTML('medialist', 'src', 'media', 'media');
84
-			if (html == "")
85
-				get("linklistrow").style.display = 'none';
86
-			else
87
-				get("linklistcontainer").innerHTML = html;
88
-
89
-			if (isVisible('filebrowser'))
90
-				get('src').style.width = '230px';
91
-
92
-			if (isVisible('video_filebrowser_altsource1'))
93
-				get('video_altsource1').style.width = '220px';
94
-
95
-			if (isVisible('video_filebrowser_altsource2'))
96
-				get('video_altsource2').style.width = '220px';
97
-
98
-			if (isVisible('audio_filebrowser_altsource1'))
99
-				get('audio_altsource1').style.width = '220px';
100
-
101
-			if (isVisible('audio_filebrowser_altsource2'))
102
-				get('audio_altsource2').style.width = '220px';
103
-
104
-			if (isVisible('filebrowser_poster'))
105
-				get('video_poster').style.width = '220px';
106
-
107
-			editor.dom.setOuterHTML(get('media_type'), self.getMediaTypeHTML(editor));
108
-
109
-			self.setDefaultDialogSettings(editor);
110
-			self.data = clone(tinyMCEPopup.getWindowArg('data'));
111
-			self.dataToForm();
112
-			self.preview();
113
-
114
-			updateColor('bgcolor_pick', 'bgcolor');
115
-		},
116
-
117
-		insert : function() {
118
-			var editor = tinyMCEPopup.editor;
119
-
120
-			this.formToData();
121
-			editor.execCommand('mceRepaint');
122
-			tinyMCEPopup.restoreSelection();
123
-			editor.selection.setNode(editor.plugins.media.dataToImg(this.data));
124
-			tinyMCEPopup.close();
125
-		},
126
-
127
-		preview : function() {
128
-			get('prev').innerHTML = this.editor.plugins.media.dataToHtml(this.data, true);
129
-		},
130
-
131
-		moveStates : function(to_form, field) {
132
-			var data = this.data, editor = this.editor,
133
-				mediaPlugin = editor.plugins.media, ext, src, typeInfo, defaultStates, src;
134
-
135
-			defaultStates = {
136
-				// QuickTime
137
-				quicktime_autoplay : true,
138
-				quicktime_controller : true,
139
-
140
-				// Flash
141
-				flash_play : true,
142
-				flash_loop : true,
143
-				flash_menu : true,
144
-
145
-				// WindowsMedia
146
-				windowsmedia_autostart : true,
147
-				windowsmedia_enablecontextmenu : true,
148
-				windowsmedia_invokeurls : true,
149
-
150
-				// RealMedia
151
-				realmedia_autogotourl : true,
152
-				realmedia_imagestatus : true
153
-			};
154
-
155
-			function parseQueryParams(str) {
156
-				var out = {};
157
-
158
-				if (str) {
159
-					tinymce.each(str.split('&'), function(item) {
160
-						var parts = item.split('=');
161
-
162
-						out[unescape(parts[0])] = unescape(parts[1]);
163
-					});
164
-				}
165
-
166
-				return out;
167
-			};
168
-
169
-			function setOptions(type, names) {
170
-				var i, name, formItemName, value, list;
171
-
172
-				if (type == data.type || type == 'global') {
173
-					names = tinymce.explode(names);
174
-					for (i = 0; i < names.length; i++) {
175
-						name = names[i];
176
-						formItemName = type == 'global' ? name : type + '_' + name;
177
-
178
-						if (type == 'global')
179
-						list = data;
180
-					else if (type == 'video' || type == 'audio') {
181
-							list = data.video.attrs;
182
-
183
-							if (!list && !to_form)
184
-							data.video.attrs = list = {};
185
-						} else
186
-						list = data.params;
187
-
188
-						if (list) {
189
-							if (to_form) {
190
-								setVal(formItemName, list[name], type == 'video' || type == 'audio' ? name : '');
191
-							} else {
192
-								delete list[name];
193
-
194
-								value = getVal(formItemName);
195
-								if ((type == 'video' || type == 'audio') && value === true)
196
-									value = name;
197
-
198
-								if (defaultStates[formItemName]) {
199
-									if (value !== defaultStates[formItemName]) {
200
-										value = "" + value;
201
-										list[name] = value;
202
-									}
203
-								} else if (value) {
204
-									value = "" + value;
205
-									list[name] = value;
206
-								}
207
-							}
208
-						}
209
-					}
210
-				}
211
-			}
212
-
213
-			if (!to_form) {
214
-				data.type = get('media_type').options[get('media_type').selectedIndex].value;
215
-				data.width = getVal('width');
216
-				data.height = getVal('height');
217
-
218
-				// Switch type based on extension
219
-				src = getVal('src');
220
-				if (field == 'src') {
221
-					ext = src.replace(/^.*\.([^.]+)$/, '$1');
222
-					if (typeInfo = mediaPlugin.getType(ext))
223
-						data.type = typeInfo.name.toLowerCase();
224
-
225
-					setVal('media_type', data.type);
226
-				}
227
-
228
-				if (data.type == "video" || data.type == "audio") {
229
-					if (!data.video.sources)
230
-						data.video.sources = [];
231
-
232
-					data.video.sources[0] = {src: getVal('src')};
233
-				}
234
-			}
235
-
236
-			// Hide all fieldsets and show the one active
237
-			get('video_options').style.display = 'none';
238
-			get('audio_options').style.display = 'none';
239
-			get('flash_options').style.display = 'none';
240
-			get('quicktime_options').style.display = 'none';
241
-			get('shockwave_options').style.display = 'none';
242
-			get('windowsmedia_options').style.display = 'none';
243
-			get('realmedia_options').style.display = 'none';
244
-			get('embeddedaudio_options').style.display = 'none';
245
-
246
-			if (get(data.type + '_options'))
247
-				get(data.type + '_options').style.display = 'block';
248
-
249
-			setVal('media_type', data.type);
250
-
251
-			setOptions('flash', 'play,loop,menu,swliveconnect,quality,scale,salign,wmode,base,flashvars');
252
-			setOptions('quicktime', 'loop,autoplay,cache,controller,correction,enablejavascript,kioskmode,autohref,playeveryframe,targetcache,scale,starttime,endtime,target,qtsrcchokespeed,volume,qtsrc');
253
-			setOptions('shockwave', 'sound,progress,autostart,swliveconnect,swvolume,swstretchstyle,swstretchhalign,swstretchvalign');
254
-			setOptions('windowsmedia', 'autostart,enabled,enablecontextmenu,fullscreen,invokeurls,mute,stretchtofit,windowlessvideo,balance,baseurl,captioningid,currentmarker,currentposition,defaultframe,playcount,rate,uimode,volume');
255
-			setOptions('realmedia', 'autostart,loop,autogotourl,center,imagestatus,maintainaspect,nojava,prefetch,shuffle,console,controls,numloop,scriptcallbacks');
256
-			setOptions('video', 'poster,autoplay,loop,muted,preload,controls');
257
-			setOptions('audio', 'autoplay,loop,preload,controls');
258
-			setOptions('embeddedaudio', 'autoplay,loop,controls');
259
-			setOptions('global', 'id,name,vspace,hspace,bgcolor,align,width,height');
260
-
261
-			if (to_form) {
262
-				if (data.type == 'video') {
263
-					if (data.video.sources[0])
264
-						setVal('src', data.video.sources[0].src);
265
-
266
-					src = data.video.sources[1];
267
-					if (src)
268
-						setVal('video_altsource1', src.src);
269
-
270
-					src = data.video.sources[2];
271
-					if (src)
272
-						setVal('video_altsource2', src.src);
273
-                } else if (data.type == 'audio') {
274
-                    if (data.video.sources[0])
275
-                        setVal('src', data.video.sources[0].src);
276
-                    
277
-                    src = data.video.sources[1];
278
-                    if (src)
279
-                        setVal('audio_altsource1', src.src);
280
-                    
281
-                    src = data.video.sources[2];
282
-                    if (src)
283
-                        setVal('audio_altsource2', src.src);
284
-				} else {
285
-					// Check flash vars
286
-					if (data.type == 'flash') {
287
-						tinymce.each(editor.getParam('flash_video_player_flashvars', {url : '$url', poster : '$poster'}), function(value, name) {
288
-							if (value == '$url')
289
-								data.params.src = parseQueryParams(data.params.flashvars)[name] || data.params.src || '';
290
-						});
291
-					}
292
-
293
-					setVal('src', data.params.src);
294
-				}
295
-			} else {
296
-				src = getVal("src");
297
-
298
-				// YouTube *NEW*
299
-				if (src.match(/youtu.be\/[a-z1-9.-_]+/)) {
300
-					data.width = 425;
301
-					data.height = 350;
302
-					data.params.frameborder = '0';
303
-					data.type = 'iframe';
304
-					src = 'http://www.youtube.com/embed/' + src.match(/youtu.be\/([a-z1-9.-_]+)/)[1];
305
-					setVal('src', src);
306
-					setVal('media_type', data.type);
307
-				}
308
-
309
-				// YouTube
310
-				if (src.match(/youtube.com(.+)v=([^&]+)/)) {
311
-					data.width = 425;
312
-					data.height = 350;
313
-					data.params.frameborder = '0';
314
-					data.type = 'iframe';
315
-					src = 'http://www.youtube.com/embed/' + src.match(/v=([^&]+)/)[1];
316
-					setVal('src', src);
317
-					setVal('media_type', data.type);
318
-				}
319
-
320
-				// Google video
321
-				if (src.match(/video.google.com(.+)docid=([^&]+)/)) {
322
-					data.width = 425;
323
-					data.height = 326;
324
-					data.type = 'flash';
325
-					src = 'http://video.google.com/googleplayer.swf?docId=' + src.match(/docid=([^&]+)/)[1] + '&hl=en';
326
-					setVal('src', src);
327
-					setVal('media_type', data.type);
328
-				}
329
-
330
-				if (data.type == 'video') {
331
-					if (!data.video.sources)
332
-						data.video.sources = [];
333
-
334
-					data.video.sources[0] = {src : src};
335
-
336
-					src = getVal("video_altsource1");
337
-					if (src)
338
-						data.video.sources[1] = {src : src};
339
-
340
-					src = getVal("video_altsource2");
341
-					if (src)
342
-						data.video.sources[2] = {src : src};
343
-                } else if (data.type == 'audio') {
344
-                    if (!data.video.sources)
345
-                        data.video.sources = [];
346
-                    
347
-                    data.video.sources[0] = {src : src};
348
-                    
349
-                    src = getVal("audio_altsource1");
350
-                    if (src)
351
-                        data.video.sources[1] = {src : src};
352
-                    
353
-                    src = getVal("audio_altsource2");
354
-                    if (src)
355
-                        data.video.sources[2] = {src : src};
356
-				} else
357
-					data.params.src = src;
358
-
359
-				// Set default size
360
-                setVal('width', data.width || (data.type == 'audio' ? 300 : 320));
361
-                setVal('height', data.height || (data.type == 'audio' ? 32 : 240));
362
-			}
363
-		},
364
-
365
-		dataToForm : function() {
366
-			this.moveStates(true);
367
-		},
368
-
369
-		formToData : function(field) {
370
-			if (field == "width" || field == "height")
371
-				this.changeSize(field);
372
-
373
-			if (field == 'source') {
374
-				this.moveStates(false, field);
375
-				setVal('source', this.editor.plugins.media.dataToHtml(this.data));
376
-				this.panel = 'source';
377
-			} else {
378
-				if (this.panel == 'source') {
379
-					this.data = clone(this.editor.plugins.media.htmlToData(getVal('source')));
380
-					this.dataToForm();
381
-					this.panel = '';
382
-				}
383
-
384
-				this.moveStates(false, field);
385
-				this.preview();
386
-			}
387
-		},
388
-
389
-		beforeResize : function() {
390
-            this.width = parseInt(getVal('width') || (this.data.type == 'audio' ? "300" : "320"), 10);
391
-            this.height = parseInt(getVal('height') || (this.data.type == 'audio' ? "32" : "240"), 10);
392
-		},
393
-
394
-		changeSize : function(type) {
395
-			var width, height, scale, size;
396
-
397
-			if (get('constrain').checked) {
398
-                width = parseInt(getVal('width') || (this.data.type == 'audio' ? "300" : "320"), 10);
399
-                height = parseInt(getVal('height') || (this.data.type == 'audio' ? "32" : "240"), 10);
400
-
401
-				if (type == 'width') {
402
-					this.height = Math.round((width / this.width) * height);
403
-					setVal('height', this.height);
404
-				} else {
405
-					this.width = Math.round((height / this.height) * width);
406
-					setVal('width', this.width);
407
-				}
408
-			}
409
-		},
410
-
411
-		getMediaListHTML : function() {
412
-			if (typeof(tinyMCEMediaList) != "undefined" && tinyMCEMediaList.length > 0) {
413
-				var html = "";
414
-
415
-				html += '<select id="linklist" name="linklist" style="width: 250px" onchange="this.form.src.value=this.options[this.selectedIndex].value;Media.formToData(\'src\');">';
416
-				html += '<option value="">---</option>';
417
-
418
-				for (var i=0; i<tinyMCEMediaList.length; i++)
419
-					html += '<option value="' + tinyMCEMediaList[i][1] + '">' + tinyMCEMediaList[i][0] + '</option>';
420
-
421
-				html += '</select>';
422
-
423
-				return html;
424
-			}
425
-
426
-			return "";
427
-		},
428
-
429
-		getMediaTypeHTML : function(editor) {
430
-			function option(media_type){
431
-				return '<option value="'+media_type+'">'+tinyMCEPopup.editor.translate("media_dlg."+media_type)+'</option>'
432
-			}
433
-			var html = "";
434
-			html += '<select id="media_type" name="media_type" onchange="Media.formToData(\'type\');">';
435
-			html += option("video");
436
-			html += option("audio");
437
-			html += option("flash");
438
-			html += option("quicktime");
439
-			html += option("shockwave");
440
-			html += option("windowsmedia");
441
-			html += option("realmedia");
442
-			html += option("iframe");
443
-
444
-			if (editor.getParam('media_embedded_audio', false)) {
445
-				html += option('embeddedaudio');
446
-			}
447
-			
448
-			html += '</select>';
449
-			return html;
450
-		},
451
-
452
-		setDefaultDialogSettings : function(editor) {
453
-			var defaultDialogSettings = editor.getParam("media_dialog_defaults", {});
454
-			tinymce.each(defaultDialogSettings, function(v, k) {
455
-				setVal(k, v);
456
-			});
457
-		}
458
-	};
459
-
460
-	tinyMCEPopup.requireLangPack();
461
-	tinyMCEPopup.onInit.add(function() {
462
-		Media.init();
463
-	});
464
-})();
Browse code

Actually use TinyMCE 3.4.8 for TinyMCE3 option instead of original 2.0.1; that version is moved to 'tinymce2' directory

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

3.5.6 efiction version

Jimako authored on 2024/03/09 16:09:42
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,628 @@
1
+tinyMCEPopup.requireLangPack();
2
+
3
+var oldWidth, oldHeight, ed, url;
4
+
5
+if (url = tinyMCEPopup.getParam("media_external_list_url"))
6
+	document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
7
+
8
+function 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 = 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 = tinyMCEPopup.editor.plugins.media._parse(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
+
180
+function insertMedia() {
181
+	var fe, f = document.forms[0], h;
182
+
183
+	tinyMCEPopup.restoreSelection();
184
+
185
+	if (!AutoValidator.validate(f)) {
186
+		alert(ed.getLang('invalid_data'));
187
+		return false;
188
+	}
189
+
190
+	f.width.value = f.width.value == "" ? 100 : f.width.value;
191
+	f.height.value = f.height.value == "" ? 100 : f.height.value;
192
+
193
+	fe = ed.selection.getNode();
194
+	if (fe != null && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(ed.dom.getAttrib(fe, 'class'))) {
195
+		switch (f.media_type.options[f.media_type.selectedIndex].value) {
196
+			case "flash":
197
+				fe.className = "mceItemFlash";
198
+				break;
199
+
200
+			case "flv":
201
+				fe.className = "mceItemFlashVideo";
202
+				break;
203
+
204
+			case "shockwave":
205
+				fe.className = "mceItemShockWave";
206
+				break;
207
+
208
+			case "qt":
209
+				fe.className = "mceItemQuickTime";
210
+				break;
211
+
212
+			case "wmp":
213
+				fe.className = "mceItemWindowsMedia";
214
+				break;
215
+
216
+			case "rmp":
217
+				fe.className = "mceItemRealMedia";
218
+				break;
219
+		}
220
+
221
+		if (fe.width != f.width.value || fe.height != f.height.height)
222
+			ed.execCommand('mceRepaint');
223
+
224
+		fe.title = serializeParameters();
225
+		fe.width = f.width.value;
226
+		fe.height = f.height.value;
227
+		fe.style.width = f.width.value + (f.width.value.indexOf('%') == -1 ? 'px' : '');
228
+		fe.style.height = f.height.value + (f.height.value.indexOf('%') == -1 ? 'px' : '');
229
+		fe.align = f.align.options[f.align.selectedIndex].value;
230
+	} else {
231
+		h = '<img src="' + tinyMCEPopup.getWindowArg("plugin_url") + '/img/trans.gif"' ;
232
+
233
+		switch (f.media_type.options[f.media_type.selectedIndex].value) {
234
+			case "flash":
235
+				h += ' class="mceItemFlash"';
236
+				break;
237
+
238
+			case "flv":
239
+				h += ' class="mceItemFlashVideo"';
240
+				break;
241
+
242
+			case "shockwave":
243
+				h += ' class="mceItemShockWave"';
244
+				break;
245
+
246
+			case "qt":
247
+				h += ' class="mceItemQuickTime"';
248
+				break;
249
+
250
+			case "wmp":
251
+				h += ' class="mceItemWindowsMedia"';
252
+				break;
253
+
254
+			case "rmp":
255
+				h += ' class="mceItemRealMedia"';
256
+				break;
257
+		}
258
+
259
+		h += ' title="' + serializeParameters() + '"';
260
+		h += ' width="' + f.width.value + '"';
261
+		h += ' height="' + f.height.value + '"';
262
+		h += ' align="' + f.align.options[f.align.selectedIndex].value + '"';
263
+
264
+		h += ' />';
265
+
266
+		ed.execCommand('mceInsertContent', false, h);
267
+	}
268
+
269
+	tinyMCEPopup.close();
270
+}
271
+
272
+function updatePreview() {
273
+	var f = document.forms[0], type;
274
+
275
+	f.width.value = f.width.value || '320';
276
+	f.height.value = f.height.value || '240';
277
+
278
+	type = getType(f.src.value);
279
+	selectByValue(f, 'media_type', type);
280
+	changedType(type);
281
+	generatePreview();
282
+}
283
+
284
+function getMediaListHTML() {
285
+	if (typeof(tinyMCEMediaList) != "undefined" && tinyMCEMediaList.length > 0) {
286
+		var html = "";
287
+
288
+		html += '<select id="linklist" name="linklist" style="width: 250px" onchange="this.form.src.value=this.options[this.selectedIndex].value;updatePreview();">';
289
+		html += '<option value="">---</option>';
290
+
291
+		for (var i=0; i<tinyMCEMediaList.length; i++)
292
+			html += '<option value="' + tinyMCEMediaList[i][1] + '">' + tinyMCEMediaList[i][0] + '</option>';
293
+
294
+		html += '</select>';
295
+
296
+		return html;
297
+	}
298
+
299
+	return "";
300
+}
301
+
302
+function getType(v) {
303
+	var fo, i, c, el, x, f = document.forms[0];
304
+
305
+	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(';');
306
+
307
+	// YouTube
308
+	if (v.match(/watch\?v=(.+)(.*)/)) {
309
+		f.width.value = '425';
310
+		f.height.value = '350';
311
+		f.src.value = 'http://www.youtube.com/v/' + v.match(/v=(.*)(.*)/)[0].split('=')[1];
312
+		return 'flash';
313
+	}
314
+
315
+	// Google video
316
+	if (v.indexOf('http://video.google.com/videoplay?docid=') == 0) {
317
+		f.width.value = '425';
318
+		f.height.value = '326';
319
+		f.src.value = 'http://video.google.com/googleplayer.swf?docId=' + v.substring('http://video.google.com/videoplay?docid='.length) + '&hl=en';
320
+		return 'flash';
321
+	}
322
+
323
+	for (i=0; i<fo.length; i++) {
324
+		c = fo[i].split('=');
325
+
326
+		el = c[1].split(',');
327
+		for (x=0; x<el.length; x++)
328
+		if (v.indexOf('.' + el[x]) != -1)
329
+			return c[0];
330
+	}
331
+
332
+	return null;
333
+}
334
+
335
+function switchType(v) {
336
+	var t = getType(v), d = document, f = d.forms[0];
337
+
338
+	if (!t)
339
+		return;
340
+
341
+	selectByValue(d.forms[0], 'media_type', t);
342
+	changedType(t);
343
+
344
+	// Update qtsrc also
345
+	if (t == 'qt' && f.src.value.toLowerCase().indexOf('rtsp://') != -1) {
346
+		alert(ed.getLang("media_qt_stream_warn"));
347
+
348
+		if (f.qt_qtsrc.value == '')
349
+			f.qt_qtsrc.value = f.src.value;
350
+	}
351
+}
352
+
353
+function changedType(t) {
354
+	var d = document;
355
+
356
+	d.getElementById('flash_options').style.display = 'none';
357
+	d.getElementById('flv_options').style.display = 'none';
358
+	d.getElementById('qt_options').style.display = 'none';
359
+	d.getElementById('shockwave_options').style.display = 'none';
360
+	d.getElementById('wmp_options').style.display = 'none';
361
+	d.getElementById('rmp_options').style.display = 'none';
362
+	d.getElementById(t + '_options').style.display = 'block';
363
+}
364
+
365
+function serializeParameters() {
366
+	var d = document, f = d.forms[0], s = '';
367
+
368
+	switch (f.media_type.options[f.media_type.selectedIndex].value) {
369
+		case "flash":
370
+			s += getBool('flash', 'play', true);
371
+			s += getBool('flash', 'loop', true);
372
+			s += getBool('flash', 'menu', true);
373
+			s += getBool('flash', 'swliveconnect', false);
374
+			s += getStr('flash', 'quality');
375
+			s += getStr('flash', 'scale');
376
+			s += getStr('flash', 'salign');
377
+			s += getStr('flash', 'wmode');
378
+			s += getStr('flash', 'base');
379
+			s += getStr('flash', 'flashvars');
380
+		break;
381
+
382
+		case "qt":
383
+			s += getBool('qt', 'loop', false);
384
+			s += getBool('qt', 'autoplay', true);
385
+			s += getBool('qt', 'cache', false);
386
+			s += getBool('qt', 'controller', true);
387
+			s += getBool('qt', 'correction', false, 'none', 'full');
388
+			s += getBool('qt', 'enablejavascript', false);
389
+			s += getBool('qt', 'kioskmode', false);
390
+			s += getBool('qt', 'autohref', false);
391
+			s += getBool('qt', 'playeveryframe', false);
392
+			s += getBool('qt', 'targetcache', false);
393
+			s += getStr('qt', 'scale');
394
+			s += getStr('qt', 'starttime');
395
+			s += getStr('qt', 'endtime');
396
+			s += getStr('qt', 'target');
397
+			s += getStr('qt', 'qtsrcchokespeed');
398
+			s += getStr('qt', 'volume');
399
+			s += getStr('qt', 'qtsrc');
400
+		break;
401
+
402
+		case "shockwave":
403
+			s += getBool('shockwave', 'sound');
404
+			s += getBool('shockwave', 'progress');
405
+			s += getBool('shockwave', 'autostart');
406
+			s += getBool('shockwave', 'swliveconnect');
407
+			s += getStr('shockwave', 'swvolume');
408
+			s += getStr('shockwave', 'swstretchstyle');
409
+			s += getStr('shockwave', 'swstretchhalign');
410
+			s += getStr('shockwave', 'swstretchvalign');
411
+		break;
412
+
413
+		case "wmp":
414
+			s += getBool('wmp', 'autostart', true);
415
+			s += getBool('wmp', 'enabled', false);
416
+			s += getBool('wmp', 'enablecontextmenu', true);
417
+			s += getBool('wmp', 'fullscreen', false);
418
+			s += getBool('wmp', 'invokeurls', true);
419
+			s += getBool('wmp', 'mute', false);
420
+			s += getBool('wmp', 'stretchtofit', false);
421
+			s += getBool('wmp', 'windowlessvideo', false);
422
+			s += getStr('wmp', 'balance');
423
+			s += getStr('wmp', 'baseurl');
424
+			s += getStr('wmp', 'captioningid');
425
+			s += getStr('wmp', 'currentmarker');
426
+			s += getStr('wmp', 'currentposition');
427
+			s += getStr('wmp', 'defaultframe');
428
+			s += getStr('wmp', 'playcount');
429
+			s += getStr('wmp', 'rate');
430
+			s += getStr('wmp', 'uimode');
431
+			s += getStr('wmp', 'volume');
432
+		break;
433
+
434
+		case "rmp":
435
+			s += getBool('rmp', 'autostart', false);
436
+			s += getBool('rmp', 'loop', false);
437
+			s += getBool('rmp', 'autogotourl', true);
438
+			s += getBool('rmp', 'center', false);
439
+			s += getBool('rmp', 'imagestatus', true);
440
+			s += getBool('rmp', 'maintainaspect', false);
441
+			s += getBool('rmp', 'nojava', false);
442
+			s += getBool('rmp', 'prefetch', false);
443
+			s += getBool('rmp', 'shuffle', false);
444
+			s += getStr('rmp', 'console');
445
+			s += getStr('rmp', 'controls');
446
+			s += getStr('rmp', 'numloop');
447
+			s += getStr('rmp', 'scriptcallbacks');
448
+		break;
449
+	}
450
+
451
+	s += getStr(null, 'id');
452
+	s += getStr(null, 'name');
453
+	s += getStr(null, 'src');
454
+	s += getStr(null, 'align');
455
+	s += getStr(null, 'bgcolor');
456
+	s += getInt(null, 'vspace');
457
+	s += getInt(null, 'hspace');
458
+	s += getStr(null, 'width');
459
+	s += getStr(null, 'height');
460
+
461
+	s = s.length > 0 ? s.substring(0, s.length - 1) : s;
462
+
463
+	return s;
464
+}
465
+
466
+function setBool(pl, p, n) {
467
+	if (typeof(pl[n]) == "undefined")
468
+		return;
469
+
470
+	document.forms[0].elements[p + "_" + n].checked = pl[n];
471
+}
472
+
473
+function setStr(pl, p, n) {
474
+	var f = document.forms[0], e = f.elements[(p != null ? p + "_" : '') + n];
475
+
476
+	if (typeof(pl[n]) == "undefined")
477
+		return;
478
+
479
+	if (e.type == "text")
480
+		e.value = pl[n];
481
+	else
482
+		selectByValue(f, (p != null ? p + "_" : '') + n, pl[n]);
483
+}
484
+
485
+function getBool(p, n, d, tv, fv) {
486
+	var v = document.forms[0].elements[p + "_" + n].checked;
487
+
488
+	tv = typeof(tv) == 'undefined' ? 'true' : "'" + jsEncode(tv) + "'";
489
+	fv = typeof(fv) == 'undefined' ? 'false' : "'" + jsEncode(fv) + "'";
490
+
491
+	return (v == d) ? '' : n + (v ? ':' + tv + ',' : ':' + fv + ',');
492
+}
493
+
494
+function getStr(p, n, d) {
495
+	var e = document.forms[0].elements[(p != null ? p + "_" : "") + n];
496
+	var v = e.type == "text" ? e.value : e.options[e.selectedIndex].value;
497
+
498
+	if (n == 'src')
499
+		v = tinyMCEPopup.editor.convertURL(v, 'src', null);
500
+
501
+	return ((n == d || v == '') ? '' : n + ":'" + jsEncode(v) + "',");
502
+}
503
+
504
+function getInt(p, n, d) {
505
+	var e = document.forms[0].elements[(p != null ? p + "_" : "") + n];
506
+	var v = e.type == "text" ? e.value : e.options[e.selectedIndex].value;
507
+
508
+	return ((n == d || v == '') ? '' : n + ":" + v.replace(/[^0-9]+/g, '') + ",");
509
+}
510
+
511
+function jsEncode(s) {
512
+	s = s.replace(new RegExp('\\\\', 'g'), '\\\\');
513
+	s = s.replace(new RegExp('"', 'g'), '\\"');
514
+	s = s.replace(new RegExp("'", 'g'), "\\'");
515
+
516
+	return s;
517
+}
518
+
519
+function generatePreview(c) {
520
+	var f = document.forms[0], p = document.getElementById('prev'), h = '', cls, pl, n, type, codebase, wp, hp, nw, nh;
521
+
522
+	p.innerHTML = '<!-- x --->';
523
+
524
+	nw = parseInt(f.width.value);
525
+	nh = parseInt(f.height.value);
526
+
527
+	if (f.width.value != "" && f.height.value != "") {
528
+		if (f.constrain.checked) {
529
+			if (c == 'width' && oldWidth != 0) {
530
+				wp = nw / oldWidth;
531
+				nh = Math.round(wp * nh);
532
+				f.height.value = nh;
533
+			} else if (c == 'height' && oldHeight != 0) {
534
+				hp = nh / oldHeight;
535
+				nw = Math.round(hp * nw);
536
+				f.width.value = nw;
537
+			}
538
+		}
539
+	}
540
+
541
+	if (f.width.value != "")
542
+		oldWidth = nw;
543
+
544
+	if (f.height.value != "")
545
+		oldHeight = nh;
546
+
547
+	// After constrain
548
+	pl = serializeParameters();
549
+
550
+	switch (f.media_type.options[f.media_type.selectedIndex].value) {
551
+		case "flash":
552
+			cls = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000';
553
+			codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
554
+			type = 'application/x-shockwave-flash';
555
+			break;
556
+
557
+		case "shockwave":
558
+			cls = 'clsid:166B1BCA-3F9C-11CF-8075-444553540000';
559
+			codebase = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0';
560
+			type = 'application/x-director';
561
+			break;
562
+
563
+		case "qt":
564
+			cls = 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';
565
+			codebase = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
566
+			type = 'video/quicktime';
567
+			break;
568
+
569
+		case "wmp":
570
+			cls = ed.getParam('media_wmp6_compatible') ? 'clsid:05589FA1-C356-11CE-BF01-00AA0055595A' : 'clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6';
571
+			codebase = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
572
+			type = 'application/x-mplayer2';
573
+			break;
574
+
575
+		case "rmp":
576
+			cls = 'clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA';
577
+			codebase = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
578
+			type = 'audio/x-pn-realaudio-plugin';
579
+			break;
580
+	}
581
+
582
+	if (pl == '') {
583
+		p.innerHTML = '';
584
+		return;
585
+	}
586
+
587
+	pl = tinyMCEPopup.editor.plugins.media._parse(pl);
588
+
589
+	if (!pl.src) {
590
+		p.innerHTML = '';
591
+		return;
592
+	}
593
+
594
+	pl.src = tinyMCEPopup.editor.documentBaseURI.toAbsolute(pl.src);
595
+	pl.width = !pl.width ? 100 : pl.width;
596
+	pl.height = !pl.height ? 100 : pl.height;
597
+	pl.id = !pl.id ? 'obj' : pl.id;
598
+	pl.name = !pl.name ? 'eobj' : pl.name;
599
+	pl.align = !pl.align ? '' : pl.align;
600
+
601
+	// Avoid annoying warning about insecure items
602
+	if (!tinymce.isIE || document.location.protocol != 'https:') {
603
+		h += '<object classid="clsid:' + cls + '" codebase="' + codebase + '" width="' + pl.width + '" height="' + pl.height + '" id="' + pl.id + '" name="' + pl.name + '" align="' + pl.align + '">';
604
+
605
+		for (n in pl) {
606
+			h += '<param name="' + n + '" value="' + pl[n] + '">';
607
+
608
+			// Add extra url parameter if it's an absolute URL
609
+			if (n == 'src' && pl[n].indexOf('://') != -1)
610
+				h += '<param name="url" value="' + pl[n] + '" />';
611
+		}
612
+	}
613
+
614
+	h += '<embed type="' + type + '" ';
615
+
616
+	for (n in pl)
617
+		h += n + '="' + pl[n] + '" ';
618
+
619
+	h += '></embed>';
620
+
621
+	// Avoid annoying warning about insecure items
622
+	if (!tinymce.isIE || document.location.protocol != 'https:')
623
+		h += '</object>';
624
+
625
+	p.innerHTML = "<!-- x --->" + h;
626
+}
627
+
628
+tinyMCEPopup.onInit.add(init);