PageRenderTime 104ms CodeModel.GetById 40ms app.highlight 16ms RepoModel.GetById 45ms app.codeStats 0ms

/static/scripts/tiny_mce/plugins/preview/editor_plugin_src.js

http://n23.googlecode.com/
JavaScript | 187 lines | 147 code | 31 blank | 9 comment | 15 complexity | 37fcdf44dd79432156c8d938863fbd6c MD5 | raw file
  1/**
  2 * $Id: editor_plugin_src.js 537 2008-01-14 16:38:33Z spocke $
  3 *
  4 * @author Moxiecode
  5 * @copyright Copyright Š 2004-2008, Moxiecode Systems AB, All rights reserved.
  6 */
  7
  8(function() {
  9	tinymce.create('tinymce.plugins.Preview', {
 10		init : function(ed, url) {
 11			var t = this;
 12
 13			t.editor = ed;
 14
 15			ed.addCommand('mcePreview', t._preview, t);
 16			ed.addButton('preview', {title : 'preview.preview_desc', cmd : 'mcePreview'});
 17		},
 18
 19		getInfo : function() {
 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		},
 28
 29		// Private methods
 30
 31		_preview : function() {
 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");
 33
 34			// Use a custom preview page
 35			if (page) {
 36				ed.windowManager.open({
 37					file : ed.getParam("plugin_preview_pageurl", null),
 38					width : w,
 39					height : h
 40				}, {
 41					resizable : "yes",
 42					scrollbars : "yes",
 43					inline : 1
 44				});
 45			} else {
 46				win = window.open("", "mcePreview", "menubar=no,toolbar=no,scrollbars=yes,resizable=yes,left=20,top=20,width=" + w + ",height="  + h);
 47				html = "";
 48				c = ed.getContent();
 49				pos = c.indexOf('<body');
 50				css = ed.getParam("content_css", '').split(',');
 51
 52				tinymce.map(css, function(u) {
 53					return ed.documentBaseURI.toAbsolute(u);
 54				});
 55
 56				if (pos != -1) {
 57					pos = c.indexOf('>', pos);
 58					pos2 = c.lastIndexOf('</body>');
 59					c = c.substring(pos + 1, pos2);
 60				}
 61
 62				html += ed.getParam('doctype');
 63				html += '<html xmlns="http://www.w3.org/1999/xhtml">';
 64				html += '<head>';
 65				html += '<title>' + ed.getLang('preview.preview_desc') + '</title>';
 66				html += '<base href="' + ed.documentBaseURI.getURI() + '" />';
 67				html += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
 68
 69				for (i=0; i<css.length; i++)
 70					html += '<link href="' + css[i] + '" rel="stylesheet" type="text/css" />';
 71
 72				html += '</head>';
 73				html += '<body dir="' + ed.getParam("directionality") + '" onload="window.opener.tinymce.EditorManager.get(\'' + ed.id + '\').plugins[\'preview\']._onLoad(window,document);">';
 74				html += c;
 75				html += '</body>';
 76				html += '</html>';
 77
 78				win.document.write(html);
 79				win.document.close();
 80			}
 81		},
 82
 83		_onLoad : function(w, d) {
 84			var t = this, nl, i, el = [], sv, ne;
 85
 86			t._doc = d;
 87			w.writeFlash = t._writeFlash;
 88			w.writeShockWave = t._writeShockWave;
 89			w.writeQuickTime = t._writeQuickTime;
 90			w.writeRealMedia = t._writeRealMedia;
 91			w.writeWindowsMedia = t._writeWindowsMedia;
 92			w.writeEmbed = t._writeEmbed;
 93
 94			nl = d.getElementsByTagName("script");
 95			for (i=0; i<nl.length; i++) {
 96				sv = tinymce.isIE ? nl[i].innerHTML : nl[i].firstChild.nodeValue;
 97
 98				if (new RegExp('write(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)\\(.*', 'g').test(sv))
 99					el[el.length] = nl[i];
100			}
101
102			for (i=0; i<el.length; i++) {
103				ne = d.createElement("div");
104				ne.innerHTML = d._embeds[i];
105				el[i].parentNode.insertBefore(ne.firstChild, el[i]);
106			}
107		},
108
109		_writeFlash : function(p) {
110			p.src = this.editor.documentBaseURI.toAbsolute(p.src);
111			TinyMCE_PreviewPlugin._writeEmbed(
112				'D27CDB6E-AE6D-11cf-96B8-444553540000',
113				'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
114				'application/x-shockwave-flash',
115				p
116			);
117		},
118
119		_writeShockWave : function(p) {
120			this.editor.documentBaseURI.toAbsolute(p.src);
121			TinyMCE_PreviewPlugin._writeEmbed(
122				'166B1BCA-3F9C-11CF-8075-444553540000',
123				'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
124				'application/x-director',
125				p
126			);
127		},
128
129		_writeQuickTime : function(p) {
130			this.editor.documentBaseURI.toAbsolute(p.src);
131			TinyMCE_PreviewPlugin._writeEmbed(
132				'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
133				'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
134				'video/quicktime',
135				p
136			);
137		},
138
139		_writeRealMedia : function(p) {
140			this.editor.documentBaseURI.toAbsolute(p.src);
141			TinyMCE_PreviewPlugin._writeEmbed(
142				'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
143				'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
144				'audio/x-pn-realaudio-plugin',
145				p
146			);
147		},
148
149		_writeWindowsMedia : function(p) {
150			this.editor.documentBaseURI.toAbsolute(p.src);
151			p.url = p.src;
152			TinyMCE_PreviewPlugin._writeEmbed(
153				'6BF52A52-394A-11D3-B153-00C04F79FAA6',
154				'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
155				'application/x-mplayer2',
156				p
157			);
158		},
159
160		_writeEmbed : function(cls, cb, mt, p) {
161			var h = '', n, d = t._doc, ne, c;
162
163			h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
164			h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
165			h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
166			h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
167			h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
168			h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
169			h += '>';
170
171			for (n in p)
172				h += '<param name="' + n + '" value="' + p[n] + '">';
173
174			h += '<embed type="' + mt + '"';
175
176			for (n in p)
177				h += n + '="' + p[n] + '" ';
178
179			h += '></embed></object>';
180
181			d._embeds[d._embeds.length] = h;
182		}
183	});
184
185	// Register plugin
186	tinymce.PluginManager.add('preview', tinymce.plugins.Preview);
187})();