source: Dev/branches/rest-dojo-ui/client/dojox/widget/Dialog.js @ 271

Last change on this file since 271 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 7.0 KB
Line 
1define([
2        "dojo", "dojox", "dojo/text!./Dialog/Dialog.html",
3        "dijit/Dialog", "dojo/window", "dojox/fx", "./DialogSimple"
4], function(dojo, dojox, template){
5
6        dojo.getObject('widget', true, dojox);
7       
8        dojo.declare('dojox.widget.Dialog', dojox.widget.DialogSimple,
9                {
10                // summary:
11                //              A Lightbox-like Modal-dialog for HTML Content
12                //
13                // description:
14                //              An HTML-capable Dialog widget with advanced sizing
15                //              options, animated show/hide and other useful options.
16                //
17                //              This Dialog is also very easy to apply custom styles to.
18                //
19                //              It works identically to a `dijit.Dialog` with several
20                //              additional parameters.
21
22                templateString: template,
23
24                // sizeToViewport: Boolean
25                //              If true, fix the size of the dialog to the Viewport based on
26                //              viewportPadding value rather than the calculated or natural
27                //              stlye. If false, base the size on a passed dimension attribute.
28                //              Eitherway, the viewportPadding value is used if the the content
29                //              extends beyond the viewport size for whatever reason.
30                sizeToViewport: false,
31
32                // viewportPadding: Integer
33                //              If sizeToViewport="true", this is the amount of padding in pixels to leave
34                //              between the dialog border and the viewport edge.
35                //              This value is also used when sizeToViewport="false" and dimensions exceeded
36                //              by dialog content to ensure dialog does not go outside viewport boundary
37                viewportPadding: 35,
38
39                // dimensions: Array
40                //              A two-element array of [widht,height] to animate the Dialog to if sizeToViewport="false"
41                //              Defaults to [300,300]
42                dimensions: null,
43
44                // easing: Function?|String?
45                //              An easing function to apply to the sizing animation.
46                easing: null,
47
48                // sizeDuration: Integer
49                //              Time (in ms) to use in the Animation for sizing.
50                sizeDuration: dijit._defaultDuration,
51
52                // sizeMethod: String
53                //              To be passed to dojox.fx.sizeTo, one of "chain" or "combine" to effect
54                //              the animation sequence.
55                sizeMethod: "chain",
56
57                // showTitle: Boolean
58                //              Toogle to show or hide the Title area. Can only be set at startup.
59                showTitle: false,
60
61                // draggable: Boolean
62                //              Make the pane draggable. Differs from dijit.Dialog by setting default to false
63                draggable: false, // simply over-ride the default from dijit.Dialog
64
65                // modal: Boolean
66                //              If true, this Dialog instance will be truly modal and prevent closing until
67                //              explicitly told to by calling hide() - Defaults to false to preserve previous
68                //              behaviors.
69                modal: false,
70
71                constructor: function(props, node){
72                        this.easing = props.easing || dojo._defaultEasing;
73                        this.dimensions = props.dimensions || [300, 300];
74                },
75
76                _setup: function(){
77                        // summary: Piggyback on dijit.Dialog's _setup for load-time options, deferred to
78
79                        this.inherited(arguments);
80                        if(!this._alreadyInitialized){
81                                this._navIn = dojo.fadeIn({ node: this.closeButtonNode });
82                                this._navOut = dojo.fadeOut({ node: this.closeButtonNode });
83                                if(!this.showTitle){
84                                        dojo.addClass(this.domNode,"dojoxDialogNoTitle");
85                                }
86                        }
87                },
88
89                layout: function(e){
90                        this._setSize();
91                        this.inherited(arguments);
92                },
93
94                _setSize: function(){
95                        // summary: cache and set our desired end position
96                        this._vp = dojo.window.getBox();
97                        var tc = this.containerNode,
98                                vpSized = this.sizeToViewport
99                        ;
100                        return this._displaysize = {
101                                w: vpSized ? tc.scrollWidth : this.dimensions[0],
102                                h: vpSized ? tc.scrollHeight : this.dimensions[1]
103                        }; // Object
104                },
105
106                show: function(){
107                        if(this.open){ return; }
108
109                        this._setSize();
110                        dojo.style(this.closeButtonNode,"opacity", 0);
111                        dojo.style(this.domNode, {
112                                overflow: "hidden",
113                                opacity: 0,
114                                width: "1px",
115                                height: "1px"
116                        });
117                        dojo.style(this.containerNode, {
118                                opacity: 0,
119                                overflow: "hidden"
120                        });
121
122                        this.inherited(arguments);
123
124                        if(this.modal){
125                                // prevent escape key from closing dialog
126                                // connect to body to trap this event from the Dialog a11y code, and stop escape key
127                                // from doing anything in the modal:true case:
128                                this._modalconnects.push(dojo.connect(dojo.body(), "onkeypress", function(e){
129                                        if(e.charOrCode == dojo.keys.ESCAPE){
130                                                dojo.stopEvent(e);
131                                        }
132                                }));
133                        }else{
134                                // otherwise, allow clicking on the underlay to close
135                                this._modalconnects.push(dojo.connect(dijit._underlay.domNode, "onclick", this, "onCancel"));
136                        }
137                        this._modalconnects.push(dojo.connect(this.domNode,"onmouseenter",this,"_handleNav"));
138                        this._modalconnects.push(dojo.connect(this.domNode,"onmouseleave",this,"_handleNav"));
139
140                },
141
142                _handleNav: function(e){
143                        // summary: Handle's showing or hiding the close icon
144
145                        var navou = "_navOut",
146                                navin = "_navIn",
147                                animou = (e.type == "mouseout" ? navin : navou),
148                                animin = (e.type == "mouseout" ? navou : navin)
149                        ;
150
151                        this[animou].stop();
152                        this[animin].play();
153
154                },
155
156                // an experiment in a quicksilver-like hide. too choppy for me.
157                /*
158                hide: function(){
159                        // summary: Hide the dialog
160
161                        // if we haven't been initialized yet then we aren't showing and we can just return
162                        if(!this._alreadyInitialized){
163                                return;
164                        }
165
166                        this._fadeIn && this._fadeIn.stop();
167
168                        if (this._scrollConnected){
169                                this._scrollConnected = false;
170                        }
171                        dojo.forEach(this._modalconnects, dojo.disconnect);
172                        this._modalconnects = [];
173                        if(this.refocus){
174                                this.connect(this._fadeOut,"onEnd",dojo.hitch(dijit,"focus",this._savedFocus));
175                        }
176                        if(this._relativePosition){
177                                delete this._relativePosition;
178                        }
179
180                        dojox.fx.sizeTo({
181                                node: this.domNode,
182                                duration:this.sizeDuration || this.duration,
183                                width: this._vp.w - 1,
184                                height: 5,
185                                onBegin: dojo.hitch(this,function(){
186                                        this._fadeOut.play(this.sizeDuration / 2);
187                                })
188                        }).play();
189
190                        this.open = false;
191                }, */
192
193                _position: function(){
194
195                        if(!this._started){ return; } // prevent content: from firing this anim #8914
196
197                        if(this._sizing){
198                                this._sizing.stop();
199                                this.disconnect(this._sizingConnect);
200                                delete this._sizing;
201                        }
202
203                        this.inherited(arguments);
204
205                        if(!this.open){ dojo.style(this.containerNode, "opacity", 0); }
206                        var pad = this.viewportPadding * 2;
207
208                        var props = {
209                                node: this.domNode,
210                                duration: this.sizeDuration || dijit._defaultDuration,
211                                easing: this.easing,
212                                method: this.sizeMethod
213                        };
214
215                        var ds = this._displaysize || this._setSize();
216                        props['width'] = ds.w = (ds.w + pad >= this._vp.w || this.sizeToViewport)
217                                ? this._vp.w - pad : ds.w;
218
219                        props['height'] = ds.h = (ds.h + pad >= this._vp.h || this.sizeToViewport)
220                                ? this._vp.h - pad : ds.h;
221
222                        this._sizing = dojox.fx.sizeTo(props);
223                        this._sizingConnect = this.connect(this._sizing,"onEnd","_showContent");
224                        this._sizing.play();
225
226                },
227
228                _showContent: function(e){
229                        // summary: Show the inner container after sizing animation
230
231                        var container = this.containerNode;
232                        dojo.style(this.domNode, {
233                                overflow: "visible",
234                                opacity: 1
235                        });
236                        dojo.style(this.closeButtonNode,"opacity",1);
237                        dojo.style(container, {
238                                height: this._displaysize.h - this.titleNode.offsetHeight + "px",
239                                width: this._displaysize.w + "px",
240                                overflow:"auto"
241                        });
242                        dojo.anim(container, { opacity:1 });
243                }
244
245        });
246
247        return dojox.widget.Dialog;
248
249});
250
Note: See TracBrowser for help on using the repository browser.