|
@@ -75,7 +75,15 @@ var m = Math,
|
|
|
|
|
|
|
|
// Events
|
|
// Events
|
|
|
onRefresh: null,
|
|
onRefresh: null,
|
|
|
- onBeforeScrollStart: function (e) { e.preventDefault(); },
|
|
|
|
|
|
|
+ onBeforeScrollStart: function (e) {
|
|
|
|
|
+ //e.preventDefault();
|
|
|
|
|
+ var target = e.target;
|
|
|
|
|
+ while (target.nodeType != 1) target = target.parentNode;
|
|
|
|
|
+
|
|
|
|
|
+ if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA') {
|
|
|
|
|
+ e.preventDefault();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
onScrollStart: null,
|
|
onScrollStart: null,
|
|
|
onBeforeScrollMove: null,
|
|
onBeforeScrollMove: null,
|
|
|
onScrollMove: null,
|
|
onScrollMove: null,
|
|
@@ -103,7 +111,7 @@ var m = Math,
|
|
|
that.scroller.style[vendor + 'TransitionDuration'] = '0';
|
|
that.scroller.style[vendor + 'TransitionDuration'] = '0';
|
|
|
that.scroller.style[vendor + 'TransformOrigin'] = '0 0';
|
|
that.scroller.style[vendor + '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[vendor + '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[vendor + 'Transform'] = trnOpen + that.x + 'px,' + that.y + 'px' + trnClose;
|
|
|
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';
|
|
|
|
|
|
|
@@ -121,7 +129,7 @@ iScroll.prototype = {
|
|
|
y: 0,
|
|
y: 0,
|
|
|
steps: [],
|
|
steps: [],
|
|
|
scale: 1,
|
|
scale: 1,
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
handleEvent: function (e) {
|
|
handleEvent: function (e) {
|
|
|
var that = this;
|
|
var that = this;
|
|
|
switch(e.type) {
|
|
switch(e.type) {
|
|
@@ -141,7 +149,7 @@ iScroll.prototype = {
|
|
|
_resize: function () {
|
|
_resize: function () {
|
|
|
this.refresh();
|
|
this.refresh();
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
_pos: function (x, y) {
|
|
_pos: function (x, y) {
|
|
|
x = this.hScroll ? x : 0;
|
|
x = this.hScroll ? x : 0;
|
|
|
y = this.vScroll ? y : 0;
|
|
y = this.vScroll ? y : 0;
|
|
@@ -167,7 +175,7 @@ iScroll.prototype = {
|
|
|
if (!that.enabled) return;
|
|
if (!that.enabled) return;
|
|
|
|
|
|
|
|
if (that.options.onBeforeScrollStart) that.options.onBeforeScrollStart.call(that, e);
|
|
if (that.options.onBeforeScrollStart) that.options.onBeforeScrollStart.call(that, e);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (that.options.useTransition) that._transitionTime(0);
|
|
if (that.options.useTransition) that._transitionTime(0);
|
|
|
|
|
|
|
|
that.moved = false;
|
|
that.moved = false;
|
|
@@ -190,7 +198,7 @@ iScroll.prototype = {
|
|
|
x = getComputedStyle(that.scroller, null).left.replace(/[^0-9-]/g, '') * 1;
|
|
x = getComputedStyle(that.scroller, null).left.replace(/[^0-9-]/g, '') * 1;
|
|
|
y = getComputedStyle(that.scroller, null).top.replace(/[^0-9-]/g, '') * 1;
|
|
y = getComputedStyle(that.scroller, null).top.replace(/[^0-9-]/g, '') * 1;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
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('webkitTransitionEnd');
|
|
|
else cancelFrame(that.aniTime);
|
|
else cancelFrame(that.aniTime);
|
|
@@ -212,7 +220,7 @@ iScroll.prototype = {
|
|
|
that._bind(END_EV);
|
|
that._bind(END_EV);
|
|
|
that._bind(CANCEL_EV);
|
|
that._bind(CANCEL_EV);
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
_move: function (e) {
|
|
_move: function (e) {
|
|
|
var that = this,
|
|
var that = this,
|
|
|
point = hasTouch ? e.touches[0] : e,
|
|
point = hasTouch ? e.touches[0] : e,
|
|
@@ -231,7 +239,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 > 0 || newY < that.maxScrollY) {
|
|
|
|
|
|
|
+ if (newY > 0 || newY < that.maxScrollY) {
|
|
|
newY = that.options.bounce ? that.y + (deltaY / 2) : newY >= 0 || that.maxScrollY >= 0 ? 0 : that.maxScrollY;
|
|
newY = that.options.bounce ? that.y + (deltaY / 2) : newY >= 0 || that.maxScrollY >= 0 ? 0 : that.maxScrollY;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -265,10 +273,10 @@ iScroll.prototype = {
|
|
|
that.startX = that.x;
|
|
that.startX = that.x;
|
|
|
that.startY = that.y;
|
|
that.startY = that.y;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (that.options.onScrollMove) that.options.onScrollMove.call(that, e);
|
|
if (that.options.onScrollMove) that.options.onScrollMove.call(that, e);
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
_end: function (e) {
|
|
_end: function (e) {
|
|
|
if (hasTouch && e.touches.length != 0) return;
|
|
if (hasTouch && e.touches.length != 0) return;
|
|
|
|
|
|
|
@@ -334,7 +342,7 @@ iScroll.prototype = {
|
|
|
that._resetPos(200);
|
|
that._resetPos(200);
|
|
|
if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
|
|
if (that.options.onTouchEnd) that.options.onTouchEnd.call(that, e);
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
_resetPos: function (time) {
|
|
_resetPos: function (time) {
|
|
|
var that = this,
|
|
var that = this,
|
|
|
resetX = that.x >= 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x,
|
|
resetX = that.x >= 0 ? 0 : that.x < that.maxScrollX ? that.maxScrollX : that.x,
|
|
@@ -351,7 +359,7 @@ iScroll.prototype = {
|
|
|
|
|
|
|
|
that.scrollTo(resetX, resetY, time || 0);
|
|
that.scrollTo(resetX, resetY, time || 0);
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
_mouseout: function (e) {
|
|
_mouseout: function (e) {
|
|
|
var t = e.relatedTarget;
|
|
var t = e.relatedTarget;
|
|
|
|
|
|
|
@@ -361,7 +369,7 @@ iScroll.prototype = {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
while (t = t.parentNode) if (t == this.wrapper) return;
|
|
while (t = t.parentNode) if (t == this.wrapper) return;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
this._end(e);
|
|
this._end(e);
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -371,7 +379,7 @@ iScroll.prototype = {
|
|
|
if (e.target != that.scroller) return;
|
|
if (e.target != that.scroller) return;
|
|
|
|
|
|
|
|
that._unbind('webkitTransitionEnd');
|
|
that._unbind('webkitTransitionEnd');
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
that._startAni();
|
|
that._startAni();
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -409,7 +417,7 @@ iScroll.prototype = {
|
|
|
else that._resetPos(0);
|
|
else that._resetPos(0);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
animate = function () {
|
|
animate = function () {
|
|
|
var now = Date.now(),
|
|
var now = Date.now(),
|
|
|
newX, newY;
|
|
newX, newY;
|
|
@@ -429,21 +437,21 @@ iScroll.prototype = {
|
|
|
that._pos(newX, newY);
|
|
that._pos(newX, newY);
|
|
|
if (that.animating) that.aniTime = nextFrame(animate);
|
|
if (that.animating) that.aniTime = nextFrame(animate);
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
animate();
|
|
animate();
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
_transitionTime: function (time) {
|
|
_transitionTime: function (time) {
|
|
|
this.scroller.style[vendor + 'TransitionDuration'] = time + 'ms';
|
|
this.scroller.style[vendor + 'TransitionDuration'] = time + 'ms';
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
_momentum: function (dist, time, maxDistUpper, maxDistLower, size) {
|
|
_momentum: function (dist, time, maxDistUpper, maxDistLower, size) {
|
|
|
var deceleration = 0.0006,
|
|
var deceleration = 0.0006,
|
|
|
speed = m.abs(dist) / time,
|
|
speed = m.abs(dist) / time,
|
|
|
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;
|
|
@@ -465,11 +473,11 @@ iScroll.prototype = {
|
|
|
_offset: function (el) {
|
|
_offset: function (el) {
|
|
|
var left = -el.offsetLeft,
|
|
var left = -el.offsetLeft,
|
|
|
top = -el.offsetTop;
|
|
top = -el.offsetTop;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
while (el = el.offsetParent) {
|
|
while (el = el.offsetParent) {
|
|
|
left -= el.offsetLeft;
|
|
left -= el.offsetLeft;
|
|
|
top -= el.offsetTop;
|
|
top -= el.offsetTop;
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return { left: left, top: top };
|
|
return { left: left, top: top };
|
|
|
},
|
|
},
|
|
@@ -501,7 +509,7 @@ iScroll.prototype = {
|
|
|
that._unbind(CANCEL_EV);
|
|
that._unbind(CANCEL_EV);
|
|
|
that._unbind('mouseout', that.wrapper);
|
|
that._unbind('mouseout', that.wrapper);
|
|
|
if (that.options.useTransition) that._unbind('webkitTransitionEnd');
|
|
if (that.options.useTransition) that._unbind('webkitTransitionEnd');
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (that.options.onDestroy) that.options.onDestroy.call(that);
|
|
if (that.options.onDestroy) that.options.onDestroy.call(that);
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -540,7 +548,7 @@ iScroll.prototype = {
|
|
|
that.stop();
|
|
that.stop();
|
|
|
|
|
|
|
|
if (!step.length) step = [{ x: x, y: y, time: time, relative: relative }];
|
|
if (!step.length) step = [{ x: x, y: y, time: time, relative: relative }];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
for (i=0, l=step.length; i<l; i++) {
|
|
for (i=0, l=step.length; i<l; i++) {
|
|
|
if (step[i].relative) { step[i].x = that.x - step[i].x; step[i].y = that.y - step[i].y; }
|
|
if (step[i].relative) { step[i].x = that.x - step[i].x; step[i].y = that.y - step[i].y; }
|
|
|
that.steps.push({ x: step[i].x, y: step[i].y, time: step[i].time || 0 });
|
|
that.steps.push({ x: step[i].x, y: step[i].y, time: step[i].time || 0 });
|
|
@@ -575,11 +583,11 @@ iScroll.prototype = {
|
|
|
this._unbind(END_EV);
|
|
this._unbind(END_EV);
|
|
|
this._unbind(CANCEL_EV);
|
|
this._unbind(CANCEL_EV);
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
enable: function () {
|
|
enable: function () {
|
|
|
this.enabled = true;
|
|
this.enabled = true;
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
stop: function () {
|
|
stop: function () {
|
|
|
cancelFrame(this.aniTime);
|
|
cancelFrame(this.aniTime);
|
|
|
this.steps = [];
|
|
this.steps = [];
|
|
@@ -591,4 +599,4 @@ iScroll.prototype = {
|
|
|
if (typeof exports !== 'undefined') exports.iScroll = iScroll;
|
|
if (typeof exports !== 'undefined') exports.iScroll = iScroll;
|
|
|
else window.iScroll = iScroll;
|
|
else window.iScroll = iScroll;
|
|
|
|
|
|
|
|
-})();
|
|
|
|
|
|
|
+})();
|