Emoji.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. MWF.xApplication.TeamWork = MWF.xApplication.TeamWork || {};
  2. MWF.xApplication.TeamWork.Emoji = new Class({
  3. Extends: MTooltips,
  4. options : {
  5. "style":"default",
  6. // displayDelay : 300,
  7. hasArrow:true,
  8. event:"click"
  9. },
  10. initialize : function( explorer,container, target, app, data, options, targetCoordinates ){
  11. //可以传入target 或者 targetCoordinates,两种选一
  12. //传入target,表示触发tooltip的节点,本类根据 this.options.event 自动绑定target的事件
  13. //传入targetCoordinates,表示 出发tooltip的位置,本类不绑定触发事件
  14. if( options ){
  15. this.setOptions(options);
  16. }
  17. this.explorer = explorer;
  18. this.container = container;
  19. this.target = target;
  20. this.targetCoordinates = targetCoordinates;
  21. this.app = app;
  22. this.lp = this.app.lp.emoji;
  23. this.data = data;
  24. this.actions = this.app.restActions;
  25. this.path = "../x_component_TeamWork/$Emoji/";
  26. this.cssPath = this.path+this.options.style+"/css.wcss";
  27. this._loadCss();
  28. if( this.target ){
  29. this.setTargetEvents();
  30. }
  31. this.fireEvent("postInitialize",[this]);
  32. },
  33. _loadCustom : function( callback ){
  34. //this.data
  35. //this.contentNode
  36. this.contentNode.setStyles({"margin":"5px"});
  37. var _self = this;
  38. var emojiPath = "../x_component_TeamWork/$Emoji/default/icon/";
  39. for(var item in this.lp){
  40. var text = this.lp[item];
  41. var emojiItem = new Element("div.emojiItem",{styles:this.css.emojiItem}).inject(this.contentNode);
  42. emojiItem.set("title",text);
  43. emojiItem.setStyles({"background-image":"url("+emojiPath+item+".png)"});
  44. emojiItem.addEvents({
  45. mouseover:function(){this.setStyles({"border":"1px solid #dedede"})},
  46. mouseout:function(){this.setStyles({"border":"1px solid #ffffff"})},
  47. click:function(){
  48. var data = {"value":this.get("title")};
  49. _self.close(data)
  50. }
  51. })
  52. }
  53. if(callback)callback();
  54. },
  55. hide: function(){
  56. if( this.node ){
  57. this.node.setStyle("display","none");
  58. this.status = "hidden";
  59. if( this.maskNode ){
  60. this.maskNode.setStyle("display","none");
  61. }
  62. this.fireEvent("hide",[this]);
  63. }
  64. if( this.maskNode ){
  65. this.maskNode.destroy();
  66. }
  67. this.close();
  68. },
  69. // 增加的方法
  70. close: function(data){
  71. if( this.node ){
  72. this.node.setStyle("display","none");
  73. this.status = "hidden";
  74. if( this.maskNode ){
  75. this.maskNode.setStyle("display","none");
  76. }
  77. this.fireEvent("hide",[this]);
  78. //this.fireEvent("close",[data]);
  79. }
  80. if( this.maskNode ){
  81. this.maskNode.destroy();
  82. }
  83. this.fireEvent("close",[data]);
  84. this.destroy();
  85. },
  86. setTargetEvents : function(){
  87. if( this.options.event == "click" ){
  88. // if( this.options.isAutoShow ){
  89. // this.target.addEvents({
  90. // "click": function( ev ){
  91. // this.load();
  92. // ev.stopPropagation();
  93. // }.bind(this)
  94. // });
  95. // }
  96. }else{
  97. if( this.options.isAutoHide || this.options.isAutoShow ){
  98. this.target.addEvents({
  99. "mouseenter": function(){
  100. if( this.timer_hide ){
  101. clearTimeout(this.timer_hide);
  102. }
  103. }.bind(this)
  104. });
  105. }
  106. if( this.options.isAutoShow ){
  107. this.target.addEvents({
  108. "mouseenter": function(){
  109. if( this.status != "display" ){
  110. this.timer_show = setTimeout( this.load.bind(this),this.options.displayDelay );
  111. }
  112. }.bind(this)
  113. });
  114. }
  115. if( this.options.isAutoHide || this.options.isAutoShow ){
  116. this.target.addEvents({
  117. "mouseleave" : function(){
  118. if( this.timer_show ){
  119. clearTimeout(this.timer_show);
  120. }
  121. }.bind(this)
  122. });
  123. }
  124. if( this.options.isAutoHide ){
  125. this.target.addEvents({
  126. "mouseleave" : function(){
  127. if( this.status == "display" ){
  128. this.timer_hide = setTimeout( this.hide.bind(this),this.options.hiddenDelay );
  129. }
  130. }.bind(this)
  131. });
  132. }
  133. }
  134. }
  135. });