1 | define(["dojo/_base/declare", "dojo/_base/lang", "dijit/registry", "dojo/dom-attr", "dojo/dom-geometry", |
---|
2 | "dojo/dom-style", "dijit/_WidgetBase", "dijit/_Container", "dijit/_Contained", "dojo/_base/array", "dojo/query", "../utils/layout", "./_ScrollableMixin"], |
---|
3 | function(declare, lang, registry, domAttr, domGeom, domStyle, WidgetBase, Container, Contained, array, query, layoutUtils, ScrollableMixin){ |
---|
4 | return declare("dojox.app.widgets.Container", [WidgetBase, Container, Contained, ScrollableMixin], { |
---|
5 | scrollable: false, |
---|
6 | fixedFooter:"", |
---|
7 | fixedHeader:"", |
---|
8 | |
---|
9 | buildRendering: function(){ |
---|
10 | //set default _constraint="center" |
---|
11 | if(!this._constraint){ |
---|
12 | this._constraint = "center"; |
---|
13 | domAttr.set(this.srcNodeRef, "data-app-constraint", "center"); |
---|
14 | } |
---|
15 | this.inherited(arguments); |
---|
16 | |
---|
17 | //fix slide transition issue on tablet |
---|
18 | domStyle.set(this.domNode, "overflow-x", "hidden"); |
---|
19 | domStyle.set(this.domNode, "overflow-y", "auto"); |
---|
20 | |
---|
21 | // build scrollable container if scrollable=true |
---|
22 | if(this.scrollable){ |
---|
23 | this.inherited(arguments); |
---|
24 | this.domNode.style.position = "absolute"; |
---|
25 | this.domNode.style.width = "100%"; |
---|
26 | this.domNode.style.height = "100%"; |
---|
27 | } |
---|
28 | }, |
---|
29 | |
---|
30 | startup: function(){ |
---|
31 | if(this._started){ |
---|
32 | return; |
---|
33 | } |
---|
34 | // startup scrollable container if scrollable=true |
---|
35 | if(this.scrollable){ |
---|
36 | this.inherited(arguments); |
---|
37 | } |
---|
38 | this._started = true; |
---|
39 | }, |
---|
40 | |
---|
41 | resize: function(changeSize, resultSize){ |
---|
42 | // summary: |
---|
43 | // Call this to resize a widget, or after its size has changed. |
---|
44 | // description: |
---|
45 | // ####Change size mode |
---|
46 | // |
---|
47 | // When changeSize is specified, changes the marginBox of this widget |
---|
48 | // and forces it to re-layout its contents accordingly. |
---|
49 | // changeSize may specify height, width, or both. |
---|
50 | // |
---|
51 | // If resultSize is specified it indicates the size the widget will |
---|
52 | // become after changeSize has been applied. |
---|
53 | // |
---|
54 | // ####Notification mode |
---|
55 | // |
---|
56 | // When changeSize is null, indicates that the caller has already changed |
---|
57 | // the size of the widget, or perhaps it changed because the browser |
---|
58 | // window was resized. Tells widget to re-layout its contents accordingly. |
---|
59 | // |
---|
60 | // If resultSize is also specified it indicates the size the widget has |
---|
61 | // become. |
---|
62 | // |
---|
63 | // In either mode, this method also: |
---|
64 | // |
---|
65 | // 1. Sets this._borderBox and this._contentBox to the new size of |
---|
66 | // the widget. Queries the current domNode size if necessary. |
---|
67 | // 2. Calls layout() to resize contents (and maybe adjust child widgets). |
---|
68 | // |
---|
69 | // changeSize: Object? |
---|
70 | // Sets the widget to this margin-box size and position. |
---|
71 | // May include any/all of the following properties: |
---|
72 | // | {w: int, h: int, l: int, t: int} |
---|
73 | // |
---|
74 | // resultSize: Object? |
---|
75 | // The margin-box size of this widget after applying changeSize (if |
---|
76 | // changeSize is specified). If caller knows this size and |
---|
77 | // passes it in, we don't need to query the browser to get the size. |
---|
78 | // | {w: int, h: int} |
---|
79 | |
---|
80 | var node = this.domNode; |
---|
81 | |
---|
82 | if(this.scrollable){ |
---|
83 | this.inherited(arguments); |
---|
84 | this.layout(); |
---|
85 | return; |
---|
86 | } |
---|
87 | |
---|
88 | // set margin box size, unless it wasn't specified, in which case use current size |
---|
89 | if(changeSize){ |
---|
90 | domGeom.setMarginBox(node, changeSize); |
---|
91 | } |
---|
92 | |
---|
93 | // If either height or width wasn't specified by the user, then query node for it. |
---|
94 | // But note that setting the margin box and then immediately querying dimensions may return |
---|
95 | // inaccurate results, so try not to depend on it. |
---|
96 | var mb = resultSize || {}; |
---|
97 | lang.mixin(mb, changeSize || {}); // changeSize overrides resultSize |
---|
98 | if( !("h" in mb) || !("w" in mb) ){ |
---|
99 | mb = lang.mixin(domGeom.getMarginBox(node), mb); // just use domGeometry.marginBox() to fill in missing values |
---|
100 | } |
---|
101 | |
---|
102 | // Compute and save the size of my border box and content box |
---|
103 | // (w/out calling domGeometry.getContentBox() since that may fail if size was recently set) |
---|
104 | var cs = domStyle.getComputedStyle(node); |
---|
105 | var me = domGeom.getMarginExtents(node, cs); |
---|
106 | var be = domGeom.getBorderExtents(node, cs); |
---|
107 | var bb = (this._borderBox = { |
---|
108 | w: mb.w - (me.w + be.w), |
---|
109 | h: mb.h - (me.h + be.h) |
---|
110 | }); |
---|
111 | var pe = domGeom.getPadExtents(node, cs); |
---|
112 | this._contentBox = { |
---|
113 | l: domStyle.toPixelValue(node, cs.paddingLeft), |
---|
114 | t: domStyle.toPixelValue(node, cs.paddingTop), |
---|
115 | w: bb.w - pe.w, |
---|
116 | h: bb.h - pe.h |
---|
117 | }; |
---|
118 | |
---|
119 | // Callback for widget to adjust size of its children |
---|
120 | this.layout(); |
---|
121 | }, |
---|
122 | |
---|
123 | layout: function(){ |
---|
124 | // summary: |
---|
125 | // layout container |
---|
126 | |
---|
127 | var children = query("> [data-app-constraint]", this.domNode).map(function(node){ |
---|
128 | var w = registry.getEnclosingWidget(node); |
---|
129 | if(w){ |
---|
130 | w._constraint = domAttr.get(node, "data-app-constraint"); |
---|
131 | return w; |
---|
132 | } |
---|
133 | |
---|
134 | return { |
---|
135 | domNode: node, |
---|
136 | _constraint: domAttr.get(node, "data-app-constraint") |
---|
137 | }; |
---|
138 | }); |
---|
139 | |
---|
140 | if(this._contentBox){ |
---|
141 | layoutUtils.layoutChildren(this.domNode, this._contentBox, children); |
---|
142 | } |
---|
143 | array.forEach(this.getChildren(), function(child){ |
---|
144 | if(!child._started && child.startup){ |
---|
145 | child.startup(); |
---|
146 | } |
---|
147 | }); |
---|
148 | } |
---|
149 | }); |
---|
150 | }); |
---|