pastepicker.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 '<div class="edui-pasteicon" onclick="$$._onClick(this)"></div>' +
  19. '<div class="edui-pastecontainer">' +
  20. '<div class="edui-title">' + this.editor.getLang("pasteOpt") + '</div>' +
  21. '<div class="edui-button">' +
  22. '<div title="' + this.editor.getLang("pasteSourceFormat") + '" onclick="$$.format(false)" stateful>' +
  23. '<div class="edui-richtxticon"></div></div>' +
  24. '<div title="' + this.editor.getLang("tagFormat") + '" onclick="$$.format(2)" stateful>' +
  25. '<div class="edui-tagicon"></div></div>' +
  26. '<div title="' + this.editor.getLang("pasteTextFormat") + '" onclick="$$.format(true)" stateful>' +
  27. '<div class="edui-plaintxticon"></div></div>' +
  28. '</div>' +
  29. '</div>' +
  30. '</div>'
  31. },
  32. getStateDom:function () {
  33. return this.target;
  34. },
  35. format:function (param) {
  36. this.editor.ui._isTransfer = true;
  37. this.editor.fireEvent('pasteTransfer', param);
  38. },
  39. _onClick:function (cur) {
  40. var node = domUtils.getNextDomNode(cur),
  41. screenHt = uiUtils.getViewportRect().height,
  42. subPop = uiUtils.getClientRect(node);
  43. if ((subPop.top + subPop.height) > screenHt)
  44. node.style.top = (-subPop.height - cur.offsetHeight) + "px";
  45. else
  46. node.style.top = "";
  47. if (/hidden/ig.test(domUtils.getComputedStyle(node, "visibility"))) {
  48. node.style.visibility = "visible";
  49. domUtils.addClass(cur, "edui-state-opened");
  50. } else {
  51. node.style.visibility = "hidden";
  52. domUtils.removeClasses(cur, "edui-state-opened")
  53. }
  54. },
  55. _UIBase_render:UIBase.prototype.render
  56. };
  57. utils.inherits(PastePicker, UIBase);
  58. utils.extend(PastePicker.prototype, Stateful, true);
  59. })();