plugin.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.0.1 (2019-02-21)
  8. */
  9. (function () {
  10. var preview = (function () {
  11. 'use strict';
  12. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  13. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  14. var getPreviewDialogWidth = function (editor) {
  15. return parseInt(editor.getParam('plugin_preview_width', '650'), 10);
  16. };
  17. var getPreviewDialogHeight = function (editor) {
  18. return parseInt(editor.getParam('plugin_preview_height', '500'), 10);
  19. };
  20. var getContentStyle = function (editor) {
  21. return editor.getParam('content_style', '');
  22. };
  23. var Settings = {
  24. getPreviewDialogWidth: getPreviewDialogWidth,
  25. getPreviewDialogHeight: getPreviewDialogHeight,
  26. getContentStyle: getContentStyle
  27. };
  28. var getPreviewHtml = function (editor) {
  29. var headHtml = '';
  30. var encode = editor.dom.encode;
  31. var contentStyle = Settings.getContentStyle(editor);
  32. headHtml += '<base href="' + encode(editor.documentBaseURI.getURI()) + '">';
  33. if (contentStyle) {
  34. headHtml += '<style type="text/css">' + contentStyle + '</style>';
  35. }
  36. global$1.each(editor.contentCSS, function (url) {
  37. headHtml += '<link type="text/css" rel="stylesheet" href="' + encode(editor.documentBaseURI.toAbsolute(url)) + '">';
  38. });
  39. var bodyId = editor.settings.body_id || 'tinymce';
  40. if (bodyId.indexOf('=') !== -1) {
  41. bodyId = editor.getParam('body_id', '', 'hash');
  42. bodyId = bodyId[editor.id] || bodyId;
  43. }
  44. var bodyClass = editor.settings.body_class || '';
  45. if (bodyClass.indexOf('=') !== -1) {
  46. bodyClass = editor.getParam('body_class', '', 'hash');
  47. bodyClass = bodyClass[editor.id] || '';
  48. }
  49. 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> ';
  50. var dirAttr = editor.settings.directionality ? ' dir="' + editor.settings.directionality + '"' : '';
  51. var previewHtml = '<!DOCTYPE html>' + '<html>' + '<head>' + headHtml + '</head>' + '<body id="' + encode(bodyId) + '" class="mce-content-body ' + encode(bodyClass) + '"' + encode(dirAttr) + '>' + editor.getContent() + preventClicksOnLinksScript + '</body>' + '</html>';
  52. return previewHtml;
  53. };
  54. var IframeContent = { getPreviewHtml: getPreviewHtml };
  55. var open = function (editor) {
  56. var content = IframeContent.getPreviewHtml(editor);
  57. var dataApi = editor.windowManager.open({
  58. title: 'Preview',
  59. size: 'large',
  60. body: {
  61. type: 'panel',
  62. items: [{
  63. name: 'preview',
  64. type: 'iframe',
  65. sandboxed: true
  66. }]
  67. },
  68. buttons: [{
  69. type: 'cancel',
  70. name: 'close',
  71. text: 'Close',
  72. primary: true
  73. }],
  74. initialData: { preview: content }
  75. });
  76. dataApi.focus('close');
  77. };
  78. var register = function (editor) {
  79. editor.addCommand('mcePreview', function () {
  80. open(editor);
  81. });
  82. };
  83. var Commands = { register: register };
  84. var register$1 = function (editor) {
  85. editor.ui.registry.addButton('preview', {
  86. icon: 'preview',
  87. tooltip: 'Preview',
  88. onAction: function () {
  89. return editor.execCommand('mcePreview');
  90. }
  91. });
  92. editor.ui.registry.addMenuItem('preview', {
  93. icon: 'preview',
  94. text: 'Preview',
  95. onAction: function () {
  96. return editor.execCommand('mcePreview');
  97. }
  98. });
  99. };
  100. var Buttons = { register: register$1 };
  101. global.add('preview', function (editor) {
  102. Commands.register(editor);
  103. Buttons.register(editor);
  104. });
  105. function Plugin () {
  106. }
  107. return Plugin;
  108. }());
  109. })();