| 1 |
define([ |
| 2 |
"dojo/_base/connect", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/event", |
| 5 |
"dojo/_base/lang", |
| 6 |
"dojo/dom", |
| 7 |
"dojo/dom-class", |
| 8 |
"dojo/dom-construct", |
| 9 |
"dojo/dom-style", |
| 10 |
"dojo/dom-attr", |
| 11 |
"./common", |
| 12 |
"./View", |
| 13 |
"./iconUtils", |
| 14 |
"./_ItemBase", |
| 15 |
"./Badge", |
| 16 |
"./sniff", |
| 17 |
"dojo/has!dojo-bidi?dojox/mobile/bidi/TabBarButton" |
| 18 |
], function(connect, declare, event, lang, dom, domClass, domConstruct, domStyle, domAttr, common, View, iconUtils, ItemBase, Badge, has, BidiTabBarButton){ |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
var TabBarButton = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiTabBarButton" : "dojox.mobile.TabBarButton", ItemBase,{ |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
icon1: "", |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
icon2: "", |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
iconPos1: "", |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
iconPos2: "", |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
selected: false, |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
transition: "none", |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
tag: "li", |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
badge: "", |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
badgeClass: "mblDomButtonRedBadge", |
| 77 |
|
| 78 |
|
| 79 |
baseClass: "mblTabBarButton", |
| 80 |
|
| 81 |
|
| 82 |
closeIcon: "mblDomButtonWhiteCross", |
| 83 |
|
| 84 |
_selStartMethod: "touch", |
| 85 |
_selEndMethod: "touch", |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
_moveTo: "", |
| 90 |
|
| 91 |
destroy: function(){ |
| 92 |
if(this.badgeObj){ |
| 93 |
delete this.badgeObj; |
| 94 |
} |
| 95 |
this.inherited(arguments); |
| 96 |
}, |
| 97 |
|
| 98 |
inheritParams: function(){ |
| 99 |
|
| 100 |
|
| 101 |
if(this.icon && !this.icon1){ this.icon1 = this.icon; } |
| 102 |
var parent = this.getParent(); |
| 103 |
if(parent){ |
| 104 |
if(!this.transition){ this.transition = parent.transition; } |
| 105 |
if(this.icon1 && parent.iconBase && |
| 106 |
parent.iconBase.charAt(parent.iconBase.length - 1) === '/'){ |
| 107 |
this.icon1 = parent.iconBase + this.icon1; |
| 108 |
} |
| 109 |
if(!this.icon1){ this.icon1 = parent.iconBase; } |
| 110 |
if(!this.iconPos1){ this.iconPos1 = parent.iconPos; } |
| 111 |
if(this.icon2 && parent.iconBase && |
| 112 |
parent.iconBase.charAt(parent.iconBase.length - 1) === '/'){ |
| 113 |
this.icon2 = parent.iconBase + this.icon2; |
| 114 |
} |
| 115 |
if(!this.icon2){ this.icon2 = parent.iconBase || this.icon1; } |
| 116 |
if(!this.iconPos2){ this.iconPos2 = parent.iconPos || this.iconPos1; } |
| 117 |
|
| 118 |
if(parent.closable){ |
| 119 |
if(!this.icon1){ |
| 120 |
this.icon1 = this.closeIcon; |
| 121 |
} |
| 122 |
if(!this.icon2){ |
| 123 |
this.icon2 = this.closeIcon; |
| 124 |
} |
| 125 |
domClass.add(this.domNode, "mblTabBarButtonClosable"); |
| 126 |
} |
| 127 |
} |
| 128 |
}, |
| 129 |
|
| 130 |
buildRendering: function(){ |
| 131 |
this.domNode = this.srcNodeRef || domConstruct.create(this.tag); |
| 132 |
if(this.srcNodeRef){ |
| 133 |
if(!this.label){ |
| 134 |
this.label = lang.trim(this.srcNodeRef.innerHTML); |
| 135 |
} |
| 136 |
this.srcNodeRef.innerHTML = ""; |
| 137 |
} |
| 138 |
|
| 139 |
this.labelNode = this.box = domConstruct.create("div", {className:"mblTabBarButtonLabel"}, this.domNode); |
| 140 |
|
| 141 |
domAttr.set(this.domNode, "role", "tab"); |
| 142 |
domAttr.set(this.domNode, "aria-selected", "false"); |
| 143 |
this._moveTo = this._getMoveToId(); |
| 144 |
if(this._moveTo){ |
| 145 |
var tabPanelNode = dom.byId(this._moveTo); |
| 146 |
if(tabPanelNode){ |
| 147 |
domAttr.set(this.domNode, "aria-controls", this._moveTo); |
| 148 |
domAttr.set(tabPanelNode, "role", "tabpanel"); |
| 149 |
domAttr.set(tabPanelNode, "aria-labelledby", this.id); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
this.inherited(arguments); |
| 154 |
}, |
| 155 |
|
| 156 |
startup: function(){ |
| 157 |
if(this._started){ return; } |
| 158 |
|
| 159 |
this._dragstartHandle = this.connect(this.domNode, "ondragstart", event.stop); |
| 160 |
this.connect(this.domNode, "onkeydown", "_onClick"); |
| 161 |
var parent = this.getParent(); |
| 162 |
if(parent && parent.closable){ |
| 163 |
this._clickCloseHandler = this.connect(this.iconDivNode, "onclick", "_onCloseButtonClick"); |
| 164 |
this._keydownCloseHandler = this.connect(this.iconDivNode, "onkeydown", "_onCloseButtonClick"); |
| 165 |
this.iconDivNode.tabIndex = "0"; |
| 166 |
} |
| 167 |
|
| 168 |
this.inherited(arguments); |
| 169 |
if(!this._isOnLine){ |
| 170 |
this._isOnLine = true; |
| 171 |
|
| 172 |
|
| 173 |
this.set({ |
| 174 |
icon: this._pendingIcon !== undefined ? this._pendingIcon : this.icon, |
| 175 |
icon1:this.icon1, |
| 176 |
icon2:this.icon2}); |
| 177 |
|
| 178 |
delete this._pendingIcon; |
| 179 |
} |
| 180 |
common.setSelectable(this.domNode, false); |
| 181 |
}, |
| 182 |
|
| 183 |
onClose: function(e){ |
| 184 |
|
| 185 |
|
| 186 |
connect.publish("/dojox/mobile/tabClose", [this]); |
| 187 |
return this.getParent().onCloseButtonClick(this); |
| 188 |
}, |
| 189 |
|
| 190 |
_onCloseButtonClick: function(e){ |
| 191 |
if(e && e.type === "keydown" && e.keyCode !== 13){ return; } |
| 192 |
if(this.onCloseButtonClick(e) === false){ return; } |
| 193 |
if(this.onClose()){ |
| 194 |
this.destroy(); |
| 195 |
} |
| 196 |
}, |
| 197 |
|
| 198 |
onCloseButtonClick: function( ){ |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
}, |
| 205 |
|
| 206 |
_onClick: function(e){ |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
if(e && e.type === "keydown" && e.keyCode !== 13){ return; } |
| 212 |
if(this.onClick(e) === false){ return; } |
| 213 |
this.defaultClickAction(e); |
| 214 |
}, |
| 215 |
|
| 216 |
onClick: function( ){ |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
}, |
| 222 |
|
| 223 |
_setIcon: function(icon, n){ |
| 224 |
if(!this.getParent()){ return; } |
| 225 |
this._set("icon" + n, icon); |
| 226 |
if(!this.iconDivNode){ |
| 227 |
this.iconDivNode = domConstruct.create("div", {className:"mblTabBarButtonIconArea"}, this.domNode, "first"); |
| 228 |
|
| 229 |
} |
| 230 |
if(!this["iconParentNode" + n]){ |
| 231 |
this["iconParentNode" + n] = domConstruct.create("div", {className:"mblTabBarButtonIconParent mblTabBarButtonIconParent" + n}, this.iconDivNode); |
| 232 |
|
| 233 |
} |
| 234 |
this["iconNode" + n] = iconUtils.setIcon(icon, this["iconPos" + n], |
| 235 |
this["iconNode" + n], this.alt, this["iconParentNode" + n]); |
| 236 |
this["icon" + n] = icon; |
| 237 |
domClass.toggle(this.domNode, "mblTabBarButtonHasIcon", icon && icon !== "none"); |
| 238 |
}, |
| 239 |
|
| 240 |
_getMoveToId: function(){ |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
if(this.moveTo){ |
| 245 |
if(this.moveTo === "#"){ return ""; } |
| 246 |
var toId = ""; |
| 247 |
if(typeof(this.moveTo) === "object" && this.moveTo.moveTo){ |
| 248 |
toId = this.moveTo.moveTo; |
| 249 |
}else{ |
| 250 |
toId = this.moveTo; |
| 251 |
} |
| 252 |
if(toId){ |
| 253 |
toId = View.prototype.convertToId(toId); |
| 254 |
} |
| 255 |
return toId; |
| 256 |
} |
| 257 |
}, |
| 258 |
|
| 259 |
_setIcon1Attr: function(icon){ |
| 260 |
this._setIcon(icon, 1); |
| 261 |
}, |
| 262 |
|
| 263 |
_setIcon2Attr: function(icon){ |
| 264 |
this._setIcon(icon, 2); |
| 265 |
}, |
| 266 |
|
| 267 |
_getBadgeAttr: function(){ |
| 268 |
return this.badgeObj && this.badgeObj.domNode.parentNode && |
| 269 |
this.badgeObj.domNode.parentNode.nodeType == 1 ? this.badgeObj.getValue() : null; |
| 270 |
}, |
| 271 |
|
| 272 |
_setBadgeAttr: function(value){ |
| 273 |
if(!this.badgeObj){ |
| 274 |
this.badgeObj = new Badge({ |
| 275 |
fontSize: 11, |
| 276 |
className: this.badgeClass |
| 277 |
}); |
| 278 |
domStyle.set(this.badgeObj.domNode, { |
| 279 |
position: "absolute", |
| 280 |
top: "0px", |
| 281 |
right: "0px" |
| 282 |
}); |
| 283 |
} |
| 284 |
this.badgeObj.setValue(value); |
| 285 |
if(value){ |
| 286 |
this.domNode.appendChild(this.badgeObj.domNode); |
| 287 |
}else{ |
| 288 |
if(this.domNode === this.badgeObj.domNode.parentNode){ |
| 289 |
this.domNode.removeChild(this.badgeObj.domNode); |
| 290 |
} |
| 291 |
} |
| 292 |
}, |
| 293 |
|
| 294 |
_setSelectedAttr: function(selected){ |
| 295 |
|
| 296 |
|
| 297 |
this.inherited(arguments); |
| 298 |
domClass.toggle(this.domNode, "mblTabBarButtonSelected", selected); |
| 299 |
domAttr.set(this.domNode, "aria-selected", selected ? "true" : "false"); |
| 300 |
if(this._moveTo){ |
| 301 |
var tabPanelNode = dom.byId(this._moveTo); |
| 302 |
if(tabPanelNode){ |
| 303 |
domAttr.set(tabPanelNode, "aria-hidden", selected ? "false" : "true"); |
| 304 |
} |
| 305 |
} |
| 306 |
} |
| 307 |
}); |
| 308 |
|
| 309 |
return has("dojo-bidi")?declare("dojox.mobile.TabBarButton", [TabBarButton, BidiTabBarButton]):TabBarButton; |
| 310 |
}); |