source: Dev/trunk/src/client/dijit/DialogUnderlay.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 5.3 KB
Line 
1define([
2        "dojo/_base/declare", // declare
3        "dojo/_base/lang", // lang.hitch
4        "dojo/aspect", // aspect.after
5        "dojo/dom-attr", // domAttr.set
6        "dojo/dom-style", // domStyle.getComputedStyle
7        "dojo/on",
8        "dojo/window", // winUtils.getBox, winUtils.get
9        "./_Widget",
10        "./_TemplatedMixin",
11        "./BackgroundIframe",
12        "./Viewport",
13        "./main" // for back-compat, exporting dijit._underlay (remove in 2.0)
14], function(declare, lang, aspect, domAttr, domStyle, on,
15                        winUtils, _Widget, _TemplatedMixin, BackgroundIframe, Viewport, dijit){
16
17        // module:
18        //              dijit/DialogUnderlay
19
20        var DialogUnderlay = declare("dijit.DialogUnderlay", [_Widget, _TemplatedMixin], {
21                // summary:
22                //              A component used to block input behind a `dijit/Dialog`.
23                //
24                //              Normally this class should not be instantiated directly, but rather shown and hidden via
25                //              DialogUnderlay.show() and DialogUnderlay.hide().  And usually the module is not accessed directly
26                //              at all, since the underlay is shown and hidden by Dialog.DialogLevelManager.
27                //
28                //              The underlay itself can be styled based on and id:
29                //      |       #myDialog_underlay { background-color:red; }
30                //
31                //              In the case of `dijit.Dialog`, this id is based on the id of the Dialog,
32                //              suffixed with _underlay.
33
34                // Template has two divs; outer div is used for fade-in/fade-out, and also to hold background iframe.
35                // Inner div has opacity specified in CSS file.
36                templateString: "<div class='dijitDialogUnderlayWrapper'><div class='dijitDialogUnderlay' tabIndex='-1' data-dojo-attach-point='node'></div></div>",
37
38                // Parameters on creation or updatable later
39
40                // dialogId: String
41                //              Id of the dialog.... DialogUnderlay's id is based on this id
42                dialogId: "",
43
44                // class: String
45                //              This class name is used on the DialogUnderlay node, in addition to dijitDialogUnderlay
46                "class": "",
47
48                // This will get overwritten as soon as show() is call, but leave an empty array in case hide() or destroy()
49                // is called first.   The array is shared between instances but that's OK because we never write into it.
50                _modalConnects: [],
51
52                _setDialogIdAttr: function(id){
53                        domAttr.set(this.node, "id", id + "_underlay");
54                        this._set("dialogId", id);
55                },
56
57                _setClassAttr: function(clazz){
58                        this.node.className = "dijitDialogUnderlay " + clazz;
59                        this._set("class", clazz);
60                },
61
62                postCreate: function(){
63                        // Append the underlay to the body
64                        this.ownerDocumentBody.appendChild(this.domNode);
65
66                        this.own(on(this.domNode, "keydown", lang.hitch(this, "_onKeyDown")));
67
68                        this.inherited(arguments);
69                },
70
71                layout: function(){
72                        // summary:
73                        //              Sets the background to the size of the viewport
74                        //
75                        // description:
76                        //              Sets the background to the size of the viewport (rather than the size
77                        //              of the document) since we need to cover the whole browser window, even
78                        //              if the document is only a few lines long.
79                        // tags:
80                        //              private
81
82                        var is = this.node.style,
83                                os = this.domNode.style;
84
85                        // hide the background temporarily, so that the background itself isn't
86                        // causing scrollbars to appear (might happen when user shrinks browser
87                        // window and then we are called to resize)
88                        os.display = "none";
89
90                        // then resize and show
91                        var viewport = winUtils.getBox(this.ownerDocument);
92                        os.top = viewport.t + "px";
93                        os.left = viewport.l + "px";
94                        is.width = viewport.w + "px";
95                        is.height = viewport.h + "px";
96                        os.display = "block";
97                },
98
99                show: function(){
100                        // summary:
101                        //              Show the dialog underlay
102                        this.domNode.style.display = "block";
103                        this.open = true;
104                        this.layout();
105                        this.bgIframe = new BackgroundIframe(this.domNode);
106
107                        var win = winUtils.get(this.ownerDocument);
108                        this._modalConnects = [
109                                Viewport.on("resize", lang.hitch(this, "layout")),
110                                on(win, "scroll", lang.hitch(this, "layout"))
111                        ];
112
113                },
114
115                hide: function(){
116                        // summary:
117                        //              Hides the dialog underlay
118
119                        this.bgIframe.destroy();
120                        delete this.bgIframe;
121                        this.domNode.style.display = "none";
122                        while(this._modalConnects.length){ (this._modalConnects.pop()).remove(); }
123                        this.open = false;
124                },
125
126                destroy: function(){
127                        while(this._modalConnects.length){ (this._modalConnects.pop()).remove(); }
128                        this.inherited(arguments);
129                },
130
131                _onKeyDown: function(){
132                        // summary:
133                        //              Extension point so Dialog can monitor keyboard events on the underlay.
134                }
135        });
136
137        DialogUnderlay.show = function(/*Object*/ attrs, /*Number*/ zIndex){
138                // summary:
139                //              Display the underlay with the given attributes set.  If the underlay is already displayed,
140                //              then adjust it's attributes as specified.
141                // attrs:
142                //              The parameters to create DialogUnderlay with.
143                // zIndex:
144                //              zIndex of the underlay
145
146                var underlay = DialogUnderlay._singleton;
147                if(!underlay || underlay._destroyed){
148                        underlay = dijit._underlay = DialogUnderlay._singleton = new DialogUnderlay(attrs);
149                }else{
150                        if(attrs){ underlay.set(attrs); }
151                }
152                domStyle.set(underlay.domNode, 'zIndex', zIndex);
153                if(!underlay.open){
154                        underlay.show();
155                }
156        };
157
158        DialogUnderlay.hide = function(){
159                // summary:
160                //              Hide the underlay.
161
162                // Guard code in case the underlay widget has already been destroyed
163                // because we are being called during page unload (when all widgets are destroyed)
164                var underlay = DialogUnderlay._singleton;
165                if(underlay && !underlay._destroyed){
166                        underlay.hide();
167                }
168        };
169
170        return DialogUnderlay;
171});
Note: See TracBrowser for help on using the repository browser.