Skip to content

Commit

Permalink
hell lot of fixes cubiq#469 cubiq#427 cubiq#482 cubiq#466 and others
Browse files Browse the repository at this point in the history
  • Loading branch information
cubiq committed Sep 16, 2013
1 parent dc40c9e commit dc9b0b3
Show file tree
Hide file tree
Showing 19 changed files with 566 additions and 144 deletions.
50 changes: 20 additions & 30 deletions build/iscroll-lite.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! iScroll v5.0.4 ~ (c) 2008-2013 Matteo Spinelli ~ http://cubiq.org/license */
/*! iScroll v5.0.5 ~ (c) 2008-2013 Matteo Spinelli ~ http://cubiq.org/license */
var IScroll = (function (window, document, Math) {
var rAF = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
Expand Down Expand Up @@ -113,7 +113,7 @@ var utils = (function () {
}

var re = new RegExp("(^|\\s)" + c + "(\\s|$)", 'g');
e.className = e.className.replace(re, '');
e.className = e.className.replace(re, ' ');
};

me.offset = function (el) {
Expand All @@ -133,6 +133,16 @@ var utils = (function () {
};
};

me.preventDefaultException = function (el, exceptions) {
for ( var i in exceptions ) {
if ( exceptions[i].test(el[i]) ) {
return true;
}
}

return false;
};

me.extend(me.eventType = {}, {
touchstart: 1,
touchmove: 1,
Expand Down Expand Up @@ -242,6 +252,7 @@ function IScroll (el, options) {
bounceEasing: '',

preventDefault: true,
preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ },

HWCompositing: true,
useTransition: true,
Expand Down Expand Up @@ -296,7 +307,7 @@ function IScroll (el, options) {
}

IScroll.prototype = {
version: '5.0.4',
version: '5.0.5',

_init: function () {
this._initEvents();
Expand Down Expand Up @@ -334,7 +345,7 @@ IScroll.prototype = {
return;
}

if ( this.options.preventDefault && !utils.isAndroidBrowser ) {
if ( this.options.preventDefault && !utils.isAndroidBrowser && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) {
e.preventDefault(); // This seems to break default Android browser
}

Expand Down Expand Up @@ -466,8 +477,8 @@ IScroll.prototype = {
return;
}

if ( this.options.preventDefault ) {
e.preventDefault(); // TODO: check if needed
if ( this.options.preventDefault && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) {
e.preventDefault();
}

var point = e.changedTouches ? e.changedTouches[0] : e,
Expand Down Expand Up @@ -520,21 +531,7 @@ IScroll.prototype = {
this.isInTransition = 1;
}

if ( this.options.snap ) {
var snap = this._nearestSnap(newX, newY);
this.currentPage = snap;
newX = snap.x;
newY = snap.y;
time = this.options.snapSpeed || Math.max(
Math.max(
Math.min(distanceX, 1000),
Math.min(distanceX, 1000)
), 300);

this.directionX = 0;
this.directionY = 0;
easing = this.options.bounceEasing;
}
// INSERT POINT: _end

if ( newX != this.x || newY != this.y ) {
// change easing function when scroller goes out of the boundaries
Expand Down Expand Up @@ -633,15 +630,8 @@ IScroll.prototype = {

this.resetPosition();

if ( this.options.snap ) {
var snap = this._nearestSnap(this.x, this.y);
if ( this.x == snap.x && this.y == snap.y ) {
return;
}
// INSERT POINT: _refresh

this.currentPage = snap;
this.scrollTo(snap.x, snap.y);
}
},

on: function (type, fn) {
Expand Down Expand Up @@ -715,7 +705,7 @@ IScroll.prototype = {
pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left;
pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top;

time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(pos.left)*2, Math.abs(pos.top)*2) : time;
time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(this.x-pos.left), Math.abs(this.y-pos.top)) : time;

this.scrollTo(pos.left, pos.top, time, easing);
},
Expand Down
100 changes: 77 additions & 23 deletions build/iscroll-probe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! iScroll v5.0.4 ~ (c) 2008-2013 Matteo Spinelli ~ http://cubiq.org/license */
/*! iScroll v5.0.5 ~ (c) 2008-2013 Matteo Spinelli ~ http://cubiq.org/license */
var IScroll = (function (window, document, Math) {
var rAF = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
Expand Down Expand Up @@ -113,7 +113,7 @@ var utils = (function () {
}

var re = new RegExp("(^|\\s)" + c + "(\\s|$)", 'g');
e.className = e.className.replace(re, '');
e.className = e.className.replace(re, ' ');
};

me.offset = function (el) {
Expand All @@ -133,6 +133,16 @@ var utils = (function () {
};
};

me.preventDefaultException = function (el, exceptions) {
for ( var i in exceptions ) {
if ( exceptions[i].test(el[i]) ) {
return true;
}
}

return false;
};

me.extend(me.eventType = {}, {
touchstart: 1,
touchmove: 1,
Expand Down Expand Up @@ -248,6 +258,7 @@ function IScroll (el, options) {
bounceEasing: '',

preventDefault: true,
preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ },

HWCompositing: true,
useTransition: true,
Expand Down Expand Up @@ -307,7 +318,7 @@ function IScroll (el, options) {
}

IScroll.prototype = {
version: '5.0.4',
version: '5.0.5',

_init: function () {
this._initEvents();
Expand Down Expand Up @@ -361,7 +372,7 @@ IScroll.prototype = {
return;
}

if ( this.options.preventDefault && !utils.isAndroidBrowser ) {
if ( this.options.preventDefault && !utils.isAndroidBrowser && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) {
e.preventDefault(); // This seems to break default Android browser
}

Expand Down Expand Up @@ -499,8 +510,8 @@ IScroll.prototype = {
return;
}

if ( this.options.preventDefault ) {
e.preventDefault(); // TODO: check if needed
if ( this.options.preventDefault && !utils.preventDefaultException(e.target, this.options.preventDefaultException) ) {
e.preventDefault();
}

var point = e.changedTouches ? e.changedTouches[0] : e,
Expand Down Expand Up @@ -553,22 +564,25 @@ IScroll.prototype = {
this.isInTransition = 1;
}


if ( this.options.snap ) {
var snap = this._nearestSnap(newX, newY);
this.currentPage = snap;
newX = snap.x;
newY = snap.y;
time = this.options.snapSpeed || Math.max(
Math.max(
Math.min(distanceX, 1000),
Math.min(distanceX, 1000)
Math.min(Math.abs(newX - snap.x), 1000),
Math.min(Math.abs(newY - snap.y), 1000)
), 300);
newX = snap.x;
newY = snap.y;

this.directionX = 0;
this.directionY = 0;
easing = this.options.bounceEasing;
}

// INSERT POINT: _end

if ( newX != this.x || newY != this.y ) {
// change easing function when scroller goes out of the boundaries
if ( newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY ) {
Expand Down Expand Up @@ -666,15 +680,8 @@ IScroll.prototype = {

this.resetPosition();

if ( this.options.snap ) {
var snap = this._nearestSnap(this.x, this.y);
if ( this.x == snap.x && this.y == snap.y ) {
return;
}
// INSERT POINT: _refresh

this.currentPage = snap;
this.scrollTo(snap.x, snap.y);
}
},

on: function (type, fn) {
Expand Down Expand Up @@ -748,7 +755,7 @@ IScroll.prototype = {
pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left;
pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top;

time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(pos.left)*2, Math.abs(pos.top)*2) : time;
time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(this.x-pos.left), Math.abs(this.y-pos.top)) : time;

this.scrollTo(pos.left, pos.top, time, easing);
},
Expand Down Expand Up @@ -981,6 +988,28 @@ IScroll.prototype = {

if ( !this.hasVerticalScroll ) {
wheelDeltaX = wheelDeltaY;
wheelDeltaY = 0;
}

if ( this.options.snap ) {
newX = this.currentPage.pageX;
newY = this.currentPage.pageY;

if ( wheelDeltaX > 0 ) {
newX--;
} else if ( wheelDeltaX < 0 ) {
newX++;
}

if ( wheelDeltaY > 0 ) {
newY--;
} else if ( wheelDeltaY < 0 ) {
newY++;
}

this.goToPage(newX, newY);

return;
}

newX = this.x + (this.hasHorizontalScroll ? wheelDeltaX * this.options.invertWheelDirection : 0);
Expand Down Expand Up @@ -1025,6 +1054,10 @@ IScroll.prototype = {

this.pages = [];

if ( !this.wrapperWidth || !this.wrapperHeight || !this.scrollerWidth || !this.scrollerHeight ) {
return;
}

if ( this.options.snap === true ) {
cx = Math.round( stepX / 2 );
cy = Math.round( stepY / 2 );
Expand Down Expand Up @@ -1114,6 +1147,10 @@ IScroll.prototype = {
},

_nearestSnap: function (x, y) {
if ( !this.pages.length ) {
return { x: 0, y: 0, pageX: 0, pageY: 0 };
}

var i = 0,
l = this.pages.length,
m = 0;
Expand Down Expand Up @@ -1193,8 +1230,8 @@ IScroll.prototype = {
x = 0;
}

if ( y >= this.pages[0].length ) {
y = this.pages[0].length - 1;
if ( y >= this.pages[x].length ) {
y = this.pages[x].length - 1;
} else if ( y < 0 ) {
y = 0;
}
Expand Down Expand Up @@ -1622,6 +1659,23 @@ Indicator.prototype = {
utils.removeEvent(window, 'MSPointerMove', this);
utils.removeEvent(window, 'mousemove', this);

if ( this.scroller.options.snap ) {
var snap = this.scroller._nearestSnap(this.scroller.x, this.scroller.y);

var time = this.options.snapSpeed || Math.max(
Math.max(
Math.min(Math.abs(this.scroller.x - snap.x), 1000),
Math.min(Math.abs(this.scroller.y - snap.y), 1000)
), 300);

if ( this.scroller.x != snap.x || this.scroller.y != snap.y ) {
this.scroller.directionX = 0;
this.scroller.directionY = 0;
this.scroller.currentPage = snap;
this.scroller.scrollTo(snap.x, snap.y, time, this.scroller.options.bounceEasing);
}
}

if ( this.moved ) {
this.scroller._execEvent('scrollEnd');
}
Expand Down Expand Up @@ -1676,7 +1730,7 @@ Indicator.prototype = {
if ( this.options.listenX ) {
this.wrapperWidth = this.wrapper.clientWidth;
if ( this.options.resize ) {
this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / this.scroller.scrollerWidth), 8);
this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8);
this.indicatorStyle.width = this.indicatorWidth + 'px';
} else {
this.indicatorWidth = this.indicator.clientWidth;
Expand All @@ -1688,7 +1742,7 @@ Indicator.prototype = {
if ( this.options.listenY ) {
this.wrapperHeight = this.wrapper.clientHeight;
if ( this.options.resize ) {
this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / this.scroller.scrollerHeight), 8);
this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / (this.scroller.scrollerHeight || this.wrapperHeight || 1)), 8);
this.indicatorStyle.height = this.indicatorHeight + 'px';
} else {
this.indicatorHeight = this.indicator.clientHeight;
Expand Down
Loading

0 comments on commit dc9b0b3

Please sign in to comment.