~ubuntu-branches/ubuntu/lucid/mahara/lucid-security

« back to all changes in this revision

Viewing changes to htdocs/js/tinymce/plugins/media/editor_plugin_src.js

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2009-11-27 22:09:03 UTC
  • mfrom: (6.3.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091127220903-aiigd3tr46z0rmcg
Tags: 1.2.0-2
Fix postrm script so that Mahara can be uninstalled

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: editor_plugin_src.js 296 2007-08-21 10:36:35Z spocke $
 
2
 * $Id: editor_plugin_src.js 1037 2009-03-02 16:41:15Z spocke $
3
3
 *
4
4
 * @author Moxiecode
5
 
 * @copyright Copyright � 2004-2007, Moxiecode Systems AB, All rights reserved.
 
5
 * @copyright Copyright � 2004-2008, Moxiecode Systems AB, All rights reserved.
6
6
 */
7
7
 
8
 
/* Import plugin specific language pack */
9
 
tinyMCE.importPluginLanguagePack('media');
10
 
 
11
 
var TinyMCE_MediaPlugin = {
12
 
        getInfo : function() {
13
 
                return {
14
 
                        longname : 'Media',
15
 
                        author : 'Moxiecode Systems AB',
16
 
                        authorurl : 'http://tinymce.moxiecode.com',
17
 
                        infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media',
18
 
                        version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
19
 
                };
20
 
        },
21
 
 
22
 
        initInstance : function(inst) {
23
 
                // Warn if user has flash plugin and media plugin at the same time
24
 
                if (inst.hasPlugin('flash') && !tinyMCE.flashWarn) {
25
 
                        alert('Flash plugin is deprecated and should not be used together with the media plugin.');
26
 
                        tinyMCE.flashWarn = true;
27
 
                }
28
 
 
29
 
                if (!tinyMCE.settings['media_skip_plugin_css'])
30
 
                        tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/media/css/content.css");
31
 
        },
32
 
 
33
 
        getControlHTML : function(cn) {
34
 
                switch (cn) {
35
 
                        case "media":
36
 
                                return tinyMCE.getButtonHTML(cn, 'lang_media_desc', '{$pluginurl}/images/media.gif', 'mceMedia');
37
 
                }
38
 
 
39
 
                return "";
40
 
        },
41
 
 
42
 
        execCommand : function(editor_id, element, command, user_interface, value) {
43
 
                // Handle commands
44
 
                switch (command) {
45
 
                        case "mceMedia":
46
 
                                tinyMCE.openWindow({
47
 
                                                file : '../../plugins/media/media.htm',
48
 
                                                width : 430 + tinyMCE.getLang('lang_media_delta_width', 0),
49
 
                                                height : 470 + tinyMCE.getLang('lang_media_delta_height', 0)
50
 
                                        }, {
51
 
                                                editor_id : editor_id,
52
 
                                                inline : "yes"
53
 
                                });
54
 
 
55
 
                                return true;
56
 
           }
57
 
 
58
 
           // Pass to next handler in chain
59
 
           return false;
60
 
        },
61
 
 
62
 
        cleanup : function(type, content, inst) {
63
 
                var nl, img, i, ne, d, s, ci;
64
 
 
65
 
                switch (type) {
66
 
                        case "insert_to_editor":
67
 
                                img = tinyMCE.getParam("theme_href") + '/images/spacer.gif';
68
 
                                content = content.replace(/<script[^>]*>\s*write(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)\(\{([^\)]*)\}\);\s*<\/script>/gi, '<img class="mceItem$1" title="$2" src="' + img + '" />');
69
 
                                content = content.replace(/<object([^>]*)>/gi, '<div class="mceItemObject" $1>');
70
 
                                content = content.replace(/<embed([^>]*)>/gi, '<div class="mceItemObjectEmbed" $1>');
71
 
                                content = content.replace(/<\/(object|embed)([^>]*)>/gi, '</div>');
72
 
                                content = content.replace(/<param([^>]*)>/gi, '<div $1 class="mceItemParam"></div>');
73
 
                                content = content.replace(new RegExp('\\/ class="mceItemParam"><\\/div>', 'gi'), 'class="mceItemParam"></div>');
74
 
                                break;
75
 
 
76
 
                        case "insert_to_editor_dom":
77
 
                                d = inst.getDoc();
78
 
                                nl = content.getElementsByTagName("img");
79
 
                                for (i=0; i<nl.length; i++) {
80
 
                                        if (/mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(nl[i].className)) {
81
 
                                                nl[i].width = nl[i].title.replace(/.*width:[^0-9]?([0-9]+)%?.*/g, '$1');
82
 
                                                nl[i].height = nl[i].title.replace(/.*height:[^0-9]?([0-9]+)%?.*/g, '$1');
83
 
                                                //nl[i].align = nl[i].title.replace(/.*align:([a-z]+).*/gi, '$1');
84
 
                                        }
85
 
                                }
86
 
 
87
 
                                nl = tinyMCE.selectElements(content, 'DIV', function (n) {return tinyMCE.hasCSSClass(n, 'mceItemObject');});
88
 
                                for (i=0; i<nl.length; i++) {
89
 
                                        ci = tinyMCE.getAttrib(nl[i], "classid").toLowerCase().replace(/\s+/g, '');
 
8
(function() {
 
9
        var each = tinymce.each;
 
10
 
 
11
        tinymce.create('tinymce.plugins.MediaPlugin', {
 
12
                init : function(ed, url) {
 
13
                        var t = this;
 
14
                        
 
15
                        t.editor = ed;
 
16
                        t.url = url;
 
17
 
 
18
                        function isMediaElm(n) {
 
19
                                return /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className);
 
20
                        };
 
21
 
 
22
                        ed.onPreInit.add(function() {
 
23
                                // Force in _value parameter this extra parameter is required for older Opera versions
 
24
                                ed.serializer.addRules('param[name|value|_mce_value]');
 
25
                        });
 
26
 
 
27
                        // Register commands
 
28
                        ed.addCommand('mceMedia', function() {
 
29
                                ed.windowManager.open({
 
30
                                        file : url + '/media.htm',
 
31
                                        width : 430 + parseInt(ed.getLang('media.delta_width', 0)),
 
32
                                        height : 470 + parseInt(ed.getLang('media.delta_height', 0)),
 
33
                                        inline : 1
 
34
                                }, {
 
35
                                        plugin_url : url
 
36
                                });
 
37
                        });
 
38
 
 
39
                        // Register buttons
 
40
                        ed.addButton('media', {title : 'media.desc', cmd : 'mceMedia'});
 
41
 
 
42
                        ed.onNodeChange.add(function(ed, cm, n) {
 
43
                                cm.setActive('media', n.nodeName == 'IMG' && isMediaElm(n));
 
44
                        });
 
45
 
 
46
                        ed.onInit.add(function() {
 
47
                                var lo = {
 
48
                                        mceItemFlash : 'flash',
 
49
                                        mceItemShockWave : 'shockwave',
 
50
                                        mceItemWindowsMedia : 'windowsmedia',
 
51
                                        mceItemQuickTime : 'quicktime',
 
52
                                        mceItemRealMedia : 'realmedia'
 
53
                                };
 
54
 
 
55
                                ed.selection.onSetContent.add(function() {
 
56
                                        t._spansToImgs(ed.getBody());
 
57
                                });
 
58
 
 
59
                                ed.selection.onBeforeSetContent.add(t._objectsToSpans, t);
 
60
 
 
61
                                if (ed.settings.content_css !== false)
 
62
                                        ed.dom.loadCSS(url + "/css/content.css");
 
63
 
 
64
                                if (ed.theme.onResolveName) {
 
65
                                        ed.theme.onResolveName.add(function(th, o) {
 
66
                                                if (o.name == 'img') {
 
67
                                                        each(lo, function(v, k) {
 
68
                                                                if (ed.dom.hasClass(o.node, k)) {
 
69
                                                                        o.name = v;
 
70
                                                                        o.title = ed.dom.getAttrib(o.node, 'title');
 
71
                                                                        return false;
 
72
                                                                }
 
73
                                                        });
 
74
                                                }
 
75
                                        });
 
76
                                }
 
77
 
 
78
                                if (ed && ed.plugins.contextmenu) {
 
79
                                        ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
 
80
                                                if (e.nodeName == 'IMG' && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(e.className)) {
 
81
                                                        m.add({title : 'media.edit', icon : 'media', cmd : 'mceMedia'});
 
82
                                                }
 
83
                                        });
 
84
                                }
 
85
                        });
 
86
 
 
87
                        ed.onBeforeSetContent.add(t._objectsToSpans, t);
 
88
 
 
89
                        ed.onSetContent.add(function() {
 
90
                                t._spansToImgs(ed.getBody());
 
91
                        });
 
92
 
 
93
                        ed.onPreProcess.add(function(ed, o) {
 
94
                                var dom = ed.dom;
 
95
 
 
96
                                if (o.set) {
 
97
                                        t._spansToImgs(o.node);
 
98
 
 
99
                                        each(dom.select('IMG', o.node), function(n) {
 
100
                                                var p;
 
101
 
 
102
                                                if (isMediaElm(n)) {
 
103
                                                        p = t._parse(n.title);
 
104
                                                        dom.setAttrib(n, 'width', dom.getAttrib(n, 'width', p.width || 100));
 
105
                                                        dom.setAttrib(n, 'height', dom.getAttrib(n, 'height', p.height || 100));
 
106
                                                }
 
107
                                        });
 
108
                                }
 
109
 
 
110
                                if (o.get) {
 
111
                                        each(dom.select('IMG', o.node), function(n) {
 
112
                                                var ci, cb, mt;
 
113
 
 
114
                                                if (ed.getParam('media_use_script')) {
 
115
                                                        if (isMediaElm(n))
 
116
                                                                n.className = n.className.replace(/mceItem/g, 'mceTemp');
 
117
 
 
118
                                                        return;
 
119
                                                }
 
120
 
 
121
                                                switch (n.className) {
 
122
                                                        case 'mceItemFlash':
 
123
                                                                ci = 'd27cdb6e-ae6d-11cf-96b8-444553540000';
 
124
                                                                cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
 
125
                                                                mt = 'application/x-shockwave-flash';
 
126
                                                                break;
 
127
 
 
128
                                                        case 'mceItemShockWave':
 
129
                                                                ci = '166b1bca-3f9c-11cf-8075-444553540000';
 
130
                                                                cb = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0';
 
131
                                                                mt = 'application/x-director';
 
132
                                                                break;
 
133
 
 
134
                                                        case 'mceItemWindowsMedia':
 
135
                                                                ci = ed.getParam('media_wmp6_compatible') ? '05589fa1-c356-11ce-bf01-00aa0055595a' : '6bf52a52-394a-11d3-b153-00c04f79faa6';
 
136
                                                                cb = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
 
137
                                                                mt = 'application/x-mplayer2';
 
138
                                                                break;
 
139
 
 
140
                                                        case 'mceItemQuickTime':
 
141
                                                                ci = '02bf25d5-8c17-4b23-bc80-d3488abddc6b';
 
142
                                                                cb = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
 
143
                                                                mt = 'video/quicktime';
 
144
                                                                break;
 
145
 
 
146
                                                        case 'mceItemRealMedia':
 
147
                                                                ci = 'cfcdaa03-8be4-11cf-b84b-0020afbbccfa';
 
148
                                                                cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
 
149
                                                                mt = 'audio/x-pn-realaudio-plugin';
 
150
                                                                break;
 
151
                                                }
 
152
 
 
153
                                                if (ci) {
 
154
                                                        dom.replace(t._buildObj({
 
155
                                                                classid : ci,
 
156
                                                                codebase : cb,
 
157
                                                                type : mt
 
158
                                                        }, n), n);
 
159
                                                }
 
160
                                        });
 
161
                                }
 
162
                        });
 
163
 
 
164
                        ed.onPostProcess.add(function(ed, o) {
 
165
                                o.content = o.content.replace(/_mce_value=/g, 'value=');
 
166
                        });
 
167
 
 
168
                        function getAttr(s, n) {
 
169
                                n = new RegExp(n + '=\"([^\"]+)\"', 'g').exec(s);
 
170
 
 
171
                                return n ? ed.dom.decode(n[1]) : '';
 
172
                        };
 
173
 
 
174
                        ed.onPostProcess.add(function(ed, o) {
 
175
                                if (ed.getParam('media_use_script')) {
 
176
                                        o.content = o.content.replace(/<img[^>]+>/g, function(im) {
 
177
                                                var cl = getAttr(im, 'class');
 
178
 
 
179
                                                if (/^(mceTempFlash|mceTempShockWave|mceTempWindowsMedia|mceTempQuickTime|mceTempRealMedia)$/.test(cl)) {
 
180
                                                        at = t._parse(getAttr(im, 'title'));
 
181
                                                        at.width = getAttr(im, 'width');
 
182
                                                        at.height = getAttr(im, 'height');
 
183
                                                        im = '<script type="text/javascript">write' + cl.substring(7) + '({' + t._serialize(at) + '});</script>';
 
184
                                                }
 
185
 
 
186
                                                return im;
 
187
                                        });
 
188
                                }
 
189
                        });
 
190
                },
 
191
 
 
192
                getInfo : function() {
 
193
                        return {
 
194
                                longname : 'Media',
 
195
                                author : 'Moxiecode Systems AB',
 
196
                                authorurl : 'http://tinymce.moxiecode.com',
 
197
                                infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media',
 
198
                                version : tinymce.majorVersion + "." + tinymce.minorVersion
 
199
                        };
 
200
                },
 
201
 
 
202
                // Private methods
 
203
                _objectsToSpans : function(ed, o) {
 
204
                        var t = this, h = o.content;
 
205
 
 
206
                        h = h.replace(/<script[^>]*>\s*write(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)\(\{([^\)]*)\}\);\s*<\/script>/gi, function(a, b, c) {
 
207
                                var o = t._parse(c);
 
208
 
 
209
                                return '<img class="mceItem' + b + '" title="' + ed.dom.encode(c) + '" src="' + t.url + '/img/trans.gif" width="' + o.width + '" height="' + o.height + '" />'
 
210
                        });
 
211
 
 
212
                        h = h.replace(/<object([^>]*)>/gi, '<span class="mceItemObject" $1>');
 
213
                        h = h.replace(/<embed([^>]*)\/?>/gi, '<span class="mceItemEmbed" $1></span>');
 
214
                        h = h.replace(/<embed([^>]*)>/gi, '<span class="mceItemEmbed" $1>');
 
215
                        h = h.replace(/<\/(object)([^>]*)>/gi, '</span>');
 
216
                        h = h.replace(/<\/embed>/gi, '');
 
217
                        h = h.replace(/<param([^>]*)>/gi, function(a, b) {return '<span ' + b.replace(/value=/gi, '_mce_value=') + ' class="mceItemParam"></span>'});
 
218
                        h = h.replace(/\/ class=\"mceItemParam\"><\/span>/gi, 'class="mceItemParam"></span>');
 
219
 
 
220
                        o.content = h;
 
221
                },
 
222
 
 
223
                _buildObj : function(o, n) {
 
224
                        var ob, ed = this.editor, dom = ed.dom, p = this._parse(n.title), stc;
 
225
                        
 
226
                        stc = ed.getParam('media_strict', true) && o.type == 'application/x-shockwave-flash';
 
227
 
 
228
                        p.width = o.width = dom.getAttrib(n, 'width') || 100;
 
229
                        p.height = o.height = dom.getAttrib(n, 'height') || 100;
 
230
 
 
231
                        if (p.src)
 
232
                                p.src = ed.convertURL(p.src, 'src', n);
 
233
 
 
234
                        if (stc) {
 
235
                                ob = dom.create('span', {
 
236
                                        id : p.id,
 
237
                                        mce_name : 'object',
 
238
                                        type : 'application/x-shockwave-flash',
 
239
                                        data : p.src,
 
240
                                        style : dom.getAttrib(n, 'style'),
 
241
                                        width : o.width,
 
242
                                        height : o.height
 
243
                                });
 
244
                        } else {
 
245
                                ob = dom.create('span', {
 
246
                                        id : p.id,
 
247
                                        mce_name : 'object',
 
248
                                        classid : "clsid:" + o.classid,
 
249
                                        style : dom.getAttrib(n, 'style'),
 
250
                                        codebase : o.codebase,
 
251
                                        width : o.width,
 
252
                                        height : o.height
 
253
                                });
 
254
                        }
 
255
 
 
256
                        each (p, function(v, k) {
 
257
                                if (!/^(width|height|codebase|classid|id|_cx|_cy)$/.test(k)) {
 
258
                                        // Use url instead of src in IE for Windows media
 
259
                                        if (o.type == 'application/x-mplayer2' && k == 'src' && !p.url)
 
260
                                                k = 'url';
 
261
 
 
262
                                        if (v)
 
263
                                                dom.add(ob, 'span', {mce_name : 'param', name : k, '_mce_value' : v});
 
264
                                }
 
265
                        });
 
266
 
 
267
                        if (!stc)
 
268
                                dom.add(ob, 'span', tinymce.extend({mce_name : 'embed', type : o.type, style : dom.getAttrib(n, 'style')}, p));
 
269
 
 
270
                        return ob;
 
271
                },
 
272
 
 
273
                _spansToImgs : function(p) {
 
274
                        var t = this, dom = t.editor.dom, im, ci;
 
275
 
 
276
                        each(dom.select('span', p), function(n) {
 
277
                                // Convert object into image
 
278
                                if (dom.getAttrib(n, 'class') == 'mceItemObject') {
 
279
                                        ci = dom.getAttrib(n, "classid").toLowerCase().replace(/\s+/g, '');
90
280
 
91
281
                                        switch (ci) {
92
282
                                                case 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000':
93
 
                                                        nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemFlash', d, nl[i]), nl[i]);
 
283
                                                        dom.replace(t._createImg('mceItemFlash', n), n);
94
284
                                                        break;
95
285
 
96
286
                                                case 'clsid:166b1bca-3f9c-11cf-8075-444553540000':
97
 
                                                        nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemShockWave', d, nl[i]), nl[i]);
 
287
                                                        dom.replace(t._createImg('mceItemShockWave', n), n);
98
288
                                                        break;
99
289
 
100
290
                                                case 'clsid:6bf52a52-394a-11d3-b153-00c04f79faa6':
101
291
                                                case 'clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95':
102
292
                                                case 'clsid:05589fa1-c356-11ce-bf01-00aa0055595a':
103
 
                                                        nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemWindowsMedia', d, nl[i]), nl[i]);
 
293
                                                        dom.replace(t._createImg('mceItemWindowsMedia', n), n);
104
294
                                                        break;
105
295
 
106
296
                                                case 'clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b':
107
 
                                                        nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemQuickTime', d, nl[i]), nl[i]);
 
297
                                                        dom.replace(t._createImg('mceItemQuickTime', n), n);
108
298
                                                        break;
109
299
 
110
300
                                                case 'clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa':
111
 
                                                        nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemRealMedia', d, nl[i]), nl[i]);
 
301
                                                        dom.replace(t._createImg('mceItemRealMedia', n), n);
112
302
                                                        break;
 
303
 
 
304
                                                default:
 
305
                                                        dom.replace(t._createImg('mceItemFlash', n), n);
113
306
                                        }
 
307
                                        
 
308
                                        return;
114
309
                                }
115
310
 
116
 
                                // Handle embed (if any)
117
 
                                nl = tinyMCE.selectNodes(content, function (n) {return n.className == 'mceItemObjectEmbed';});
118
 
                                for (i=0; i<nl.length; i++) {
119
 
                                        switch (tinyMCE.getAttrib(nl[i], 'type')) {
 
311
                                // Convert embed into image
 
312
                                if (dom.getAttrib(n, 'class') == 'mceItemEmbed') {
 
313
                                        switch (dom.getAttrib(n, 'type')) {
120
314
                                                case 'application/x-shockwave-flash':
121
 
                                                        TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemFlash');
 
315
                                                        dom.replace(t._createImg('mceItemFlash', n), n);
122
316
                                                        break;
123
317
 
124
318
                                                case 'application/x-director':
125
 
                                                        TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemShockWave');
 
319
                                                        dom.replace(t._createImg('mceItemShockWave', n), n);
126
320
                                                        break;
127
321
 
128
322
                                                case 'application/x-mplayer2':
129
 
                                                        TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemWindowsMedia');
 
323
                                                        dom.replace(t._createImg('mceItemWindowsMedia', n), n);
130
324
                                                        break;
131
325
 
132
326
                                                case 'video/quicktime':
133
 
                                                        TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemQuickTime');
 
327
                                                        dom.replace(t._createImg('mceItemQuickTime', n), n);
134
328
                                                        break;
135
329
 
136
330
                                                case 'audio/x-pn-realaudio-plugin':
137
 
                                                        TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemRealMedia');
 
331
                                                        dom.replace(t._createImg('mceItemRealMedia', n), n);
138
332
                                                        break;
139
 
                                        }
140
 
                                }
141
 
                                break;
142
 
 
143
 
                        case "get_from_editor":
144
 
                                var startPos = -1, endPos, attribs, chunkBefore, chunkAfter, embedHTML, at, pl, cb, mt, ex;
145
 
 
146
 
                                while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
147
 
                                        endPos = content.indexOf('/>', startPos);
148
 
                                        attribs = TinyMCE_MediaPlugin._parseAttributes(content.substring(startPos + 4, endPos));
149
 
 
150
 
                                        // Is not flash, skip it
151
 
                                        if (!/mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(attribs['class']))
152
 
                                                continue;
153
 
 
154
 
                                        endPos += 2;
155
 
 
156
 
                                        // Parse attributes
157
 
                                        at = attribs['title'];
158
 
                                        if (at) {
159
 
                                                at = at.replace(/&(#39|apos);/g, "'");
160
 
                                                at = at.replace(/&#quot;/g, '"');
161
 
 
162
 
                                                try {
163
 
                                                        pl = eval('x={' + at + '};');
164
 
                                                } catch (ex) {
165
 
                                                        pl = {};
166
 
                                                }
167
 
                                        }
168
 
 
169
 
                                        // Use object/embed
170
 
                                        if (!tinyMCE.getParam('media_use_script', false)) {
171
 
                                                switch (attribs['class']) {
172
 
                                                        case 'mceItemFlash':
173
 
                                                                ci = 'd27cdb6e-ae6d-11cf-96b8-444553540000';
174
 
                                                                cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
175
 
                                                                mt = 'application/x-shockwave-flash';
176
 
                                                                break;
177
 
 
178
 
                                                        case 'mceItemShockWave':
179
 
                                                                ci = '166B1BCA-3F9C-11CF-8075-444553540000';
180
 
                                                                cb = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0';
181
 
                                                                mt = 'application/x-director';
182
 
                                                                break;
183
 
 
184
 
                                                        case 'mceItemWindowsMedia':
185
 
                                                                ci = tinyMCE.getParam('media_wmp6_compatible') ? '05589FA1-C356-11CE-BF01-00AA0055595A' : '6BF52A52-394A-11D3-B153-00C04F79FAA6';
186
 
                                                                cb = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
187
 
                                                                mt = 'application/x-mplayer2';
188
 
                                                                break;
189
 
 
190
 
                                                        case 'mceItemQuickTime':
191
 
                                                                ci = '02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';
192
 
                                                                cb = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
193
 
                                                                mt = 'video/quicktime';
194
 
                                                                break;
195
 
 
196
 
                                                        case 'mceItemRealMedia':
197
 
                                                                ci = 'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA';
198
 
                                                                cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
199
 
                                                                mt = 'audio/x-pn-realaudio-plugin';
200
 
                                                                break;
201
 
                                                }
202
 
 
203
 
                                                // Convert the URL
204
 
                                                pl.src = tinyMCE.convertURL(pl.src, null, true);
205
 
 
206
 
                                                embedHTML = TinyMCE_MediaPlugin._getEmbed(ci, cb, mt, pl, attribs);
207
 
                                        } else {
208
 
                                                // Use script version
209
 
                                                switch (attribs['class']) {
210
 
                                                        case 'mceItemFlash':
211
 
                                                                s = 'writeFlash';
212
 
                                                                break;
213
 
 
214
 
                                                        case 'mceItemShockWave':
215
 
                                                                s = 'writeShockWave';
216
 
                                                                break;
217
 
 
218
 
                                                        case 'mceItemWindowsMedia':
219
 
                                                                s = 'writeWindowsMedia';
220
 
                                                                break;
221
 
 
222
 
                                                        case 'mceItemQuickTime':
223
 
                                                                s = 'writeQuickTime';
224
 
                                                                break;
225
 
 
226
 
                                                        case 'mceItemRealMedia':
227
 
                                                                s = 'writeRealMedia';
228
 
                                                                break;
229
 
                                                }
230
 
 
231
 
                                                if (attribs.width)
232
 
                                                        at = at.replace(/width:[^0-9]?[0-9]+%?[^0-9]?/g, "width:'" + attribs.width + "'");
233
 
 
234
 
                                                if (attribs.height)
235
 
                                                        at = at.replace(/height:[^0-9]?[0-9]+%?[^0-9]?/g, "height:'" + attribs.height + "'");
236
 
 
237
 
                                                // Force absolute URL
238
 
                                                pl.src = tinyMCE.convertURL(pl.src, null, true);
239
 
                                                at = at.replace(new RegExp("src:'[^']*'", "g"), "src:'" + pl.src + "'");
240
 
 
241
 
                                                embedHTML = '<script type="text/javascript">' + s + '({' + at + '});</script>';
242
 
                                        }
243
 
 
244
 
                                        // Insert embed/object chunk
245
 
                                        chunkBefore = content.substring(0, startPos);
246
 
                                        chunkAfter = content.substring(endPos);
247
 
                                        content = chunkBefore + embedHTML + chunkAfter;
248
 
                                }
249
 
                                break;
250
 
                }
251
 
 
252
 
                return content;
253
 
        },
254
 
 
255
 
        handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
256
 
                if (node == null)
257
 
                        return;
258
 
 
259
 
                do {
260
 
                        if (node.nodeName == "IMG" && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(tinyMCE.getAttrib(node, 'class'))) {
261
 
                                tinyMCE.switchClass(editor_id + '_media', 'mceButtonSelected');
262
 
                                return true;
263
 
                        }
264
 
                } while ((node = node.parentNode));
265
 
 
266
 
                tinyMCE.switchClass(editor_id + '_media', 'mceButtonNormal');
267
 
 
268
 
                return true;
269
 
        },
270
 
 
271
 
        _createImgFromEmbed : function(n, d, cl) {
272
 
                var ne, at, i, ti = '', an;
273
 
 
274
 
                ne = d.createElement('img');
275
 
                ne.src = tinyMCE.getParam("theme_href") + '/images/spacer.gif';
276
 
                ne.width = tinyMCE.getAttrib(n, 'width');
277
 
                ne.height = tinyMCE.getAttrib(n, 'height');
278
 
                ne.className = cl;
279
 
 
280
 
                at = n.attributes;
281
 
                for (i=0; i<at.length; i++) {
282
 
                        if (at[i].specified && at[i].nodeValue) {
283
 
                                an = at[i].nodeName.toLowerCase();
284
 
 
285
 
                                if (an == 'src')
286
 
                                        continue;
287
 
 
288
 
                                if (an == 'mce_src')
289
 
                                        an = 'src';
290
 
 
291
 
                                if (an.indexOf('mce_') == -1 && !new RegExp('^(class|type)$').test(an))
292
 
                                        ti += an.toLowerCase() + ':\'' + at[i].nodeValue + "',";
293
 
                        }
294
 
                }
295
 
 
296
 
                ti = ti.length > 0 ? ti.substring(0, ti.length - 1) : ti;
297
 
                ne.title = ti;
298
 
 
299
 
                n.parentNode.replaceChild(ne, n);
300
 
        },
301
 
 
302
 
        _createImg : function(cl, d, n) {
303
 
                var i, nl, ti = "", an, av, al = new Array();
304
 
 
305
 
                ne = d.createElement('img');
306
 
                ne.src = tinyMCE.getParam("theme_href") + '/images/spacer.gif';
307
 
                ne.width = tinyMCE.getAttrib(n, 'width');
308
 
                ne.height = tinyMCE.getAttrib(n, 'height');
309
 
                ne.className = cl;
310
 
 
311
 
                al.id = tinyMCE.getAttrib(n, 'id');
312
 
                al.name = tinyMCE.getAttrib(n, 'name');
313
 
                al.width = tinyMCE.getAttrib(n, 'width');
314
 
                al.height = tinyMCE.getAttrib(n, 'height');
315
 
                al.bgcolor = tinyMCE.getAttrib(n, 'bgcolor');
316
 
                al.align = tinyMCE.getAttrib(n, 'align');
317
 
                al.class_name = tinyMCE.getAttrib(n, 'mce_class');
318
 
 
319
 
                nl = n.getElementsByTagName('div');
320
 
                for (i=0; i<nl.length; i++) {
321
 
                        av = tinyMCE.getAttrib(nl[i], 'value');
322
 
                        av = av.replace(new RegExp('\\\\', 'g'), '\\\\');
323
 
                        av = av.replace(new RegExp('"', 'g'), '\\"');
324
 
                        av = av.replace(new RegExp("'", 'g'), "\\'");
325
 
                        an = tinyMCE.getAttrib(nl[i], 'name');
326
 
                        al[an] = av;
327
 
                }
328
 
 
329
 
                if (al.movie) {
330
 
                        al.src = al.movie;
331
 
                        al.movie = null;
332
 
                }
333
 
 
334
 
                for (an in al) {
335
 
                        if (al[an] != null && typeof(al[an]) != "function" && al[an] != '')
336
 
                                ti += an.toLowerCase() + ':\'' + al[an] + "',";
337
 
                }
338
 
 
339
 
                ti = ti.length > 0 ? ti.substring(0, ti.length - 1) : ti;
340
 
                ne.title = ti;
341
 
 
342
 
                return ne;
343
 
        },
344
 
 
345
 
        _getEmbed : function(cls, cb, mt, p, at) {
346
 
                var h = '', n;
347
 
 
348
 
                p.width = at.width ? at.width : p.width;
349
 
                p.height = at.height ? at.height : p.height;
350
 
 
351
 
                h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
352
 
                h += typeof(p.id) != "undefined" ? ' id="' + p.id + '"' : '';
353
 
                h += typeof(p.name) != "undefined" ? ' name="' + p.name + '"' : '';
354
 
                h += typeof(p.width) != "undefined" ? ' width="' + p.width + '"' : '';
355
 
                h += typeof(p.height) != "undefined" ? ' height="' + p.height + '"' : '';
356
 
                h += typeof(p.align) != "undefined" ? ' align="' + p.align + '"' : '';
357
 
                h += '>';
358
 
 
359
 
                for (n in p) {
360
 
                        if (typeof(p[n]) != "undefined" && typeof(p[n]) != "function") {
361
 
                                h += '<param name="' + n + '" value="' + p[n] + '" />';
362
 
 
363
 
                                // Add extra url parameter if it's an absolute URL on WMP
364
 
                                if (n == 'src' && p[n].indexOf('://') != -1 && mt == 'application/x-mplayer2')
365
 
                                        h += '<param name="url" value="' + p[n] + '" />';
366
 
                        }
367
 
                }
368
 
 
369
 
                h += '<embed type="' + mt + '"';
370
 
 
371
 
                for (n in p) {
372
 
                        if (typeof(p[n]) == "function")
373
 
                                continue;
374
 
 
375
 
                        // Skip url parameter for embed tag on WMP
376
 
                        if (!(n == 'url' && mt == 'application/x-mplayer2'))
377
 
                                h += ' ' + n + '="' + p[n] + '"';
378
 
                }
379
 
 
380
 
                h += '></embed></object>';
381
 
 
382
 
                return h;
383
 
        },
384
 
 
385
 
        _parseAttributes : function(attribute_string) {
386
 
                var attributeName = "", endChr = '"';
387
 
                var attributeValue = "";
388
 
                var withInName;
389
 
                var withInValue;
390
 
                var attributes = new Array();
391
 
                var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
392
 
 
393
 
                if (attribute_string == null || attribute_string.length < 2)
394
 
                        return null;
395
 
 
396
 
                withInName = withInValue = false;
397
 
 
398
 
                for (var i=0; i<attribute_string.length; i++) {
399
 
                        var chr = attribute_string.charAt(i);
400
 
 
401
 
                        if ((chr == '"' || chr == "'") && !withInValue) {
402
 
                                withInValue = true;
403
 
                                endChr = chr;
404
 
                        } else if (chr == endChr && withInValue) {
405
 
                                withInValue = false;
406
 
 
407
 
                                var pos = attributeName.lastIndexOf(' ');
408
 
                                if (pos != -1)
409
 
                                        attributeName = attributeName.substring(pos+1);
410
 
 
411
 
                                attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
412
 
 
413
 
                                attributeName = "";
414
 
                                attributeValue = "";
415
 
                        } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
416
 
                                withInName = true;
417
 
 
418
 
                        if (chr == '=' && withInName)
419
 
                                withInName = false;
420
 
 
421
 
                        if (withInName)
422
 
                                attributeName += chr;
423
 
 
424
 
                        if (withInValue)
425
 
                                attributeValue += chr;
426
 
                }
427
 
 
428
 
                return attributes;
429
 
        }
430
 
};
431
 
 
432
 
tinyMCE.addPlugin("media", TinyMCE_MediaPlugin);
 
333
 
 
334
                                                default:
 
335
                                                        dom.replace(t._createImg('mceItemFlash', n), n);
 
336
                                        }
 
337
                                }                       
 
338
                        });
 
339
                },
 
340
 
 
341
                _createImg : function(cl, n) {
 
342
                        var im, dom = this.editor.dom, pa = {}, ti = '', args;
 
343
 
 
344
                        args = ['id', 'name', 'width', 'height', 'bgcolor', 'align', 'flashvars', 'src', 'wmode', 'allowfullscreen', 'quality'];        
 
345
 
 
346
                        // Create image
 
347
                        im = dom.create('img', {
 
348
                                src : this.url + '/img/trans.gif',
 
349
                                width : dom.getAttrib(n, 'width') || 100,
 
350
                                height : dom.getAttrib(n, 'height') || 100,
 
351
                                style : dom.getAttrib(n, 'style'),
 
352
                                'class' : cl
 
353
                        });
 
354
 
 
355
                        // Setup base parameters
 
356
                        each(args, function(na) {
 
357
                                var v = dom.getAttrib(n, na);
 
358
 
 
359
                                if (v)
 
360
                                        pa[na] = v;
 
361
                        });
 
362
 
 
363
                        // Add optional parameters
 
364
                        each(dom.select('span', n), function(n) {
 
365
                                if (dom.hasClass(n, 'mceItemParam'))
 
366
                                        pa[dom.getAttrib(n, 'name')] = dom.getAttrib(n, '_mce_value');
 
367
                        });
 
368
 
 
369
                        // Use src not movie
 
370
                        if (pa.movie) {
 
371
                                pa.src = pa.movie;
 
372
                                delete pa.movie;
 
373
                        }
 
374
 
 
375
                        // Merge with embed args
 
376
                        n = dom.select('.mceItemEmbed', n)[0];
 
377
                        if (n) {
 
378
                                each(args, function(na) {
 
379
                                        var v = dom.getAttrib(n, na);
 
380
 
 
381
                                        if (v && !pa[na])
 
382
                                                pa[na] = v;
 
383
                                });
 
384
                        }
 
385
 
 
386
                        delete pa.width;
 
387
                        delete pa.height;
 
388
 
 
389
                        im.title = this._serialize(pa);
 
390
 
 
391
                        return im;
 
392
                },
 
393
 
 
394
                _parse : function(s) {
 
395
                        return tinymce.util.JSON.parse('{' + s + '}');
 
396
                },
 
397
 
 
398
                _serialize : function(o) {
 
399
                        return tinymce.util.JSON.serialize(o).replace(/[{}]/g, '');
 
400
                }
 
401
        });
 
402
 
 
403
        // Register plugin
 
404
        tinymce.PluginManager.add('media', tinymce.plugins.MediaPlugin);
 
405
})();
 
 
b'\\ No newline at end of file'