pastepicker.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ///import core
  2. ///import uicore
  3. (function() {
  4. var utils = baidu.editor.utils,
  5. Stateful = baidu.editor.ui.Stateful,
  6. uiUtils = baidu.editor.ui.uiUtils,
  7. UIBase = baidu.editor.ui.UIBase;
  8. var PastePicker = (baidu.editor.ui.PastePicker = function(options) {
  9. this.initOptions(options);
  10. this.initPastePicker();
  11. });
  12. PastePicker.prototype = {
  13. initPastePicker: function() {
  14. this.initUIBase();
  15. this.Stateful_init();
  16. },
  17. getHtmlTpl: function() {
  18. return (
  19. '<div class="edui-pasteicon" onclick="$$._onClick(this)"></div>' +
  20. '<div class="edui-pastecontainer">' +
  21. '<div class="edui-title">' +
  22. this.editor.getLang("pasteOpt") +
  23. "</div>" +
  24. '<div class="edui-button">' +
  25. '<div title="' +
  26. this.editor.getLang("pasteSourceFormat") +
  27. '" onclick="$$.format(false)" stateful>' +
  28. '<div class="edui-richtxticon"></div></div>' +
  29. '<div title="' +
  30. this.editor.getLang("tagFormat") +
  31. '" onclick="$$.format(2)" stateful>' +
  32. '<div class="edui-tagicon"></div></div>' +
  33. '<div title="' +
  34. this.editor.getLang("pasteTextFormat") +
  35. '" onclick="$$.format(true)" stateful>' +
  36. '<div class="edui-plaintxticon"></div></div>' +
  37. "</div>" +
  38. "</div>" +
  39. "</div>"
  40. );
  41. },
  42. getStateDom: function() {
  43. return this.target;
  44. },
  45. format: function(param) {
  46. this.editor.ui._isTransfer = true;
  47. this.editor.fireEvent("pasteTransfer", param);
  48. },
  49. _onClick: function(cur) {
  50. var node = domUtils.getNextDomNode(cur),
  51. screenHt = uiUtils.getViewportRect().height,
  52. subPop = uiUtils.getClientRect(node);
  53. if (subPop.top + subPop.height > screenHt)
  54. node.style.top = -subPop.height - cur.offsetHeight + "px";
  55. else node.style.top = "";
  56. if (/hidden/gi.test(domUtils.getComputedStyle(node, "visibility"))) {
  57. node.style.visibility = "visible";
  58. domUtils.addClass(cur, "edui-state-opened");
  59. } else {
  60. node.style.visibility = "hidden";
  61. domUtils.removeClasses(cur, "edui-state-opened");
  62. }
  63. },
  64. _UIBase_render: UIBase.prototype.render
  65. };
  66. utils.inherits(PastePicker, UIBase);
  67. utils.extend(PastePicker.prototype, Stateful, true);
  68. })();