message.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ///import core
  2. ///import uicore
  3. (function() {
  4. var utils = baidu.editor.utils,
  5. domUtils = baidu.editor.dom.domUtils,
  6. UIBase = baidu.editor.ui.UIBase,
  7. Message = (baidu.editor.ui.Message = function(options) {
  8. this.initOptions(options);
  9. this.initMessage();
  10. });
  11. Message.prototype = {
  12. initMessage: function() {
  13. this.initUIBase();
  14. },
  15. getHtmlTpl: function() {
  16. return (
  17. '<div id="##" class="edui-message %%">' +
  18. ' <div id="##_closer" class="edui-message-closer">×</div>' +
  19. ' <div id="##_body" class="edui-message-body edui-message-type-info">' +
  20. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  21. ' <div class="edui-shadow"></div>' +
  22. ' <div id="##_content" class="edui-message-content">' +
  23. " </div>" +
  24. " </div>" +
  25. "</div>"
  26. );
  27. },
  28. reset: function(opt) {
  29. var me = this;
  30. if (!opt.keepshow) {
  31. clearTimeout(this.timer);
  32. me.timer = setTimeout(function() {
  33. me.hide();
  34. }, opt.timeout || 4000);
  35. }
  36. opt.content !== undefined && me.setContent(opt.content);
  37. opt.type !== undefined && me.setType(opt.type);
  38. me.show();
  39. },
  40. postRender: function() {
  41. var me = this,
  42. closer = this.getDom("closer");
  43. closer &&
  44. domUtils.on(closer, "click", function() {
  45. me.hide();
  46. });
  47. },
  48. setContent: function(content) {
  49. this.getDom("content").innerHTML = content;
  50. },
  51. setType: function(type) {
  52. type = type || "info";
  53. var body = this.getDom("body");
  54. body.className = body.className.replace(
  55. /edui-message-type-[\w-]+/,
  56. "edui-message-type-" + type
  57. );
  58. },
  59. getContent: function() {
  60. return this.getDom("content").innerHTML;
  61. },
  62. getType: function() {
  63. var arr = this.getDom("body").match(/edui-message-type-([\w-]+)/);
  64. return arr ? arr[1] : "";
  65. },
  66. show: function() {
  67. this.getDom().style.display = "block";
  68. },
  69. hide: function() {
  70. var dom = this.getDom();
  71. if (dom) {
  72. dom.style.display = "none";
  73. dom.parentNode && dom.parentNode.removeChild(dom);
  74. }
  75. }
  76. };
  77. utils.inherits(Message, UIBase);
  78. })();