2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
5 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
8 /* Import plugin specific language pack */
9 tinyMCE.importPluginLanguagePack('preview');
11 var TinyMCE_PreviewPlugin = {
12 getInfo : function() {
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
23 * Returns the HTML contents of the preview control.
25 getControlHTML : function(cn) {
28 return tinyMCE.getButtonHTML(cn, 'lang_preview_desc', '{$pluginurl}/images/preview.gif', 'mcePreview');
35 * Executes the mcePreview command.
37 execCommand : function(editor_id, element, command, user_interface, value) {
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");
45 // Use a custom preview page
47 var template = new Array();
49 template['file'] = previewPage;
50 template['width'] = previewWidth;
51 template['height'] = previewHeight;
53 tinyMCE.openWindow(template, {editor_id : editor_id, resizable : "yes", scrollbars : "yes", inline : "yes", content : tinyMCE.getContent(), content_css : tinyMCE.getParam("content_css")});
55 var win = window.open("", "mcePreview", "menubar=no,toolbar=no,scrollbars=yes,resizable=yes,left=20,top=20,width=" + previewWidth + ",height=" + previewHeight);
57 var c = tinyMCE.getContent();
58 var pos = c.indexOf('<body'), pos2, css = tinyMCE.getParam("content_css").split(',');
61 pos = c.indexOf('>', pos);
62 pos2 = c.lastIndexOf('</body>');
63 c = c.substring(pos + 1, pos2);
66 html += tinyMCE.getParam('doctype');
67 html += '<html xmlns="http://www.w3.org/1999/xhtml">';
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" />';
73 for (i=0; i<css.length; i++)
74 html += '<link href="' + css[i] + '" rel="stylesheet" type="text/css" />';
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;';
87 html += '<body dir="' + tinyMCE.getParam("directionality") + '" onload="window.opener.TinyMCE_PreviewPlugin._onLoad();">';
92 win.document.write(html);
102 _setDoc : function(d) {
103 TinyMCE_PreviewPlugin._doc = d;
104 d._embeds = new Array();
107 _setWin : function(d) {
108 TinyMCE_PreviewPlugin._win = d;
111 _onLoad : function() {
112 var nl, i, el = new Array(), d = TinyMCE_PreviewPlugin._doc, sv, ne;
114 nl = d.getElementsByTagName("script");
115 for (i=0; i<nl.length; i++) {
116 sv = tinyMCE.isMSIE ? nl[i].innerHTML : nl[i].firstChild.nodeValue;
118 if (new RegExp('write(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)\\(.*', 'g').test(sv))
119 el[el.length] = nl[i];
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]);
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',
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',
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',
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',
169 _writeWindowsMedia : function(p) {
170 p.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], 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',
180 _writeEmbed : function(cls, cb, mt, p) {
181 var h = '', n, d = TinyMCE_PreviewPlugin._doc, ne, c;
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 + '"' : '';
192 h += '<param name="' + n + '" value="' + p[n] + '">';
194 h += '<embed type="' + mt + '"';
197 h += n + '="' + p[n] + '" ';
199 h += '></embed></object>';
201 d._embeds[d._embeds.length] = h;
205 tinyMCE.addPlugin("preview", TinyMCE_PreviewPlugin);