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