[483] | 1 | define([ |
---|
| 2 | "dojo/_base/array", |
---|
| 3 | "dojo/_base/declare", |
---|
| 4 | "dojo/_base/window", |
---|
| 5 | "dojo/dom-class", |
---|
| 6 | "dojo/dom-geometry", |
---|
| 7 | "dijit/_Contained", |
---|
| 8 | "dijit/_Container", |
---|
| 9 | "dijit/_WidgetBase", |
---|
| 10 | "dojo/has" |
---|
| 11 | ], function(array, declare, win, domClass, domGeometry, Contained, Container, WidgetBase, has){ |
---|
| 12 | |
---|
| 13 | // module: |
---|
| 14 | // dojox/mobile/FixedSplitter |
---|
| 15 | |
---|
| 16 | return declare("dojox.mobile.FixedSplitter", [WidgetBase, Container, Contained], { |
---|
| 17 | // summary: |
---|
| 18 | // A layout container that splits the window horizontally or |
---|
| 19 | // vertically. |
---|
| 20 | // description: |
---|
| 21 | // FixedSplitter is a very simple container widget that layouts its |
---|
| 22 | // child DOM nodes side by side either horizontally or |
---|
| 23 | // vertically. An example usage of this widget would be to realize |
---|
| 24 | // the split view on iPad. There is no visual splitter between the |
---|
| 25 | // children, and there is no function to resize the child panes |
---|
| 26 | // with drag-and-drop. If you need a visual splitter, you can |
---|
| 27 | // specify a border of a child DOM node with CSS. |
---|
| 28 | // |
---|
| 29 | // FixedSplitter has no knowledge of its child widgets. |
---|
| 30 | // dojox/mobile/Container, dojox/mobile/Pane, or dojox/mobile/ContentPane |
---|
| 31 | // can be used as a child widget of FixedSplitter. |
---|
| 32 | // |
---|
| 33 | // - Use dojox/mobile/Container if your content consists of ONLY |
---|
| 34 | // Dojo widgets. |
---|
| 35 | // - Use dojox/mobile/Pane if your content is an inline HTML |
---|
| 36 | // fragment (may or may not include Dojo widgets). |
---|
| 37 | // - Use dojox/mobile/ContentPane if your content is an external |
---|
| 38 | // HTML fragment (may or may not include Dojo widgets). |
---|
| 39 | // |
---|
| 40 | // example: |
---|
| 41 | // | <div data-dojo-type="dojox.mobile.FixedSplitter" orientation="H"> |
---|
| 42 | // | <div data-dojo-type="dojox.mobile.Pane" |
---|
| 43 | // | style="width:200px;border-right:1px solid black;"> |
---|
| 44 | // | pane #1 (width=200px) |
---|
| 45 | // | </div> |
---|
| 46 | // | <div data-dojo-type="dojox.mobile.Pane"> |
---|
| 47 | // | pane #2 |
---|
| 48 | // | </div> |
---|
| 49 | // | </div> |
---|
| 50 | |
---|
| 51 | // orientation: String |
---|
| 52 | // The direction of split. If "H" is specified, panes are split |
---|
| 53 | // horizontally. If "V" is specified, panes are split vertically. |
---|
| 54 | orientation: "H", |
---|
| 55 | |
---|
| 56 | // variablePane: Number |
---|
| 57 | // The index of a pane that fills the remainig space. |
---|
| 58 | // If -1, the last child pane fills the remaining space. |
---|
| 59 | variablePane: -1, |
---|
| 60 | |
---|
| 61 | // screenSizeAware: Boolean |
---|
| 62 | // If true, dynamically load a screen-size-aware module. |
---|
| 63 | screenSizeAware: false, |
---|
| 64 | |
---|
| 65 | // screenSizeAwareClass: String |
---|
| 66 | // A screen-size-aware module to load. |
---|
| 67 | screenSizeAwareClass: "dojox/mobile/ScreenSizeAware", |
---|
| 68 | |
---|
| 69 | /* internal properties */ |
---|
| 70 | |
---|
| 71 | // baseClass: String |
---|
| 72 | // The name of the CSS class of this widget. |
---|
| 73 | baseClass: "mblFixedSplitter", |
---|
| 74 | |
---|
| 75 | startup: function(){ |
---|
| 76 | if(this._started){ return; } |
---|
| 77 | domClass.add(this.domNode, this.baseClass + this.orientation); |
---|
| 78 | |
---|
| 79 | var parent = this.getParent(), f; |
---|
| 80 | if(!parent || !parent.resize){ // top level widget |
---|
| 81 | var _this = this; |
---|
| 82 | f = function(){ |
---|
| 83 | _this.defer(function(){ |
---|
| 84 | _this.resize(); |
---|
| 85 | }); |
---|
| 86 | }; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if(this.screenSizeAware){ |
---|
| 90 | require([this.screenSizeAwareClass], function(module){ |
---|
| 91 | module.getInstance(); |
---|
| 92 | f && f(); |
---|
| 93 | }); |
---|
| 94 | }else{ |
---|
| 95 | f && f(); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | this.inherited(arguments); |
---|
| 99 | }, |
---|
| 100 | |
---|
| 101 | resize: function(){ |
---|
| 102 | var paddingTop = domGeometry.getPadExtents(this.domNode).t; |
---|
| 103 | var wh = this.orientation === "H" ? "w" : "h", // width/height |
---|
| 104 | tl = this.orientation === "H" ? "l" : "t", // top/left |
---|
| 105 | props1 = {}, props2 = {}, |
---|
| 106 | i, c, h, |
---|
| 107 | a = [], offset = 0, total = 0, |
---|
| 108 | children = array.filter(this.domNode.childNodes, function(node){ return node.nodeType == 1; }), |
---|
| 109 | idx = this.variablePane == -1 ? children.length - 1 : this.variablePane; |
---|
| 110 | for(i = 0; i < children.length; i++){ |
---|
| 111 | if(i != idx){ |
---|
| 112 | a[i] = domGeometry.getMarginBox(children[i])[wh]; |
---|
| 113 | total += a[i]; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | if(this.orientation == "V"){ |
---|
| 118 | if(this.domNode.parentNode.tagName == "BODY"){ |
---|
| 119 | if(array.filter(win.body().childNodes, function(node){ return node.nodeType == 1; }).length == 1){ |
---|
| 120 | h = (win.global.innerHeight||win.doc.documentElement.clientHeight); |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | var l = (h || domGeometry.getMarginBox(this.domNode)[wh]) - total; |
---|
| 125 | if(this.orientation === "V"){ |
---|
| 126 | l -= paddingTop; |
---|
| 127 | } |
---|
| 128 | props2[wh] = a[idx] = l; |
---|
| 129 | c = children[idx]; |
---|
| 130 | domGeometry.setMarginBox(c, props2); |
---|
| 131 | c.style[this.orientation === "H" ? "height" : "width"] = ""; |
---|
| 132 | // dojox.mobile mirroring support |
---|
| 133 | if(has("dojo-bidi") && (this.orientation=="H" && !this.isLeftToRight())){ |
---|
| 134 | offset = l; |
---|
| 135 | for(i = children.length - 1; i >= 0; i--){ |
---|
| 136 | c = children[i]; |
---|
| 137 | props1[tl] = l - offset; |
---|
| 138 | domGeometry.setMarginBox(c, props1); |
---|
| 139 | if(this.orientation === "H"){ |
---|
| 140 | c.style.top = paddingTop +"px"; |
---|
| 141 | }else{ |
---|
| 142 | c.style.left = ""; |
---|
| 143 | } |
---|
| 144 | offset -= a[i]; |
---|
| 145 | } |
---|
| 146 | }else{ |
---|
| 147 | if(this.orientation === "V"){ |
---|
| 148 | offset = offset ? offset + paddingTop : paddingTop; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | for(i = 0; i < children.length; i++){ |
---|
| 152 | c = children[i]; |
---|
| 153 | props1[tl] = offset; |
---|
| 154 | |
---|
| 155 | domGeometry.setMarginBox(c, props1); |
---|
| 156 | if(this.orientation === "H"){ |
---|
| 157 | c.style.top = paddingTop +"px"; |
---|
| 158 | }else{ |
---|
| 159 | c.style.left = ""; |
---|
| 160 | } |
---|
| 161 | offset += a[i]; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | array.forEach(this.getChildren(), function(child){ |
---|
| 166 | if(child.resize){ child.resize(); } |
---|
| 167 | }); |
---|
| 168 | }, |
---|
| 169 | |
---|
| 170 | _setOrientationAttr: function(/*String*/orientation){ |
---|
| 171 | // summary: |
---|
| 172 | // Sets the direction of split. |
---|
| 173 | // description: |
---|
| 174 | // The value must be either "H" or "V". |
---|
| 175 | // If "H" is specified, panes are split horizontally. |
---|
| 176 | // If "V" is specified, panes are split vertically. |
---|
| 177 | // tags: |
---|
| 178 | // private |
---|
| 179 | var s = this.baseClass; |
---|
| 180 | domClass.replace(this.domNode, s + orientation, s + this.orientation); |
---|
| 181 | this.orientation = orientation; |
---|
| 182 | if(this._started){ |
---|
| 183 | this.resize(); |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | }); |
---|
| 187 | }); |
---|