annotate WebContent/jscripts/tiny_mce/plugins/media/editor_plugin_src.js @ 6:5bb7cc86069c

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