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