[483] | 1 | define([ |
---|
| 2 | "dojo/_base/array", |
---|
| 3 | "dojo/_base/connect", |
---|
| 4 | "dojo/_base/declare", |
---|
| 5 | "dojo/_base/lang", |
---|
| 6 | "dojo/_base/window", |
---|
| 7 | "dojo/dom", |
---|
| 8 | "dojo/dom-class", |
---|
| 9 | "dojo/dom-construct", |
---|
| 10 | "dojo/dom-style", |
---|
| 11 | "dojo/dom-attr", |
---|
| 12 | "dijit/registry", |
---|
| 13 | "dijit/_Contained", |
---|
| 14 | "dijit/_Container", |
---|
| 15 | "dijit/_WidgetBase", |
---|
| 16 | "./ProgressIndicator", |
---|
| 17 | "./ToolBarButton", |
---|
| 18 | "./View", |
---|
| 19 | "dojo/has", |
---|
| 20 | "dojo/has!dojo-bidi?dojox/mobile/bidi/Heading" |
---|
| 21 | ], function(array, connect, declare, lang, win, dom, domClass, domConstruct, domStyle, domAttr, registry, Contained, Container, WidgetBase, ProgressIndicator, ToolBarButton, View, has, BidiHeading){ |
---|
| 22 | |
---|
| 23 | // module: |
---|
| 24 | // dojox/mobile/Heading |
---|
| 25 | |
---|
| 26 | var dm = lang.getObject("dojox.mobile", true); |
---|
| 27 | |
---|
| 28 | var Heading = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiHeading" : "dojox.mobile.Heading", [WidgetBase, Container, Contained],{ |
---|
| 29 | // summary: |
---|
| 30 | // A widget that represents a navigation bar. |
---|
| 31 | // description: |
---|
| 32 | // Heading is a widget that represents a navigation bar, which |
---|
| 33 | // usually appears at the top of an application. It usually |
---|
| 34 | // displays the title of the current view and can contain a |
---|
| 35 | // navigational control. If you use it with |
---|
| 36 | // dojox/mobile/ScrollableView, it can also be used as a fixed |
---|
| 37 | // header bar or a fixed footer bar. In such cases, specify the |
---|
| 38 | // fixed="top" attribute to be a fixed header bar or the |
---|
| 39 | // fixed="bottom" attribute to be a fixed footer bar. Heading can |
---|
| 40 | // have one or more ToolBarButton widgets as its children. |
---|
| 41 | |
---|
| 42 | // back: String |
---|
| 43 | // A label for the navigational control to return to the previous View. |
---|
| 44 | back: "", |
---|
| 45 | |
---|
| 46 | // href: String |
---|
| 47 | // A URL to open when the navigational control is pressed. |
---|
| 48 | href: "", |
---|
| 49 | |
---|
| 50 | // moveTo: String |
---|
| 51 | // The id of the transition destination of the navigation control. |
---|
| 52 | // If the value has a hash sign ('#') before the id (e.g. #view1) |
---|
| 53 | // and the dojox/mobile/bookmarkable module is loaded by the user application, |
---|
| 54 | // the view transition updates the hash in the browser URL so that the |
---|
| 55 | // user can bookmark the destination view. In this case, the user |
---|
| 56 | // can also use the browser's back/forward button to navigate |
---|
| 57 | // through the views in the browser history. |
---|
| 58 | // |
---|
| 59 | // If null, transitions to a blank view. |
---|
| 60 | // If '#', returns immediately without transition. |
---|
| 61 | moveTo: "", |
---|
| 62 | |
---|
| 63 | // transition: String |
---|
| 64 | // A type of animated transition effect. You can choose from the |
---|
| 65 | // standard transition types, "slide", "fade", "flip", or from the |
---|
| 66 | // extended transition types, "cover", "coverv", "dissolve", |
---|
| 67 | // "reveal", "revealv", "scaleIn", "scaleOut", "slidev", |
---|
| 68 | // "swirl", "zoomIn", "zoomOut", "cube", and "swap". If "none" is |
---|
| 69 | // specified, transition occurs immediately without animation. |
---|
| 70 | transition: "slide", |
---|
| 71 | |
---|
| 72 | // label: String |
---|
| 73 | // A title text of the heading. If the label is not specified, the |
---|
| 74 | // innerHTML of the node is used as a label. |
---|
| 75 | label: "", |
---|
| 76 | |
---|
| 77 | // iconBase: String |
---|
| 78 | // The default icon path for child items. |
---|
| 79 | iconBase: "", |
---|
| 80 | |
---|
| 81 | // tag: String |
---|
| 82 | // A name of HTML tag to create as domNode. |
---|
| 83 | tag: "h1", |
---|
| 84 | |
---|
| 85 | // busy: Boolean |
---|
| 86 | // If true, a progress indicator spins on this widget. |
---|
| 87 | busy: false, |
---|
| 88 | |
---|
| 89 | // progStyle: String |
---|
| 90 | // A css class name to add to the progress indicator. |
---|
| 91 | progStyle: "mblProgWhite", |
---|
| 92 | |
---|
| 93 | /* internal properties */ |
---|
| 94 | |
---|
| 95 | // baseClass: String |
---|
| 96 | // The name of the CSS class of this widget. |
---|
| 97 | baseClass: "mblHeading", |
---|
| 98 | |
---|
| 99 | buildRendering: function(){ |
---|
| 100 | if(!this.templateString){ // true if this widget is not templated |
---|
| 101 | // Create root node if it wasn't created by _TemplatedMixin |
---|
| 102 | this.domNode = this.containerNode = this.srcNodeRef || win.doc.createElement(this.tag); |
---|
| 103 | } |
---|
| 104 | this.inherited(arguments); |
---|
| 105 | |
---|
| 106 | if(!this.templateString){ // true if this widget is not templated |
---|
| 107 | if(!this.label){ |
---|
| 108 | array.forEach(this.domNode.childNodes, function(n){ |
---|
| 109 | if(n.nodeType == 3){ |
---|
| 110 | var v = lang.trim(n.nodeValue); |
---|
| 111 | if(v){ |
---|
| 112 | this.label = v; |
---|
| 113 | this.labelNode = domConstruct.create("span", {innerHTML:v}, n, "replace"); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | }, this); |
---|
| 117 | } |
---|
| 118 | if(!this.labelNode){ |
---|
| 119 | this.labelNode = domConstruct.create("span", null, this.domNode); |
---|
| 120 | } |
---|
| 121 | this.labelNode.className = "mblHeadingSpanTitle"; |
---|
| 122 | this.labelDivNode = domConstruct.create("div", { |
---|
| 123 | className: "mblHeadingDivTitle", |
---|
| 124 | innerHTML: this.labelNode.innerHTML |
---|
| 125 | }, this.domNode); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | if(this.labelDivNode){ |
---|
| 129 | domAttr.set(this.labelDivNode, "role", "heading"); //a11y |
---|
| 130 | domAttr.set(this.labelDivNode, "aria-level", "1"); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | dom.setSelectable(this.domNode, false); |
---|
| 134 | }, |
---|
| 135 | |
---|
| 136 | startup: function(){ |
---|
| 137 | if(this._started){ return; } |
---|
| 138 | var parent = this.getParent && this.getParent(); |
---|
| 139 | if(!parent || !parent.resize){ // top level widget |
---|
| 140 | var _this = this; |
---|
| 141 | _this.defer(function(){ // necessary to render correctly |
---|
| 142 | _this.resize(); |
---|
| 143 | }); |
---|
| 144 | } |
---|
| 145 | this.inherited(arguments); |
---|
| 146 | }, |
---|
| 147 | |
---|
| 148 | resize: function(){ |
---|
| 149 | if(this.labelNode){ |
---|
| 150 | // find the rightmost left button (B), and leftmost right button (C) |
---|
| 151 | // +-----------------------------+ |
---|
| 152 | // | |A| |B| |C| |D| | |
---|
| 153 | // +-----------------------------+ |
---|
| 154 | var leftBtn, rightBtn; |
---|
| 155 | var children = this.containerNode.childNodes; |
---|
| 156 | for(var i = children.length - 1; i >= 0; i--){ |
---|
| 157 | var c = children[i]; |
---|
| 158 | if(c.nodeType === 1 && domStyle.get(c, "display") !== "none"){ |
---|
| 159 | if(!rightBtn && domStyle.get(c, "float") === "right"){ |
---|
| 160 | rightBtn = c; |
---|
| 161 | } |
---|
| 162 | if(!leftBtn && domStyle.get(c, "float") === "left"){ |
---|
| 163 | leftBtn = c; |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | if(!this.labelNodeLen && this.label){ |
---|
| 169 | this.labelNode.style.display = "inline"; |
---|
| 170 | this.labelNodeLen = this.labelNode.offsetWidth; |
---|
| 171 | this.labelNode.style.display = ""; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | var bw = this.domNode.offsetWidth; // bar width |
---|
| 175 | var rw = rightBtn ? bw - rightBtn.offsetLeft + 5 : 0; // rightBtn width |
---|
| 176 | var lw = leftBtn ? leftBtn.offsetLeft + leftBtn.offsetWidth + 5 : 0; // leftBtn width |
---|
| 177 | var tw = this.labelNodeLen || 0; // title width |
---|
| 178 | domClass[bw - Math.max(rw,lw)*2 > tw ? "add" : "remove"](this.domNode, "mblHeadingCenterTitle"); |
---|
| 179 | } |
---|
| 180 | array.forEach(this.getChildren(), function(child){ |
---|
| 181 | if(child.resize){ child.resize(); } |
---|
| 182 | }); |
---|
| 183 | }, |
---|
| 184 | |
---|
| 185 | _setBackAttr: function(/*String*/back){ |
---|
| 186 | // tags: |
---|
| 187 | // private |
---|
| 188 | this._set("back", back); |
---|
| 189 | if(!this.backButton){ |
---|
| 190 | this.backButton = new ToolBarButton({ |
---|
| 191 | arrow: "left", |
---|
| 192 | label: back, |
---|
| 193 | moveTo: this.moveTo, |
---|
| 194 | back: !this.moveTo && !this.href, // use browser history unless moveTo or href |
---|
| 195 | href: this.href, |
---|
| 196 | transition: this.transition, |
---|
| 197 | transitionDir: -1, |
---|
| 198 | dir: this.isLeftToRight() ? "ltr" : "rtl" |
---|
| 199 | }); |
---|
| 200 | this.backButton.placeAt(this.domNode, "first"); |
---|
| 201 | }else{ |
---|
| 202 | this.backButton.set("label", back); |
---|
| 203 | } |
---|
| 204 | this.resize(); |
---|
| 205 | }, |
---|
| 206 | |
---|
| 207 | _setMoveToAttr: function(/*String*/moveTo){ |
---|
| 208 | // tags: |
---|
| 209 | // private |
---|
| 210 | this._set("moveTo", moveTo); |
---|
| 211 | if(this.backButton){ |
---|
| 212 | this.backButton.set("moveTo", moveTo); |
---|
| 213 | this.backButton.set("back", !moveTo && !this.href); |
---|
| 214 | } |
---|
| 215 | }, |
---|
| 216 | |
---|
| 217 | _setHrefAttr: function(/*String*/href){ |
---|
| 218 | // tags: |
---|
| 219 | // private |
---|
| 220 | this._set("href", href); |
---|
| 221 | if(this.backButton){ |
---|
| 222 | this.backButton.set("href", href); |
---|
| 223 | this.backButton.set("back", !this.moveTo && !href); |
---|
| 224 | } |
---|
| 225 | }, |
---|
| 226 | |
---|
| 227 | _setTransitionAttr: function(/*String*/transition){ |
---|
| 228 | // tags: |
---|
| 229 | // private |
---|
| 230 | this._set("transition", transition); |
---|
| 231 | if(this.backButton){ |
---|
| 232 | this.backButton.set("transition", transition); |
---|
| 233 | } |
---|
| 234 | }, |
---|
| 235 | |
---|
| 236 | _setLabelAttr: function(/*String*/label){ |
---|
| 237 | // tags: |
---|
| 238 | // private |
---|
| 239 | this._set("label", label); |
---|
| 240 | this.labelNode.innerHTML = this.labelDivNode.innerHTML = this._cv ? this._cv(label) : label; |
---|
| 241 | }, |
---|
| 242 | |
---|
| 243 | _setBusyAttr: function(/*Boolean*/busy){ |
---|
| 244 | // tags: |
---|
| 245 | // private |
---|
| 246 | var prog = this._prog; |
---|
| 247 | if(busy){ |
---|
| 248 | if(!prog){ |
---|
| 249 | prog = this._prog = new ProgressIndicator({size:30, center:false}); |
---|
| 250 | domClass.add(prog.domNode, this.progStyle); |
---|
| 251 | } |
---|
| 252 | domConstruct.place(prog.domNode, this.domNode, "first"); |
---|
| 253 | prog.start(); |
---|
| 254 | }else if(prog){ |
---|
| 255 | prog.stop(); |
---|
| 256 | } |
---|
| 257 | this._set("busy", busy); |
---|
| 258 | } |
---|
| 259 | }); |
---|
| 260 | |
---|
| 261 | return has("dojo-bidi") ? declare("dojox.mobile.Heading", [Heading, BidiHeading]) : Heading; |
---|
| 262 | }); |
---|