]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/tiny_mce/plugins/media/editor_plugin_src.js
Release 6.5.0
[Github/sugarcrm.git] / include / javascript / tiny_mce / plugins / media / editor_plugin_src.js
1 /**
2  * editor_plugin_src.js
3  *
4  * Copyright 2009, Moxiecode Systems AB
5  * Released under LGPL License.
6  *
7  * License: http://tinymce.moxiecode.com/license
8  * Contributing: http://tinymce.moxiecode.com/contributing
9  */
10
11 (function() {
12         var rootAttributes = tinymce.explode('id,name,width,height,style,align,class,hspace,vspace,bgcolor,type'), excludedAttrs = tinymce.makeMap(rootAttributes.join(',')), Node = tinymce.html.Node,
13                 mediaTypes, scriptRegExp, JSON = tinymce.util.JSON, mimeTypes;
14
15         // Media types supported by this plugin
16         mediaTypes = [
17                 // Type, clsid:s, mime types, codebase
18                 ["Flash", "d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash", "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"],
19                 ["ShockWave", "166b1bca-3f9c-11cf-8075-444553540000", "application/x-director", "http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0"],
20                 ["WindowsMedia", "6bf52a52-394a-11d3-b153-00c04f79faa6,22d6f312-b0f6-11d0-94ab-0080c74c7e95,05589fa1-c356-11ce-bf01-00aa0055595a", "application/x-mplayer2", "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"],
21                 ["QuickTime", "02bf25d5-8c17-4b23-bc80-d3488abddc6b", "video/quicktime", "http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0"],
22                 ["RealMedia", "cfcdaa03-8be4-11cf-b84b-0020afbbccfa", "audio/x-pn-realaudio-plugin", "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"],
23                 ["Java", "8ad9c840-044e-11d1-b3e9-00805f499d93", "application/x-java-applet", "http://java.sun.com/products/plugin/autodl/jinstall-1_5_0-windows-i586.cab#Version=1,5,0,0"],
24                 ["Silverlight", "dfeaf541-f3e1-4c24-acac-99c30715084a", "application/x-silverlight-2"],
25                 ["Iframe"],
26                 ["Video"],
27                 ["Audio"]
28         ];
29
30         function toArray(obj) {
31                 var undef, out, i;
32
33                 if (obj && !obj.splice) {
34                         out = [];
35
36                         for (i = 0; true; i++) {
37                                 if (obj[i])
38                                         out[i] = obj[i];
39                                 else
40                                         break;
41                         }
42
43                         return out;
44                 }
45
46                 return obj;
47         };
48
49         tinymce.create('tinymce.plugins.MediaPlugin', {
50                 init : function(ed, url) {
51                         var self = this, lookup = {}, i, y, item, name;
52
53                         function isMediaImg(node) {
54                                 return node && node.nodeName === 'IMG' && ed.dom.hasClass(node, 'mceItemMedia');
55                         };
56
57                         self.editor = ed;
58                         self.url = url;
59
60                         // Parse media types into a lookup table
61                         scriptRegExp = '';
62                         for (i = 0; i < mediaTypes.length; i++) {
63                                 name = mediaTypes[i][0];
64
65                                 item = {
66                                         name : name,
67                                         clsids : tinymce.explode(mediaTypes[i][1] || ''),
68                                         mimes : tinymce.explode(mediaTypes[i][2] || ''),
69                                         codebase : mediaTypes[i][3]
70                                 };
71
72                                 for (y = 0; y < item.clsids.length; y++)
73                                         lookup['clsid:' + item.clsids[y]] = item;
74
75                                 for (y = 0; y < item.mimes.length; y++)
76                                         lookup[item.mimes[y]] = item;
77
78                                 lookup['mceItem' + name] = item;
79                                 lookup[name.toLowerCase()] = item;
80
81                                 scriptRegExp += (scriptRegExp ? '|' : '') + name;
82                         }
83
84                         // Handle the media_types setting
85                         tinymce.each(ed.getParam("media_types",
86                                 "video=mp4,m4v,ogv,webm;" +
87                                 "silverlight=xap;" +
88                                 "flash=swf,flv;" +
89                                 "shockwave=dcr;" +
90                                 "quicktime=mov,qt,mpg,mpeg;" +
91                                 "shockwave=dcr;" +
92                                 "windowsmedia=avi,wmv,wm,asf,asx,wmx,wvx;" +
93                                 "realmedia=rm,ra,ram;" +
94                                 "java=jar;" +
95                                 "audio=mp3,ogg"
96                         ).split(';'), function(item) {
97                                 var i, extensions, type;
98
99                                 item = item.split(/=/);
100                                 extensions = tinymce.explode(item[1].toLowerCase());
101                                 for (i = 0; i < extensions.length; i++) {
102                                         type = lookup[item[0].toLowerCase()];
103
104                                         if (type)
105                                                 lookup[extensions[i]] = type;
106                                 }
107                         });
108
109                         scriptRegExp = new RegExp('write(' + scriptRegExp + ')\\(([^)]+)\\)');
110                         self.lookup = lookup;
111
112                         ed.onPreInit.add(function() {
113                                 // Allow video elements
114                                 ed.schema.addValidElements('object[id|style|width|height|classid|codebase|*],param[name|value],embed[id|style|width|height|type|src|*],video[*],audio[*],source[*]');
115
116                                 // Convert video elements to image placeholder
117                                 ed.parser.addNodeFilter('object,embed,video,audio,script,iframe', function(nodes) {
118                                         var i = nodes.length;
119
120                                         while (i--)
121                                                 self.objectToImg(nodes[i]);
122                                 });
123
124                                 // Convert image placeholders to video elements
125                                 ed.serializer.addNodeFilter('img', function(nodes, name, args) {
126                                         var i = nodes.length, node;
127
128                                         while (i--) {
129                                                 node = nodes[i];
130                                                 if ((node.attr('class') || '').indexOf('mceItemMedia') !== -1)
131                                                         self.imgToObject(node, args);
132                                         }
133                                 });
134                         });
135
136                         ed.onInit.add(function() {
137                                 // Display "media" instead of "img" in element path
138                                 if (ed.theme && ed.theme.onResolveName) {
139                                         ed.theme.onResolveName.add(function(theme, path_object) {
140                                                 if (path_object.name === 'img' && ed.dom.hasClass(path_object.node, 'mceItemMedia'))
141                                                         path_object.name = 'media';
142                                         });
143                                 }
144
145                                 // Add contect menu if it's loaded
146                                 if (ed && ed.plugins.contextmenu) {
147                                         ed.plugins.contextmenu.onContextMenu.add(function(plugin, menu, element) {
148                                                 if (element.nodeName === 'IMG' && element.className.indexOf('mceItemMedia') !== -1)
149                                                         menu.add({title : 'media.edit', icon : 'media', cmd : 'mceMedia'});
150                                         });
151                                 }
152                         });
153
154                         // Register commands
155                         ed.addCommand('mceMedia', function() {
156                                 var data, img;
157
158                                 img = ed.selection.getNode();
159                                 if (isMediaImg(img)) {
160                                         data = ed.dom.getAttrib(img, 'data-mce-json');
161                                         if (data) {
162                                                 data = JSON.parse(data);
163
164                                                 // Add some extra properties to the data object
165                                                 tinymce.each(rootAttributes, function(name) {
166                                                         var value = ed.dom.getAttrib(img, name);
167
168                                                         if (value)
169                                                                 data[name] = value;
170                                                 });
171
172                                                 data.type = self.getType(img.className).name.toLowerCase();
173                                         }
174                                 }
175
176                                 if (!data) {
177                                         data = {
178                                                 type : 'flash',
179                                                 video: {sources:[]},
180                                                 params: {}
181                                         };
182                                 }
183
184                                 ed.windowManager.open({
185                                         file : url + '/media.htm',
186                                         width : 430 + parseInt(ed.getLang('media.delta_width', 0)),
187                                         height : 500 + parseInt(ed.getLang('media.delta_height', 0)),
188                                         inline : 1
189                                 }, {
190                                         plugin_url : url,
191                                         data : data
192                                 });
193                         });
194
195                         // Register buttons
196                         ed.addButton('media', {title : 'media.desc', cmd : 'mceMedia'});
197
198                         // Update media selection status
199                         ed.onNodeChange.add(function(ed, cm, node) {
200                                 cm.setActive('media', isMediaImg(node));
201                         });
202                 },
203
204                 convertUrl : function(url, force_absolute) {
205                         var self = this, editor = self.editor, settings = editor.settings,
206                                 urlConverter = settings.url_converter,
207                                 urlConverterScope = settings.url_converter_scope || self;
208
209                         if (!url)
210                                 return url;
211
212                         if (force_absolute)
213                                 return editor.documentBaseURI.toAbsolute(url);
214
215                         return urlConverter.call(urlConverterScope, url, 'src', 'object');
216                 },
217
218                 getInfo : function() {
219                         return {
220                                 longname : 'Media',
221                                 author : 'Moxiecode Systems AB',
222                                 authorurl : 'http://tinymce.moxiecode.com',
223                                 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media',
224                                 version : tinymce.majorVersion + "." + tinymce.minorVersion
225                         };
226                 },
227
228                 /**
229                  * Converts the JSON data object to an img node.
230                  */
231                 dataToImg : function(data, force_absolute) {
232                         var self = this, editor = self.editor, baseUri = editor.documentBaseURI, sources, attrs, img, i;
233
234                         data.params.src = self.convertUrl(data.params.src, force_absolute);
235
236                         attrs = data.video.attrs;
237                         if (attrs)
238                                 attrs.src = self.convertUrl(attrs.src, force_absolute);
239
240                         if (attrs)
241                                 attrs.poster = self.convertUrl(attrs.poster, force_absolute);
242
243                         sources = toArray(data.video.sources);
244                         if (sources) {
245                                 for (i = 0; i < sources.length; i++)
246                                         sources[i].src = self.convertUrl(sources[i].src, force_absolute);
247                         }
248
249                         img = self.editor.dom.create('img', {
250                                 id : data.id,
251                                 style : data.style,
252                                 align : data.align,
253                                 src : self.editor.theme.url + '/img/trans.gif',
254                                 'class' : 'mceItemMedia mceItem' + self.getType(data.type).name,
255                                 'data-mce-json' : JSON.serialize(data, "'")
256                         });
257
258                         img.width = data.width || (data.type == 'audio' ? "300" : "320");
259                         img.height = data.height || (data.type == 'audio' ? "32" : "240");
260
261                         return img;
262                 },
263
264                 /**
265                  * Converts the JSON data object to a HTML string.
266                  */
267                 dataToHtml : function(data, force_absolute) {
268                         return this.editor.serializer.serialize(this.dataToImg(data, force_absolute), {forced_root_block : '', force_absolute : force_absolute});
269                 },
270
271                 /**
272                  * Converts the JSON data object to a HTML string.
273                  */
274                 htmlToData : function(html) {
275                         var fragment, img, data;
276
277                         data = {
278                                 type : 'flash',
279                                 video: {sources:[]},
280                                 params: {}
281                         };
282
283                         fragment = this.editor.parser.parse(html);
284                         img = fragment.getAll('img')[0];
285
286                         if (img) {
287                                 data = JSON.parse(img.attr('data-mce-json'));
288                                 data.type = this.getType(img.attr('class')).name.toLowerCase();
289
290                                 // Add some extra properties to the data object
291                                 tinymce.each(rootAttributes, function(name) {
292                                         var value = img.attr(name);
293
294                                         if (value)
295                                                 data[name] = value;
296                                 });
297                         }
298
299                         return data;
300                 },
301
302                 /**
303                  * Get type item by extension, class, clsid or mime type.
304                  *
305                  * @method getType
306                  * @param {String} value Value to get type item by.
307                  * @return {Object} Type item object or undefined.
308                  */
309                 getType : function(value) {
310                         var i, values, typeItem;
311
312                         // Find type by checking the classes
313                         values = tinymce.explode(value, ' ');
314                         for (i = 0; i < values.length; i++) {
315                                 typeItem = this.lookup[values[i]];
316
317                                 if (typeItem)
318                                         return typeItem;
319                         }
320                 },
321
322                 /**
323                  * Converts a tinymce.html.Node image element to video/object/embed.
324                  */
325                 imgToObject : function(node, args) {
326                         var self = this, editor = self.editor, video, object, embed, iframe, name, value, data,
327                                 source, sources, params, param, typeItem, i, item, mp4Source, replacement,
328                                 posterSrc, style, audio;
329
330                         // Adds the flash player
331                         function addPlayer(video_src, poster_src) {
332                                 var baseUri, flashVars, flashVarsOutput, params, flashPlayer;
333
334                                 flashPlayer = editor.getParam('flash_video_player_url', self.convertUrl(self.url + '/moxieplayer.swf'));
335                                 if (flashPlayer) {
336                                         baseUri = editor.documentBaseURI;
337                                         data.params.src = flashPlayer;
338
339                                         // Convert the movie url to absolute urls
340                                         if (editor.getParam('flash_video_player_absvideourl', true)) {
341                                                 video_src = baseUri.toAbsolute(video_src || '', true);
342                                                 poster_src = baseUri.toAbsolute(poster_src || '', true);
343                                         }
344
345                                         // Generate flash vars
346                                         flashVarsOutput = '';
347                                         flashVars = editor.getParam('flash_video_player_flashvars', {url : '$url', poster : '$poster'});
348                                         tinymce.each(flashVars, function(value, name) {
349                                                 // Replace $url and $poster variables in flashvars value
350                                                 value = value.replace(/\$url/, video_src || '');
351                                                 value = value.replace(/\$poster/, poster_src || '');
352
353                                                 if (value.length > 0)
354                                                         flashVarsOutput += (flashVarsOutput ? '&' : '') + name + '=' + escape(value);
355                                         });
356
357                                         if (flashVarsOutput.length)
358                                                 data.params.flashvars = flashVarsOutput;
359
360                                         params = editor.getParam('flash_video_player_params', {
361                                                 allowfullscreen: true,
362                                                 allowscriptaccess: true
363                                         });
364
365                                         tinymce.each(params, function(value, name) {
366                                                 data.params[name] = "" + value;
367                                         });
368                                 }
369                         };
370
371                         data = node.attr('data-mce-json');
372                         if (!data)
373                                 return;
374
375                         data = JSON.parse(data);
376                         typeItem = this.getType(node.attr('class'));
377
378                         style = node.attr('data-mce-style')
379                         if (!style) {
380                                 style = node.attr('style');
381
382                                 if (style)
383                                         style = editor.dom.serializeStyle(editor.dom.parseStyle(style, 'img'));
384                         }
385
386                         // Handle iframe
387                         if (typeItem.name === 'Iframe') {
388                                 replacement = new Node('iframe', 1);
389
390                                 tinymce.each(rootAttributes, function(name) {
391                                         var value = node.attr(name);
392
393                                         if (name == 'class' && value)
394                                                 value = value.replace(/mceItem.+ ?/g, '');
395
396                                         if (value && value.length > 0)
397                                                 replacement.attr(name, value);
398                                 });
399
400                                 for (name in data.params)
401                                         replacement.attr(name, data.params[name]);
402
403                                 replacement.attr({
404                                         style: style,
405                                         src: data.params.src
406                                 });
407
408                                 node.replace(replacement);
409
410                                 return;
411                         }
412
413                         // Handle scripts
414                         if (this.editor.settings.media_use_script) {
415                                 replacement = new Node('script', 1).attr('type', 'text/javascript');
416
417                                 value = new Node('#text', 3);
418                                 value.value = 'write' + typeItem.name + '(' + JSON.serialize(tinymce.extend(data.params, {
419                                         width: node.attr('width'),
420                                         height: node.attr('height')
421                                 })) + ');';
422
423                                 replacement.append(value);
424                                 node.replace(replacement);
425
426                                 return;
427                         }
428
429                         // Add HTML5 video element
430                         if (typeItem.name === 'Video' && data.video.sources[0]) {
431                                 // Create new object element
432                                 video = new Node('video', 1).attr(tinymce.extend({
433                                         id : node.attr('id'),
434                                         width: node.attr('width'),
435                                         height: node.attr('height'),
436                                         style : style
437                                 }, data.video.attrs));
438
439                                 // Get poster source and use that for flash fallback
440                                 if (data.video.attrs)
441                                         posterSrc = data.video.attrs.poster;
442
443                                 sources = data.video.sources = toArray(data.video.sources);
444                                 for (i = 0; i < sources.length; i++) {
445                                         if (/\.mp4$/.test(sources[i].src))
446                                                 mp4Source = sources[i].src;
447                                 }
448
449                                 if (!sources[0].type) {
450                                         video.attr('src', sources[0].src);
451                                         sources.splice(0, 1);
452                                 }
453
454                                 for (i = 0; i < sources.length; i++) {
455                                         source = new Node('source', 1).attr(sources[i]);
456                                         source.shortEnded = true;
457                                         video.append(source);
458                                 }
459
460                                 // Create flash fallback for video if we have a mp4 source
461                                 if (mp4Source) {
462                                         addPlayer(mp4Source, posterSrc);
463                                         typeItem = self.getType('flash');
464                                 } else
465                                         data.params.src = '';
466                         }
467
468                         // Add HTML5 audio element
469                         if (typeItem.name === 'Audio' && data.video.sources[0]) {
470                                 // Create new object element
471                                 audio = new Node('audio', 1).attr(tinymce.extend({
472                                         id : node.attr('id'),
473                                         width: node.attr('width'),
474                                         height: node.attr('height'),
475                                         style : style
476                                 }, data.video.attrs));
477
478                                 // Get poster source and use that for flash fallback
479                                 if (data.video.attrs)
480                                         posterSrc = data.video.attrs.poster;
481
482                                 sources = data.video.sources = toArray(data.video.sources);
483                                 if (!sources[0].type) {
484                                         audio.attr('src', sources[0].src);
485                                         sources.splice(0, 1);
486                                 }
487
488                                 for (i = 0; i < sources.length; i++) {
489                                         source = new Node('source', 1).attr(sources[i]);
490                                         source.shortEnded = true;
491                                         audio.append(source);
492                                 }
493
494                                 data.params.src = '';
495                         }
496
497                         // Do we have a params src then we can generate object
498                         if (data.params.src) {
499                                 // Is flv movie add player for it
500                                 if (/\.flv$/i.test(data.params.src))
501                                         addPlayer(data.params.src, '');
502
503                                 if (args && args.force_absolute)
504                                         data.params.src = editor.documentBaseURI.toAbsolute(data.params.src);
505
506                                 // Create new object element
507                                 object = new Node('object', 1).attr({
508                                         id : node.attr('id'),
509                                         width: node.attr('width'),
510                                         height: node.attr('height'),
511                                         style : style
512                                 });
513
514                                 tinymce.each(rootAttributes, function(name) {
515                                         if (data[name] && name != 'type')
516                                                 object.attr(name, data[name]);
517                                 });
518
519                                 // Add params
520                                 for (name in data.params) {
521                                         param = new Node('param', 1);
522                                         param.shortEnded = true;
523                                         value = data.params[name];
524
525                                         // Windows media needs to use url instead of src for the media URL
526                                         if (name === 'src' && typeItem.name === 'WindowsMedia')
527                                                 name = 'url';
528
529                                         param.attr({name: name, value: value});
530                                         object.append(param);
531                                 }
532
533                                 // Setup add type and classid if strict is disabled
534                                 if (this.editor.getParam('media_strict', true)) {
535                                         object.attr({
536                                                 data: data.params.src,
537                                                 type: typeItem.mimes[0]
538                                         });
539                                 } else {
540                                         object.attr({
541                                                 classid: "clsid:" + typeItem.clsids[0],
542                                                 codebase: typeItem.codebase
543                                         });
544
545                                         embed = new Node('embed', 1);
546                                         embed.shortEnded = true;
547                                         embed.attr({
548                                                 id: node.attr('id'),
549                                                 width: node.attr('width'),
550                                                 height: node.attr('height'),
551                                                 style : style,
552                                                 type: typeItem.mimes[0]
553                                         });
554
555                                         for (name in data.params)
556                                                 embed.attr(name, data.params[name]);
557
558                                         tinymce.each(rootAttributes, function(name) {
559                                                 if (data[name] && name != 'type')
560                                                         embed.attr(name, data[name]);
561                                         });
562
563                                         object.append(embed);
564                                 }
565
566                                 // Insert raw HTML
567                                 if (data.object_html) {
568                                         value = new Node('#text', 3);
569                                         value.raw = true;
570                                         value.value = data.object_html;
571                                         object.append(value);
572                                 }
573
574                                 // Append object to video element if it exists
575                                 if (video)
576                                         video.append(object);
577                         }
578
579                         if (video) {
580                                 // Insert raw HTML
581                                 if (data.video_html) {
582                                         value = new Node('#text', 3);
583                                         value.raw = true;
584                                         value.value = data.video_html;
585                                         video.append(value);
586                                 }
587                         }
588
589                         if (audio) {
590                                 // Insert raw HTML
591                                 if (data.video_html) {
592                                         value = new Node('#text', 3);
593                                         value.raw = true;
594                                         value.value = data.video_html;
595                                         audio.append(value);
596                                 }
597                         }
598
599                         if (video || audio || object)
600                                 node.replace(video || audio || object);
601                         else
602                                 node.remove();
603                 },
604
605                 /**
606                  * Converts a tinymce.html.Node video/object/embed to an img element.
607                  *
608                  * The video/object/embed will be converted into an image placeholder with a JSON data attribute like this:
609                  * <img class="mceItemMedia mceItemFlash" width="100" height="100" data-mce-json="{..}" />
610                  *
611                  * The JSON structure will be like this:
612                  * {'params':{'flashvars':'something','quality':'high','src':'someurl'}, 'video':{'sources':[{src: 'someurl', type: 'video/mp4'}]}}
613                  */
614                 objectToImg : function(node) {
615                         var object, embed, video, iframe, img, name, id, width, height, style, i, html,
616                                 param, params, source, sources, data, type, lookup = this.lookup,
617                                 matches, attrs, urlConverter = this.editor.settings.url_converter,
618                                 urlConverterScope = this.editor.settings.url_converter_scope;
619
620                         function getInnerHTML(node) {
621                                 return new tinymce.html.Serializer({
622                                         inner: true,
623                                         validate: false
624                                 }).serialize(node);
625                         };
626
627                         // If node isn't in document
628                         if (!node.parent)
629                                 return;
630
631                         // Handle media scripts
632                         if (node.name === 'script') {
633                                 if (node.firstChild)
634                                         matches = scriptRegExp.exec(node.firstChild.value);
635
636                                 if (!matches)
637                                         return;
638
639                                 type = matches[1];
640                                 data = {video : {}, params : JSON.parse(matches[2])};
641                                 width = data.params.width;
642                                 height = data.params.height;
643                         }
644
645                         // Setup data objects
646                         data = data || {
647                                 video : {},
648                                 params : {}
649                         };
650
651                         // Setup new image object
652                         img = new Node('img', 1);
653                         img.attr({
654                                 src : this.editor.theme.url + '/img/trans.gif'
655                         });
656
657                         // Video element
658                         name = node.name;
659                         if (name === 'video' || name == 'audio') {
660                                 video = node;
661                                 object = node.getAll('object')[0];
662                                 embed = node.getAll('embed')[0];
663                                 width = video.attr('width');
664                                 height = video.attr('height');
665                                 id = video.attr('id');
666                                 data.video = {attrs : {}, sources : []};
667
668                                 // Get all video attributes
669                                 attrs = data.video.attrs;
670                                 for (name in video.attributes.map)
671                                         attrs[name] = video.attributes.map[name];
672
673                                 source = node.attr('src');
674                                 if (source)
675                                         data.video.sources.push({src : urlConverter.call(urlConverterScope, source, 'src', node.name)});
676
677                                 // Get all sources
678                                 sources = video.getAll("source");
679                                 for (i = 0; i < sources.length; i++) {
680                                         source = sources[i].remove();
681
682                                         data.video.sources.push({
683                                                 src: urlConverter.call(urlConverterScope, source.attr('src'), 'src', 'source'),
684                                                 type: source.attr('type'),
685                                                 media: source.attr('media')
686                                         });
687                                 }
688
689                                 // Convert the poster URL
690                                 if (attrs.poster)
691                                         attrs.poster = urlConverter.call(urlConverterScope, attrs.poster, 'poster', node.name);
692                         }
693
694                         // Object element
695                         if (node.name === 'object') {
696                                 object = node;
697                                 embed = node.getAll('embed')[0];
698                         }
699
700                         // Embed element
701                         if (node.name === 'embed')
702                                 embed = node;
703
704                         // Iframe element
705                         if (node.name === 'iframe') {
706                                 iframe = node;
707                                 type = 'Iframe';
708                         }
709
710                         if (object) {
711                                 // Get width/height
712                                 width = width || object.attr('width');
713                                 height = height || object.attr('height');
714                                 style = style || object.attr('style');
715                                 id = id || object.attr('id');
716
717                                 // Get all object params
718                                 params = object.getAll("param");
719                                 for (i = 0; i < params.length; i++) {
720                                         param = params[i];
721                                         name = param.remove().attr('name');
722
723                                         if (!excludedAttrs[name])
724                                                 data.params[name] = param.attr('value');
725                                 }
726
727                                 data.params.src = data.params.src || object.attr('data');
728                         }
729
730                         if (embed) {
731                                 // Get width/height
732                                 width = width || embed.attr('width');
733                                 height = height || embed.attr('height');
734                                 style = style || embed.attr('style');
735                                 id = id || embed.attr('id');
736
737                                 // Get all embed attributes
738                                 for (name in embed.attributes.map) {
739                                         if (!excludedAttrs[name] && !data.params[name])
740                                                 data.params[name] = embed.attributes.map[name];
741                                 }
742                         }
743
744                         if (iframe) {
745                                 // Get width/height
746                                 width = iframe.attr('width');
747                                 height = iframe.attr('height');
748                                 style = style || iframe.attr('style');
749                                 id = iframe.attr('id');
750
751                                 tinymce.each(rootAttributes, function(name) {
752                                         img.attr(name, iframe.attr(name));
753                                 });
754
755                                 // Get all iframe attributes
756                                 for (name in iframe.attributes.map) {
757                                         if (!excludedAttrs[name] && !data.params[name])
758                                                 data.params[name] = iframe.attributes.map[name];
759                                 }
760                         }
761
762                         // Use src not movie
763                         if (data.params.movie) {
764                                 data.params.src = data.params.src || data.params.movie;
765                                 delete data.params.movie;
766                         }
767
768                         // Convert the URL to relative/absolute depending on configuration
769                         if (data.params.src)
770                                 data.params.src = urlConverter.call(urlConverterScope, data.params.src, 'src', 'object');
771
772                         if (video) {
773                                 if (node.name === 'video')
774                                         type = lookup.video.name;
775                                 else if (node.name === 'audio')
776                                         type = lookup.audio.name;
777                         }
778
779                         if (object && !type)
780                                 type = (lookup[(object.attr('clsid') || '').toLowerCase()] || lookup[(object.attr('type') || '').toLowerCase()] || {}).name;
781
782                         if (embed && !type)
783                                 type = (lookup[(embed.attr('type') || '').toLowerCase()] || {}).name;
784
785                         // Replace the video/object/embed element with a placeholder image containing the data
786                         node.replace(img);
787
788                         // Remove embed
789                         if (embed)
790                                 embed.remove();
791
792                         // Serialize the inner HTML of the object element
793                         if (object) {
794                                 html = getInnerHTML(object.remove());
795
796                                 if (html)
797                                         data.object_html = html;
798                         }
799
800                         // Serialize the inner HTML of the video element
801                         if (video) {
802                                 html = getInnerHTML(video.remove());
803
804                                 if (html)
805                                         data.video_html = html;
806                         }
807
808                         // Set width/height of placeholder
809                         img.attr({
810                                 id : id,
811                                 'class' : 'mceItemMedia mceItem' + (type || 'Flash'),
812                                 style : style,
813                                 width : width || (node.name == 'audio' ? "300" : "320"),
814                                 height : height || (node.name == 'audio' ? "32" : "240"),
815                                 "data-mce-json" : JSON.serialize(data, "'")
816                         });
817                 }
818         });
819
820         // Register plugin
821         tinymce.PluginManager.add('media', tinymce.plugins.MediaPlugin);
822 })();