message.js 2.6 KB

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