1 /** |
1 /** |
2 * $Id: editor_plugin_src.js 537 2008-01-14 16:38:33Z spocke $ |
2 * $Id: editor_plugin_src.js 895 2008-07-10 14:34:23Z spocke $ |
3 * |
3 * |
4 * @author Moxiecode |
4 * @author Moxiecode |
5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. |
5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved. |
6 */ |
6 */ |
7 |
7 |
8 (function() { |
8 (function() { |
9 tinymce.create('tinymce.plugins.Preview', { |
9 tinymce.create('tinymce.plugins.Preview', { |
10 init : function(ed, url) { |
10 init : function(ed, url) { |
11 var t = this; |
11 var t = this, css = tinymce.explode(ed.settings.content_css); |
12 |
12 |
13 t.editor = ed; |
13 t.editor = ed; |
14 |
14 |
15 ed.addCommand('mcePreview', t._preview, t); |
15 // Force absolute CSS urls |
|
16 tinymce.each(css, function(u, k) { |
|
17 css[k] = ed.documentBaseURI.toAbsolute(u); |
|
18 }); |
|
19 |
|
20 ed.addCommand('mcePreview', function() { |
|
21 ed.windowManager.open({ |
|
22 file : ed.getParam("plugin_preview_pageurl", url + "/preview.html"), |
|
23 width : parseInt(ed.getParam("plugin_preview_width", "550")), |
|
24 height : parseInt(ed.getParam("plugin_preview_height", "600")), |
|
25 resizable : "yes", |
|
26 scrollbars : "yes", |
|
27 popup_css : css.join(','), |
|
28 inline : ed.getParam("plugin_preview_inline", 1) |
|
29 }, { |
|
30 base : ed.documentBaseURI.getURI() |
|
31 }); |
|
32 }); |
|
33 |
16 ed.addButton('preview', {title : 'preview.preview_desc', cmd : 'mcePreview'}); |
34 ed.addButton('preview', {title : 'preview.preview_desc', cmd : 'mcePreview'}); |
17 }, |
35 }, |
18 |
36 |
19 getInfo : function() { |
37 getInfo : function() { |
20 return { |
38 return { |
22 author : 'Moxiecode Systems AB', |
40 author : 'Moxiecode Systems AB', |
23 authorurl : 'http://tinymce.moxiecode.com', |
41 authorurl : 'http://tinymce.moxiecode.com', |
24 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/preview', |
42 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/preview', |
25 version : tinymce.majorVersion + "." + tinymce.minorVersion |
43 version : tinymce.majorVersion + "." + tinymce.minorVersion |
26 }; |
44 }; |
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 } |
45 } |
183 }); |
46 }); |
184 |
47 |
185 // Register plugin |
48 // Register plugin |
186 tinymce.PluginManager.add('preview', tinymce.plugins.Preview); |
49 tinymce.PluginManager.add('preview', tinymce.plugins.Preview); |