paste.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. CKEDITOR.dialog.add("paste", function(c) {
  6. function k(a) {
  7. var b = new CKEDITOR.dom.document(a.document),
  8. g = b.getBody(),
  9. d = b.getById("cke_actscrpt");
  10. d && d.remove();
  11. g.setAttribute("contenteditable", !0);
  12. g.on(e.mainPasteEvent, function(a) {
  13. a = e.initPasteDataTransfer(a);
  14. f ? a != f && (f = e.initPasteDataTransfer()) : (f = a);
  15. });
  16. if (CKEDITOR.env.ie && 8 > CKEDITOR.env.version)
  17. b.getWindow().on("blur", function() {
  18. b.$.selection.empty();
  19. });
  20. b.on(
  21. "keydown",
  22. function(a) {
  23. a = a.data;
  24. var b;
  25. switch (a.getKeystroke()) {
  26. case 27:
  27. this.hide();
  28. b = 1;
  29. break;
  30. case 9:
  31. case CKEDITOR.SHIFT + 9:
  32. this.changeFocus(1), (b = 1);
  33. }
  34. b && a.preventDefault();
  35. },
  36. this
  37. );
  38. c.fire("ariaWidget", new CKEDITOR.dom.element(a.frameElement));
  39. b
  40. .getWindow()
  41. .getFrame()
  42. .removeCustomData("pendingFocus") && g.focus();
  43. }
  44. var h = c.lang.clipboard,
  45. e = CKEDITOR.plugins.clipboard,
  46. f;
  47. c.on(
  48. "pasteDialogCommit",
  49. function(a) {
  50. a.data &&
  51. c.fire("paste", {
  52. type: "auto",
  53. dataValue: a.data.dataValue,
  54. method: "paste",
  55. dataTransfer: a.data.dataTransfer || e.initPasteDataTransfer()
  56. });
  57. },
  58. null,
  59. null,
  60. 1e3
  61. );
  62. return {
  63. title: h.paste,
  64. minWidth: CKEDITOR.env.ie && CKEDITOR.env.quirks ? 370 : 350,
  65. minHeight: CKEDITOR.env.quirks ? 250 : 245,
  66. onShow: function() {
  67. this.parts.dialog.$.offsetHeight;
  68. this.setupContent();
  69. this._.committed = !1;
  70. },
  71. onLoad: function() {
  72. (CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat) &&
  73. "rtl" == c.lang.dir &&
  74. this.parts.contents.setStyle("overflow", "hidden");
  75. },
  76. onOk: function() {
  77. this.commitContent();
  78. },
  79. contents: [
  80. {
  81. id: "general",
  82. label: c.lang.common.generalTab,
  83. elements: [
  84. {
  85. type: "html",
  86. id: "pasteMsg",
  87. html:
  88. '\x3cdiv style\x3d"white-space:normal;width:340px"\x3e' +
  89. h.pasteMsg +
  90. "\x3c/div\x3e"
  91. },
  92. {
  93. type: "html",
  94. id: "editing_area",
  95. style: "width:100%;height:100%",
  96. html: "",
  97. focus: function() {
  98. var a = this.getInputElement(),
  99. b = a.getFrameDocument().getBody();
  100. !b || b.isReadOnly()
  101. ? a.setCustomData("pendingFocus", 1)
  102. : b.focus();
  103. },
  104. setup: function() {
  105. var a = this.getDialog(),
  106. b =
  107. '\x3chtml dir\x3d"' +
  108. c.config.contentsLangDirection +
  109. '" lang\x3d"' +
  110. (c.config.contentsLanguage || c.langCode) +
  111. '"\x3e\x3chead\x3e\x3cstyle\x3ebody{margin:3px;height:95%;word-break:break-all;}\x3c/style\x3e\x3c/head\x3e\x3cbody\x3e\x3cscript id\x3d"cke_actscrpt" type\x3d"text/javascript"\x3ewindow.parent.CKEDITOR.tools.callFunction(' +
  112. CKEDITOR.tools.addFunction(k, a) +
  113. ",this);\x3c/script\x3e\x3c/body\x3e\x3c/html\x3e",
  114. g = CKEDITOR.env.air
  115. ? "javascript:void(0)"
  116. : CKEDITOR.env.ie && !CKEDITOR.env.edge
  117. ? "javascript:void((function(){" +
  118. encodeURIComponent(
  119. "document.open();(" +
  120. CKEDITOR.tools.fixDomain +
  121. ")();document.close();"
  122. ) +
  123. '})())"'
  124. : "",
  125. d = CKEDITOR.dom.element.createFromHtml(
  126. '\x3ciframe class\x3d"cke_pasteframe" frameborder\x3d"0" allowTransparency\x3d"true" src\x3d"' +
  127. g +
  128. '" aria-label\x3d"' +
  129. h.pasteArea +
  130. '" aria-describedby\x3d"' +
  131. a.getContentElement("general", "pasteMsg").domId +
  132. '"\x3e\x3c/iframe\x3e'
  133. );
  134. f = null;
  135. d.on(
  136. "load",
  137. function(a) {
  138. a.removeListener();
  139. a = d.getFrameDocument();
  140. a.write(b);
  141. c.focusManager.add(a.getBody());
  142. CKEDITOR.env.air && k.call(this, a.getWindow().$);
  143. },
  144. a
  145. );
  146. d.setCustomData("dialog", a);
  147. a = this.getElement();
  148. a.setHtml("");
  149. a.append(d);
  150. if (CKEDITOR.env.ie && !CKEDITOR.env.edge) {
  151. var e = CKEDITOR.dom.element.createFromHtml(
  152. '\x3cspan tabindex\x3d"-1" style\x3d"position:absolute" role\x3d"presentation"\x3e\x3c/span\x3e'
  153. );
  154. e.on("focus", function() {
  155. setTimeout(function() {
  156. d.$.contentWindow.focus();
  157. });
  158. });
  159. a.append(e);
  160. this.focus = function() {
  161. e.focus();
  162. this.fire("focus");
  163. };
  164. }
  165. this.getInputElement = function() {
  166. return d;
  167. };
  168. CKEDITOR.env.ie &&
  169. (a.setStyle("display", "block"),
  170. a.setStyle("height", d.$.offsetHeight + 2 + "px"));
  171. },
  172. commit: function() {
  173. var a = this.getDialog().getParentEditor(),
  174. b = this.getInputElement()
  175. .getFrameDocument()
  176. .getBody(),
  177. c = b.getBogus();
  178. c && c.remove();
  179. b = b.getHtml();
  180. this.getDialog()._.committed = !0;
  181. a.fire("pasteDialogCommit", {
  182. dataValue: b,
  183. dataTransfer: f || e.initPasteDataTransfer()
  184. });
  185. }
  186. }
  187. ]
  188. }
  189. ]
  190. };
  191. });