includes/clientside/tinymce/plugins/preview/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 444 2007-11-26 16:17:54Z 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('preview');
     9 	tinymce.create('tinymce.plugins.Preview', {
       
    10 		init : function(ed, url) {
       
    11 			var t = this;
    10 
    12 
    11 var TinyMCE_PreviewPlugin = {
    13 			t.editor = ed;
    12 	getInfo : function() {
       
    13 		return {
       
    14 			longname : 'Preview',
       
    15 			author : 'Moxiecode Systems AB',
       
    16 			authorurl : 'http://tinymce.moxiecode.com',
       
    17 			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/preview',
       
    18 			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
       
    19 		};
       
    20 	},
       
    21 
    14 
    22 	/**
    15 			ed.addCommand('mcePreview', t._preview, t);
    23 	 * Returns the HTML contents of the preview control.
    16 			ed.addButton('preview', {title : 'preview.preview_desc', cmd : 'mcePreview'});
    24 	 */
    17 		},
    25 	getControlHTML : function(cn) {
       
    26 		switch (cn) {
       
    27 			case "preview":
       
    28 				return tinyMCE.getButtonHTML(cn, 'lang_preview_desc', '{$pluginurl}/images/preview.gif', 'mcePreview');
       
    29 		}
       
    30 
    18 
    31 		return "";
    19 		getInfo : function() {
    32 	},
    20 			return {
       
    21 				longname : 'Preview',
       
    22 				author : 'Moxiecode Systems AB',
       
    23 				authorurl : 'http://tinymce.moxiecode.com',
       
    24 				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/preview',
       
    25 				version : tinymce.majorVersion + "." + tinymce.minorVersion
       
    26 			};
       
    27 		},
    33 
    28 
    34 	/**
    29 		// Private methods
    35 	 * Executes the mcePreview command.
       
    36 	 */
       
    37 	execCommand : function(editor_id, element, command, user_interface, value) {
       
    38 		// Handle commands
       
    39 		switch (command) {
       
    40 			case "mcePreview":
       
    41 				var previewPage = tinyMCE.getParam("plugin_preview_pageurl", null);
       
    42 				var previewWidth = tinyMCE.getParam("plugin_preview_width", "550");
       
    43 				var previewHeight = tinyMCE.getParam("plugin_preview_height", "600");
       
    44 
    30 
    45 				// Use a custom preview page
    31 		_preview : function() {
    46 				if (previewPage) {
    32 			var ed = this.editor, win, html, c, pos, pos2, css, i, page = ed.getParam("plugin_preview_pageurl", null), w = ed.getParam("plugin_preview_width", "550"), h = ed.getParam("plugin_preview_height", "600");
    47 					var template = new Array();
       
    48 
    33 
    49 					template['file'] = previewPage;
    34 			// Use a custom preview page
    50 					template['width'] = previewWidth;
    35 			if (page) {
    51 					template['height'] = previewHeight;
    36 				ed.windowManager.open({
       
    37 					file : ed.getParam("plugin_preview_pageurl", null),
       
    38 					width : w,
       
    39 					height : h
       
    40 				}, {
       
    41 					editor_id : editor_id,
       
    42 					resizable : "yes",
       
    43 					scrollbars : "yes",
       
    44 					inline : 1,
       
    45 					content : ed.getContent(),
       
    46 					content_css : ed.getParam("content_css")
       
    47 				});
       
    48 			} else {
       
    49 				win = window.open("", "mcePreview", "menubar=no,toolbar=no,scrollbars=yes,resizable=yes,left=20,top=20,width=" + w + ",height="  + h);
       
    50 				html = "";
       
    51 				c = ed.getContent();
       
    52 				pos = c.indexOf('<body');
       
    53 				css = ed.getParam("content_css", '').split(',');
    52 
    54 
    53 					tinyMCE.openWindow(template, {editor_id : editor_id, resizable : "yes", scrollbars : "yes", inline : "yes", content : tinyMCE.getContent(), content_css : tinyMCE.getParam("content_css")});
    55 				tinymce.map(css, function(u) {
    54 				} else {
    56 					return ed.documentBaseURI.toAbsolute(u);
    55 					var win = window.open("", "mcePreview", "menubar=no,toolbar=no,scrollbars=yes,resizable=yes,left=20,top=20,width=" + previewWidth + ",height="  + previewHeight);
    57 				});
    56 					var html = "", i;
       
    57 					var c = tinyMCE.getContent();
       
    58 					var pos = c.indexOf('<body'), pos2, css = tinyMCE.getParam("content_css").split(',');
       
    59 
    58 
    60 					if (pos != -1) {
    59 				if (pos != -1) {
    61 						pos = c.indexOf('>', pos);
    60 					pos = c.indexOf('>', pos);
    62 						pos2 = c.lastIndexOf('</body>');
    61 					pos2 = c.lastIndexOf('</body>');
    63 						c = c.substring(pos + 1, pos2);
    62 					c = c.substring(pos + 1, pos2);
    64 					}
       
    65 
       
    66 					html += tinyMCE.getParam('doctype');
       
    67 					html += '<html xmlns="http://www.w3.org/1999/xhtml">';
       
    68 					html += '<head>';
       
    69 					html += '<title>' + tinyMCE.getLang('lang_preview_desc') + '</title>';
       
    70 					html += '<base href="' + tinyMCE.settings['base_href'] + '" />';
       
    71 					html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
       
    72 
       
    73 					for (i=0; i<css.length; i++)
       
    74 						html += '<link href="' + css[i] + '" rel="stylesheet" type="text/css" />';
       
    75 
       
    76 					html += '<script type="text/javascript">';
       
    77 					html += 'window.opener.TinyMCE_PreviewPlugin._setDoc(document);';
       
    78 					html += 'window.opener.TinyMCE_PreviewPlugin._setWin(window);';
       
    79 					html += 'writeFlash = window.opener.TinyMCE_PreviewPlugin._writeFlash;';
       
    80 					html += 'writeShockWave = window.opener.TinyMCE_PreviewPlugin._writeShockWave;';
       
    81 					html += 'writeQuickTime = window.opener.TinyMCE_PreviewPlugin._writeQuickTime;';
       
    82 					html += 'writeRealMedia = window.opener.TinyMCE_PreviewPlugin._writeRealMedia;';
       
    83 					html += 'writeWindowsMedia = window.opener.TinyMCE_PreviewPlugin._writeWindowsMedia;';
       
    84 					html += 'writeEmbed = window.opener.TinyMCE_PreviewPlugin._writeEmbed;';
       
    85 					html += '</script>';
       
    86 					html += '</head>';
       
    87 					html += '<body dir="' + tinyMCE.getParam("directionality") + '" onload="window.opener.TinyMCE_PreviewPlugin._onLoad();">';
       
    88 					html += c;
       
    89 					html += '</body>';
       
    90 					html += '</html>';
       
    91 
       
    92 					win.document.write(html);
       
    93 					win.document.close();
       
    94 				}
    63 				}
    95 
    64 
    96 				return true;
    65 				html += ed.getParam('doctype');
       
    66 				html += '<html xmlns="http://www.w3.org/1999/xhtml">';
       
    67 				html += '<head>';
       
    68 				html += '<title>' + ed.getLang('preview.preview_desc') + '</title>';
       
    69 				html += '<base href="' + ed.documentBaseURI.getURI() + '" />';
       
    70 				html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
       
    71 
       
    72 				for (i=0; i<css.length; i++)
       
    73 					html += '<link href="' + css[i] + '" rel="stylesheet" type="text/css" />';
       
    74 
       
    75 				html += '</head>';
       
    76 				html += '<body dir="' + ed.getParam("directionality") + '" onload="window.opener.tinymce.EditorManager.get(\'' + ed.id + '\').plugins[\'preview\']._onLoad(window,document);">';
       
    77 				html += c;
       
    78 				html += '</body>';
       
    79 				html += '</html>';
       
    80 
       
    81 				win.document.write(html);
       
    82 				win.document.close();
       
    83 			}
       
    84 		},
       
    85 
       
    86 		_onLoad : function(w, d) {
       
    87 			var t = this, nl, i, el = [], sv, ne;
       
    88 
       
    89 			t._doc = d;
       
    90 			w.writeFlash = t._writeFlash;
       
    91 			w.writeShockWave = t._writeShockWave;
       
    92 			w.writeQuickTime = t._writeQuickTime;
       
    93 			w.writeRealMedia = t._writeRealMedia;
       
    94 			w.writeWindowsMedia = t._writeWindowsMedia;
       
    95 			w.writeEmbed = t._writeEmbed;
       
    96 
       
    97 			nl = d.getElementsByTagName("script");
       
    98 			for (i=0; i<nl.length; i++) {
       
    99 				sv = tinymce.isIE ? nl[i].innerHTML : nl[i].firstChild.nodeValue;
       
   100 
       
   101 				if (new RegExp('write(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)\\(.*', 'g').test(sv))
       
   102 					el[el.length] = nl[i];
       
   103 			}
       
   104 
       
   105 			for (i=0; i<el.length; i++) {
       
   106 				ne = d.createElement("div");
       
   107 				ne.innerHTML = d._embeds[i];
       
   108 				el[i].parentNode.insertBefore(ne.firstChild, el[i]);
       
   109 			}
       
   110 		},
       
   111 
       
   112 		_writeFlash : function(p) {
       
   113 			p.src = this.editor.documentBaseURI.toAbsolute(p.src);
       
   114 			TinyMCE_PreviewPlugin._writeEmbed(
       
   115 				'D27CDB6E-AE6D-11cf-96B8-444553540000',
       
   116 				'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
       
   117 				'application/x-shockwave-flash',
       
   118 				p
       
   119 			);
       
   120 		},
       
   121 
       
   122 		_writeShockWave : function(p) {
       
   123 			this.editor.documentBaseURI.toAbsolute(p.src);
       
   124 			TinyMCE_PreviewPlugin._writeEmbed(
       
   125 				'166B1BCA-3F9C-11CF-8075-444553540000',
       
   126 				'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
       
   127 				'application/x-director',
       
   128 				p
       
   129 			);
       
   130 		},
       
   131 
       
   132 		_writeQuickTime : function(p) {
       
   133 			this.editor.documentBaseURI.toAbsolute(p.src);
       
   134 			TinyMCE_PreviewPlugin._writeEmbed(
       
   135 				'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
       
   136 				'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
       
   137 				'video/quicktime',
       
   138 				p
       
   139 			);
       
   140 		},
       
   141 
       
   142 		_writeRealMedia : function(p) {
       
   143 			this.editor.documentBaseURI.toAbsolute(p.src);
       
   144 			TinyMCE_PreviewPlugin._writeEmbed(
       
   145 				'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
       
   146 				'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
       
   147 				'audio/x-pn-realaudio-plugin',
       
   148 				p
       
   149 			);
       
   150 		},
       
   151 
       
   152 		_writeWindowsMedia : function(p) {
       
   153 			this.editor.documentBaseURI.toAbsolute(p.src);
       
   154 			p.url = p.src;
       
   155 			TinyMCE_PreviewPlugin._writeEmbed(
       
   156 				'6BF52A52-394A-11D3-B153-00C04F79FAA6',
       
   157 				'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
       
   158 				'application/x-mplayer2',
       
   159 				p
       
   160 			);
       
   161 		},
       
   162 
       
   163 		_writeEmbed : function(cls, cb, mt, p) {
       
   164 			var h = '', n, d = t._doc, ne, c;
       
   165 
       
   166 			h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
       
   167 			h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
       
   168 			h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
       
   169 			h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
       
   170 			h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
       
   171 			h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
       
   172 			h += '>';
       
   173 
       
   174 			for (n in p)
       
   175 				h += '<param name="' + n + '" value="' + p[n] + '">';
       
   176 
       
   177 			h += '<embed type="' + mt + '"';
       
   178 
       
   179 			for (n in p)
       
   180 				h += n + '="' + p[n] + '" ';
       
   181 
       
   182 			h += '></embed></object>';
       
   183 
       
   184 			d._embeds[d._embeds.length] = h;
    97 		}
   185 		}
       
   186 	});
    98 
   187 
    99 		return false;
   188 	// Register plugin
   100 	},
   189 	tinymce.PluginManager.add('preview', tinymce.plugins.Preview);
   101 
   190 })();
   102 	_setDoc : function(d) {
       
   103 		TinyMCE_PreviewPlugin._doc = d;
       
   104 		d._embeds = new Array();
       
   105 	},
       
   106 
       
   107 	_setWin : function(d) {
       
   108 		TinyMCE_PreviewPlugin._win = d;
       
   109 	},
       
   110 
       
   111 	_onLoad : function() {
       
   112 		var nl, i, el = new Array(), d = TinyMCE_PreviewPlugin._doc, sv, ne;
       
   113 
       
   114 		nl = d.getElementsByTagName("script");
       
   115 		for (i=0; i<nl.length; i++) {
       
   116 			sv = tinyMCE.isMSIE ? nl[i].innerHTML : nl[i].firstChild.nodeValue;
       
   117 
       
   118 			if (new RegExp('write(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)\\(.*', 'g').test(sv))
       
   119 				el[el.length] = nl[i];
       
   120 		}
       
   121 
       
   122 		for (i=0; i<el.length; i++) {
       
   123 			ne = d.createElement("div");
       
   124 			ne.innerHTML = d._embeds[i];
       
   125 			el[i].parentNode.insertBefore(ne.firstChild, el[i]);
       
   126 		}
       
   127 	},
       
   128 
       
   129 	_writeFlash : function(p) {
       
   130 		p.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], p.src);
       
   131 		TinyMCE_PreviewPlugin._writeEmbed(
       
   132 			'D27CDB6E-AE6D-11cf-96B8-444553540000',
       
   133 			'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
       
   134 			'application/x-shockwave-flash',
       
   135 			p
       
   136 		);
       
   137 	},
       
   138 
       
   139 	_writeShockWave : function(p) {
       
   140 		p.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], p.src);
       
   141 		TinyMCE_PreviewPlugin._writeEmbed(
       
   142 			'166B1BCA-3F9C-11CF-8075-444553540000',
       
   143 			'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
       
   144 			'application/x-director',
       
   145 			p
       
   146 		);
       
   147 	},
       
   148 
       
   149 	_writeQuickTime : function(p) {
       
   150 		p.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], p.src);
       
   151 		TinyMCE_PreviewPlugin._writeEmbed(
       
   152 			'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
       
   153 			'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
       
   154 			'video/quicktime',
       
   155 			p
       
   156 		);
       
   157 	},
       
   158 
       
   159 	_writeRealMedia : function(p) {
       
   160 		p.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], p.src);
       
   161 		TinyMCE_PreviewPlugin._writeEmbed(
       
   162 			'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
       
   163 			'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
       
   164 			'audio/x-pn-realaudio-plugin',
       
   165 			p
       
   166 		);
       
   167 	},
       
   168 
       
   169 	_writeWindowsMedia : function(p) {
       
   170 		p.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], p.src);
       
   171 		p.url = p.src;
       
   172 		TinyMCE_PreviewPlugin._writeEmbed(
       
   173 			'6BF52A52-394A-11D3-B153-00C04F79FAA6',
       
   174 			'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
       
   175 			'application/x-mplayer2',
       
   176 			p
       
   177 		);
       
   178 	},
       
   179 
       
   180 	_writeEmbed : function(cls, cb, mt, p) {
       
   181 		var h = '', n, d = TinyMCE_PreviewPlugin._doc, ne, c;
       
   182 
       
   183 		h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
       
   184 		h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
       
   185 		h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
       
   186 		h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
       
   187 		h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
       
   188 		h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
       
   189 		h += '>';
       
   190 
       
   191 		for (n in p)
       
   192 			h += '<param name="' + n + '" value="' + p[n] + '">';
       
   193 
       
   194 		h += '<embed type="' + mt + '"';
       
   195 
       
   196 		for (n in p)
       
   197 			h += n + '="' + p[n] + '" ';
       
   198 
       
   199 		h += '></embed></object>';
       
   200 
       
   201 		d._embeds[d._embeds.length] = h;
       
   202 	}
       
   203 };
       
   204 
       
   205 tinyMCE.addPlugin("preview", TinyMCE_PreviewPlugin);