| 1 |
define([ |
| 2 |
"dojo/_base/kernel", |
| 3 |
"dojo/_base/connect", |
| 4 |
"dojo/_base/event", |
| 5 |
"dojo/_base/lang", |
| 6 |
"dojo/_base/window", |
| 7 |
"dojo/dom-class", |
| 8 |
"dojo/dom-construct", |
| 9 |
"dojo/dom-style", |
| 10 |
"dojo/dom-geometry", |
| 11 |
"dojo/touch", |
| 12 |
"dijit/registry", |
| 13 |
"dijit/form/_TextBoxMixin", |
| 14 |
"./sniff", |
| 15 |
"./_css3", |
| 16 |
"./_maskUtils", |
| 17 |
"./common", |
| 18 |
"dojo/_base/declare", |
| 19 |
"dojo/has!dojo-bidi?dojox/mobile/bidi/Scrollable" |
| 20 |
], function(dojo, connect, event, lang, win, domClass, domConstruct, domStyle, |
| 21 |
domGeom, touch, registry, TextBoxMixin, has, css3, maskUtils, common, declare, BidiScrollable){ |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
var dm = lang.getObject("dojox.mobile", true); |
| 30 |
|
| 31 |
|
| 32 |
has.add("translate3d", function(){ |
| 33 |
if(has("css3-animations")){ |
| 34 |
var elem = win.doc.createElement("div"); |
| 35 |
elem.style[css3.name("transform")] = "translate3d(0px,1px,0px)"; |
| 36 |
win.doc.documentElement.appendChild(elem); |
| 37 |
var v = win.doc.defaultView.getComputedStyle(elem, '')[css3.name("transform", true)]; |
| 38 |
var hasTranslate3d = v && v.indexOf("matrix") === 0; |
| 39 |
win.doc.documentElement.removeChild(elem); |
| 40 |
return hasTranslate3d; |
| 41 |
} |
| 42 |
}); |
| 43 |
|
| 44 |
var Scrollable = function(){ |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
}; |
| 67 |
|
| 68 |
lang.extend(Scrollable, { |
| 69 |
|
| 70 |
|
| 71 |
fixedHeaderHeight: 0, |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
fixedFooterHeight: 0, |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
isLocalFooter: false, |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
scrollBar: true, |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
scrollDir: "v", |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
weight: 0.6, |
| 92 |
|
| 93 |
|
| 94 |
fadeScrollBar: true, |
| 95 |
|
| 96 |
|
| 97 |
disableFlashScrollBar: false, |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
threshold: 4, |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
constraint: true, |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
touchNode: null, |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
propagatable: true, |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
dirLock: false, |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
height: "", |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
scrollType: 0, |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
_parentPadBorderExtentsBottom: 0, |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
_moved: false, |
| 138 |
|
| 139 |
init: function(params){ |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
if(params){ |
| 148 |
for(var p in params){ |
| 149 |
if(params.hasOwnProperty(p)){ |
| 150 |
this[p] = ((p == "domNode" || p == "containerNode") && typeof params[p] == "string") ? |
| 151 |
win.doc.getElementById(params[p]) : params[p]; |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
common._setTouchAction(this.domNode, "none"); |
| 157 |
this.touchNode = this.touchNode || this.containerNode; |
| 158 |
this._v = (this.scrollDir.indexOf("v") != -1); |
| 159 |
this._h = (this.scrollDir.indexOf("h") != -1); |
| 160 |
this._f = (this.scrollDir == "f"); |
| 161 |
|
| 162 |
this._ch = []; |
| 163 |
this._ch.push(connect.connect(this.touchNode, touch.press, this, "onTouchStart")); |
| 164 |
if(has("css3-animations")){ |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
this._useTopLeft = this.scrollType ? this.scrollType === 2 : false; |
| 169 |
|
| 170 |
|
| 171 |
if(!this._useTopLeft){ |
| 172 |
this._useTransformTransition = |
| 173 |
this.scrollType ? this.scrollType === 3 : has("ios") >= 6 || has("android") || has("bb"); |
| 174 |
} |
| 175 |
if(!this._useTopLeft){ |
| 176 |
if(this._useTransformTransition){ |
| 177 |
this._ch.push(connect.connect(this.containerNode, css3.name("transitionEnd"), this, "onFlickAnimationEnd")); |
| 178 |
|
| 179 |
}else{ |
| 180 |
this._ch.push(connect.connect(this.containerNode, css3.name("animationEnd"), this, "onFlickAnimationEnd")); |
| 181 |
this._ch.push(connect.connect(this.containerNode, css3.name("animationStart"), this, "onFlickAnimationStart")); |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
for(var i = 0; i < 3; i++){ |
| 187 |
this.setKeyframes(null, null, i); |
| 188 |
} |
| 189 |
} |
| 190 |
if(has("translate3d")){ |
| 191 |
domStyle.set(this.containerNode, css3.name("transform"), "translate3d(0,0,0)"); |
| 192 |
} |
| 193 |
}else{ |
| 194 |
this._ch.push(connect.connect(this.containerNode, css3.name("transitionEnd"), this, "onFlickAnimationEnd")); |
| 195 |
|
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
this._speed = {x:0, y:0}; |
| 200 |
this._appFooterHeight = 0; |
| 201 |
if(this.isTopLevel() && !this.noResize){ |
| 202 |
this.resize(); |
| 203 |
} |
| 204 |
var _this = this; |
| 205 |
setTimeout(function(){ |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
_this.flashScrollBar(); |
| 210 |
}, 600); |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
if(win.global.addEventListener){ |
| 218 |
|
| 219 |
this._onScroll = function(e){ |
| 220 |
if(!_this.domNode || _this.domNode.style.display === 'none'){ return; } |
| 221 |
var scrollTop = _this.domNode.scrollTop; |
| 222 |
var scrollLeft = _this.domNode.scrollLeft; |
| 223 |
var pos; |
| 224 |
if(scrollTop > 0 || scrollLeft > 0){ |
| 225 |
pos = _this.getPos(); |
| 226 |
|
| 227 |
_this.domNode.scrollLeft = 0; |
| 228 |
_this.domNode.scrollTop = 0; |
| 229 |
_this.scrollTo({x: pos.x - scrollLeft, y: pos.y - scrollTop}); |
| 230 |
} |
| 231 |
}; |
| 232 |
win.global.addEventListener("scroll", this._onScroll, true); |
| 233 |
} |
| 234 |
|
| 235 |
if(!this.disableTouchScroll && this.domNode.addEventListener){ |
| 236 |
this._onFocusScroll = function(e){ |
| 237 |
if(!_this.domNode || _this.domNode.style.display === 'none'){ return; } |
| 238 |
var node = win.doc.activeElement; |
| 239 |
var nodeRect, scrollableRect; |
| 240 |
if(node){ |
| 241 |
nodeRect = node.getBoundingClientRect(); |
| 242 |
scrollableRect = _this.domNode.getBoundingClientRect(); |
| 243 |
if(nodeRect.height < _this.getDim().d.h){ |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
if(nodeRect.top < (scrollableRect.top + _this.fixedHeaderHeight)){ |
| 249 |
|
| 250 |
|
| 251 |
_this.scrollIntoView(node, true); |
| 252 |
}else if((nodeRect.top + nodeRect.height) > |
| 253 |
(scrollableRect.top + scrollableRect.height - _this.fixedFooterHeight)){ |
| 254 |
|
| 255 |
|
| 256 |
_this.scrollIntoView(node, false); |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
}; |
| 261 |
this.domNode.addEventListener("focus", this._onFocusScroll, true); |
| 262 |
} |
| 263 |
}, |
| 264 |
|
| 265 |
isTopLevel: function(){ |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
return true; |
| 271 |
}, |
| 272 |
|
| 273 |
cleanup: function(){ |
| 274 |
|
| 275 |
|
| 276 |
if(this._ch){ |
| 277 |
for(var i = 0; i < this._ch.length; i++){ |
| 278 |
connect.disconnect(this._ch[i]); |
| 279 |
} |
| 280 |
this._ch = null; |
| 281 |
} |
| 282 |
if(this._onScroll && win.global.removeEventListener){ |
| 283 |
win.global.removeEventListener("scroll", this._onScroll, true); |
| 284 |
this._onScroll = null; |
| 285 |
} |
| 286 |
|
| 287 |
if(this._onFocusScroll && this.domNode.removeEventListener){ |
| 288 |
this.domNode.removeEventListener("focus", this._onFocusScroll, true); |
| 289 |
this._onFocusScroll = null; |
| 290 |
} |
| 291 |
}, |
| 292 |
|
| 293 |
findDisp: function(node){ |
| 294 |
|
| 295 |
|
| 296 |
if(!node.parentNode){ return null; } |
| 297 |
|
| 298 |
|
| 299 |
if(node.nodeType === 1 && domClass.contains(node, "mblSwapView") && node.style.display !== "none"){ |
| 300 |
return node; |
| 301 |
} |
| 302 |
|
| 303 |
var nodes = node.parentNode.childNodes; |
| 304 |
for(var i = 0; i < nodes.length; i++){ |
| 305 |
var n = nodes[i]; |
| 306 |
if(n.nodeType === 1 && domClass.contains(n, "mblView") && n.style.display !== "none"){ |
| 307 |
return n; |
| 308 |
} |
| 309 |
} |
| 310 |
return node; |
| 311 |
}, |
| 312 |
|
| 313 |
getScreenSize: function(){ |
| 314 |
|
| 315 |
|
| 316 |
return { |
| 317 |
h: win.global.innerHeight||win.doc.documentElement.clientHeight||win.doc.documentElement.offsetHeight, |
| 318 |
w: win.global.innerWidth||win.doc.documentElement.clientWidth||win.doc.documentElement.offsetWidth |
| 319 |
}; |
| 320 |
}, |
| 321 |
|
| 322 |
resize: function(e){ |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
this._appFooterHeight = (this._fixedAppFooter) ? this._fixedAppFooter.offsetHeight : 0; |
| 336 |
if(this.isLocalHeader){ |
| 337 |
this.containerNode.style.marginTop = this.fixedHeaderHeight + "px"; |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
var top = 0; |
| 342 |
for(var n = this.domNode; n && n.tagName != "BODY"; n = n.offsetParent){ |
| 343 |
n = this.findDisp(n); |
| 344 |
if(!n){ break; } |
| 345 |
top += n.offsetTop + domGeom.getBorderExtents(n).h; |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
var h, |
| 350 |
screenHeight = this.getScreenSize().h, |
| 351 |
dh = screenHeight - top - this._appFooterHeight; |
| 352 |
if(this.height === "inherit"){ |
| 353 |
if(this.domNode.offsetParent){ |
| 354 |
h = domGeom.getContentBox(this.domNode.offsetParent).h - domGeom.getBorderExtents(this.domNode).h + "px"; |
| 355 |
} |
| 356 |
}else if(this.height === "auto"){ |
| 357 |
var parent = this.domNode.offsetParent; |
| 358 |
if(parent){ |
| 359 |
this.domNode.style.height = "0px"; |
| 360 |
var parentRect = parent.getBoundingClientRect(), |
| 361 |
scrollableRect = this.domNode.getBoundingClientRect(), |
| 362 |
contentBottom = parentRect.bottom - this._appFooterHeight - this._parentPadBorderExtentsBottom; |
| 363 |
if(scrollableRect.bottom >= contentBottom){ |
| 364 |
dh = screenHeight - (scrollableRect.top - parentRect.top) - this._appFooterHeight - this._parentPadBorderExtentsBottom; |
| 365 |
}else{ |
| 366 |
dh = contentBottom - scrollableRect.bottom; |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
var contentHeight = Math.max(this.domNode.scrollHeight, this.containerNode.scrollHeight); |
| 371 |
h = (contentHeight ? Math.min(contentHeight, dh) : dh) + "px"; |
| 372 |
}else if(this.height){ |
| 373 |
h = this.height; |
| 374 |
} |
| 375 |
if(!h){ |
| 376 |
h = dh + "px"; |
| 377 |
} |
| 378 |
if(h.charAt(0) !== "-" && |
| 379 |
h !== "default"){ |
| 380 |
this.domNode.style.height = h; |
| 381 |
} |
| 382 |
|
| 383 |
if(!this._conn){ |
| 384 |
|
| 385 |
this.onTouchEnd(); |
| 386 |
} |
| 387 |
}, |
| 388 |
|
| 389 |
onFlickAnimationStart: function(e){ |
| 390 |
if(e){ |
| 391 |
event.stop(e); |
| 392 |
} |
| 393 |
}, |
| 394 |
|
| 395 |
onFlickAnimationEnd: function(e){ |
| 396 |
if(has("ios")){ |
| 397 |
this._keepInputCaretInActiveElement(); |
| 398 |
} |
| 399 |
if(e){ |
| 400 |
var an = e.animationName; |
| 401 |
if(an && an.indexOf("scrollableViewScroll2") === -1){ |
| 402 |
if(an.indexOf("scrollableViewScroll0") !== -1){ |
| 403 |
if(this._scrollBarNodeV){ domClass.remove(this._scrollBarNodeV, "mblScrollableScrollTo0"); } |
| 404 |
}else if(an.indexOf("scrollableViewScroll1") !== -1){ |
| 405 |
if(this._scrollBarNodeH){ domClass.remove(this._scrollBarNodeH, "mblScrollableScrollTo1"); } |
| 406 |
}else{ |
| 407 |
if(this._scrollBarNodeV){ this._scrollBarNodeV.className = ""; } |
| 408 |
if(this._scrollBarNodeH){ this._scrollBarNodeH.className = ""; } |
| 409 |
} |
| 410 |
return; |
| 411 |
} |
| 412 |
if(this._useTransformTransition || this._useTopLeft){ |
| 413 |
var n = e.target; |
| 414 |
if(n === this._scrollBarV || n === this._scrollBarH){ |
| 415 |
var cls = "mblScrollableScrollTo" + (n === this._scrollBarV ? "0" : "1"); |
| 416 |
if(domClass.contains(n, cls)){ |
| 417 |
domClass.remove(n, cls); |
| 418 |
}else{ |
| 419 |
n.className = ""; |
| 420 |
} |
| 421 |
return; |
| 422 |
} |
| 423 |
} |
| 424 |
if(e.srcElement){ |
| 425 |
event.stop(e); |
| 426 |
} |
| 427 |
} |
| 428 |
this.stopAnimation(); |
| 429 |
if(this._bounce){ |
| 430 |
var _this = this; |
| 431 |
var bounce = _this._bounce; |
| 432 |
setTimeout(function(){ |
| 433 |
_this.slideTo(bounce, 0.3, "ease-out"); |
| 434 |
}, 0); |
| 435 |
_this._bounce = undefined; |
| 436 |
}else{ |
| 437 |
this.hideScrollBar(); |
| 438 |
this.removeCover(); |
| 439 |
} |
| 440 |
}, |
| 441 |
|
| 442 |
isFormElement: function(node){ |
| 443 |
|
| 444 |
|
| 445 |
if(node && node.nodeType !== 1){ node = node.parentNode; } |
| 446 |
if(!node || node.nodeType !== 1){ return false; } |
| 447 |
var t = node.tagName; |
| 448 |
return (t === "SELECT" || t === "INPUT" || t === "TEXTAREA" || t === "BUTTON"); |
| 449 |
}, |
| 450 |
|
| 451 |
onTouchStart: function(e){ |
| 452 |
|
| 453 |
|
| 454 |
if(this.disableTouchScroll){ return; } |
| 455 |
if(this._conn && (new Date()).getTime() - this.startTime < 500){ |
| 456 |
return; |
| 457 |
} |
| 458 |
if(!this._conn){ |
| 459 |
this._conn = []; |
| 460 |
this._conn.push(connect.connect(win.doc, touch.move, this, "onTouchMove")); |
| 461 |
this._conn.push(connect.connect(win.doc, touch.release, this, "onTouchEnd")); |
| 462 |
} |
| 463 |
|
| 464 |
this._aborted = false; |
| 465 |
if(domClass.contains(this.containerNode, "mblScrollableScrollTo2")){ |
| 466 |
this.abort(); |
| 467 |
}else{ |
| 468 |
if(this._scrollBarNodeV){ this._scrollBarNodeV.className = ""; } |
| 469 |
if(this._scrollBarNodeH){ this._scrollBarNodeH.className = ""; } |
| 470 |
} |
| 471 |
this.touchStartX = e.touches ? e.touches[0].pageX : e.clientX; |
| 472 |
this.touchStartY = e.touches ? e.touches[0].pageY : e.clientY; |
| 473 |
this.startTime = (new Date()).getTime(); |
| 474 |
this.startPos = this.getPos(); |
| 475 |
this._dim = this.getDim(); |
| 476 |
this._time = [0]; |
| 477 |
this._posX = [this.touchStartX]; |
| 478 |
this._posY = [this.touchStartY]; |
| 479 |
this._locked = false; |
| 480 |
this._moved = false; |
| 481 |
|
| 482 |
this._preventDefaultInNextTouchMove = true; |
| 483 |
if(!this.isFormElement(e.target)){ |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
this.propagatable ? e.preventDefault() : event.stop(e); |
| 489 |
this._preventDefaultInNextTouchMove = false; |
| 490 |
} |
| 491 |
}, |
| 492 |
|
| 493 |
onTouchMove: function(e){ |
| 494 |
|
| 495 |
|
| 496 |
if(this._locked){ return; } |
| 497 |
|
| 498 |
if(this._preventDefaultInNextTouchMove){ |
| 499 |
this._preventDefaultInNextTouchMove = false; |
| 500 |
var enclosingWidget = registry.getEnclosingWidget( |
| 501 |
|
| 502 |
|
| 503 |
((e.targetTouches && e.targetTouches.length === 1) ? e.targetTouches[0] : e).target); |
| 504 |
if(enclosingWidget && enclosingWidget.isInstanceOf(TextBoxMixin)){ |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
this.propagatable ? e.preventDefault() : event.stop(e); |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
var x = e.touches ? e.touches[0].pageX : e.clientX; |
| 514 |
var y = e.touches ? e.touches[0].pageY : e.clientY; |
| 515 |
var dx = x - this.touchStartX; |
| 516 |
var dy = y - this.touchStartY; |
| 517 |
var to = {x:this.startPos.x + dx, y:this.startPos.y + dy}; |
| 518 |
var dim = this._dim; |
| 519 |
|
| 520 |
dx = Math.abs(dx); |
| 521 |
dy = Math.abs(dy); |
| 522 |
if(this._time.length == 1){ |
| 523 |
if(this.dirLock){ |
| 524 |
if(this._v && !this._h && dx >= this.threshold && dx >= dy || |
| 525 |
(this._h || this._f) && !this._v && dy >= this.threshold && dy >= dx){ |
| 526 |
this._locked = true; |
| 527 |
return; |
| 528 |
} |
| 529 |
} |
| 530 |
if(this._v && this._h){ |
| 531 |
if(dy < this.threshold && |
| 532 |
dx < this.threshold){ |
| 533 |
return; |
| 534 |
} |
| 535 |
}else{ |
| 536 |
if(this._v && dy < this.threshold || |
| 537 |
(this._h || this._f) && dx < this.threshold){ |
| 538 |
return; |
| 539 |
} |
| 540 |
} |
| 541 |
this._moved = true; |
| 542 |
this.addCover(); |
| 543 |
this.showScrollBar(); |
| 544 |
} |
| 545 |
|
| 546 |
var weight = this.weight; |
| 547 |
if(this._v && this.constraint){ |
| 548 |
if(to.y > 0){ |
| 549 |
to.y = Math.round(to.y * weight); |
| 550 |
}else if(to.y < -dim.o.h){ |
| 551 |
if(dim.c.h < dim.d.h){ |
| 552 |
to.y = Math.round(to.y * weight); |
| 553 |
}else{ |
| 554 |
to.y = -dim.o.h - Math.round((-dim.o.h - to.y) * weight); |
| 555 |
} |
| 556 |
} |
| 557 |
} |
| 558 |
if((this._h || this._f) && this.constraint){ |
| 559 |
if(to.x > 0){ |
| 560 |
to.x = Math.round(to.x * weight); |
| 561 |
}else if(to.x < -dim.o.w){ |
| 562 |
if(dim.c.w < dim.d.w){ |
| 563 |
to.x = Math.round(to.x * weight); |
| 564 |
}else{ |
| 565 |
to.x = -dim.o.w - Math.round((-dim.o.w - to.x) * weight); |
| 566 |
} |
| 567 |
} |
| 568 |
} |
| 569 |
this.scrollTo(to); |
| 570 |
|
| 571 |
var max = 10; |
| 572 |
var n = this._time.length; |
| 573 |
if(n >= 2){ |
| 574 |
this._moved = true; |
| 575 |
|
| 576 |
|
| 577 |
var d0, d1; |
| 578 |
if(this._v && !this._h){ |
| 579 |
d0 = this._posY[n - 1] - this._posY[n - 2]; |
| 580 |
d1 = y - this._posY[n - 1]; |
| 581 |
}else if(!this._v && this._h){ |
| 582 |
d0 = this._posX[n - 1] - this._posX[n - 2]; |
| 583 |
d1 = x - this._posX[n - 1]; |
| 584 |
} |
| 585 |
if(d0 * d1 < 0){ |
| 586 |
|
| 587 |
this._time = [this._time[n - 1]]; |
| 588 |
this._posX = [this._posX[n - 1]]; |
| 589 |
this._posY = [this._posY[n - 1]]; |
| 590 |
n = 1; |
| 591 |
} |
| 592 |
} |
| 593 |
if(n == max){ |
| 594 |
this._time.shift(); |
| 595 |
this._posX.shift(); |
| 596 |
this._posY.shift(); |
| 597 |
} |
| 598 |
this._time.push((new Date()).getTime() - this.startTime); |
| 599 |
this._posX.push(x); |
| 600 |
this._posY.push(y); |
| 601 |
}, |
| 602 |
|
| 603 |
_keepInputCaretInActiveElement: function(){ |
| 604 |
var activeElement = win.doc.activeElement; |
| 605 |
var initialValue; |
| 606 |
if(activeElement && (activeElement.tagName == "INPUT" || activeElement.tagName == "TEXTAREA")){ |
| 607 |
initialValue = activeElement.value; |
| 608 |
if(activeElement.type == "number" || activeElement.type == "week"){ |
| 609 |
if(initialValue){ |
| 610 |
activeElement.value = activeElement.value + 1; |
| 611 |
}else{ |
| 612 |
activeElement.value = (activeElement.type == "week") ? "2013-W10" : 1; |
| 613 |
} |
| 614 |
activeElement.value = initialValue; |
| 615 |
}else{ |
| 616 |
activeElement.value = activeElement.value + " "; |
| 617 |
activeElement.value = initialValue; |
| 618 |
} |
| 619 |
} |
| 620 |
}, |
| 621 |
|
| 622 |
onTouchEnd: function(e){ |
| 623 |
|
| 624 |
|
| 625 |
if(this._locked){ return; } |
| 626 |
var speed = this._speed = {x:0, y:0}; |
| 627 |
var dim = this._dim; |
| 628 |
var pos = this.getPos(); |
| 629 |
var to = {}; |
| 630 |
if(e){ |
| 631 |
if(!this._conn){ return; } |
| 632 |
for(var i = 0; i < this._conn.length; i++){ |
| 633 |
connect.disconnect(this._conn[i]); |
| 634 |
} |
| 635 |
this._conn = null; |
| 636 |
|
| 637 |
var clicked = false; |
| 638 |
if(!this._aborted && !this._moved){ |
| 639 |
clicked = true; |
| 640 |
} |
| 641 |
if(clicked){ |
| 642 |
this.hideScrollBar(); |
| 643 |
this.removeCover(); |
| 644 |
|
| 645 |
if(has("touch") && has("clicks-prevented") && !this.isFormElement(e.target)){ |
| 646 |
var elem = e.target; |
| 647 |
if(elem.nodeType != 1){ |
| 648 |
elem = elem.parentNode; |
| 649 |
} |
| 650 |
setTimeout(function(){ |
| 651 |
dm._sendClick(elem, e); |
| 652 |
}); |
| 653 |
} |
| 654 |
return; |
| 655 |
} |
| 656 |
speed = this._speed = this.getSpeed(); |
| 657 |
}else{ |
| 658 |
if(pos.x == 0 && pos.y == 0){ return; } |
| 659 |
dim = this.getDim(); |
| 660 |
} |
| 661 |
|
| 662 |
if(this._v){ |
| 663 |
to.y = pos.y + speed.y; |
| 664 |
} |
| 665 |
if(this._h || this._f){ |
| 666 |
to.x = pos.x + speed.x; |
| 667 |
} |
| 668 |
|
| 669 |
if(this.adjustDestination(to, pos, dim) === false){ return; } |
| 670 |
if(this.constraint){ |
| 671 |
if(this.scrollDir == "v" && dim.c.h < dim.d.h){ |
| 672 |
this.slideTo({y:0}, 0.3, "ease-out"); |
| 673 |
return; |
| 674 |
}else if(this.scrollDir == "h" && dim.c.w < dim.d.w){ |
| 675 |
this.slideTo({x:0}, 0.3, "ease-out"); |
| 676 |
return; |
| 677 |
}else if(this._v && this._h && dim.c.h < dim.d.h && dim.c.w < dim.d.w){ |
| 678 |
this.slideTo({x:0, y:0}, 0.3, "ease-out"); |
| 679 |
return; |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
var duration, easing = "ease-out"; |
| 684 |
var bounce = {}; |
| 685 |
if(this._v && this.constraint){ |
| 686 |
if(to.y > 0){ |
| 687 |
if(pos.y > 0){ |
| 688 |
duration = 0.3; |
| 689 |
to.y = 0; |
| 690 |
}else{ |
| 691 |
to.y = Math.min(to.y, 20); |
| 692 |
easing = "linear"; |
| 693 |
bounce.y = 0; |
| 694 |
} |
| 695 |
}else if(-speed.y > dim.o.h - (-pos.y)){ |
| 696 |
if(pos.y < -dim.o.h){ |
| 697 |
duration = 0.3; |
| 698 |
to.y = dim.c.h <= dim.d.h ? 0 : -dim.o.h; |
| 699 |
}else{ |
| 700 |
to.y = Math.max(to.y, -dim.o.h - 20); |
| 701 |
easing = "linear"; |
| 702 |
bounce.y = -dim.o.h; |
| 703 |
} |
| 704 |
} |
| 705 |
} |
| 706 |
if((this._h || this._f) && this.constraint){ |
| 707 |
if(to.x > 0){ |
| 708 |
if(pos.x > 0){ |
| 709 |
duration = 0.3; |
| 710 |
to.x = 0; |
| 711 |
}else{ |
| 712 |
to.x = Math.min(to.x, 20); |
| 713 |
easing = "linear"; |
| 714 |
bounce.x = 0; |
| 715 |
} |
| 716 |
}else if(-speed.x > dim.o.w - (-pos.x)){ |
| 717 |
if(pos.x < -dim.o.w){ |
| 718 |
duration = 0.3; |
| 719 |
to.x = dim.c.w <= dim.d.w ? 0 : -dim.o.w; |
| 720 |
}else{ |
| 721 |
to.x = Math.max(to.x, -dim.o.w - 20); |
| 722 |
easing = "linear"; |
| 723 |
bounce.x = -dim.o.w; |
| 724 |
} |
| 725 |
} |
| 726 |
} |
| 727 |
this._bounce = (bounce.x !== undefined || bounce.y !== undefined) ? bounce : undefined; |
| 728 |
|
| 729 |
if(duration === undefined){ |
| 730 |
var distance, velocity; |
| 731 |
if(this._v && this._h){ |
| 732 |
velocity = Math.sqrt(speed.x*speed.x + speed.y*speed.y); |
| 733 |
distance = Math.sqrt(Math.pow(to.y - pos.y, 2) + Math.pow(to.x - pos.x, 2)); |
| 734 |
}else if(this._v){ |
| 735 |
velocity = speed.y; |
| 736 |
distance = to.y - pos.y; |
| 737 |
}else if(this._h){ |
| 738 |
velocity = speed.x; |
| 739 |
distance = to.x - pos.x; |
| 740 |
} |
| 741 |
if(distance === 0 && !e){ return; } |
| 742 |
duration = velocity !== 0 ? Math.abs(distance / velocity) : 0.01; |
| 743 |
} |
| 744 |
this.slideTo(to, duration, easing); |
| 745 |
}, |
| 746 |
|
| 747 |
adjustDestination: function(to, pos, dim){ |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
return true; |
| 764 |
}, |
| 765 |
|
| 766 |
abort: function(){ |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
this._aborted = true; |
| 774 |
this.scrollTo(this.getPos()); |
| 775 |
this.stopAnimation(); |
| 776 |
}, |
| 777 |
|
| 778 |
stopAnimation: function(){ |
| 779 |
|
| 780 |
|
| 781 |
domClass.remove(this.containerNode, "mblScrollableScrollTo2"); |
| 782 |
this.containerNode.className = this.containerNode.className |
| 783 |
.replace(/mblScrollableScrollTo2-[^ ]+/, ""); |
| 784 |
|
| 785 |
|
| 786 |
if(this._scrollBarV){ |
| 787 |
this._scrollBarV.className = ""; |
| 788 |
} |
| 789 |
if(this._scrollBarH){ |
| 790 |
this._scrollBarH.className = ""; |
| 791 |
} |
| 792 |
if(this._useTransformTransition || this._useTopLeft){ |
| 793 |
this.containerNode.style[css3.name("transition")] = ""; |
| 794 |
if(this._scrollBarV) { this._scrollBarV.style[css3.name("transition")] = ""; } |
| 795 |
if(this._scrollBarH) { this._scrollBarH.style[css3.name("transition")] = ""; } |
| 796 |
} |
| 797 |
}, |
| 798 |
|
| 799 |
scrollIntoView: function(node, alignWithTop, duration){ |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
if(!this._v){ return; } |
| 816 |
|
| 817 |
var c = this.containerNode, |
| 818 |
h = this.getDim().d.h, |
| 819 |
top = 0; |
| 820 |
|
| 821 |
|
| 822 |
for(var n = node; n !== c; n = n.offsetParent){ |
| 823 |
if(!n || n.tagName === "BODY"){ return; } |
| 824 |
top += n.offsetTop; |
| 825 |
} |
| 826 |
|
| 827 |
var y = alignWithTop ? Math.max(h - c.offsetHeight, -top) : Math.min(0, h - top - node.offsetHeight); |
| 828 |
|
| 829 |
|
| 830 |
(duration && typeof duration === "number") ? |
| 831 |
this.slideTo({y: y}, duration, "ease-out") : this.scrollTo({y: y}); |
| 832 |
}, |
| 833 |
|
| 834 |
getSpeed: function(){ |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
var x = 0, y = 0, n = this._time.length; |
| 841 |
|
| 842 |
if(n >= 2 && (new Date()).getTime() - this.startTime - this._time[n - 1] < 500){ |
| 843 |
var dy = this._posY[n - (n > 3 ? 2 : 1)] - this._posY[(n - 6) >= 0 ? n - 6 : 0]; |
| 844 |
var dx = this._posX[n - (n > 3 ? 2 : 1)] - this._posX[(n - 6) >= 0 ? n - 6 : 0]; |
| 845 |
var dt = this._time[n - (n > 3 ? 2 : 1)] - this._time[(n - 6) >= 0 ? n - 6 : 0]; |
| 846 |
y = this.calcSpeed(dy, dt); |
| 847 |
x = this.calcSpeed(dx, dt); |
| 848 |
} |
| 849 |
return {x:x, y:y}; |
| 850 |
}, |
| 851 |
|
| 852 |
calcSpeed: function(distance, time){ |
| 853 |
|
| 854 |
|
| 855 |
return Math.round(distance / time * 100) * 4; |
| 856 |
}, |
| 857 |
|
| 858 |
scrollTo: function(to, doNotMoveScrollBar, node){ |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
var scrollEvent, beforeTopHeight, afterBottomHeight; |
| 873 |
var doScroll = true; |
| 874 |
if(!this._aborted && this._conn){ |
| 875 |
if(!this._dim){ |
| 876 |
this._dim = this.getDim(); |
| 877 |
} |
| 878 |
beforeTopHeight = (to.y > 0)?to.y:0; |
| 879 |
afterBottomHeight = (this._dim.o.h + to.y < 0)?-1 * (this._dim.o.h + to.y):0; |
| 880 |
scrollEvent = {bubbles: false, |
| 881 |
cancelable: false, |
| 882 |
x: to.x, |
| 883 |
y: to.y, |
| 884 |
beforeTop: beforeTopHeight > 0, |
| 885 |
beforeTopHeight: beforeTopHeight, |
| 886 |
afterBottom: afterBottomHeight > 0, |
| 887 |
afterBottomHeight: afterBottomHeight}; |
| 888 |
|
| 889 |
doScroll = this.onBeforeScroll(scrollEvent); |
| 890 |
} |
| 891 |
|
| 892 |
if(doScroll){ |
| 893 |
var s = (node || this.containerNode).style; |
| 894 |
if(has("css3-animations")){ |
| 895 |
if(!this._useTopLeft){ |
| 896 |
if(this._useTransformTransition){ |
| 897 |
s[css3.name("transition")] = ""; |
| 898 |
} |
| 899 |
s[css3.name("transform")] = this.makeTranslateStr(to); |
| 900 |
}else{ |
| 901 |
s[css3.name("transition")] = ""; |
| 902 |
if(this._v){ |
| 903 |
s.top = to.y + "px"; |
| 904 |
} |
| 905 |
if(this._h || this._f){ |
| 906 |
s.left = to.x + "px"; |
| 907 |
} |
| 908 |
} |
| 909 |
}else{ |
| 910 |
if(this._v){ |
| 911 |
s.top = to.y + "px"; |
| 912 |
} |
| 913 |
if(this._h || this._f){ |
| 914 |
s.left = to.x + "px"; |
| 915 |
} |
| 916 |
} |
| 917 |
if(has("ios")){ |
| 918 |
this._keepInputCaretInActiveElement(); |
| 919 |
} |
| 920 |
if(!doNotMoveScrollBar){ |
| 921 |
this.scrollScrollBarTo(this.calcScrollBarPos(to)); |
| 922 |
} |
| 923 |
if(scrollEvent){ |
| 924 |
|
| 925 |
this.onAfterScroll(scrollEvent); |
| 926 |
} |
| 927 |
} |
| 928 |
}, |
| 929 |
|
| 930 |
onBeforeScroll: function(e){ |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
return true; |
| 945 |
}, |
| 946 |
|
| 947 |
onAfterScroll: function(e){ |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
}, |
| 961 |
|
| 962 |
slideTo: function(to, duration, easing){ |
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
this._runSlideAnimation(this.getPos(), to, duration, easing, this.containerNode, 2); |
| 975 |
this.slideScrollBarTo(to, duration, easing); |
| 976 |
}, |
| 977 |
|
| 978 |
makeTranslateStr: function(to){ |
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
var y = this._v && typeof to.y == "number" ? to.y+"px" : "0px"; |
| 987 |
var x = (this._h||this._f) && typeof to.x == "number" ? to.x+"px" : "0px"; |
| 988 |
return has("translate3d") ? |
| 989 |
"translate3d("+x+","+y+",0px)" : "translate("+x+","+y+")"; |
| 990 |
}, |
| 991 |
|
| 992 |
getPos: function(){ |
| 993 |
|
| 994 |
|
| 995 |
if(has("css3-animations")){ |
| 996 |
var s = win.doc.defaultView.getComputedStyle(this.containerNode, ''); |
| 997 |
if(!this._useTopLeft){ |
| 998 |
var m = s[css3.name("transform")]; |
| 999 |
if(m && m.indexOf("matrix") === 0){ |
| 1000 |
var arr = m.split(/[,\s\)]+/); |
| 1001 |
|
| 1002 |
var i = m.indexOf("matrix3d") === 0 ? 12 : 4; |
| 1003 |
return {y:arr[i+1] - 0, x:arr[i] - 0}; |
| 1004 |
} |
| 1005 |
return {x:0, y:0}; |
| 1006 |
}else{ |
| 1007 |
return {x:parseInt(s.left) || 0, y:parseInt(s.top) || 0}; |
| 1008 |
} |
| 1009 |
}else{ |
| 1010 |
|
| 1011 |
|
| 1012 |
var y = parseInt(this.containerNode.style.top) || 0; |
| 1013 |
return {y:y, x:this.containerNode.offsetLeft}; |
| 1014 |
} |
| 1015 |
}, |
| 1016 |
|
| 1017 |
getDim: function(){ |
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
var d = {}; |
| 1022 |
|
| 1023 |
d.c = {h:this.containerNode.offsetHeight, w:this.containerNode.offsetWidth}; |
| 1024 |
|
| 1025 |
|
| 1026 |
d.v = {h:this.domNode.offsetHeight + this._appFooterHeight, w:this.domNode.offsetWidth}; |
| 1027 |
|
| 1028 |
|
| 1029 |
d.d = {h:d.v.h - this.fixedHeaderHeight - this.fixedFooterHeight - this._appFooterHeight, w:d.v.w}; |
| 1030 |
|
| 1031 |
|
| 1032 |
d.o = {h:d.c.h - d.v.h + this.fixedHeaderHeight + this.fixedFooterHeight + this._appFooterHeight, w:d.c.w - d.v.w}; |
| 1033 |
return d; |
| 1034 |
}, |
| 1035 |
|
| 1036 |
showScrollBar: function(){ |
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
if(!this.scrollBar){ return; } |
| 1045 |
|
| 1046 |
var dim = this._dim; |
| 1047 |
if(this.scrollDir == "v" && dim.c.h <= dim.d.h){ return; } |
| 1048 |
if(this.scrollDir == "h" && dim.c.w <= dim.d.w){ return; } |
| 1049 |
if(this._v && this._h && dim.c.h <= dim.d.h && dim.c.w <= dim.d.w){ return; } |
| 1050 |
|
| 1051 |
var createBar = function(self, dir){ |
| 1052 |
var bar = self["_scrollBarNode" + dir]; |
| 1053 |
if(!bar){ |
| 1054 |
var wrapper = domConstruct.create("div", null, self.domNode); |
| 1055 |
var props = { position: "absolute", overflow: "hidden" }; |
| 1056 |
if(dir == "V"){ |
| 1057 |
props.right = "2px"; |
| 1058 |
props.width = "5px"; |
| 1059 |
}else{ |
| 1060 |
props.bottom = (self.isLocalFooter ? self.fixedFooterHeight : 0) + 2 + "px"; |
| 1061 |
props.height = "5px"; |
| 1062 |
} |
| 1063 |
domStyle.set(wrapper, props); |
| 1064 |
wrapper.className = "mblScrollBarWrapper"; |
| 1065 |
self["_scrollBarWrapper"+dir] = wrapper; |
| 1066 |
|
| 1067 |
bar = domConstruct.create("div", null, wrapper); |
| 1068 |
domStyle.set(bar, css3.add({ |
| 1069 |
opacity: 0.6, |
| 1070 |
position: "absolute", |
| 1071 |
backgroundColor: "#606060", |
| 1072 |
fontSize: "1px", |
| 1073 |
MozBorderRadius: "2px", |
| 1074 |
zIndex: 2147483647 |
| 1075 |
}, { |
| 1076 |
borderRadius: "2px", |
| 1077 |
transformOrigin: "0 0" |
| 1078 |
})); |
| 1079 |
domStyle.set(bar, dir == "V" ? {width: "5px"} : {height: "5px"}); |
| 1080 |
self["_scrollBarNode" + dir] = bar; |
| 1081 |
} |
| 1082 |
return bar; |
| 1083 |
}; |
| 1084 |
if(this._v && !this._scrollBarV){ |
| 1085 |
this._scrollBarV = createBar(this, "V"); |
| 1086 |
} |
| 1087 |
if(this._h && !this._scrollBarH){ |
| 1088 |
this._scrollBarH = createBar(this, "H"); |
| 1089 |
} |
| 1090 |
this.resetScrollBar(); |
| 1091 |
}, |
| 1092 |
|
| 1093 |
hideScrollBar: function(){ |
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
if(this.fadeScrollBar && has("css3-animations")){ |
| 1101 |
if(!dm._fadeRule){ |
| 1102 |
var node = domConstruct.create("style", null, win.doc.getElementsByTagName("head")[0]); |
| 1103 |
node.textContent = |
| 1104 |
".mblScrollableFadeScrollBar{"+ |
| 1105 |
" " + css3.name("animation-duration", true) + ": 1s;"+ |
| 1106 |
" " + css3.name("animation-name", true) + ": scrollableViewFadeScrollBar;}"+ |
| 1107 |
"@" + css3.name("keyframes", true) + " scrollableViewFadeScrollBar{"+ |
| 1108 |
" from { opacity: 0.6; }"+ |
| 1109 |
" to { opacity: 0; }}"; |
| 1110 |
dm._fadeRule = node.sheet.cssRules[1]; |
| 1111 |
} |
| 1112 |
} |
| 1113 |
if(!this.scrollBar){ return; } |
| 1114 |
var f = function(bar, self){ |
| 1115 |
domStyle.set(bar, css3.add({ |
| 1116 |
opacity: 0 |
| 1117 |
}, { |
| 1118 |
animationDuration: "" |
| 1119 |
})); |
| 1120 |
|
| 1121 |
|
| 1122 |
if(!(self._useTopLeft && has('android'))){ |
| 1123 |
bar.className = "mblScrollableFadeScrollBar"; |
| 1124 |
} |
| 1125 |
}; |
| 1126 |
if(this._scrollBarV){ |
| 1127 |
f(this._scrollBarV, this); |
| 1128 |
this._scrollBarV = null; |
| 1129 |
} |
| 1130 |
if(this._scrollBarH){ |
| 1131 |
f(this._scrollBarH, this); |
| 1132 |
this._scrollBarH = null; |
| 1133 |
} |
| 1134 |
}, |
| 1135 |
|
| 1136 |
calcScrollBarPos: function(to){ |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
var pos = {}; |
| 1147 |
var dim = this._dim; |
| 1148 |
var f = function(wrapperH, barH, t, d, c){ |
| 1149 |
var y = Math.round((d - barH - 8) / (d - c) * t); |
| 1150 |
if(y < -barH + 5){ |
| 1151 |
y = -barH + 5; |
| 1152 |
} |
| 1153 |
if(y > wrapperH - 5){ |
| 1154 |
y = wrapperH - 5; |
| 1155 |
} |
| 1156 |
return y; |
| 1157 |
}; |
| 1158 |
if(typeof to.y == "number" && this._scrollBarV){ |
| 1159 |
pos.y = f(this._scrollBarWrapperV.offsetHeight, this._scrollBarV.offsetHeight, to.y, dim.d.h, dim.c.h); |
| 1160 |
} |
| 1161 |
if(typeof to.x == "number" && this._scrollBarH){ |
| 1162 |
pos.x = f(this._scrollBarWrapperH.offsetWidth, this._scrollBarH.offsetWidth, to.x, dim.d.w, dim.c.w); |
| 1163 |
} |
| 1164 |
return pos; |
| 1165 |
}, |
| 1166 |
|
| 1167 |
scrollScrollBarTo: function(to){ |
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
if(!this.scrollBar){ return; } |
| 1175 |
if(this._v && this._scrollBarV && typeof to.y == "number"){ |
| 1176 |
if(has("css3-animations")){ |
| 1177 |
if(!this._useTopLeft){ |
| 1178 |
if(this._useTransformTransition){ |
| 1179 |
this._scrollBarV.style[css3.name("transition")] = ""; |
| 1180 |
} |
| 1181 |
this._scrollBarV.style[css3.name("transform")] = this.makeTranslateStr({y:to.y}); |
| 1182 |
}else{ |
| 1183 |
domStyle.set(this._scrollBarV, css3.add({ |
| 1184 |
top: to.y + "px" |
| 1185 |
}, { |
| 1186 |
transition: "" |
| 1187 |
})); |
| 1188 |
} |
| 1189 |
}else{ |
| 1190 |
this._scrollBarV.style.top = to.y + "px"; |
| 1191 |
} |
| 1192 |
} |
| 1193 |
if(this._h && this._scrollBarH && typeof to.x == "number"){ |
| 1194 |
if(has("css3-animations")){ |
| 1195 |
if(!this._useTopLeft){ |
| 1196 |
if(this._useTransformTransition){ |
| 1197 |
this._scrollBarH.style[css3.name("transition")] = ""; |
| 1198 |
} |
| 1199 |
this._scrollBarH.style[css3.name("transform")] = this.makeTranslateStr({x:to.x}); |
| 1200 |
}else{ |
| 1201 |
domStyle.set(this._scrollBarH, css3.add({ |
| 1202 |
left: to.x + "px" |
| 1203 |
}, { |
| 1204 |
transition: "" |
| 1205 |
})); |
| 1206 |
} |
| 1207 |
}else{ |
| 1208 |
this._scrollBarH.style.left = to.x + "px"; |
| 1209 |
} |
| 1210 |
} |
| 1211 |
}, |
| 1212 |
|
| 1213 |
slideScrollBarTo: function(to, duration, easing){ |
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
if(!this.scrollBar){ return; } |
| 1226 |
var fromPos = this.calcScrollBarPos(this.getPos()); |
| 1227 |
var toPos = this.calcScrollBarPos(to); |
| 1228 |
if(this._v && this._scrollBarV){ |
| 1229 |
this._runSlideAnimation({y:fromPos.y}, {y:toPos.y}, duration, easing, this._scrollBarV, 0); |
| 1230 |
} |
| 1231 |
if(this._h && this._scrollBarH){ |
| 1232 |
this._runSlideAnimation({x:fromPos.x}, {x:toPos.x}, duration, easing, this._scrollBarH, 1); |
| 1233 |
} |
| 1234 |
}, |
| 1235 |
|
| 1236 |
_runSlideAnimation: function(from, to, duration, easing, node, idx){ |
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
if(has("css3-animations")){ |
| 1242 |
if(!this._useTopLeft){ |
| 1243 |
if(this._useTransformTransition){ |
| 1244 |
|
| 1245 |
if(to.x === undefined){ to.x = from.x; } |
| 1246 |
if(to.y === undefined){ to.y = from.y; } |
| 1247 |
|
| 1248 |
if(to.x !== from.x || to.y !== from.y){ |
| 1249 |
this.onFlickAnimationStart(); |
| 1250 |
domStyle.set(node, css3.add({}, { |
| 1251 |
transitionProperty: css3.name("transform"), |
| 1252 |
transitionDuration: duration + "s", |
| 1253 |
transitionTimingFunction: easing |
| 1254 |
})); |
| 1255 |
var t = this.makeTranslateStr(to); |
| 1256 |
setTimeout(function(){ |
| 1257 |
domStyle.set(node, css3.add({}, { |
| 1258 |
transform: t |
| 1259 |
})); |
| 1260 |
}, 0); |
| 1261 |
domClass.add(node, "mblScrollableScrollTo"+idx); |
| 1262 |
} else { |
| 1263 |
|
| 1264 |
this.hideScrollBar(); |
| 1265 |
this.removeCover(); |
| 1266 |
} |
| 1267 |
}else{ |
| 1268 |
|
| 1269 |
var entering = this.findDisp(this.domNode) === this.domNode; |
| 1270 |
var className = this.setKeyframes(from, to, idx, entering); |
| 1271 |
domStyle.set(node, css3.add({}, { |
| 1272 |
animationDuration: duration + "s", |
| 1273 |
animationTimingFunction: easing |
| 1274 |
})); |
| 1275 |
domClass.add(node, className); |
| 1276 |
domClass.add(node, "mblScrollableScrollTo"+idx); |
| 1277 |
if(idx == 2){ |
| 1278 |
this.scrollTo(to, true, node); |
| 1279 |
}else{ |
| 1280 |
this.scrollScrollBarTo(to); |
| 1281 |
} |
| 1282 |
} |
| 1283 |
}else if(to.x !== undefined || to.y !== undefined){ |
| 1284 |
this.onFlickAnimationStart(); |
| 1285 |
domStyle.set(node, css3.add({}, { |
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
transitionProperty: (to.x !== undefined && to.y !== undefined) ? |
| 1290 |
"top, left" : |
| 1291 |
to.y !== undefined ? "top" : "left", |
| 1292 |
transitionDuration: duration + "s", |
| 1293 |
transitionTimingFunction: easing |
| 1294 |
})); |
| 1295 |
setTimeout(function(){ |
| 1296 |
var style = {}; |
| 1297 |
if(to.x !== undefined){ |
| 1298 |
style.left = to.x + "px"; |
| 1299 |
} |
| 1300 |
if(to.y !== undefined){ |
| 1301 |
style.top = to.y + "px"; |
| 1302 |
} |
| 1303 |
domStyle.set(node, style); |
| 1304 |
}, 0); |
| 1305 |
domClass.add(node, "mblScrollableScrollTo"+idx); |
| 1306 |
} |
| 1307 |
}else if(dojo.fx && dojo.fx.easing && duration){ |
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
var self = this; |
| 1318 |
var s = dojo.fx.slideTo({ |
| 1319 |
node: node, |
| 1320 |
duration: duration*1000, |
| 1321 |
left: to.x, |
| 1322 |
top: to.y, |
| 1323 |
easing: (easing == "ease-out") ? dojo.fx.easing.quadOut : dojo.fx.easing.linear, |
| 1324 |
onBegin: function(){ |
| 1325 |
if(idx == 2){ |
| 1326 |
self.onFlickAnimationStart(); |
| 1327 |
} |
| 1328 |
}, |
| 1329 |
onEnd: function(){ |
| 1330 |
if(idx == 2){ |
| 1331 |
self.onFlickAnimationEnd(); |
| 1332 |
} |
| 1333 |
} |
| 1334 |
}).play(); |
| 1335 |
}else{ |
| 1336 |
|
| 1337 |
if(idx == 2){ |
| 1338 |
this.onFlickAnimationStart(); |
| 1339 |
this.scrollTo(to, false, node); |
| 1340 |
this.onFlickAnimationEnd(); |
| 1341 |
}else{ |
| 1342 |
this.scrollScrollBarTo(to); |
| 1343 |
} |
| 1344 |
} |
| 1345 |
}, |
| 1346 |
|
| 1347 |
resetScrollBar: function(){ |
| 1348 |
|
| 1349 |
|
| 1350 |
var f = function(wrapper, bar, d, c, hd, v){ |
| 1351 |
if(!bar){ return; } |
| 1352 |
var props = {}; |
| 1353 |
props[v ? "top" : "left"] = hd + 4 + "px"; |
| 1354 |
var t = (d - 8) <= 0 ? 1 : d - 8; |
| 1355 |
props[v ? "height" : "width"] = t + "px"; |
| 1356 |
domStyle.set(wrapper, props); |
| 1357 |
var l = Math.round(d * d / c); |
| 1358 |
l = Math.min(Math.max(l - 8, 5), t); |
| 1359 |
bar.style[v ? "height" : "width"] = l + "px"; |
| 1360 |
domStyle.set(bar, {"opacity": 0.6}); |
| 1361 |
}; |
| 1362 |
var dim = this.getDim(); |
| 1363 |
f(this._scrollBarWrapperV, this._scrollBarV, dim.d.h, dim.c.h, this.fixedHeaderHeight, true); |
| 1364 |
f(this._scrollBarWrapperH, this._scrollBarH, dim.d.w, dim.c.w, 0); |
| 1365 |
this.createMask(); |
| 1366 |
}, |
| 1367 |
|
| 1368 |
createMask: function(){ |
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
if(!(has("mask-image"))){ return; } |
| 1376 |
if(this._scrollBarWrapperV){ |
| 1377 |
var h = this._scrollBarWrapperV.offsetHeight; |
| 1378 |
maskUtils.createRoundMask(this._scrollBarWrapperV, 0, 0, 0, 0, 5, h, 2, 2, 0.5); |
| 1379 |
} |
| 1380 |
if(this._scrollBarWrapperH){ |
| 1381 |
var w = this._scrollBarWrapperH.offsetWidth; |
| 1382 |
maskUtils.createRoundMask(this._scrollBarWrapperH, 0, 0, 0, 0, w, 5, 2, 2, 0.5); |
| 1383 |
} |
| 1384 |
}, |
| 1385 |
|
| 1386 |
flashScrollBar: function(){ |
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
if(this.disableFlashScrollBar || !this.domNode){ return; } |
| 1394 |
this._dim = this.getDim(); |
| 1395 |
if(this._dim.d.h <= 0){ return; } |
| 1396 |
this.showScrollBar(); |
| 1397 |
var _this = this; |
| 1398 |
setTimeout(function(){ |
| 1399 |
_this.hideScrollBar(); |
| 1400 |
}, 300); |
| 1401 |
}, |
| 1402 |
|
| 1403 |
addCover: function(){ |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
if(!has("touch") && !(has("pointer-events") || has("MSPointer")) && !this.noCover){ |
| 1414 |
if(!dm._cover){ |
| 1415 |
dm._cover = domConstruct.create("div", null, win.doc.body); |
| 1416 |
dm._cover.className = "mblScrollableCover"; |
| 1417 |
domStyle.set(dm._cover, { |
| 1418 |
backgroundColor: "#ffff00", |
| 1419 |
opacity: 0, |
| 1420 |
position: "absolute", |
| 1421 |
top: "0px", |
| 1422 |
left: "0px", |
| 1423 |
width: "100%", |
| 1424 |
height: "100%", |
| 1425 |
zIndex: 2147483647 |
| 1426 |
}); |
| 1427 |
this._ch.push(connect.connect(dm._cover, touch.press, this, "onTouchEnd")); |
| 1428 |
}else{ |
| 1429 |
dm._cover.style.display = ""; |
| 1430 |
} |
| 1431 |
this.setSelectable(dm._cover, false); |
| 1432 |
this.setSelectable(this.domNode, false); |
| 1433 |
} |
| 1434 |
}, |
| 1435 |
|
| 1436 |
removeCover: function(){ |
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
if(!has("touch") && dm._cover){ |
| 1441 |
dm._cover.style.display = "none"; |
| 1442 |
this.setSelectable(dm._cover, true); |
| 1443 |
this.setSelectable(this.domNode, true); |
| 1444 |
} |
| 1445 |
}, |
| 1446 |
|
| 1447 |
setKeyframes: function(from, to, idx, entering){ |
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
if(!dm._rule){ |
| 1452 |
dm._rule = []; |
| 1453 |
} |
| 1454 |
|
| 1455 |
var keyframeId = idx + (entering ? "-in" : "-out"); |
| 1456 |
|
| 1457 |
|
| 1458 |
if(!(dm._rule[keyframeId])){ |
| 1459 |
var node = domConstruct.create("style", null, win.doc.getElementsByTagName("head")[0]); |
| 1460 |
node.textContent = |
| 1461 |
".mblScrollableScrollTo"+keyframeId+"{" + css3.name("animation-name", true) + ": scrollableViewScroll"+keyframeId+";}"+ |
| 1462 |
"@" + css3.name("keyframes", true) + " scrollableViewScroll"+keyframeId+"{}"; |
| 1463 |
dm._rule[keyframeId] = node.sheet.cssRules[1]; |
| 1464 |
} |
| 1465 |
var rule = dm._rule[keyframeId]; |
| 1466 |
if(rule){ |
| 1467 |
if(from){ |
| 1468 |
rule.deleteRule(has("webkit")?"from":0); |
| 1469 |
(rule.insertRule||rule.appendRule).call(rule, "from { " + css3.name("transform", true) + ": "+this.makeTranslateStr(from)+"; }"); |
| 1470 |
} |
| 1471 |
if(to){ |
| 1472 |
if(to.x === undefined){ to.x = from.x; } |
| 1473 |
if(to.y === undefined){ to.y = from.y; } |
| 1474 |
rule.deleteRule(has("webkit")?"to":1); |
| 1475 |
(rule.insertRule||rule.appendRule).call(rule, "to { " + css3.name("transform", true) + ": "+this.makeTranslateStr(to)+"; }"); |
| 1476 |
} |
| 1477 |
} |
| 1478 |
return "mblScrollableScrollTo"+keyframeId; |
| 1479 |
}, |
| 1480 |
|
| 1481 |
setSelectable: function(node, selectable){ |
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
node.style.KhtmlUserSelect = selectable ? "auto" : "none"; |
| 1487 |
node.style.MozUserSelect = selectable ? "" : "none"; |
| 1488 |
node.onselectstart = selectable ? null : function(){return false;}; |
| 1489 |
if(has("ie")){ |
| 1490 |
node.unselectable = selectable ? "" : "on"; |
| 1491 |
var nodes = node.getElementsByTagName("*"); |
| 1492 |
for(var i = 0; i < nodes.length; i++){ |
| 1493 |
nodes[i].unselectable = selectable ? "" : "on"; |
| 1494 |
} |
| 1495 |
} |
| 1496 |
} |
| 1497 |
}); |
| 1498 |
Scrollable = has("dojo-bidi") ? declare("dojox.mobile.Scrollable", [Scrollable, BidiScrollable]) : Scrollable; |
| 1499 |
lang.setObject("dojox.mobile.scrollable", Scrollable); |
| 1500 |
|
| 1501 |
return Scrollable; |
| 1502 |
}); |