root / trunk / web / dojo / dojox / widget / Toaster.js
History | View | Annotate | Download (4.85 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.widget.Toaster"]){ |
||
9 | dojo._hasResource["dojox.widget.Toaster"]=true; |
||
10 | dojo.provide("dojox.widget.Toaster");
|
||
11 | dojo.require("dojo.fx");
|
||
12 | dojo.require("dojo.window");
|
||
13 | dojo.require("dijit._Widget");
|
||
14 | dojo.require("dijit._Templated");
|
||
15 | dojo.declare("dojox.widget.Toaster",[dijit._Widget,dijit._Templated],{templateString:"<div class=\"dijitToasterClip\" dojoAttachPoint=\"clipNode\"><div class=\"dijitToasterContainer\" dojoAttachPoint=\"containerNode\" dojoAttachEvent=\"onclick:onSelect\"><div class=\"dijitToasterContent\" dojoAttachPoint=\"contentNode\"></div></div></div>",messageTopic:"",messageTypes:{MESSAGE:"message",WARNING:"warning",ERROR:"error",FATAL:"fatal"},defaultType:"message",positionDirection:"br-up",positionDirectionTypes:["br-up","br-left","bl-up","bl-right","tr-down","tr-left","tl-down","tl-right"],duration:2000,slideDuration:500,separator:"<hr></hr>",postCreate:function(){ |
||
16 | this.inherited(arguments); |
||
17 | this.hide();
|
||
18 | dojo.body().appendChild(this.domNode);
|
||
19 | if(this.messageTopic){ |
||
20 | dojo.subscribe(this.messageTopic,this,"_handleMessage"); |
||
21 | } |
||
22 | },_handleMessage:function(_1){ |
||
23 | if(dojo.isString(_1)){
|
||
24 | this.setContent(_1);
|
||
25 | }else{
|
||
26 | this.setContent(_1.message,_1.type,_1.duration);
|
||
27 | } |
||
28 | },_capitalize:function(w){ |
||
29 | return w.substring(0,1).toUpperCase()+w.substring(1); |
||
30 | },setContent:function(_2,_3,_4){ |
||
31 | _4=_4||this.duration;
|
||
32 | if(this.slideAnim){ |
||
33 | if(this.slideAnim.status()!="playing"){ |
||
34 | this.slideAnim.stop();
|
||
35 | } |
||
36 | if(this.slideAnim.status()=="playing"||(this.fadeAnim&&this.fadeAnim.status()=="playing")){ |
||
37 | setTimeout(dojo.hitch(this,function(){ |
||
38 | this.setContent(_2,_3,_4);
|
||
39 | }),50);
|
||
40 | return;
|
||
41 | } |
||
42 | } |
||
43 | for(var _5 in this.messageTypes){ |
||
44 | dojo.removeClass(this.containerNode,"dijitToaster"+this._capitalize(this.messageTypes[_5])); |
||
45 | } |
||
46 | dojo.style(this.containerNode,"opacity",1); |
||
47 | this._setContent(_2);
|
||
48 | dojo.addClass(this.containerNode,"dijitToaster"+this._capitalize(_3||this.defaultType)); |
||
49 | this.show();
|
||
50 | var _6=dojo.marginBox(this.containerNode); |
||
51 | this._cancelHideTimer();
|
||
52 | if(this.isVisible){ |
||
53 | this._placeClip();
|
||
54 | if(!this._stickyMessage){ |
||
55 | this._setHideTimer(_4);
|
||
56 | } |
||
57 | }else{
|
||
58 | var _7=this.containerNode.style; |
||
59 | var pd=this.positionDirection; |
||
60 | if(pd.indexOf("-up")>=0){ |
||
61 | _7.left=0+"px"; |
||
62 | _7.top=_6.h+10+"px"; |
||
63 | }else{
|
||
64 | if(pd.indexOf("-left")>=0){ |
||
65 | _7.left=_6.w+10+"px"; |
||
66 | _7.top=0+"px"; |
||
67 | }else{
|
||
68 | if(pd.indexOf("-right")>=0){ |
||
69 | _7.left=0-_6.w-10+"px"; |
||
70 | _7.top=0+"px"; |
||
71 | }else{
|
||
72 | if(pd.indexOf("-down")>=0){ |
||
73 | _7.left=0+"px"; |
||
74 | _7.top=0-_6.h-10+"px"; |
||
75 | }else{
|
||
76 | throw new Error(this.id+".positionDirection is invalid: "+pd); |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | this.slideAnim=dojo.fx.slideTo({node:this.containerNode,top:0,left:0,duration:this.slideDuration}); |
||
82 | this.connect(this.slideAnim,"onEnd",function(_8,_9){ |
||
83 | this.fadeAnim=dojo.fadeOut({node:this.containerNode,duration:1000}); |
||
84 | this.connect(this.fadeAnim,"onEnd",function(_a){ |
||
85 | this.isVisible=false; |
||
86 | this.hide();
|
||
87 | }); |
||
88 | this._setHideTimer(_4);
|
||
89 | this.connect(this,"onSelect",function(_b){ |
||
90 | this._cancelHideTimer();
|
||
91 | this._stickyMessage=false; |
||
92 | this.fadeAnim.play();
|
||
93 | }); |
||
94 | this.isVisible=true; |
||
95 | }); |
||
96 | this.slideAnim.play();
|
||
97 | } |
||
98 | },_setContent:function(_c){ |
||
99 | if(dojo.isFunction(_c)){
|
||
100 | _c(this);
|
||
101 | return;
|
||
102 | } |
||
103 | if(_c&&this.isVisible){ |
||
104 | _c=this.contentNode.innerHTML+this.separator+_c; |
||
105 | } |
||
106 | this.contentNode.innerHTML=_c;
|
||
107 | },_cancelHideTimer:function(){ |
||
108 | if(this._hideTimer){ |
||
109 | clearTimeout(this._hideTimer);
|
||
110 | this._hideTimer=null; |
||
111 | } |
||
112 | },_setHideTimer:function(_d){ |
||
113 | this._cancelHideTimer();
|
||
114 | if(_d>0){ |
||
115 | this._cancelHideTimer();
|
||
116 | this._hideTimer=setTimeout(dojo.hitch(this,function(_e){ |
||
117 | if(this.bgIframe&&this.bgIframe.iframe){ |
||
118 | this.bgIframe.iframe.style.display="none"; |
||
119 | } |
||
120 | this._hideTimer=null; |
||
121 | this._stickyMessage=false; |
||
122 | this.fadeAnim.play();
|
||
123 | }),_d); |
||
124 | }else{
|
||
125 | this._stickyMessage=true; |
||
126 | } |
||
127 | },_placeClip:function(){ |
||
128 | var _f=dojo.window.getBox();
|
||
129 | var _10=dojo.marginBox(this.containerNode); |
||
130 | var _11=this.clipNode.style; |
||
131 | _11.height=_10.h+"px";
|
||
132 | _11.width=_10.w+"px";
|
||
133 | var pd=this.positionDirection; |
||
134 | if(pd.match(/^t/)){ |
||
135 | _11.top=_f.t+"px";
|
||
136 | }else{
|
||
137 | if(pd.match(/^b/)){ |
||
138 | _11.top=(_f.h-_10.h-2+_f.t)+"px"; |
||
139 | } |
||
140 | } |
||
141 | if(pd.match(/^[tb]r-/)){ |
||
142 | _11.left=(_f.w-_10.w-1-_f.l)+"px"; |
||
143 | }else{
|
||
144 | if(pd.match(/^[tb]l-/)){ |
||
145 | _11.left=0+"px"; |
||
146 | } |
||
147 | } |
||
148 | _11.clip="rect(0px, "+_10.w+"px, "+_10.h+"px, 0px)"; |
||
149 | if(dojo.isIE){
|
||
150 | if(!this.bgIframe){ |
||
151 | this.clipNode.id=dijit.getUniqueId("dojox_widget_Toaster_clipNode"); |
||
152 | this.bgIframe=new dijit.BackgroundIframe(this.clipNode); |
||
153 | } |
||
154 | var _12=this.bgIframe.iframe; |
||
155 | if(_12){
|
||
156 | _12.style.display="block";
|
||
157 | } |
||
158 | } |
||
159 | },onSelect:function(e){ |
||
160 | },show:function(){ |
||
161 | dojo.style(this.domNode,"display","block"); |
||
162 | this._placeClip();
|
||
163 | if(!this._scrollConnected){ |
||
164 | this._scrollConnected=dojo.connect(window,"onscroll",this,this._placeClip); |
||
165 | } |
||
166 | },hide:function(){ |
||
167 | dojo.style(this.domNode,"display","none"); |
||
168 | if(this._scrollConnected){ |
||
169 | dojo.disconnect(this._scrollConnected);
|
||
170 | this._scrollConnected=false; |
||
171 | } |
||
172 | dojo.style(this.containerNode,"opacity",1); |
||
173 | }}); |
||
174 | } |