updated iScroll

updated iScroll to version 4.2.5. Also fixed an error with this version
of iScroll (an error where form elements could'nt be clicked)
This commit is contained in:
Andre Meyering 2013-01-23 15:45:34 +01:00
parent 5f95713d87
commit 681925845f
2 changed files with 181 additions and 144 deletions

312
src/libs/iscroll.js Executable file → Normal file
View File

@ -1,60 +1,88 @@
/*! /*!
* iScroll v4.1.9 ~ Copyright (c) 2011 Matteo Spinelli, http://cubiq.org * iScroll v4.2.5 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org
* Released under MIT license, http://cubiq.org/license * Released under MIT license, http://cubiq.org/license
*/ */
(function(){ (function(window, doc){
var m = Math, var m = Math,
mround = function (r) { return r >> 0; }, dummyStyle = doc.createElement('div').style,
vendor = (/webkit/i).test(navigator.appVersion) ? 'webkit' : vendor = (function () {
(/firefox/i).test(navigator.userAgent) ? 'Moz' : var vendors = 't,webkitT,MozT,msT,OT'.split(','),
(/trident/i).test(navigator.userAgent) ? 'ms' : t,
'opera' in window ? 'O' : '', i = 0,
l = vendors.length;
for ( ; i < l; i++ ) {
t = vendors[i] + 'ransform';
if ( t in dummyStyle ) {
return vendors[i].substr(0, vendors[i].length - 1);
}
}
return false;
})(),
cssVendor = vendor ? '-' + vendor.toLowerCase() + '-' : '',
// Style properties
transform = prefixStyle('transform'),
transitionProperty = prefixStyle('transitionProperty'),
transitionDuration = prefixStyle('transitionDuration'),
transformOrigin = prefixStyle('transformOrigin'),
transitionTimingFunction = prefixStyle('transitionTimingFunction'),
transitionDelay = prefixStyle('transitionDelay'),
// Browser capabilities // Browser capabilities
isAndroid = (/android/gi).test(navigator.appVersion), isAndroid = (/android/gi).test(navigator.appVersion),
isIDevice = (/iphone|ipad/gi).test(navigator.appVersion), isIDevice = (/iphone|ipad/gi).test(navigator.appVersion),
isPlaybook = (/playbook/gi).test(navigator.appVersion), isTouchPad = (/hp-tablet/gi).test(navigator.appVersion),
isTouchPad = (/hp-tablet/gi).test(navigator.appVersion),
has3d = 'WebKitCSSMatrix' in window && 'm11' in new WebKitCSSMatrix(), has3d = prefixStyle('perspective') in dummyStyle,
hasTouch = 'ontouchstart' in window && !isTouchPad, hasTouch = 'ontouchstart' in window && !isTouchPad,
hasTransform = vendor + 'Transform' in document.documentElement.style, hasTransform = vendor !== false,
hasTransitionEnd = isIDevice || isPlaybook, hasTransitionEnd = prefixStyle('transition') in dummyStyle,
nextFrame = (function() {
return window.requestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.oRequestAnimationFrame
|| window.msRequestAnimationFrame
|| function(callback) { return setTimeout(callback, 1); }
})(),
cancelFrame = (function () {
return window.cancelRequestAnimationFrame
|| window.webkitCancelAnimationFrame
|| window.webkitCancelRequestAnimationFrame
|| window.mozCancelRequestAnimationFrame
|| window.oCancelRequestAnimationFrame
|| window.msCancelRequestAnimationFrame
|| clearTimeout
})(),
// Events
RESIZE_EV = 'onorientationchange' in window ? 'orientationchange' : 'resize', RESIZE_EV = 'onorientationchange' in window ? 'orientationchange' : 'resize',
START_EV = hasTouch ? 'touchstart' : 'mousedown', START_EV = hasTouch ? 'touchstart' : 'mousedown',
MOVE_EV = hasTouch ? 'touchmove' : 'mousemove', MOVE_EV = hasTouch ? 'touchmove' : 'mousemove',
END_EV = hasTouch ? 'touchend' : 'mouseup', END_EV = hasTouch ? 'touchend' : 'mouseup',
CANCEL_EV = hasTouch ? 'touchcancel' : 'mouseup', CANCEL_EV = hasTouch ? 'touchcancel' : 'mouseup',
WHEEL_EV = vendor == 'Moz' ? 'DOMMouseScroll' : 'mousewheel', TRNEND_EV = (function () {
if ( vendor === false ) return false;
var transitionEnd = {
'' : 'transitionend',
'webkit' : 'webkitTransitionEnd',
'Moz' : 'transitionend',
'O' : 'otransitionend',
'ms' : 'MSTransitionEnd'
};
return transitionEnd[vendor];
})(),
nextFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback) { return setTimeout(callback, 1); };
})(),
cancelFrame = (function () {
return window.cancelRequestAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFrame ||
window.oCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame ||
clearTimeout;
})(),
// Helpers // Helpers
trnOpen = 'translate' + (has3d ? '3d(' : '('), translateZ = has3d ? ' translateZ(0)' : '',
trnClose = has3d ? ',0)' : ')',
// Constructor // Constructor
iScroll = function (el, options) { iScroll = function (el, options) {
var that = this, var that = this,
doc = document,
i; i;
that.wrapper = typeof el == 'object' ? el : doc.getElementById(el); that.wrapper = typeof el == 'object' ? el : doc.getElementById(el);
@ -75,6 +103,7 @@ var m = Math,
useTransition: false, useTransition: false,
topOffset: 0, topOffset: 0,
checkDOMChanges: false, // Experimental checkDOMChanges: false, // Experimental
handleClick: true,
// Scrollbar // Scrollbar
hScrollbar: true, hScrollbar: true,
@ -118,27 +147,26 @@ var m = Math,
that.y = that.options.y; that.y = that.options.y;
// Normalize options // Normalize options
that.options.useTransform = hasTransform ? that.options.useTransform : false; that.options.useTransform = hasTransform && that.options.useTransform;
that.options.hScrollbar = that.options.hScroll && that.options.hScrollbar; that.options.hScrollbar = that.options.hScroll && that.options.hScrollbar;
that.options.vScrollbar = that.options.vScroll && that.options.vScrollbar; that.options.vScrollbar = that.options.vScroll && that.options.vScrollbar;
that.options.zoom = that.options.useTransform && that.options.zoom; that.options.zoom = that.options.useTransform && that.options.zoom;
that.options.useTransition = hasTransitionEnd && that.options.useTransition; that.options.useTransition = hasTransitionEnd && that.options.useTransition;
// Helpers FIX ANDROID BUG! // Helpers FIX ANDROID BUG!
// translate3d and scale doesn't work together! // translate3d and scale doesn't work together!
// Ignoring 3d ONLY WHEN YOU SET that.options.zoom // Ignoring 3d ONLY WHEN YOU SET that.options.zoom
if ( that.options.zoom && isAndroid ){ if ( that.options.zoom && isAndroid ){
trnOpen = 'translate('; translateZ = '';
trnClose = ')';
} }
// Set some default styles // Set some default styles
that.scroller.style[vendor + 'TransitionProperty'] = that.options.useTransform ? '-' + vendor.toLowerCase() + '-transform' : 'top left'; that.scroller.style[transitionProperty] = that.options.useTransform ? cssVendor + 'transform' : 'top left';
that.scroller.style[vendor + 'TransitionDuration'] = '0'; that.scroller.style[transitionDuration] = '0';
that.scroller.style[vendor + 'TransformOrigin'] = '0 0'; that.scroller.style[transformOrigin] = '0 0';
if (that.options.useTransition) that.scroller.style[vendor + 'TransitionTimingFunction'] = 'cubic-bezier(0.33,0.66,0.66,1)'; if (that.options.useTransition) that.scroller.style[transitionTimingFunction] = 'cubic-bezier(0.33,0.66,0.66,1)';
if (that.options.useTransform) that.scroller.style[vendor + 'Transform'] = trnOpen + that.x + 'px,' + that.y + 'px' + trnClose; if (that.options.useTransform) that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px)' + translateZ;
else that.scroller.style.cssText += ';position:absolute;top:' + that.y + 'px;left:' + that.x + 'px'; else that.scroller.style.cssText += ';position:absolute;top:' + that.y + 'px;left:' + that.x + 'px';
if (that.options.useTransition) that.options.fixedScrollbar = true; if (that.options.useTransition) that.options.fixedScrollbar = true;
@ -148,9 +176,10 @@ var m = Math,
that._bind(RESIZE_EV, window); that._bind(RESIZE_EV, window);
that._bind(START_EV); that._bind(START_EV);
if (!hasTouch) { if (!hasTouch) {
that._bind('mouseout', that.wrapper); if (that.options.wheelAction != 'none') {
if (that.options.wheelAction != 'none') that._bind('DOMMouseScroll');
that._bind(WHEEL_EV); that._bind('mousewheel');
}
} }
if (that.options.checkDOMChanges) that.checkDOMTime = setInterval(function () { if (that.options.checkDOMChanges) that.checkDOMTime = setInterval(function () {
@ -175,17 +204,14 @@ iScroll.prototype = {
switch(e.type) { switch(e.type) {
case START_EV: case START_EV:
if (!hasTouch && e.button !== 0) return; if (!hasTouch && e.button !== 0) return;
var nodeName = e.target.nodeName.toUpperCase();
if (nodeName == "TEXTAREA" || nodeName == "INPUT" || nodeName == "SELECT" ) return;
that._start(e); that._start(e);
break; break;
case MOVE_EV: that._move(e); break; case MOVE_EV: that._move(e); break;
case END_EV: case END_EV:
case CANCEL_EV: that._end(e); break; case CANCEL_EV: that._end(e); break;
case RESIZE_EV: that._resize(); break; case RESIZE_EV: that._resize(); break;
case WHEEL_EV: that._wheel(e); break; case 'DOMMouseScroll': case 'mousewheel': that._wheel(e); break;
case 'mouseout': that._mouseout(e); break; case TRNEND_EV: that._transitionEnd(e); break;
case 'webkitTransitionEnd': that._transitionEnd(e); break;
} }
}, },
@ -198,12 +224,11 @@ iScroll.prototype = {
_scrollbar: function (dir) { _scrollbar: function (dir) {
var that = this, var that = this,
doc = document,
bar; bar;
if (!that[dir + 'Scrollbar']) { if (!that[dir + 'Scrollbar']) {
if (that[dir + 'ScrollbarWrapper']) { if (that[dir + 'ScrollbarWrapper']) {
if (hasTransform) that[dir + 'ScrollbarIndicator'].style[vendor + 'Transform'] = ''; if (hasTransform) that[dir + 'ScrollbarIndicator'].style[transform] = '';
that[dir + 'ScrollbarWrapper'].parentNode.removeChild(that[dir + 'ScrollbarWrapper']); that[dir + 'ScrollbarWrapper'].parentNode.removeChild(that[dir + 'ScrollbarWrapper']);
that[dir + 'ScrollbarWrapper'] = null; that[dir + 'ScrollbarWrapper'] = null;
that[dir + 'ScrollbarIndicator'] = null; that[dir + 'ScrollbarIndicator'] = null;
@ -219,7 +244,7 @@ iScroll.prototype = {
if (that.options.scrollbarClass) bar.className = that.options.scrollbarClass + dir.toUpperCase(); if (that.options.scrollbarClass) bar.className = that.options.scrollbarClass + dir.toUpperCase();
else bar.style.cssText = 'position:absolute;z-index:100;' + (dir == 'h' ? 'height:7px;bottom:1px;left:2px;right:' + (that.vScrollbar ? '7' : '2') + 'px' : 'width:7px;bottom:' + (that.hScrollbar ? '7' : '2') + 'px;top:2px;right:1px'); else bar.style.cssText = 'position:absolute;z-index:100;' + (dir == 'h' ? 'height:7px;bottom:1px;left:2px;right:' + (that.vScrollbar ? '7' : '2') + 'px' : 'width:7px;bottom:' + (that.hScrollbar ? '7' : '2') + 'px;top:2px;right:1px');
bar.style.cssText += ';pointer-events:none;-' + vendor + '-transition-property:opacity;-' + vendor + '-transition-duration:' + (that.options.fadeScrollbar ? '350ms' : '0') + ';overflow:hidden;opacity:' + (that.options.hideScrollbar ? '0' : '1'); bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:opacity;' + cssVendor + 'transition-duration:' + (that.options.fadeScrollbar ? '350ms' : '0') + ';overflow:hidden;opacity:' + (that.options.hideScrollbar ? '0' : '1');
that.wrapper.appendChild(bar); that.wrapper.appendChild(bar);
that[dir + 'ScrollbarWrapper'] = bar; that[dir + 'ScrollbarWrapper'] = bar;
@ -227,10 +252,10 @@ iScroll.prototype = {
// Create the scrollbar indicator // Create the scrollbar indicator
bar = doc.createElement('div'); bar = doc.createElement('div');
if (!that.options.scrollbarClass) { if (!that.options.scrollbarClass) {
bar.style.cssText = 'position:absolute;z-index:100;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);-' + vendor + '-background-clip:padding-box;-' + vendor + '-box-sizing:border-box;' + (dir == 'h' ? 'height:100%' : 'width:100%') + ';-' + vendor + '-border-radius:3px;border-radius:3px'; bar.style.cssText = 'position:absolute;z-index:100;background:rgba(0,0,0,0.5);border:1px solid rgba(255,255,255,0.9);' + cssVendor + 'background-clip:padding-box;' + cssVendor + 'box-sizing:border-box;' + (dir == 'h' ? 'height:100%' : 'width:100%') + ';' + cssVendor + 'border-radius:3px;border-radius:3px';
} }
bar.style.cssText += ';pointer-events:none;-' + vendor + '-transition-property:-' + vendor + '-transform;-' + vendor + '-transition-timing-function:cubic-bezier(0.33,0.66,0.66,1);-' + vendor + '-transition-duration:0;-' + vendor + '-transform:' + trnOpen + '0,0' + trnClose; bar.style.cssText += ';pointer-events:none;' + cssVendor + 'transition-property:' + cssVendor + 'transform;' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1);' + cssVendor + 'transition-duration:0;' + cssVendor + 'transform: translate(0,0)' + translateZ;
if (that.options.useTransition) bar.style.cssText += ';-' + vendor + '-transition-timing-function:cubic-bezier(0.33,0.66,0.66,1)'; if (that.options.useTransition) bar.style.cssText += ';' + cssVendor + 'transition-timing-function:cubic-bezier(0.33,0.66,0.66,1)';
that[dir + 'ScrollbarWrapper'].appendChild(bar); that[dir + 'ScrollbarWrapper'].appendChild(bar);
that[dir + 'ScrollbarIndicator'] = bar; that[dir + 'ScrollbarIndicator'] = bar;
@ -238,13 +263,13 @@ iScroll.prototype = {
if (dir == 'h') { if (dir == 'h') {
that.hScrollbarSize = that.hScrollbarWrapper.clientWidth; that.hScrollbarSize = that.hScrollbarWrapper.clientWidth;
that.hScrollbarIndicatorSize = m.max(mround(that.hScrollbarSize * that.hScrollbarSize / that.scrollerW), 8); that.hScrollbarIndicatorSize = m.max(m.round(that.hScrollbarSize * that.hScrollbarSize / that.scrollerW), 8);
that.hScrollbarIndicator.style.width = that.hScrollbarIndicatorSize + 'px'; that.hScrollbarIndicator.style.width = that.hScrollbarIndicatorSize + 'px';
that.hScrollbarMaxScroll = that.hScrollbarSize - that.hScrollbarIndicatorSize; that.hScrollbarMaxScroll = that.hScrollbarSize - that.hScrollbarIndicatorSize;
that.hScrollbarProp = that.hScrollbarMaxScroll / that.maxScrollX; that.hScrollbarProp = that.hScrollbarMaxScroll / that.maxScrollX;
} else { } else {
that.vScrollbarSize = that.vScrollbarWrapper.clientHeight; that.vScrollbarSize = that.vScrollbarWrapper.clientHeight;
that.vScrollbarIndicatorSize = m.max(mround(that.vScrollbarSize * that.vScrollbarSize / that.scrollerH), 8); that.vScrollbarIndicatorSize = m.max(m.round(that.vScrollbarSize * that.vScrollbarSize / that.scrollerH), 8);
that.vScrollbarIndicator.style.height = that.vScrollbarIndicatorSize + 'px'; that.vScrollbarIndicator.style.height = that.vScrollbarIndicatorSize + 'px';
that.vScrollbarMaxScroll = that.vScrollbarSize - that.vScrollbarIndicatorSize; that.vScrollbarMaxScroll = that.vScrollbarSize - that.vScrollbarIndicatorSize;
that.vScrollbarProp = that.vScrollbarMaxScroll / that.maxScrollY; that.vScrollbarProp = that.vScrollbarMaxScroll / that.maxScrollY;
@ -260,14 +285,16 @@ iScroll.prototype = {
}, },
_pos: function (x, y) { _pos: function (x, y) {
if (this.zoomed) return;
x = this.hScroll ? x : 0; x = this.hScroll ? x : 0;
y = this.vScroll ? y : 0; y = this.vScroll ? y : 0;
if (this.options.useTransform) { if (this.options.useTransform) {
this.scroller.style[vendor + 'Transform'] = trnOpen + x + 'px,' + y + 'px' + trnClose + ' scale(' + this.scale + ')'; this.scroller.style[transform] = 'translate(' + x + 'px,' + y + 'px) scale(' + this.scale + ')' + translateZ;
} else { } else {
x = mround(x); x = m.round(x);
y = mround(y); y = m.round(y);
this.scroller.style.left = x + 'px'; this.scroller.style.left = x + 'px';
this.scroller.style.top = y + 'px'; this.scroller.style.top = y + 'px';
} }
@ -290,14 +317,14 @@ iScroll.prototype = {
if (pos < 0) { if (pos < 0) {
if (!that.options.fixedScrollbar) { if (!that.options.fixedScrollbar) {
size = that[dir + 'ScrollbarIndicatorSize'] + mround(pos * 3); size = that[dir + 'ScrollbarIndicatorSize'] + m.round(pos * 3);
if (size < 8) size = 8; if (size < 8) size = 8;
that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px'; that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px';
} }
pos = 0; pos = 0;
} else if (pos > that[dir + 'ScrollbarMaxScroll']) { } else if (pos > that[dir + 'ScrollbarMaxScroll']) {
if (!that.options.fixedScrollbar) { if (!that.options.fixedScrollbar) {
size = that[dir + 'ScrollbarIndicatorSize'] - mround((pos - that[dir + 'ScrollbarMaxScroll']) * 3); size = that[dir + 'ScrollbarIndicatorSize'] - m.round((pos - that[dir + 'ScrollbarMaxScroll']) * 3);
if (size < 8) size = 8; if (size < 8) size = 8;
that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px'; that[dir + 'ScrollbarIndicator'].style[dir == 'h' ? 'width' : 'height'] = size + 'px';
pos = that[dir + 'ScrollbarMaxScroll'] + (that[dir + 'ScrollbarIndicatorSize'] - size); pos = that[dir + 'ScrollbarMaxScroll'] + (that[dir + 'ScrollbarIndicatorSize'] - size);
@ -306,9 +333,9 @@ iScroll.prototype = {
} }
} }
that[dir + 'ScrollbarWrapper'].style[vendor + 'TransitionDelay'] = '0'; that[dir + 'ScrollbarWrapper'].style[transitionDelay] = '0';
that[dir + 'ScrollbarWrapper'].style.opacity = hidden && that.options.hideScrollbar ? '0' : '1'; that[dir + 'ScrollbarWrapper'].style.opacity = hidden && that.options.hideScrollbar ? '0' : '1';
that[dir + 'ScrollbarIndicator'].style[vendor + 'Transform'] = trnOpen + (dir == 'h' ? pos + 'px,0' : '0,' + pos + 'px') + trnClose; that[dir + 'ScrollbarIndicator'].style[transform] = 'translate(' + (dir == 'h' ? pos + 'px,0)' : '0,' + pos + 'px)') + translateZ;
}, },
_start: function (e) { _start: function (e) {
@ -348,19 +375,20 @@ iScroll.prototype = {
if (that.options.momentum) { if (that.options.momentum) {
if (that.options.useTransform) { if (that.options.useTransform) {
// Very lame general purpose alternative to CSSMatrix // Very lame general purpose alternative to CSSMatrix
matrix = getComputedStyle(that.scroller, null)[vendor + 'Transform'].replace(/[^0-9-.,]/g, '').split(','); matrix = getComputedStyle(that.scroller, null)[transform].replace(/[^0-9\-.,]/g, '').split(',');
x = matrix[4] * 1; x = +(matrix[12] || matrix[4]);
y = matrix[5] * 1; y = +(matrix[13] || matrix[5]);
} else { } else {
x = getComputedStyle(that.scroller, null).left.replace(/[^0-9-]/g, '') * 1; x = +getComputedStyle(that.scroller, null).left.replace(/[^0-9-]/g, '');
y = getComputedStyle(that.scroller, null).top.replace(/[^0-9-]/g, '') * 1; y = +getComputedStyle(that.scroller, null).top.replace(/[^0-9-]/g, '');
} }
if (x != that.x || y != that.y) { if (x != that.x || y != that.y) {
if (that.options.useTransition) that._unbind('webkitTransitionEnd'); if (that.options.useTransition) that._unbind(TRNEND_EV);
else cancelFrame(that.aniTime); else cancelFrame(that.aniTime);
that.steps = []; that.steps = [];
that._pos(x, y); that._pos(x, y);
if (that.options.onScrollEnd) that.options.onScrollEnd.call(that);
} }
} }
@ -376,9 +404,9 @@ iScroll.prototype = {
if (that.options.onScrollStart) that.options.onScrollStart.call(that, e); if (that.options.onScrollStart) that.options.onScrollStart.call(that, e);
that._bind(MOVE_EV); that._bind(MOVE_EV, window);
that._bind(END_EV); that._bind(END_EV, window);
that._bind(CANCEL_EV); that._bind(CANCEL_EV, window);
}, },
_move: function (e) { _move: function (e) {
@ -411,7 +439,7 @@ iScroll.prototype = {
newX = this.originX - this.originX * that.lastScale + this.x, newX = this.originX - this.originX * that.lastScale + this.x,
newY = this.originY - this.originY * that.lastScale + this.y; newY = this.originY - this.originY * that.lastScale + this.y;
this.scroller.style[vendor + 'Transform'] = trnOpen + newX + 'px,' + newY + 'px' + trnClose + ' scale(' + scale + ')'; this.scroller.style[transform] = 'translate(' + newX + 'px,' + newY + 'px) scale(' + scale + ')' + translateZ;
if (that.options.onZoom) that.options.onZoom.call(that, e); if (that.options.onZoom) that.options.onZoom.call(that, e);
return; return;
@ -424,7 +452,7 @@ iScroll.prototype = {
if (newX > 0 || newX < that.maxScrollX) { if (newX > 0 || newX < that.maxScrollX) {
newX = that.options.bounce ? that.x + (deltaX / 2) : newX >= 0 || that.maxScrollX >= 0 ? 0 : that.maxScrollX; newX = that.options.bounce ? that.x + (deltaX / 2) : newX >= 0 || that.maxScrollX >= 0 ? 0 : that.maxScrollX;
} }
if (newY > that.minScrollY || newY < that.maxScrollY) { if (newY > that.minScrollY || newY < that.maxScrollY) {
newY = that.options.bounce ? that.y + (deltaY / 2) : newY >= that.minScrollY || that.maxScrollY >= 0 ? that.minScrollY : that.maxScrollY; newY = that.options.bounce ? that.y + (deltaY / 2) : newY >= that.minScrollY || that.maxScrollY >= 0 ? that.minScrollY : that.maxScrollY;
} }
@ -463,7 +491,7 @@ iScroll.prototype = {
}, },
_end: function (e) { _end: function (e) {
if (hasTouch && e.touches.length != 0) return; if (hasTouch && e.touches.length !== 0) return;
var that = this, var that = this,
point = hasTouch ? e.changedTouches[0] : e, point = hasTouch ? e.changedTouches[0] : e,
@ -478,9 +506,9 @@ iScroll.prototype = {
snap, snap,
scale; scale;
that._unbind(MOVE_EV); that._unbind(MOVE_EV, window);
that._unbind(END_EV); that._unbind(END_EV, window);
that._unbind(CANCEL_EV); that._unbind(CANCEL_EV, window);
if (that.options.onBeforeScrollEnd) that.options.onBeforeScrollEnd.call(that, e); if (that.options.onBeforeScrollEnd) that.options.onBeforeScrollEnd.call(that, e);
@ -494,8 +522,8 @@ iScroll.prototype = {
that.x = that.originX - that.originX * that.lastScale + that.x; that.x = that.originX - that.originX * that.lastScale + that.x;
that.y = that.originY - that.originY * that.lastScale + that.y; that.y = that.originY - that.originY * that.lastScale + that.y;
that.scroller.style[vendor + 'TransitionDuration'] = '200ms'; that.scroller.style[transitionDuration] = '200ms';
that.scroller.style[vendor + 'Transform'] = trnOpen + that.x + 'px,' + that.y + 'px' + trnClose + ' scale(' + that.scale + ')'; that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px) scale(' + that.scale + ')' + translateZ;
that.zoomed = false; that.zoomed = false;
that.refresh(); that.refresh();
@ -517,7 +545,7 @@ iScroll.prototype = {
that.options.onZoomEnd.call(that, e); that.options.onZoomEnd.call(that, e);
}, 200); // 200 is default zoom duration }, 200); // 200 is default zoom duration
} }
} else { } else if (this.options.handleClick) {
that.doubleTapTimer = setTimeout(function () { that.doubleTapTimer = setTimeout(function () {
that.doubleTapTimer = null; that.doubleTapTimer = null;
@ -526,7 +554,7 @@ iScroll.prototype = {
while (target.nodeType != 1) target = target.parentNode; while (target.nodeType != 1) target = target.parentNode;
if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA') { if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA') {
ev = document.createEvent('MouseEvents'); ev = doc.createEvent('MouseEvents');
ev.initMouseEvent('click', true, true, e.view, 1, ev.initMouseEvent('click', true, true, e.view, 1,
point.screenX, point.screenY, point.clientX, point.clientY, point.screenX, point.screenY, point.clientX, point.clientY,
e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
@ -538,7 +566,7 @@ iScroll.prototype = {
} }
} }
that._resetPos(200); that._resetPos(400);
if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e); if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
return; return;
@ -551,8 +579,8 @@ iScroll.prototype = {
newPosX = that.x + momentumX.dist; newPosX = that.x + momentumX.dist;
newPosY = that.y + momentumY.dist; newPosY = that.y + momentumY.dist;
if ((that.x > 0 && newPosX > 0) || (that.x < that.maxScrollX && newPosX < that.maxScrollX)) momentumX = { dist:0, time:0 }; if ((that.x > 0 && newPosX > 0) || (that.x < that.maxScrollX && newPosX < that.maxScrollX)) momentumX = { dist:0, time:0 };
if ((that.y > that.minScrollY && newPosY > that.minScrollY) || (that.y < that.maxScrollY && newPosY < that.maxScrollY)) momentumY = { dist:0, time:0 }; if ((that.y > that.minScrollY && newPosY > that.minScrollY) || (that.y < that.maxScrollY && newPosY < that.maxScrollY)) momentumY = { dist:0, time:0 };
} }
if (momentumX.dist || momentumY.dist) { if (momentumX.dist || momentumY.dist) {
@ -571,7 +599,7 @@ iScroll.prototype = {
} }
} }
that.scrollTo(mround(newPosX), mround(newPosY), newDuration); that.scrollTo(m.round(newPosX), m.round(newPosY), newDuration);
if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e); if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
return; return;
@ -607,11 +635,11 @@ iScroll.prototype = {
} }
if (that.hScrollbar && that.options.hideScrollbar) { if (that.hScrollbar && that.options.hideScrollbar) {
if (vendor == 'webkit') that.hScrollbarWrapper.style[vendor + 'TransitionDelay'] = '300ms'; if (vendor == 'webkit') that.hScrollbarWrapper.style[transitionDelay] = '300ms';
that.hScrollbarWrapper.style.opacity = '0'; that.hScrollbarWrapper.style.opacity = '0';
} }
if (that.vScrollbar && that.options.hideScrollbar) { if (that.vScrollbar && that.options.hideScrollbar) {
if (vendor == 'webkit') that.vScrollbarWrapper.style[vendor + 'TransitionDelay'] = '300ms'; if (vendor == 'webkit') that.vScrollbarWrapper.style[transitionDelay] = '300ms';
that.vScrollbarWrapper.style.opacity = '0'; that.vScrollbarWrapper.style.opacity = '0';
} }
@ -666,39 +694,28 @@ iScroll.prototype = {
if (deltaY > that.minScrollY) deltaY = that.minScrollY; if (deltaY > that.minScrollY) deltaY = that.minScrollY;
else if (deltaY < that.maxScrollY) deltaY = that.maxScrollY; else if (deltaY < that.maxScrollY) deltaY = that.maxScrollY;
that.scrollTo(deltaX, deltaY, 0); if (that.maxScrollY < 0) {
that.scrollTo(deltaX, deltaY, 0);
}
}, },
_mouseout: function (e) {
var t = e.relatedTarget;
if (!t) {
this._end(e);
return;
}
while (t = t.parentNode) if (t == this.wrapper) return;
this._end(e);
},
_transitionEnd: function (e) { _transitionEnd: function (e) {
var that = this; var that = this;
if (e.target != that.scroller) return; if (e.target != that.scroller) return;
that._unbind('webkitTransitionEnd'); that._unbind(TRNEND_EV);
that._startAni(); that._startAni();
}, },
/** /**
* *
* Utilities * Utilities
* *
*/ */
_startAni: function () { _startAni: function () {
var that = this, var that = this,
startX = that.x, startY = that.y, startX = that.x, startY = that.y,
@ -724,7 +741,7 @@ iScroll.prototype = {
that._transitionTime(step.time); that._transitionTime(step.time);
that._pos(step.x, step.y); that._pos(step.x, step.y);
that.animating = false; that.animating = false;
if (step.time) that._bind('webkitTransitionEnd'); if (step.time) that._bind(TRNEND_EV);
else that._resetPos(0); else that._resetPos(0);
return; return;
} }
@ -754,9 +771,9 @@ iScroll.prototype = {
_transitionTime: function (time) { _transitionTime: function (time) {
time += 'ms'; time += 'ms';
this.scroller.style[vendor + 'TransitionDuration'] = time; this.scroller.style[transitionDuration] = time;
if (this.hScrollbar) this.hScrollbarIndicator.style[vendor + 'TransitionDuration'] = time; if (this.hScrollbar) this.hScrollbarIndicator.style[transitionDuration] = time;
if (this.vScrollbar) this.vScrollbarIndicator.style[vendor + 'TransitionDuration'] = time; if (this.vScrollbar) this.vScrollbarIndicator.style[transitionDuration] = time;
}, },
_momentum: function (dist, time, maxDistUpper, maxDistLower, size) { _momentum: function (dist, time, maxDistUpper, maxDistLower, size) {
@ -765,7 +782,7 @@ iScroll.prototype = {
newDist = (speed * speed) / (2 * deceleration), newDist = (speed * speed) / (2 * deceleration),
newTime = 0, outsideDist = 0; newTime = 0, outsideDist = 0;
// Proportinally reduce speed if we are outside of the boundaries // Proportinally reduce speed if we are outside of the boundaries
if (dist > 0 && newDist > maxDistUpper) { if (dist > 0 && newDist > maxDistUpper) {
outsideDist = size / (6 / (newDist / speed * deceleration)); outsideDist = size / (6 / (newDist / speed * deceleration));
maxDistUpper = maxDistUpper + outsideDist; maxDistUpper = maxDistUpper + outsideDist;
@ -781,7 +798,7 @@ iScroll.prototype = {
newDist = newDist * (dist < 0 ? -1 : 1); newDist = newDist * (dist < 0 ? -1 : 1);
newTime = speed / deceleration; newTime = speed / deceleration;
return { dist: newDist, time: mround(newTime) }; return { dist: newDist, time: m.round(newTime) };
}, },
_offset: function (el) { _offset: function (el) {
@ -836,7 +853,7 @@ iScroll.prototype = {
that.currPageY = page; that.currPageY = page;
// Snap with constant speed (proportional duration) // Snap with constant speed (proportional duration)
time = mround(m.max(sizeX, sizeY)) || 200; time = m.round(m.max(sizeX, sizeY)) || 200;
return { x: x, y: y, time: time }; return { x: x, y: y, time: time };
}, },
@ -851,14 +868,14 @@ iScroll.prototype = {
/** /**
* *
* Public methods * Public methods
* *
*/ */
destroy: function () { destroy: function () {
var that = this; var that = this;
that.scroller.style[vendor + 'Transform'] = ''; that.scroller.style[transform] = '';
// Remove the scrollbars // Remove the scrollbars
that.hScrollbar = false; that.hScrollbar = false;
@ -869,16 +886,16 @@ iScroll.prototype = {
// Remove the event listeners // Remove the event listeners
that._unbind(RESIZE_EV, window); that._unbind(RESIZE_EV, window);
that._unbind(START_EV); that._unbind(START_EV);
that._unbind(MOVE_EV); that._unbind(MOVE_EV, window);
that._unbind(END_EV); that._unbind(END_EV, window);
that._unbind(CANCEL_EV); that._unbind(CANCEL_EV, window);
if (!that.options.hasTouch) { if (!that.options.hasTouch) {
that._unbind('mouseout', that.wrapper); that._unbind('DOMMouseScroll');
that._unbind(WHEEL_EV); that._unbind('mousewheel');
} }
if (that.options.useTransition) that._unbind('webkitTransitionEnd'); if (that.options.useTransition) that._unbind(TRNEND_EV);
if (that.options.checkDOMChanges) clearInterval(that.checkDOMTime); if (that.options.checkDOMChanges) clearInterval(that.checkDOMTime);
@ -898,8 +915,8 @@ iScroll.prototype = {
that.wrapperH = that.wrapper.clientHeight || 1; that.wrapperH = that.wrapper.clientHeight || 1;
that.minScrollY = -that.options.topOffset || 0; that.minScrollY = -that.options.topOffset || 0;
that.scrollerW = mround(that.scroller.offsetWidth * that.scale); that.scrollerW = m.round(that.scroller.offsetWidth * that.scale);
that.scrollerH = mround((that.scroller.offsetHeight + that.minScrollY) * that.scale); that.scrollerH = m.round((that.scroller.offsetHeight + that.minScrollY) * that.scale);
that.maxScrollX = that.wrapperW - that.scrollerW; that.maxScrollX = that.wrapperW - that.scrollerW;
that.maxScrollY = that.wrapperH - that.scrollerH + that.minScrollY; that.maxScrollY = that.wrapperH - that.scrollerH + that.minScrollY;
that.dirX = 0; that.dirX = 0;
@ -954,8 +971,8 @@ iScroll.prototype = {
that._scrollbar('v'); that._scrollbar('v');
if (!that.zoomed) { if (!that.zoomed) {
that.scroller.style[vendor + 'TransitionDuration'] = '0'; that.scroller.style[transitionDuration] = '0';
that._resetPos(200); that._resetPos(400);
} }
}, },
@ -1026,9 +1043,9 @@ iScroll.prototype = {
this.enabled = false; this.enabled = false;
// If disabled after touchstart we make sure that there are no left over events // If disabled after touchstart we make sure that there are no left over events
this._unbind(MOVE_EV); this._unbind(MOVE_EV, window);
this._unbind(END_EV); this._unbind(END_EV, window);
this._unbind(CANCEL_EV); this._unbind(CANCEL_EV, window);
}, },
enable: function () { enable: function () {
@ -1036,7 +1053,7 @@ iScroll.prototype = {
}, },
stop: function () { stop: function () {
if (this.options.useTransition) this._unbind('webkitTransitionEnd'); if (this.options.useTransition) this._unbind(TRNEND_EV);
else cancelFrame(this.aniTime); else cancelFrame(this.aniTime);
this.steps = []; this.steps = [];
this.moved = false; this.moved = false;
@ -1062,8 +1079,8 @@ iScroll.prototype = {
that.x = that.x > 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x; that.x = that.x > 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x;
that.y = that.y > that.minScrollY ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y; that.y = that.y > that.minScrollY ? that.minScrollY : that.y < that.maxScrollY ? that.maxScrollY : that.y;
that.scroller.style[vendor + 'TransitionDuration'] = time + 'ms'; that.scroller.style[transitionDuration] = time + 'ms';
that.scroller.style[vendor + 'Transform'] = trnOpen + that.x + 'px,' + that.y + 'px' + trnClose + ' scale(' + scale + ')'; that.scroller.style[transform] = 'translate(' + that.x + 'px,' + that.y + 'px) scale(' + scale + ')' + translateZ;
that.zoomed = false; that.zoomed = false;
}, },
@ -1072,7 +1089,16 @@ iScroll.prototype = {
} }
}; };
function prefixStyle (style) {
if ( vendor === '' ) return style;
style = style.charAt(0).toUpperCase() + style.substr(1);
return vendor + style;
}
dummyStyle = null; // for the sake of it
if (typeof exports !== 'undefined') exports.iScroll = iScroll; if (typeof exports !== 'undefined') exports.iScroll = iScroll;
else window.iScroll = iScroll; else window.iScroll = iScroll;
})(); })(window, document);

View File

@ -311,7 +311,18 @@ ViewNavigator.prototype.resetScroller = function() {
var cssString = 'translate3d(0px, '+(originalTopMargin).toString()+'px, 0px)'; var cssString = 'translate3d(0px, '+(originalTopMargin).toString()+'px, 0px)';
targetDiv.css( '-webkit-transform', cssString ); targetDiv.css( '-webkit-transform', cssString );
} }
self.scroller = new iScroll( id ); self.scroller = new iScroll( id , {
useTransition: true,
onBeforeScrollStart: function (e) {
var target = e.target;
while ( target.nodeType != 1 ) target = target.parentNode;
if ( target.tagName !== 'SELECT' && target.tagName !== 'INPUT' && target.tagName !== 'TEXTAREA' ) {
e.preventDefault();
}
}
});
if ( currentViewDescriptor.maintainScrollPosition !== false && scrollY != undefined && scrollY != '' ) { if ( currentViewDescriptor.maintainScrollPosition !== false && scrollY != undefined && scrollY != '' ) {
self.scroller.scrollTo( 0, parseInt( scrollY, 10 ) ); self.scroller.scrollTo( 0, parseInt( scrollY, 10 ) );
} }