plugin.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. (function () {
  2. var preview = (function () {
  3. 'use strict';
  4. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  5. var global$1 = tinymce.util.Tools.resolve('tinymce.Env');
  6. var getPreviewDialogWidth = function (editor) {
  7. return parseInt(editor.getParam('plugin_preview_width', '650'), 10);
  8. };
  9. var getPreviewDialogHeight = function (editor) {
  10. return parseInt(editor.getParam('plugin_preview_height', '500'), 10);
  11. };
  12. var getContentStyle = function (editor) {
  13. return editor.getParam('content_style', '');
  14. };
  15. var $_ffk79jjfjnlpb2ix = {
  16. getPreviewDialogWidth: getPreviewDialogWidth,
  17. getPreviewDialogHeight: getPreviewDialogHeight,
  18. getContentStyle: getContentStyle
  19. };
  20. var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  21. var getPreviewHtml = function (editor) {
  22. var previewHtml;
  23. var headHtml = '';
  24. var encode = editor.dom.encode;
  25. var contentStyle = $_ffk79jjfjnlpb2ix.getContentStyle(editor);
  26. headHtml += '<base href="' + encode(editor.documentBaseURI.getURI()) + '">';
  27. if (contentStyle) {
  28. headHtml += '<style type="text/css">' + contentStyle + '</style>';
  29. }
  30. global$2.each(editor.contentCSS, function (url) {
  31. headHtml += '<link type="text/css" rel="stylesheet" href="' + encode(editor.documentBaseURI.toAbsolute(url)) + '">';
  32. });
  33. var bodyId = editor.settings.body_id || 'tinymce';
  34. if (bodyId.indexOf('=') !== -1) {
  35. bodyId = editor.getParam('body_id', '', 'hash');
  36. bodyId = bodyId[editor.id] || bodyId;
  37. }
  38. var bodyClass = editor.settings.body_class || '';
  39. if (bodyClass.indexOf('=') !== -1) {
  40. bodyClass = editor.getParam('body_class', '', 'hash');
  41. bodyClass = bodyClass[editor.id] || '';
  42. }
  43. var preventClicksOnLinksScript = '<script>' + 'document.addEventListener && document.addEventListener("click", function(e) {' + 'for (var elm = e.target; elm; elm = elm.parentNode) {' + 'if (elm.nodeName === "A") {' + 'e.preventDefault();' + '}' + '}' + '}, false);' + '</script> ';
  44. var dirAttr = editor.settings.directionality ? ' dir="' + editor.settings.directionality + '"' : '';
  45. previewHtml = '<!DOCTYPE html>' + '<html>' + '<head>' + headHtml + '</head>' + '<body id="' + encode(bodyId) + '" class="mce-content-body ' + encode(bodyClass) + '"' + encode(dirAttr) + '>' + editor.getContent() + preventClicksOnLinksScript + '</body>' + '</html>';
  46. return previewHtml;
  47. };
  48. var injectIframeContent = function (editor, iframe, sandbox) {
  49. var previewHtml = getPreviewHtml(editor);
  50. if (!sandbox) {
  51. var doc = iframe.contentWindow.document;
  52. doc.open();
  53. doc.write(previewHtml);
  54. doc.close();
  55. } else {
  56. iframe.src = 'data:text/html;charset=utf-8,' + encodeURIComponent(previewHtml);
  57. }
  58. };
  59. var $_5yhtiwjgjnlpb2iy = {
  60. getPreviewHtml: getPreviewHtml,
  61. injectIframeContent: injectIframeContent
  62. };
  63. var open = function (editor) {
  64. var sandbox = !global$1.ie;
  65. var dialogHtml = '<iframe src="" frameborder="0"' + (sandbox ? ' sandbox="allow-scripts"' : '') + '></iframe>';
  66. var dialogWidth = $_ffk79jjfjnlpb2ix.getPreviewDialogWidth(editor);
  67. var dialogHeight = $_ffk79jjfjnlpb2ix.getPreviewDialogHeight(editor);
  68. editor.windowManager.open({
  69. title: 'Preview',
  70. width: dialogWidth,
  71. height: dialogHeight,
  72. html: dialogHtml,
  73. buttons: {
  74. text: 'Close',
  75. onclick: function (e) {
  76. e.control.parent().parent().close();
  77. }
  78. },
  79. onPostRender: function (e) {
  80. var iframeElm = e.control.getEl('body').firstChild;
  81. $_5yhtiwjgjnlpb2iy.injectIframeContent(editor, iframeElm, sandbox);
  82. }
  83. });
  84. };
  85. var $_5zz6kjjdjnlpb2iv = { open: open };
  86. var register = function (editor) {
  87. editor.addCommand('mcePreview', function () {
  88. $_5zz6kjjdjnlpb2iv.open(editor);
  89. });
  90. };
  91. var $_aj65e1jcjnlpb2it = { register: register };
  92. var register$1 = function (editor) {
  93. editor.addButton('preview', {
  94. title: 'Preview',
  95. cmd: 'mcePreview'
  96. });
  97. editor.addMenuItem('preview', {
  98. text: 'Preview',
  99. cmd: 'mcePreview',
  100. context: 'view'
  101. });
  102. };
  103. var $_e8rxhijijnlpb2j4 = { register: register$1 };
  104. global.add('preview', function (editor) {
  105. $_aj65e1jcjnlpb2it.register(editor);
  106. $_e8rxhijijnlpb2j4.register(editor);
  107. });
  108. function Plugin () {
  109. }
  110. return Plugin;
  111. }());
  112. })();