| 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-class", |
| 8 |
"dojo/dom-construct", |
| 9 |
"dojo/dom-style", |
| 10 |
"dojo/dom-attr", |
| 11 |
"dijit/registry", |
| 12 |
"./common", |
| 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, domClass, domConstruct, domStyle, domAttr, registry, common, Contained, Container, WidgetBase, ProgressIndicator, ToolBarButton, View, has, BidiHeading){ |
| 22 |
|
| 23 |
|
| 24 |
|
| 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 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
back: "", |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
href: "", |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
moveTo: "", |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
transition: "slide", |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
label: "", |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
iconBase: "", |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
tag: "h1", |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
busy: false, |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
progStyle: "mblProgWhite", |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
baseClass: "mblHeading", |
| 98 |
|
| 99 |
buildRendering: function(){ |
| 100 |
if(!this.templateString){ |
| 101 |
|
| 102 |
this.domNode = this.containerNode = this.srcNodeRef || win.doc.createElement(this.tag); |
| 103 |
} |
| 104 |
this.inherited(arguments); |
| 105 |
|
| 106 |
if(!this.templateString){ |
| 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"); |
| 130 |
domAttr.set(this.labelDivNode, "aria-level", "1"); |
| 131 |
} |
| 132 |
|
| 133 |
common.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){ |
| 140 |
var _this = this; |
| 141 |
_this.defer(function(){ |
| 142 |
_this.resize(); |
| 143 |
}); |
| 144 |
} |
| 145 |
this.inherited(arguments); |
| 146 |
}, |
| 147 |
|
| 148 |
resize: function(){ |
| 149 |
if(this.labelNode){ |
| 150 |
|
| 151 |
|
| 152 |
|
| 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; |
| 175 |
var rw = rightBtn ? bw - rightBtn.offsetLeft + 5 : 0; |
| 176 |
var lw = leftBtn ? leftBtn.offsetLeft + leftBtn.offsetWidth + 5 : 0; |
| 177 |
var tw = this.labelNodeLen || 0; |
| 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(back){ |
| 186 |
|
| 187 |
|
| 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, |
| 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(moveTo){ |
| 208 |
|
| 209 |
|
| 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(href){ |
| 218 |
|
| 219 |
|
| 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(transition){ |
| 228 |
|
| 229 |
|
| 230 |
this._set("transition", transition); |
| 231 |
if(this.backButton){ |
| 232 |
this.backButton.set("transition", transition); |
| 233 |
} |
| 234 |
}, |
| 235 |
|
| 236 |
_setLabelAttr: function(label){ |
| 237 |
|
| 238 |
|
| 239 |
this._set("label", label); |
| 240 |
this.labelNode.innerHTML = this.labelDivNode.innerHTML = this._cv ? this._cv(label) : label; |
| 241 |
delete this.labelNodeLen; |
| 242 |
}, |
| 243 |
|
| 244 |
_setBusyAttr: function(busy){ |
| 245 |
|
| 246 |
|
| 247 |
var prog = this._prog; |
| 248 |
if(busy){ |
| 249 |
if(!prog){ |
| 250 |
prog = this._prog = new ProgressIndicator({size:30, center:false}); |
| 251 |
domClass.add(prog.domNode, this.progStyle); |
| 252 |
} |
| 253 |
domConstruct.place(prog.domNode, this.domNode, "first"); |
| 254 |
prog.start(); |
| 255 |
}else if(prog){ |
| 256 |
prog.stop(); |
| 257 |
} |
| 258 |
this._set("busy", busy); |
| 259 |
} |
| 260 |
}); |
| 261 |
|
| 262 |
return has("dojo-bidi") ? declare("dojox.mobile.Heading", [Heading, BidiHeading]) : Heading; |
| 263 |
}); |