Permalink
Browse files

Merge branch 'master' into changepage-prevent

  • Loading branch information...
2 parents 6aa8c8f + d0fe757 commit 04623c21cf7cc5959a958362e5392cdeba3e9b42 @jblas jblas committed Sep 8, 2011
View
@@ -36,7 +36,7 @@
defaultPageTransition: "slide",
// Minimum scroll distance that will be remembered when returning to a page
- minScrollBack: screen.height / 2,
+ minScrollBack: 250,
// Set default dialog transition - 'none' for no transitions
defaultDialogTransition: "pop",
View
@@ -78,16 +78,19 @@ $.event.special.tap = {
return false;
}
- var touching = true,
- origTarget = event.target,
+ var origTarget = event.target,
origEvent = event.originalEvent,
timer;
+ function clearTapTimer() {
+ clearTimeout( timer );
+ }
+
function clearTapHandlers() {
- touching = false;
- clearTimeout(timer);
+ clearTapTimer();
$this.unbind( "vclick", clickHandler )
+ .unbind( "vmouseup", clearTapTimer )
.unbind( "vmousecancel", clearTapHandlers );
}
@@ -102,12 +105,11 @@ $.event.special.tap = {
}
$this.bind( "vmousecancel", clearTapHandlers )
+ .bind( "vmouseup", clearTapTimer )
.bind( "vclick", clickHandler );
timer = setTimeout(function() {
- if ( touching ) {
- triggerCustomEvent( thisObject, "taphold", event );
- }
+ triggerCustomEvent( thisObject, "taphold", $.Event( "taphold" ) );
}, 750 );
});
}
@@ -103,7 +103,7 @@
.delegate( ".ui-li>a", "focusout", function() {
$( this ).attr( "tabindex", "-1" );
})
- .delegate( "li:not(.ui-disabled, .ui-li-divider)", "vclick", function( event ) {
+ .delegate( "li:not(.ui-disabled, .ui-li-divider)", "click", function( event ) {
// index of option tag to be selected
var oldIndex = self.select[ 0 ].selectedIndex,
@@ -174,7 +174,7 @@
// If enter or space is pressed, trigger click
case 13:
case 32:
- target.trigger( "vclick" );
+ target.trigger( "click" );
return false;
break;
@@ -140,16 +140,9 @@ $.widget( "mobile.slider", $.mobile.widget, {
if ( !self.userModified ) {
//tap occurred, but value didn't change. flip it!
+ handle.addClass( "ui-slider-handle-snapping" );
self.refresh( !self.beforeStart ? 1 : 0 );
}
- var curval = val();
- var snapped = Math.round( curval / ( max - min ) * 100 );
- handle
- .addClass( "ui-slider-handle-snapping" )
- .css( "left", snapped + "%" )
- .animationComplete( function() {
- handle.removeClass( "ui-slider-handle-snapping" );
- });
}
return false;
}
@@ -77,7 +77,7 @@ $( document ).bind( "mobileinit.htmlclass", function() {
var ev = $.support.orientation;
- $window.bind( "orientationchange.htmlclass throttledResize.htmlclass", function( event ) {
+ $window.bind( "orientationchange.htmlclass throttledresize.htmlclass", function( event ) {
// add orientation class to HTML element on flip/resize.
if ( event.orientation ) {
@@ -354,20 +354,13 @@
//direct focus to the page title, or otherwise first focusable element
function reFocus( page ) {
- var lastClicked = page.jqmData( "lastClicked" );
+ var pageTitle = page.find( ".ui-title:eq(0)" );
- if( lastClicked && lastClicked.length ) {
- lastClicked.focus();
+ if( pageTitle.length ) {
+ pageTitle.focus();
}
- else {
- var pageTitle = page.find( ".ui-title:eq(0)" );
-
- if( pageTitle.length ) {
- pageTitle.focus();
- }
- else{
- page.find( focusable ).eq( 0 ).focus();
- }
+ else{
+ page.focus();
}
}
@@ -385,32 +378,46 @@
$.mobile.changePage.apply( null, pageTransitionQueue.pop() );
}
}
+
+ // Save the last scroll distance per page, before it is hidden
+ var getLastScroll = (function( lastScrollEnabled ){
+ return function(){
+ if( !lastScrollEnabled ){
+ lastScrollEnabled = true;
+ return;
+ }
+
+ lastScrollEnabled = false;
+
+ var active = $.mobile.urlHistory.getActive();
+
+ if( active ){
+ var lastScroll = $( window ).scrollTop();
+
+ // Set active page's lastScroll prop.
+ // If the Y location we're scrolling to is less than minScrollBack, let it go.
+ active.lastScroll = lastScroll < $.mobile.minScrollBack ? $.mobile.defaultHomeScroll : lastScroll;
+ }
+ };
+ })( true );
+
+ // to get last scroll, we need to get scrolltop before the page change
+ // using beforechangepage or popstate/hashchange (whichever comes first)
+ $( document ).bind( "beforechangepage", getLastScroll );
+ $( window ).bind( $.support.pushState ? "popstate" : "hashchange", getLastScroll );
//function for transitioning between two existing pages
function transitionPages( toPage, fromPage, transition, reverse ) {
//get current scroll distance
- var currScroll = $.support.scrollTop ? $window.scrollTop() : true,
- toScroll = toPage.data( "lastScroll" ) || $.mobile.defaultHomeScroll,
+ var active = $.mobile.urlHistory.getActive(),
+ toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
screenHeight = getScreenHeight();
- //if scrolled down, scroll to top
- if( currScroll ){
- window.scrollTo( 0, $.mobile.defaultHomeScroll );
- }
-
- //if the Y location we're scrolling to is less than 10px, let it go for sake of smoothness
- if( toScroll < $.mobile.minScrollBack ){
- toScroll = 0;
- }
+ // Scroll to top
+ window.scrollTo( 0, $.mobile.defaultHomeScroll );
if( fromPage ) {
- //set as data for returning to that spot
- fromPage
- .height( screenHeight + currScroll )
- .jqmData( "lastScroll", currScroll )
- .jqmData( "lastClicked", $activeClickedLink );
-
//trigger before show/hide events
fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
}
@@ -430,15 +437,12 @@
promise.done(function() {
//reset toPage height bac
toPage.height( "" );
-
- //jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
- if( toScroll ){
- $.mobile.silentScroll( toScroll );
- $( document ).one( "silentscroll", function() { reFocus( toPage ); } );
- }
- else{
- reFocus( toPage );
- }
+
+ // Send focus to the newly shown page
+ reFocus( toPage );
+
+ // Jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
+ $.mobile.silentScroll( toScroll );
//trigger show/hide events
if( fromPage ) {
@@ -463,6 +467,8 @@
return pageMin;
}
+
+ $.mobile.getScreenHeight = getScreenHeight;
//simply set the active page's minimum height to screen height, depending on orientation
function resetActivePageHeight(){
View
@@ -17,7 +17,9 @@ $.widget( "mobile.page", $.mobile.widget, {
this._trigger( "beforecreate" );
- this.element.addClass( "ui-page ui-body-" + this.options.theme );
+ this.element
+ .attr( "tabindex", "0" )
+ .addClass( "ui-page ui-body-" + this.options.theme );
}
});
View
@@ -164,27 +164,35 @@ function clearResetTimer() {
}
function triggerVirtualEvent( eventType, event, flags ) {
- var defaultPrevented = false,
- ve;
+ var ve;
if ( ( flags && flags[ eventType ] ) ||
( !flags && getClosestElementWithVirtualBinding( event.target, eventType ) ) ) {
ve = createVirtualEvent( event, eventType );
$( event.target).trigger( ve );
-
- defaultPrevented = ve.isDefaultPrevented();
}
- return defaultPrevented;
+ return ve;
}
function mouseEventCallback( event ) {
var touchID = $.data(event.target, touchTargetPropertyName);
if ( !blockMouseTriggers && ( !lastTouchID || lastTouchID !== touchID ) ){
- triggerVirtualEvent( "v" + event.type, event );
+ var ve = triggerVirtualEvent( "v" + event.type, event );
+ if ( ve ) {
+ if ( ve.isDefaultPrevented() ) {
+ event.preventDefault();
+ }
+ if ( ve.isPropagationStopped() ) {
+ event.stopPropagation();
+ }
+ if ( ve.isImmediatePropagationStopped() ) {
+ event.stopImmediatePropagation();
+ }
+ }
}
}
@@ -264,7 +272,8 @@ function handleTouchEnd( event ) {
triggerVirtualEvent( "vmouseup", event, flags );
if ( !didScroll ) {
- if ( triggerVirtualEvent( "vclick", event, flags ) ) {
+ var ve = triggerVirtualEvent( "vclick", event, flags );
+ if ( ve && ve.isDefaultPrevented() ) {
// The target of the mouse events that follow the touchend
// event don't necessarily match the target used during the
// touch. This means we need to rely on coordinates for blocking
Oops, something went wrong.

0 comments on commit 04623c2

Please sign in to comment.