From 3f627acba8a3ba4fadc43dbd93bde47f10dad7e8 Mon Sep 17 00:00:00 2001 From: Kin Blas Date: Fri, 25 Feb 2011 22:20:04 -0800 Subject: [PATCH] - Added support for a vmouseevent that is triggered when a touch results in the window scrolling. - Modified the button markup behavior so that it uses the virtual mouse events and adds the ui-btn-active class on vmousedown, and then removes it on vmousemove or vmouseup. --- js/jquery.mobile.buttonMarkup.js | 14 +++++++------- js/jquery.mobile.vmouse.js | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/js/jquery.mobile.buttonMarkup.js b/js/jquery.mobile.buttonMarkup.js index a17de316..a4c77d2d 100644 --- a/js/jquery.mobile.buttonMarkup.js +++ b/js/jquery.mobile.buttonMarkup.js @@ -83,21 +83,21 @@ $.fn.buttonMarkup.defaults = { var attachEvents = function() { $(".ui-btn:not(.ui-disabled)").live({ - "touchstart mousedown": function() { + "vmousedown": function() { var theme = $(this).attr( "data-theme" ); - $(this).removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme ); + $(this).removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-down-" + theme + " " + $.mobile.activeBtnClass); }, - "touchmove touchend mouseup": function() { + "vmousemove vmouseup": function() { var theme = $(this).attr( "data-theme" ); - $(this).removeClass( "ui-btn-down-" + theme ).addClass( "ui-btn-up-" + theme ); + $(this).removeClass( "ui-btn-down-" + theme + " " + $.mobile.activeBtnClass ).addClass( "ui-btn-up-" + theme ); }, - "mouseover focus": function() { + "vmouseover focus": function() { var theme = $(this).attr( "data-theme" ); $(this).removeClass( "ui-btn-up-" + theme ).addClass( "ui-btn-hover-" + theme ); }, - "mouseout blur": function() { + "vmouseout blur": function() { var theme = $(this).attr( "data-theme" ); - $(this).removeClass( "ui-btn-hover-" + theme ).addClass( "ui-btn-up-" + theme ); + $(this).removeClass( "ui-btn-hover-" + theme + " " + $.mobile.activeBtnClass ).addClass( "ui-btn-up-" + theme ); } }); diff --git a/js/jquery.mobile.vmouse.js b/js/jquery.mobile.vmouse.js index 9d18cb7d..18b32dd9 100644 --- a/js/jquery.mobile.vmouse.js +++ b/js/jquery.mobile.vmouse.js @@ -216,6 +216,10 @@ function handleTouchStart(event) function handleScroll(event) { + if (!didScroll){ + triggerVirtualEvent("vmousecancel", event); + } + didScroll = true; startResetTimer(); } @@ -224,10 +228,14 @@ function handleTouchMove(event) { var t = getNativeEvent(event).touches[0]; + var didCancel = didScroll; didScroll = didScroll || (scrollTopSupported && (startScrollX != window.pageXOffset || startScrollY != window.pageYOffset)) || (Math.abs(t.pageX - startX) > scrollThreshold || Math.abs(t.pageY - startY) > scrollThreshold); + if (didScroll && !didCancel){ + triggerVirtualEvent("vmousecancel", event); + } triggerVirtualEvent("vmousemove", event); startResetTimer(); }