1 | define(["dojo/_base/lang", "dojo/_base/declare", "dojo/sniff", "dojo/_base/window", "dojo/_base/config", |
---|
2 | "dojo/dom-attr", "dojo/topic", "dojo/dom-style", "../utils/constraints", "../Controller"], |
---|
3 | function(lang, declare, has, win, config, domAttr, topic, domStyle, constraints, Controller){ |
---|
4 | // module: |
---|
5 | // dojox/app/controllers/LayoutBase |
---|
6 | // summary: |
---|
7 | // Bind "app-initLayout", "app-layoutView" and "app-resize" events on application instance. |
---|
8 | |
---|
9 | return declare("dojox.app.controllers.LayoutBase", Controller, { |
---|
10 | |
---|
11 | constructor: function(app, events){ |
---|
12 | // summary: |
---|
13 | // bind "app-initLayout", "app-layoutView" and "app-resize" events on application instance. |
---|
14 | // |
---|
15 | // app: |
---|
16 | // dojox/app application instance. |
---|
17 | // events: |
---|
18 | // {event : handler} |
---|
19 | this.events = { |
---|
20 | "app-initLayout": this.initLayout, |
---|
21 | "app-layoutView": this.layoutView, |
---|
22 | "app-resize": this.onResize |
---|
23 | }; |
---|
24 | // if we are using dojo mobile & we are hiding address bar we need to be bit smarter and listen to |
---|
25 | // dojo mobile events instead |
---|
26 | if(config.mblHideAddressBar){ |
---|
27 | topic.subscribe("/dojox/mobile/afterResizeAll", lang.hitch(this, this.onResize)); |
---|
28 | }else{ |
---|
29 | // bind to browsers orientationchange event for ios otherwise bind to browsers resize |
---|
30 | this.bind(win.global, has("ios") ? "orientationchange" : "resize", lang.hitch(this, this.onResize)); |
---|
31 | } |
---|
32 | }, |
---|
33 | |
---|
34 | onResize: function(){ |
---|
35 | this._doResize(this.app); |
---|
36 | // this is needed to resize the children on an orientation change or a resize of the browser. |
---|
37 | // it was being done in _doResize, but was not needed for every call to _doResize. |
---|
38 | for(var hash in this.app.selectedChildren){ // need this to handle all selectedChildren |
---|
39 | if(this.app.selectedChildren[hash]){ |
---|
40 | this._doResize(this.app.selectedChildren[hash]); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | }, |
---|
45 | |
---|
46 | initLayout: function(event){ |
---|
47 | // summary: |
---|
48 | // Response to dojox/app "app-initLayout" event. |
---|
49 | // |
---|
50 | // example: |
---|
51 | // Use emit to trigger "app-initLayout" event, and this function will respond to the event. For example: |
---|
52 | // | this.app.emit("app-initLayout", view); |
---|
53 | // |
---|
54 | // event: Object |
---|
55 | // | {"view": view, "callback": function(){}}; |
---|
56 | domAttr.set(event.view.domNode, "id", event.view.id); // Set the id for the domNode |
---|
57 | if(event.callback){ // if the event has a callback, call it. |
---|
58 | event.callback(); |
---|
59 | } |
---|
60 | }, |
---|
61 | |
---|
62 | _doLayout: function(view){ |
---|
63 | // summary: |
---|
64 | // do view layout. |
---|
65 | // |
---|
66 | // view: Object |
---|
67 | // view instance needs to do layout. |
---|
68 | |
---|
69 | if(!view){ |
---|
70 | console.warn("layout empty view."); |
---|
71 | } |
---|
72 | }, |
---|
73 | |
---|
74 | _doResize: function(view){ |
---|
75 | // summary: |
---|
76 | // resize view. |
---|
77 | // |
---|
78 | // view: Object |
---|
79 | // view instance needs to do resize. |
---|
80 | this.app.log("in LayoutBase _doResize called for view.id="+view.id+" view=",view); |
---|
81 | this._doLayout(view); |
---|
82 | }, |
---|
83 | |
---|
84 | layoutView: function(event){ |
---|
85 | // summary: |
---|
86 | // Response to dojox/app "app-layoutView" event. |
---|
87 | // |
---|
88 | // example: |
---|
89 | // Use emit to trigger "app-layoutView" event, and this function will response the event. For example: |
---|
90 | // | this.app.emit("app-layoutView", view); |
---|
91 | // |
---|
92 | // event: Object |
---|
93 | // | {"parent":parent, "view":view, "removeView": boolean} |
---|
94 | var parent = event.parent || this.app; |
---|
95 | var view = event.view; |
---|
96 | |
---|
97 | if(!view){ |
---|
98 | return; |
---|
99 | } |
---|
100 | |
---|
101 | this.app.log("in LayoutBase layoutView called for event.view.id="+event.view.id); |
---|
102 | |
---|
103 | // if the parent has a child in the view constraint it has to be hidden, and this view displayed. |
---|
104 | var parentSelChild = constraints.getSelectedChild(parent, view.constraint); |
---|
105 | if(event.removeView){ // if this view is being removed set display to none and the selectedChildren entry to null |
---|
106 | view.viewShowing = false; |
---|
107 | this.hideView(view); |
---|
108 | if(view == parentSelChild){ |
---|
109 | constraints.setSelectedChild(parent, view.constraint, null); // remove from selectedChildren |
---|
110 | } |
---|
111 | }else if(view !== parentSelChild){ |
---|
112 | if(parentSelChild){ |
---|
113 | // domStyle.set(parentSelChild.domNode, "zIndex", 25); |
---|
114 | parentSelChild.viewShowing = false; |
---|
115 | if(event.transition == "none" || event.currentLastSubChildMatch !== parentSelChild){ |
---|
116 | this.hideView(parentSelChild); // only call hideView for transition none or when the transition will not hide it |
---|
117 | } |
---|
118 | } |
---|
119 | view.viewShowing = true; |
---|
120 | this.showView(view); |
---|
121 | //domStyle.set(view.domNode, "zIndex", 50); |
---|
122 | constraints.setSelectedChild(parent, view.constraint, view); |
---|
123 | }else{ // this view is already the selected child and showing |
---|
124 | view.viewShowing = true; |
---|
125 | } |
---|
126 | }, |
---|
127 | |
---|
128 | hideView: function(view){ |
---|
129 | this.app.log("logTransitions:","LayoutBase"+" setting domStyle display none for view.id=["+view.id+"], visibility=["+view.domNode.style.visibility+"]"); |
---|
130 | domStyle.set(view.domNode, "display", "none"); |
---|
131 | }, |
---|
132 | |
---|
133 | showView: function(view){ |
---|
134 | if(view.domNode){ |
---|
135 | this.app.log("logTransitions:","LayoutBase"+" setting domStyle display to display for view.id=["+view.id+"], visibility=["+view.domNode.style.visibility+"]"); |
---|
136 | domStyle.set(view.domNode, "display", ""); |
---|
137 | } |
---|
138 | } |
---|
139 | }); |
---|
140 | }); |
---|