| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/_base/window", |
| 6 |
"dojo/dom-class", |
| 7 |
"dojo/touch", |
| 8 |
"dijit/registry", |
| 9 |
"dijit/_Contained", |
| 10 |
"dijit/_Container", |
| 11 |
"dijit/_WidgetBase", |
| 12 |
"./TransitionEvent", |
| 13 |
"./iconUtils", |
| 14 |
"./sniff", |
| 15 |
"./viewRegistry", |
| 16 |
"dojo/has!dojo-bidi?dojox/mobile/bidi/_ItemBase" |
| 17 |
], function(array, declare, lang, win, domClass, touch, registry, Contained, Container, |
| 18 |
WidgetBase, TransitionEvent, iconUtils, has, viewRegistry, BidiItemBase){ |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
var _ItemBase = declare(has("dojo-bidi") ? "dojox.mobile._NonBidiItemBase" : "dojox.mobile._ItemBase", [WidgetBase, Container, Contained], { |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
icon: "", |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
iconPos: "", |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
alt: "", |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
href: "", |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
hrefTarget: "", |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
moveTo: "", |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
scene: "", |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
clickable: false, |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
url: "", |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
urlTarget: "", |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
back: false, |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
transition: "", |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
transitionDir: 1, |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
transitionOptions: null, |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
callback: null, |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
label: "", |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
toggle: false, |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
selected: false, |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
tabIndex: "0", |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
_setTabIndexAttr: "", |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
paramsToInherit: "transition,icon", |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
_selStartMethod: "none", |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
_selEndMethod: "none", |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
_delayedSelection: false, |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
_duration: 800, |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
_handleClick: true, |
| 180 |
|
| 181 |
buildRendering: function(){ |
| 182 |
this.inherited(arguments); |
| 183 |
this._isOnLine = this.inheritParams(); |
| 184 |
}, |
| 185 |
|
| 186 |
startup: function(){ |
| 187 |
if(this._started){ return; } |
| 188 |
if(!this._isOnLine){ |
| 189 |
this.inheritParams(); |
| 190 |
} |
| 191 |
this._updateHandles(); |
| 192 |
this.inherited(arguments); |
| 193 |
}, |
| 194 |
|
| 195 |
inheritParams: function(){ |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
var parent = this.getParent(); |
| 200 |
if(parent){ |
| 201 |
array.forEach(this.paramsToInherit.split(/,/), function(p){ |
| 202 |
if(p.match(/icon/i)){ |
| 203 |
var base = p + "Base", pos = p + "Pos"; |
| 204 |
if(this[p] && parent[base] && |
| 205 |
parent[base].charAt(parent[base].length - 1) === '/'){ |
| 206 |
this[p] = parent[base] + this[p]; |
| 207 |
} |
| 208 |
if(!this[p]){ this[p] = parent[base]; } |
| 209 |
if(!this[pos]){ this[pos] = parent[pos]; } |
| 210 |
} |
| 211 |
if(!this[p]){ this[p] = parent[p]; } |
| 212 |
}, this); |
| 213 |
} |
| 214 |
return !!parent; |
| 215 |
}, |
| 216 |
|
| 217 |
_updateHandles: function(){ |
| 218 |
|
| 219 |
|
| 220 |
if(this._handleClick && this._selStartMethod === "touch"){ |
| 221 |
if(!this._onTouchStartHandle){ |
| 222 |
this._onTouchStartHandle = this.connect(this.domNode, touch.press, "_onTouchStart"); |
| 223 |
} |
| 224 |
}else{ |
| 225 |
if(this._onTouchStartHandle){ |
| 226 |
this.disconnect(this._onTouchStartHandle); |
| 227 |
this._onTouchStartHandle = null; |
| 228 |
} |
| 229 |
} |
| 230 |
}, |
| 231 |
|
| 232 |
getTransOpts: function(){ |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
var opts = this.transitionOptions || {}; |
| 237 |
array.forEach(["moveTo", "href", "hrefTarget", "url", "target", |
| 238 |
"urlTarget", "scene", "transition", "transitionDir"], function(p){ |
| 239 |
opts[p] = opts[p] || this[p]; |
| 240 |
}, this); |
| 241 |
return opts; |
| 242 |
}, |
| 243 |
|
| 244 |
userClickAction: function( ){ |
| 245 |
|
| 246 |
|
| 247 |
}, |
| 248 |
|
| 249 |
defaultClickAction: function(e){ |
| 250 |
|
| 251 |
|
| 252 |
this.handleSelection(e); |
| 253 |
if(this.userClickAction(e) === false){ return; } |
| 254 |
this.makeTransition(e); |
| 255 |
}, |
| 256 |
|
| 257 |
handleSelection: function(e){ |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
if(this._delayedSelection){ |
| 264 |
this.set("selected", true); |
| 265 |
} |
| 266 |
|
| 267 |
if(this._onTouchEndHandle){ |
| 268 |
this.disconnect(this._onTouchEndHandle); |
| 269 |
this._onTouchEndHandle = null; |
| 270 |
} |
| 271 |
|
| 272 |
var p = this.getParent(); |
| 273 |
if(this.toggle){ |
| 274 |
this.set("selected", !this._currentSel); |
| 275 |
}else if(p && p.selectOne){ |
| 276 |
this.set("selected", true); |
| 277 |
}else{ |
| 278 |
if(this._selEndMethod === "touch"){ |
| 279 |
this.set("selected", false); |
| 280 |
}else if(this._selEndMethod === "timer"){ |
| 281 |
this.defer(function(){ |
| 282 |
this.set("selected", false); |
| 283 |
}, this._duration); |
| 284 |
} |
| 285 |
} |
| 286 |
}, |
| 287 |
|
| 288 |
makeTransition: function(e){ |
| 289 |
|
| 290 |
|
| 291 |
if(this.back && history){ |
| 292 |
history.back(); |
| 293 |
return; |
| 294 |
} |
| 295 |
if (this.href && this.hrefTarget && this.hrefTarget != "_self") { |
| 296 |
win.global.open(this.href, this.hrefTarget || "_blank"); |
| 297 |
this._onNewWindowOpened(e); |
| 298 |
return; |
| 299 |
} |
| 300 |
var opts = this.getTransOpts(); |
| 301 |
var doTransition = |
| 302 |
!!(opts.moveTo || opts.href || opts.url || opts.target || opts.scene); |
| 303 |
if(this._prepareForTransition(e, doTransition ? opts : null) === false){ return; } |
| 304 |
if(doTransition){ |
| 305 |
this.setTransitionPos(e); |
| 306 |
new TransitionEvent(this.domNode, opts, e).dispatch(); |
| 307 |
} |
| 308 |
}, |
| 309 |
|
| 310 |
_onNewWindowOpened: function( ){ |
| 311 |
|
| 312 |
|
| 313 |
}, |
| 314 |
|
| 315 |
_prepareForTransition: function(e, transOpts){ |
| 316 |
|
| 317 |
|
| 318 |
}, |
| 319 |
|
| 320 |
_onTouchStart: function(e){ |
| 321 |
|
| 322 |
|
| 323 |
if(this.getParent().isEditing || this.onTouchStart(e) === false){ return; } |
| 324 |
var enclosingScrollable = viewRegistry.getEnclosingScrollable(this.domNode); |
| 325 |
if(enclosingScrollable && |
| 326 |
domClass.contains(enclosingScrollable.containerNode, "mblScrollableScrollTo2")){ |
| 327 |
|
| 328 |
return; |
| 329 |
} |
| 330 |
if(!this._onTouchEndHandle && this._selStartMethod === "touch"){ |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
this._onTouchMoveHandle = this.connect(win.body(), touch.move, "_onTouchMove"); |
| 335 |
this._onTouchEndHandle = this.connect(win.body(), touch.release, "_onTouchEnd"); |
| 336 |
} |
| 337 |
this.touchStartX = e.touches ? e.touches[0].pageX : e.clientX; |
| 338 |
this.touchStartY = e.touches ? e.touches[0].pageY : e.clientY; |
| 339 |
this._currentSel = this.selected; |
| 340 |
|
| 341 |
if(this._delayedSelection){ |
| 342 |
|
| 343 |
this._selTimer = this.defer(function(){ |
| 344 |
this.set("selected", true); |
| 345 |
}, 100); |
| 346 |
}else{ |
| 347 |
this.set("selected", true); |
| 348 |
} |
| 349 |
}, |
| 350 |
|
| 351 |
onTouchStart: function( ){ |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
}, |
| 357 |
|
| 358 |
_onTouchMove: function(e){ |
| 359 |
|
| 360 |
|
| 361 |
var x = e.touches ? e.touches[0].pageX : e.clientX; |
| 362 |
var y = e.touches ? e.touches[0].pageY : e.clientY; |
| 363 |
if(Math.abs(x - this.touchStartX) >= 4 || |
| 364 |
Math.abs(y - this.touchStartY) >= 4){ |
| 365 |
this.cancel(); |
| 366 |
var p = this.getParent(); |
| 367 |
if(p && p.selectOne){ |
| 368 |
this._prevSel && this._prevSel.set("selected", true); |
| 369 |
}else{ |
| 370 |
this.set("selected", false); |
| 371 |
} |
| 372 |
} |
| 373 |
}, |
| 374 |
|
| 375 |
_disconnect: function(){ |
| 376 |
|
| 377 |
|
| 378 |
this.disconnect(this._onTouchMoveHandle); |
| 379 |
this.disconnect(this._onTouchEndHandle); |
| 380 |
this._onTouchMoveHandle = this._onTouchEndHandle = null; |
| 381 |
}, |
| 382 |
|
| 383 |
cancel: function(){ |
| 384 |
|
| 385 |
|
| 386 |
if(this._selTimer){ |
| 387 |
this._selTimer.remove(); |
| 388 |
this._selTimer = null; |
| 389 |
} |
| 390 |
this._disconnect(); |
| 391 |
}, |
| 392 |
|
| 393 |
_onTouchEnd: function(e){ |
| 394 |
|
| 395 |
|
| 396 |
if(!this._selTimer && this._delayedSelection){ return; } |
| 397 |
this.cancel(); |
| 398 |
this._onClick(e); |
| 399 |
}, |
| 400 |
|
| 401 |
setTransitionPos: function(e){ |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
var w = this; |
| 408 |
while(true){ |
| 409 |
w = w.getParent(); |
| 410 |
if(!w || domClass.contains(w.domNode, "mblView")){ break; } |
| 411 |
} |
| 412 |
if(w){ |
| 413 |
w.clickedPosX = e.clientX; |
| 414 |
w.clickedPosY = e.clientY; |
| 415 |
} |
| 416 |
}, |
| 417 |
|
| 418 |
transitionTo: function(moveTo, href, url, scene){ |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
var opts = (moveTo && typeof(moveTo) === "object") ? moveTo : |
| 426 |
{moveTo: moveTo, href: href, url: url, scene: scene, |
| 427 |
transition: this.transition, transitionDir: this.transitionDir}; |
| 428 |
new TransitionEvent(this.domNode, opts).dispatch(); |
| 429 |
}, |
| 430 |
|
| 431 |
_setIconAttr: function(icon){ |
| 432 |
|
| 433 |
|
| 434 |
if(!this._isOnLine){ |
| 435 |
|
| 436 |
this._pendingIcon = icon; |
| 437 |
return; |
| 438 |
} |
| 439 |
this._set("icon", icon); |
| 440 |
this.iconNode = iconUtils.setIcon(icon, this.iconPos, this.iconNode, this.alt, this.iconParentNode, this.refNode, this.position); |
| 441 |
}, |
| 442 |
|
| 443 |
_setLabelAttr: function(text){ |
| 444 |
|
| 445 |
|
| 446 |
this._set("label", text); |
| 447 |
this.labelNode.innerHTML = this._cv ? this._cv(text) : text; |
| 448 |
}, |
| 449 |
|
| 450 |
_setSelectedAttr: function(selected){ |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
if(selected){ |
| 458 |
var p = this.getParent(); |
| 459 |
if(p && p.selectOne){ |
| 460 |
|
| 461 |
var arr = array.filter(p.getChildren(), function(w){ |
| 462 |
return w.selected; |
| 463 |
}); |
| 464 |
array.forEach(arr, function(c){ |
| 465 |
this._prevSel = c; |
| 466 |
c.set("selected", false); |
| 467 |
}, this); |
| 468 |
} |
| 469 |
} |
| 470 |
this._set("selected", selected); |
| 471 |
} |
| 472 |
}); |
| 473 |
return has("dojo-bidi") ? declare("dojox.mobile._ItemBase", [_ItemBase, BidiItemBase]) : _ItemBase; |
| 474 |
}); |