MessageMobile.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. MWF.xDesktop.MessageMobile = new Class({
  2. Implements: [Options, Events],
  3. options: {
  4. "css":{
  5. "messageContainerNode": {
  6. "width": "100%",
  7. "position": "absolute",
  8. "z-index": 500000,
  9. "top": "0px",
  10. "left": "0px",
  11. "background-color": "#FFF",
  12. "overflow": "hidden"
  13. },
  14. "messageContentNode":{
  15. "overflow": "hidden"
  16. },
  17. "messageHideContentNode": {
  18. "height": "10px",
  19. "line-height": "6px",
  20. "text-align": "center",
  21. "display": "none",
  22. "border-bottom": "1px solid #999",
  23. "background-color": "#EEE"
  24. },
  25. "messageItemNode": {
  26. "padding": "5px",
  27. "overflow": "hidden",
  28. "border-bottom": "1px solid #CCC",
  29. "background": "transparent",
  30. "cursor": "default"
  31. },
  32. "messageItemTopNode": {
  33. "height": "24px",
  34. "line-height": "24px",
  35. "font-size": "16px",
  36. "color": "#4387cd"
  37. },
  38. "messageItemCloseNode": {
  39. "height": "30px",
  40. "width": "16px",
  41. "float": "right",
  42. "cursor": "pointer",
  43. "background": "url("+MWF.defaultPath+"/xDesktop/$Layout/default/message/close.png) no-repeat center center"
  44. },
  45. "messageItemSubjectNode": {
  46. "height": "24px",
  47. "margin-right": "18px"
  48. },
  49. "messageItemContentNode": {
  50. "overflow": "hidden",
  51. "color": "#333",
  52. "font-size": "12px",
  53. "line-height": "20px"
  54. },
  55. "messageItemBottomNode": {
  56. "height": "24px",
  57. "font-size": "12px",
  58. "line-height": "24px"
  59. },
  60. "messageItemDateNode": {
  61. "color": "#666"
  62. }
  63. }
  64. },
  65. initialize: function(options){
  66. this.setOptions(options);
  67. this.container = $(document.body);
  68. this.css = this.options.css;
  69. this.isShow = false;
  70. this.isMorph = false;
  71. },
  72. load: function(){
  73. this.node = new Element("div", {"styles": this.css.messageContainerNode});
  74. this.node.inject(this.container);
  75. this.contentNode = new Element("div", {"styles": this.css.messageContentNode}).inject(this.node);
  76. this.hideNode = new Element("div", {"styles": this.css.messageHideContentNode, "text": "——"}).inject(this.node);
  77. this.hideNode.addEvent("click", this.hide.bind(this));
  78. this.setPosition();
  79. },
  80. show: function(){
  81. if (!this.isMorph){
  82. this.isMorph = true;
  83. if (!this.morph){
  84. this.morph = new Fx.Morph(this.node, {
  85. duration: "200",
  86. transition: Fx.Transitions.Sine.easeOut
  87. });
  88. }
  89. this.node.setStyle("display", "block");
  90. this.hideNode.setStyle("display", "block");
  91. this.setPosition();
  92. this.morph.start({"top": "0px"}).chain(function(){
  93. this.isShow = true;
  94. this.isMorph = false;
  95. }.bind(this));
  96. }
  97. },
  98. hide: function(){
  99. if (!this.isMorph){
  100. this.isMorph = true;
  101. if (!this.morph){
  102. this.morph = new Fx.Morph(this.node, {
  103. duration: "200",
  104. transition: Fx.Transitions.Sine.easeOut
  105. });
  106. }
  107. var position = this.node.getPosition();
  108. var size = this.node.getSize();
  109. var top = 0-size.y;
  110. this.morph.start({"top": ""+top+"px"}).chain(function(){
  111. this.node.setStyle("display", "none");
  112. this.isShow = false;
  113. this.isMorph = false;
  114. }.bind(this));
  115. }
  116. },
  117. addMessage: function(msg){
  118. var item = new MWF.xDesktop.MessageMobile.Item(this,msg);
  119. if (!this.isShow){
  120. this.setPosition();
  121. //this.show();
  122. }
  123. return item;
  124. },
  125. setPosition: function(){
  126. if (!this.isShow){
  127. var size = this.node.getSize();
  128. var top = 0-size.y;
  129. this.node.setStyle("top", ""+top+"px");
  130. }
  131. },
  132. addTooltip: function(msg){}
  133. });
  134. MWF.xDesktop.MessageMobile.Item = new Class({
  135. initialize: function(message, msg){
  136. this.message = message;
  137. this.container = this.message.contentNode;
  138. this.css = this.message.css;
  139. this.msg = msg;
  140. this.load();
  141. },
  142. load: function(){
  143. this.node = new Element("div", {"styles": this.css.messageItemNode});
  144. this.topNode = new Element("div", {"styles": this.css.messageItemTopNode}).inject(this.node);
  145. this.closeNode = new Element("div", {"styles": this.css.messageItemCloseNode}).inject(this.topNode);
  146. this.subjectNode = new Element("div", {"styles": this.css.messageItemSubjectNode}).inject(this.topNode);
  147. this.contentNode = new Element("div", {"styles": this.css.messageItemContentNode}).inject(this.node);
  148. this.bottomNode = new Element("div", {"styles": this.css.messageItemBottomNode}).inject(this.node);
  149. this.dateNode = new Element("div", {"styles": this.css.messageItemDateNode}).inject(this.bottomNode);
  150. this.subjectNode.set({"text": this.msg.subject, "title": this.msg.subject});
  151. this.contentNode.set({"html": this.msg.content});
  152. this.contentNode.set({"title": this.contentNode.get("text")});
  153. this.dateNode.set("text", (new Date()).format("db"));
  154. this.node.inject(this.container, "top");
  155. this.setEvent();
  156. },
  157. setEvent: function(){
  158. this.closeNode.addEvents({
  159. "click": function(){
  160. this.close();
  161. }.bind(this)
  162. });
  163. },
  164. close: function(callback){
  165. var morph = new Fx.Morph(this.node, {
  166. duration: "200"
  167. // transition: Fx.Transitions.Sine.easeOut
  168. });
  169. var size = this.node.getSize();
  170. this.node.setStyle("height", ""+size.y+"px");
  171. morph.start({
  172. "opacity": 0,
  173. "height": "0px"
  174. }).chain(function(){
  175. this.node.destroy();
  176. delete this;
  177. }.bind(this));
  178. },
  179. closeItem: function(callback){
  180. var morph = new Fx.Morph(this.node, {
  181. duration: "200"
  182. // transition: Fx.Transitions.Sine.easeOut
  183. });
  184. var size = this.node.getSize();
  185. this.node.setStyle("height", ""+size.y+"px");
  186. morph.start({
  187. "opacity": 0,
  188. "height": "0px"
  189. }).chain(function(){
  190. //this.message.addUnread(-1);
  191. this.node.destroy();
  192. if (callback) callback();
  193. delete this;
  194. }.bind(this));
  195. }
  196. });