bgneal@312: /**
bgneal@312: * editor_plugin_src.js
bgneal@312: *
bgneal@312: * Copyright 2009, Moxiecode Systems AB
bgneal@312: * Released under LGPL License.
bgneal@312: *
bgneal@312: * License: http://tinymce.moxiecode.com/license
bgneal@312: * Contributing: http://tinymce.moxiecode.com/contributing
bgneal@312: */
bgneal@312:
bgneal@312: (function() {
bgneal@312: var each = tinymce.each;
bgneal@312:
bgneal@312: tinymce.create('tinymce.plugins.MediaPlugin', {
bgneal@312: init : function(ed, url) {
bgneal@312: var t = this;
bgneal@312:
bgneal@312: t.editor = ed;
bgneal@312: t.url = url;
bgneal@312:
bgneal@312: function isMediaElm(n) {
bgneal@312: return /^(mceItemFlash|mceItemShockWave|mceItemWindowsMedia|mceItemQuickTime|mceItemRealMedia)$/.test(n.className);
bgneal@312: };
bgneal@312:
bgneal@312: ed.onPreInit.add(function() {
bgneal@312: // Force in _value parameter this extra parameter is required for older Opera versions
bgneal@312: ed.serializer.addRules('param[name|value|_mce_value]');
bgneal@312: });
bgneal@312:
bgneal@312: // Register commands
bgneal@312: ed.addCommand('mceMedia', function() {
bgneal@312: ed.windowManager.open({
bgneal@312: file : url + '/media.htm',
bgneal@312: width : 430 + parseInt(ed.getLang('media.delta_width', 0)),
bgneal@312: height : 470 + parseInt(ed.getLang('media.delta_height', 0)),
bgneal@312: inline : 1
bgneal@312: }, {
bgneal@312: plugin_url : url
bgneal@312: });
bgneal@312: });
bgneal@312:
bgneal@312: // Register buttons
bgneal@312: ed.addButton('media', {title : 'media.desc', cmd : 'mceMedia'});
bgneal@312:
bgneal@312: ed.onNodeChange.add(function(ed, cm, n) {
bgneal@312: cm.setActive('media', n.nodeName == 'IMG' && isMediaElm(n));
bgneal@312: });
bgneal@312:
bgneal@312: ed.onInit.add(function() {
bgneal@312: var lo = {
bgneal@312: mceItemFlash : 'flash',
bgneal@312: mceItemShockWave : 'shockwave',
bgneal@312: mceItemWindowsMedia : 'windowsmedia',
bgneal@312: mceItemQuickTime : 'quicktime',
bgneal@312: mceItemRealMedia : 'realmedia'
bgneal@312: };
bgneal@312:
bgneal@312: ed.selection.onSetContent.add(function() {
bgneal@312: t._spansToImgs(ed.getBody());
bgneal@312: });
bgneal@312:
bgneal@312: ed.selection.onBeforeSetContent.add(t._objectsToSpans, t);
bgneal@312:
bgneal@312: if (ed.settings.content_css !== false)
bgneal@312: ed.dom.loadCSS(url + "/css/content.css");
bgneal@312:
bgneal@312: if (ed.theme && ed.theme.onResolveName) {
bgneal@312: ed.theme.onResolveName.add(function(th, o) {
bgneal@312: if (o.name == 'img') {
bgneal@312: each(lo, function(v, k) {
bgneal@312: if (ed.dom.hasClass(o.node, k)) {
bgneal@312: o.name = v;
bgneal@312: o.title = ed.dom.getAttrib(o.node, 'title');
bgneal@312: return false;
bgneal@312: }
bgneal@312: });
bgneal@312: }
bgneal@312: });
bgneal@312: }
bgneal@312:
bgneal@312: if (ed && ed.plugins.contextmenu) {
bgneal@312: ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
bgneal@312: if (e.nodeName == 'IMG' && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(e.className)) {
bgneal@312: m.add({title : 'media.edit', icon : 'media', cmd : 'mceMedia'});
bgneal@312: }
bgneal@312: });
bgneal@312: }
bgneal@312: });
bgneal@312:
bgneal@312: ed.onBeforeSetContent.add(t._objectsToSpans, t);
bgneal@312:
bgneal@312: ed.onSetContent.add(function() {
bgneal@312: t._spansToImgs(ed.getBody());
bgneal@312: });
bgneal@312:
bgneal@312: ed.onPreProcess.add(function(ed, o) {
bgneal@312: var dom = ed.dom;
bgneal@312:
bgneal@312: if (o.set) {
bgneal@312: t._spansToImgs(o.node);
bgneal@312:
bgneal@312: each(dom.select('IMG', o.node), function(n) {
bgneal@312: var p;
bgneal@312:
bgneal@312: if (isMediaElm(n)) {
bgneal@312: p = t._parse(n.title);
bgneal@312: dom.setAttrib(n, 'width', dom.getAttrib(n, 'width', p.width || 100));
bgneal@312: dom.setAttrib(n, 'height', dom.getAttrib(n, 'height', p.height || 100));
bgneal@312: }
bgneal@312: });
bgneal@312: }
bgneal@312:
bgneal@312: if (o.get) {
bgneal@312: each(dom.select('IMG', o.node), function(n) {
bgneal@312: var ci, cb, mt;
bgneal@312:
bgneal@312: if (ed.getParam('media_use_script')) {
bgneal@312: if (isMediaElm(n))
bgneal@312: n.className = n.className.replace(/mceItem/g, 'mceTemp');
bgneal@312:
bgneal@312: return;
bgneal@312: }
bgneal@312:
bgneal@312: switch (n.className) {
bgneal@312: case 'mceItemFlash':
bgneal@312: ci = 'd27cdb6e-ae6d-11cf-96b8-444553540000';
bgneal@312: cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
bgneal@312: mt = 'application/x-shockwave-flash';
bgneal@312: break;
bgneal@312:
bgneal@312: case 'mceItemShockWave':
bgneal@312: ci = '166b1bca-3f9c-11cf-8075-444553540000';
bgneal@312: cb = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0';
bgneal@312: mt = 'application/x-director';
bgneal@312: break;
bgneal@312:
bgneal@312: case 'mceItemWindowsMedia':
bgneal@312: ci = ed.getParam('media_wmp6_compatible') ? '05589fa1-c356-11ce-bf01-00aa0055595a' : '6bf52a52-394a-11d3-b153-00c04f79faa6';
bgneal@312: cb = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
bgneal@312: mt = 'application/x-mplayer2';
bgneal@312: break;
bgneal@312:
bgneal@312: case 'mceItemQuickTime':
bgneal@312: ci = '02bf25d5-8c17-4b23-bc80-d3488abddc6b';
bgneal@312: cb = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
bgneal@312: mt = 'video/quicktime';
bgneal@312: break;
bgneal@312:
bgneal@312: case 'mceItemRealMedia':
bgneal@312: ci = 'cfcdaa03-8be4-11cf-b84b-0020afbbccfa';
bgneal@312: cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
bgneal@312: mt = 'audio/x-pn-realaudio-plugin';
bgneal@312: break;
bgneal@312: }
bgneal@312:
bgneal@312: if (ci) {
bgneal@312: dom.replace(t._buildObj({
bgneal@312: classid : ci,
bgneal@312: codebase : cb,
bgneal@312: type : mt
bgneal@312: }, n), n);
bgneal@312: }
bgneal@312: });
bgneal@312: }
bgneal@312: });
bgneal@312:
bgneal@312: ed.onPostProcess.add(function(ed, o) {
bgneal@312: o.content = o.content.replace(/_mce_value=/g, 'value=');
bgneal@312: });
bgneal@312:
bgneal@312: function getAttr(s, n) {
bgneal@312: n = new RegExp(n + '=\"([^\"]+)\"', 'g').exec(s);
bgneal@312:
bgneal@312: return n ? ed.dom.decode(n[1]) : '';
bgneal@312: };
bgneal@312:
bgneal@312: ed.onPostProcess.add(function(ed, o) {
bgneal@312: if (ed.getParam('media_use_script')) {
bgneal@312: o.content = o.content.replace(/]+>/g, function(im) {
bgneal@312: var cl = getAttr(im, 'class');
bgneal@312:
bgneal@312: if (/^(mceTempFlash|mceTempShockWave|mceTempWindowsMedia|mceTempQuickTime|mceTempRealMedia)$/.test(cl)) {
bgneal@312: at = t._parse(getAttr(im, 'title'));
bgneal@312: at.width = getAttr(im, 'width');
bgneal@312: at.height = getAttr(im, 'height');
bgneal@312: im = '';
bgneal@312: }
bgneal@312:
bgneal@312: return im;
bgneal@312: });
bgneal@312: }
bgneal@312: });
bgneal@312: },
bgneal@312:
bgneal@312: getInfo : function() {
bgneal@312: return {
bgneal@312: longname : 'Media',
bgneal@312: author : 'Moxiecode Systems AB',
bgneal@312: authorurl : 'http://tinymce.moxiecode.com',
bgneal@312: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media',
bgneal@312: version : tinymce.majorVersion + "." + tinymce.minorVersion
bgneal@312: };
bgneal@312: },
bgneal@312:
bgneal@312: // Private methods
bgneal@312: _objectsToSpans : function(ed, o) {
bgneal@312: var t = this, h = o.content;
bgneal@312:
bgneal@312: h = h.replace(/