Toaster.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:7k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2. Copyright (c) 2004-2006, The Dojo Foundation
  3. All Rights Reserved.
  4. Licensed under the Academic Free License version 2.1 or above OR the
  5. modified BSD license. For more information on Dojo licensing, see:
  6. http://dojotoolkit.org/community/licensing.shtml
  7. */
  8. dojo.provide("dojo.widget.Toaster");
  9. dojo.require("dojo.widget.*");
  10. dojo.require("dojo.lfx.*");
  11. dojo.require("dojo.html.iframe");
  12. dojo.widget.defineWidget("dojo.widget.Toaster", dojo.widget.HtmlWidget, {templateString:"<div dojoAttachPoint="clipNode"><div dojoAttachPoint="containerNode" dojoAttachEvent="onClick:onSelect"><div dojoAttachPoint="contentNode"></div></div></div>", templateCssString:".dojoToasterClip {ntposition: absolute;ntoverflow: hidden;n}nn.dojoToasterContainer {ntdisplay: block;ntposition: absolute;ntwidth: 17.5em;ntz-index: 5000;ntmargin: 0px;ntfont:0.75em Tahoma, Helvetica, Verdana, Arial;n}nn.dojoToasterContent{ntpadding:1em;ntpadding-top:0.25em;ntbackground:#73c74a;n}nn.dojoToasterMessage{ ntcolor:#fff;n}n.dojoToasterWarning{ }n.dojoToasterError,n.dojoToasterFatal{ntfont-weight:bold;ntcolor:#fff;n}nnn.dojoToasterWarning .dojoToasterContent{ntpadding:1em;ntpadding-top:0.25em;ntbackground:#d4d943;n} nn.dojoToasterError .dojoToasterContent{ntpadding:1em;ntpadding-top:0.25em;ntbackground:#c46600;n} n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Toaster.css"), messageTopic:"", messageTypes:{MESSAGE:"MESSAGE", WARNING:"WARNING", ERROR:"ERROR", FATAL:"FATAL"}, defaultType:"MESSAGE", clipCssClass:"dojoToasterClip", containerCssClass:"dojoToasterContainer", contentCssClass:"dojoToasterContent", messageCssClass:"dojoToasterMessage", warningCssClass:"dojoToasterWarning", errorCssClass:"dojoToasterError", fatalCssClass:"dojoToasterFatal", positionDirection:"br-up", positionDirectionTypes:["br-up", "br-left", "bl-up", "bl-right", "tr-down", "tr-left", "tl-down", "tl-right"], showDelay:2000, postCreate:function () {
  13. this.hide();
  14. dojo.html.setClass(this.clipNode, this.clipCssClass);
  15. dojo.html.addClass(this.containerNode, this.containerCssClass);
  16. dojo.html.setClass(this.contentNode, this.contentCssClass);
  17. if (this.messageTopic) {
  18. dojo.event.topic.subscribe(this.messageTopic, this, "_handleMessage");
  19. }
  20. if (!this.positionDirection || !dojo.lang.inArray(this.positionDirectionTypes, this.positionDirection)) {
  21. this.positionDirection = this.positionDirectionTypes.BRU;
  22. }
  23. }, _handleMessage:function (msg) {
  24. if (dojo.lang.isString(msg)) {
  25. this.setContent(msg);
  26. } else {
  27. this.setContent(msg["message"], msg["type"], msg["delay"]);
  28. }
  29. }, setContent:function (msg, messageType, delay) {
  30. var delay = delay || this.showDelay;
  31. if (this.slideAnim && this.slideAnim.status() == "playing") {
  32. dojo.lang.setTimeout(50, dojo.lang.hitch(this, function () {
  33. this.setContent(msg, messageType);
  34. }));
  35. return;
  36. } else {
  37. if (this.slideAnim) {
  38. this.slideAnim.stop();
  39. if (this.fadeAnim) {
  40. this.fadeAnim.stop();
  41. }
  42. }
  43. }
  44. if (!msg) {
  45. dojo.debug(this.widgetId + ".setContent() incoming content was null, ignoring.");
  46. return;
  47. }
  48. if (!this.positionDirection || !dojo.lang.inArray(this.positionDirectionTypes, this.positionDirection)) {
  49. dojo.raise(this.widgetId + ".positionDirection is an invalid value: " + this.positionDirection);
  50. }
  51. dojo.html.removeClass(this.containerNode, this.messageCssClass);
  52. dojo.html.removeClass(this.containerNode, this.warningCssClass);
  53. dojo.html.removeClass(this.containerNode, this.errorCssClass);
  54. dojo.html.removeClass(this.containerNode, this.fatalCssClass);
  55. dojo.html.clearOpacity(this.containerNode);
  56. if (msg instanceof String || typeof msg == "string") {
  57. this.contentNode.innerHTML = msg;
  58. } else {
  59. if (dojo.html.isNode(msg)) {
  60. this.contentNode.innerHTML = dojo.html.getContentAsString(msg);
  61. } else {
  62. dojo.raise("Toaster.setContent(): msg is of unknown type:" + msg);
  63. }
  64. }
  65. switch (messageType) {
  66.   case this.messageTypes.WARNING:
  67. dojo.html.addClass(this.containerNode, this.warningCssClass);
  68. break;
  69.   case this.messageTypes.ERROR:
  70. dojo.html.addClass(this.containerNode, this.errorCssClass);
  71. break;
  72.   case this.messageTypes.FATAL:
  73. dojo.html.addClass(this.containerNode, this.fatalCssClass);
  74. break;
  75.   case this.messageTypes.MESSAGE:
  76.   default:
  77. dojo.html.addClass(this.containerNode, this.messageCssClass);
  78. break;
  79. }
  80. this.show();
  81. var nodeSize = dojo.html.getMarginBox(this.containerNode);
  82. if (this.positionDirection.indexOf("-up") >= 0) {
  83. this.containerNode.style.left = 0 + "px";
  84. this.containerNode.style.top = nodeSize.height + 10 + "px";
  85. } else {
  86. if (this.positionDirection.indexOf("-left") >= 0) {
  87. this.containerNode.style.left = nodeSize.width + 10 + "px";
  88. this.containerNode.style.top = 0 + "px";
  89. } else {
  90. if (this.positionDirection.indexOf("-right") >= 0) {
  91. this.containerNode.style.left = 0 - nodeSize.width - 10 + "px";
  92. this.containerNode.style.top = 0 + "px";
  93. } else {
  94. if (this.positionDirection.indexOf("-down") >= 0) {
  95. this.containerNode.style.left = 0 + "px";
  96. this.containerNode.style.top = 0 - nodeSize.height - 10 + "px";
  97. } else {
  98. dojo.raise(this.widgetId + ".positionDirection is an invalid value: " + this.positionDirection);
  99. }
  100. }
  101. }
  102. }
  103. this.slideAnim = dojo.lfx.html.slideTo(this.containerNode, {top:0, left:0}, 450, null, dojo.lang.hitch(this, function (nodes, anim) {
  104. dojo.lang.setTimeout(dojo.lang.hitch(this, function (evt) {
  105. if (this.bgIframe) {
  106. this.bgIframe.hide();
  107. }
  108. this.fadeAnim = dojo.lfx.html.fadeOut(this.containerNode, 1000, null, dojo.lang.hitch(this, function (evt) {
  109. this.hide();
  110. })).play();
  111. }), delay);
  112. })).play();
  113. }, _placeClip:function () {
  114. var scroll = dojo.html.getScroll();
  115. var view = dojo.html.getViewport();
  116. var nodeSize = dojo.html.getMarginBox(this.containerNode);
  117. this.clipNode.style.height = nodeSize.height + "px";
  118. this.clipNode.style.width = nodeSize.width + "px";
  119. if (this.positionDirection.match(/^t/)) {
  120. this.clipNode.style.top = scroll.top + "px";
  121. } else {
  122. if (this.positionDirection.match(/^b/)) {
  123. this.clipNode.style.top = (view.height - nodeSize.height - 2 + scroll.top) + "px";
  124. }
  125. }
  126. if (this.positionDirection.match(/^[tb]r-/)) {
  127. this.clipNode.style.left = (view.width - nodeSize.width - 1 - scroll.left) + "px";
  128. } else {
  129. if (this.positionDirection.match(/^[tb]l-/)) {
  130. this.clipNode.style.left = 0 + "px";
  131. }
  132. }
  133. this.clipNode.style.clip = "rect(0px, " + nodeSize.width + "px, " + nodeSize.height + "px, 0px)";
  134. if (dojo.render.html.ie) {
  135. if (!this.bgIframe) {
  136. this.bgIframe = new dojo.html.BackgroundIframe(this.containerNode);
  137. this.bgIframe.setZIndex(this.containerNode);
  138. }
  139. this.bgIframe.onResized();
  140. this.bgIframe.show();
  141. }
  142. }, onSelect:function (e) {
  143. }, show:function () {
  144. dojo.widget.Toaster.superclass.show.call(this);
  145. this._placeClip();
  146. if (!this._scrollConnected) {
  147. this._scrollConnected = true;
  148. dojo.event.connect(window, "onscroll", this, "_placeClip");
  149. }
  150. }, hide:function () {
  151. dojo.widget.Toaster.superclass.hide.call(this);
  152. if (this._scrollConnected) {
  153. this._scrollConnected = false;
  154. dojo.event.disconnect(window, "onscroll", this, "_placeClip");
  155. }
  156. dojo.html.setOpacity(this.containerNode, 1);
  157. }});