Skip to content

Commit

Permalink
Fixed (worked around) a click-jump to top problem. iScroll event rece…
Browse files Browse the repository at this point in the history
…ived an partially initialized 'that' object that causes resetPosition to scroll to Y:0 everytime. I couldn't figured out why, but could find a workaround that reinitialize required params. Ported to jonathan's way to emulate tap. It works much better on iPhone, less so on desktop which is opposited to before. Renamed touchSelectors to actionSelectors. Added tap 'status bar' to scroll to page top listener (only work inside the mobile browse, but not full screen mode.)
  • Loading branch information
thomasyip committed Feb 10, 2011
1 parent ca79a29 commit 88d23ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
14 changes: 14 additions & 0 deletions demos/iscroll/iscroll.js
Expand Up @@ -59,6 +59,10 @@ function iScroll (el, options) {
that.refresh();

window.addEventListener('onorientationchange' in window ? 'orientationchange' : 'resize', that, false);

window.addEventListener('scroll', function(){
that.scrollTo(0, 0, 1000);
}, false);

if (isTouch || that.options.desktopCompatibility) {
that.element.addEventListener(START_EVENT, that, false);
Expand Down Expand Up @@ -415,6 +419,16 @@ iScroll.prototype = {
resetX = that.x,
resetY = that.y;

if (that.maxScrollX === 0 && that.maxScrollY === 0) {
// workaround a bug that maxScrollX is not set
that.scrollWidth = that.wrapper.clientWidth;
that.scrollHeight = that.wrapper.clientHeight;
that.scrollerWidth = that.element.offsetWidth;
that.scrollerHeight = that.element.offsetHeight;
that.maxScrollX = that.scrollWidth - that.scrollerWidth;
that.maxScrollY = that.scrollHeight - that.scrollerHeight;
}

if (that.x >= 0) {
resetX = 0;
} else if (that.x < that.maxScrollX) {
Expand Down
22 changes: 11 additions & 11 deletions jqtouch/jqtouch.js
Expand Up @@ -48,7 +48,7 @@
tapReady=true,
lastTime=0,
lastAnimationTime=0,
touchSelectors=[],
actionSelectors=[],
publicObj={},
tapBuffer=351,
extensions=$.jQTouch.prototype.extensions,
Expand Down Expand Up @@ -885,8 +885,8 @@
var $el = $(e.target);

// Find the nearest tappable ancestor
if (!$el.is(touchSelectors.join(', '))) {
var $el = $(e.target).closest(touchSelectors.join(', '));
if (!$el.is(actionSelectors.join(', '))) {
var $el = $(e.target).closest(actionSelectors.join(', '));
}

// Prevent default if we found an internal link (relative or absolute)
Expand All @@ -910,9 +910,9 @@
// Grab the clicked element
var $el = $(e.currentTarget);

var anyTouchSelectors = touchSelectors.join(', ');
if (!$el.is(anyTouchSelectors)) {
var $link = $(e.target).closest(anyTouchSelectors);
var anyActionSelectors = actionSelectors.join(', ');
if (!$el.is(anyActionSelectors)) {
var $link = $(e.target).closest(anyActionSelectors);

if ($link.length) {
$el = $link;
Expand Down Expand Up @@ -1079,7 +1079,6 @@
setTimeout(function() {
handlepress(e);
}, 1000);

};

function handlemove(e) {
Expand Down Expand Up @@ -1235,14 +1234,15 @@
var name = actionNodeTypes[i];
var selector = jQTSettings[name + 'Selector'];
if (typeof(selector) == 'string' && selector.length > 0) {
touchSelectors.push(selector);
actionSelectors.push(selector);
} else {
console.warn('invalid selector for nodetype: ' + name);
}
}
$(touchSelectors.join(', ')).live('click', tapHandler);
$(touchSelectors.join(', ')).css('-webkit-touch-callout', 'none');
$(touchSelectors.join(', ')).css('-webkit-user-drag', 'none');
$(window).live('click', clickHandler);
$(actionSelectors.join(', ')).live('tap', tapHandler);
$(actionSelectors.join(', ')).css('-webkit-touch-callout', 'none');
$(actionSelectors.join(', ')).css('-webkit-user-drag', 'none');
$(document).live('touchmove', function(e) { e.preventDefault(); });

// listen to touch events
Expand Down

0 comments on commit 88d23ce

Please sign in to comment.