source: Dev/branches/rest-dojo-ui/client/dojox/mobile/Overlay.js @ 256

Last change on this file since 256 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: 3.1 KB
Line 
1define([
2        "dojo/_base/declare",
3        "dojo/_base/lang",
4        "dojo/_base/sniff",
5        "dojo/_base/window",
6        "dojo/dom-class",
7        "dojo/dom-geometry",
8        "dojo/dom-style",
9        "dojo/window",
10        "dijit/_WidgetBase",
11        "dojo/_base/array",
12        "dijit/registry"
13], function(declare, lang, has, win, domClass, domGeometry, domStyle, windowUtils, WidgetBase, array, registry){
14
15        /*=====
16                WidgetBase = dijit._WidgetBase;
17        =====*/
18        return declare("dojox.mobile.Overlay", WidgetBase, {
19                // summary:
20                //              A non-templated widget that animates up from the bottom, overlaying the current content
21                //
22
23                baseClass: "mblOverlay mblOverlayHidden",
24
25                show: function(/*DomNode?*/aroundNode){
26                        // summary:
27                        //              Scroll the overlay up into view
28                        array.forEach(registry.findWidgets(this.domNode), function(w){
29                                if(w && w.height == "auto" && typeof w.resize == "function"){
30                                        w.resize();
31                                }
32                        });
33                        var vp, popupPos;
34                        var reposition = lang.hitch(this, function(){
35                                domStyle.set(this.domNode, { position: "", top: "auto", bottom: "0px" });
36                                popupPos = domGeometry.position(this.domNode);
37                                vp = windowUtils.getBox();
38                                if((popupPos.y+popupPos.h) != vp.h // TODO: should be a has() test for position:fixed not scrolling
39                                        || has('android') < 3){ // android 2.x supports position:fixed but child transforms don't persist
40                                        popupPos.y = vp.t + vp.h - popupPos.h;
41                                        domStyle.set(this.domNode, { position: "absolute", top: popupPos.y + "px", bottom: "auto" });
42                                }
43                        });
44                        reposition();
45                        if(aroundNode){
46                                var aroundPos = domGeometry.position(aroundNode);
47                                if(popupPos.y < aroundPos.y){ // if the aroundNode is under the popup, try to scroll it up
48                                        win.global.scrollBy(0, aroundPos.y + aroundPos.h - popupPos.y);
49                                        reposition();
50                                }
51                        }
52                        domClass.replace(this.domNode, ["mblCoverv", "mblIn"], ["mblOverlayHidden", "mblRevealv", "mblOut", "mblReverse"]);
53                        var _domNode = this.domNode;
54                        setTimeout(function(){
55                                domClass.add(_domNode, "mblTransition");
56                        }, 100);
57                        var timeoutHandler = null;
58                        this._moveHandle = this.connect(win.doc.documentElement, "ontouchmove", function(){
59                                if(timeoutHandler){
60                                        clearTimeout(timeoutHandler);
61                                }
62                                timeoutHandler = setTimeout(function(){
63                                        reposition();
64                                        timeoutHandler = null;
65                                }, 0);
66                        });
67                },
68
69                hide: function(){
70                        // summary:
71                        //              Scroll the overlay down and then make it invisible
72                        if(this._moveHandle){
73                                this.disconnect(this._moveHandle);
74                                this._moveHandle = null;
75                        }
76                        if(has("webkit")){
77                                var handler = this.connect(this.domNode, "webkitTransitionEnd", function(){
78                                        this.disconnect(handler);
79                                        domClass.replace(this.domNode, ["mblOverlayHidden"], ["mblRevealv", "mblOut", "mblReverse", "mblTransition"]);
80                                });
81                                domClass.replace(this.domNode, ["mblRevealv", "mblOut", "mblReverse"], ["mblCoverv", "mblIn", "mblTransition"]);
82                                var _domNode = this.domNode;
83                                setTimeout(function(){
84                                        domClass.add(_domNode, "mblTransition");
85                                }, 100);
86                        }else{
87                                domClass.replace(this.domNode, ["mblOverlayHidden"], ["mblCoverv", "mblIn", "mblRevealv", "mblOut", "mblReverse"]);
88                        }
89                },
90
91                onBlur: function(/*Event*/e){
92                        return false; // touching outside the overlay area does not call hide()
93                }
94        });
95});
Note: See TracBrowser for help on using the repository browser.