source: Dev/branches/rest-dojo-ui/client/dojox/mobile/Opener.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: 2.6 KB
Line 
1define([
2        "dojo/_base/declare",
3        "dojo/_base/lang",
4        "dojo/_base/window",
5        "dojo/dom-class",
6        "dojo/dom-construct",
7        "dojo/dom-style",
8        "dojo/dom-geometry",
9        "./Tooltip",
10        "./Overlay"
11], function(declare, lang, win, domClass, domConstruct, domStyle, domGeometry, Tooltip, Overlay){
12
13        /*=====
14                Tooltip = dojox.mobile.Tooltip;
15                Overlay = dojox.mobile.Overlay;
16        =====*/
17        var isOverlay = domClass.contains(win.doc.documentElement, "dj_phone");
18        var cls = declare("dojox.mobile.Opener", isOverlay ? Overlay : Tooltip, {
19                // summary:
20                //              A non-templated popup widget that will use either Tooltip or Overlay depending on screen size
21                //
22                buildRendering: function(){
23                        this.inherited(arguments);
24                        this.cover = domConstruct.create('div', { onclick: lang.hitch(this, '_onBlur'), 'class': 'mblOpenerUnderlay', style: { top:'0px', left:'0px', width:'0px', height:'0px', position: isOverlay ? 'absolute' : 'fixed', backgroundColor:'transparent', overflow:'hidden', zIndex:'-1' }}, this.domNode, 'first');
25                        this.connect(null, win.global.onorientationchange !== undefined ? "onorientationchange" : "onresize", lang.hitch(this, function(){
26                                if(domStyle.get(this.cover, "height") !== '0px'){ // resize cover when shown
27                                        this._resizeCover();
28                                }
29                        }));
30                },
31
32                onShow: function(/*DomNode*/node){},
33                onHide: function(/*DomNode*/node, /*Anything*/v){},
34
35                show: function(node, positions){
36                        this.node = node;
37                        this.onShow(node);
38                        this._resizeCover();
39                        return this.inherited(arguments);
40                },
41
42                hide: function(/*Anything*/ val){
43                        this.inherited(arguments);
44                        domStyle.set(this.cover, { height:'0px' });
45                        this.onHide(this.node, val);
46                },
47               
48                _resizeCover: function(){
49                        if(isOverlay){
50                                domStyle.set(this.cover, { height:'0px' }); // hide cover temporarily to calculate domNode size
51                                setTimeout(lang.hitch(this, function(){ // show cover after positioning popup
52                                        var pos = domGeometry.position(this.domNode, false);
53                                        domStyle.set(this.cover, { top:-pos.y+'px', left:-pos.x+'px', width:(pos.w+pos.x)+'px', height:(pos.h+pos.y)+'px' });
54                                }), 0);
55                        }else{
56                                domStyle.set(this.cover, {
57                                        width:Math.max(win.doc.documentElement.scrollWidth || win.body().scrollWidth || win.doc.documentElement.clientWidth)+'px',
58                                        height:Math.max(win.doc.documentElement.scrollHeight || win.body().scrollHeight || win.doc.documentElement.clientHeight)+'px'
59                                });
60                        }                       
61                },
62               
63                _onBlur: function(e){
64                        var ret = this.onBlur(e);
65                        if(ret !== false){ // only exactly false prevents hide()
66                                this.hide(e);
67                        }
68                        return ret;
69                }
70        });
71        cls.prototype.baseClass += " mblOpener"; // add to either mblOverlay or mblTooltip
72        return cls;
73});
Note: See TracBrowser for help on using the repository browser.