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