Skip to content

Commit

Permalink
Merge branch 'master' into changepage-prevent
Browse files Browse the repository at this point in the history
  • Loading branch information
jblas committed Sep 8, 2011
2 parents 6aa8c8f + d0fe757 commit 04623c2
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 107 deletions.
2 changes: 1 addition & 1 deletion js/jquery.mobile.core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
defaultPageTransition: "slide", defaultPageTransition: "slide",


// Minimum scroll distance that will be remembered when returning to a page // 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 // Set default dialog transition - 'none' for no transitions
defaultDialogTransition: "pop", defaultDialogTransition: "pop",
Expand Down
16 changes: 9 additions & 7 deletions js/jquery.mobile.event.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,16 +78,19 @@ $.event.special.tap = {
return false; return false;
} }


var touching = true, var origTarget = event.target,
origTarget = event.target,
origEvent = event.originalEvent, origEvent = event.originalEvent,
timer; timer;


function clearTapTimer() {
clearTimeout( timer );
}

function clearTapHandlers() { function clearTapHandlers() {
touching = false; clearTapTimer();
clearTimeout(timer);


$this.unbind( "vclick", clickHandler ) $this.unbind( "vclick", clickHandler )
.unbind( "vmouseup", clearTapTimer )
.unbind( "vmousecancel", clearTapHandlers ); .unbind( "vmousecancel", clearTapHandlers );
} }


Expand All @@ -102,12 +105,11 @@ $.event.special.tap = {
} }


$this.bind( "vmousecancel", clearTapHandlers ) $this.bind( "vmousecancel", clearTapHandlers )
.bind( "vmouseup", clearTapTimer )
.bind( "vclick", clickHandler ); .bind( "vclick", clickHandler );


timer = setTimeout(function() { timer = setTimeout(function() {
if ( touching ) { triggerCustomEvent( thisObject, "taphold", $.Event( "taphold" ) );
triggerCustomEvent( thisObject, "taphold", event );
}
}, 750 ); }, 750 );
}); });
} }
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.mobile.forms.select.custom.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
.delegate( ".ui-li>a", "focusout", function() { .delegate( ".ui-li>a", "focusout", function() {
$( this ).attr( "tabindex", "-1" ); $( 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 // index of option tag to be selected
var oldIndex = self.select[ 0 ].selectedIndex, var oldIndex = self.select[ 0 ].selectedIndex,
Expand Down Expand Up @@ -174,7 +174,7 @@
// If enter or space is pressed, trigger click // If enter or space is pressed, trigger click
case 13: case 13:
case 32: case 32:
target.trigger( "vclick" ); target.trigger( "click" );


return false; return false;
break; break;
Expand Down
9 changes: 1 addition & 8 deletions js/jquery.mobile.forms.slider.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -140,16 +140,9 @@ $.widget( "mobile.slider", $.mobile.widget, {


if ( !self.userModified ) { if ( !self.userModified ) {
//tap occurred, but value didn't change. flip it! //tap occurred, but value didn't change. flip it!
handle.addClass( "ui-slider-handle-snapping" );
self.refresh( !self.beforeStart ? 1 : 0 ); 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; return false;
} }
Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.media.classes.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ $( document ).bind( "mobileinit.htmlclass", function() {


var ev = $.support.orientation; 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. // add orientation class to HTML element on flip/resize.
if ( event.orientation ) { if ( event.orientation ) {
Expand Down
82 changes: 44 additions & 38 deletions js/jquery.mobile.navigation.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -354,20 +354,13 @@


//direct focus to the page title, or otherwise first focusable element //direct focus to the page title, or otherwise first focusable element
function reFocus( page ) { function reFocus( page ) {
var lastClicked = page.jqmData( "lastClicked" ); var pageTitle = page.find( ".ui-title:eq(0)" );


if( lastClicked && lastClicked.length ) { if( pageTitle.length ) {
lastClicked.focus(); pageTitle.focus();
} }
else { else{
var pageTitle = page.find( ".ui-title:eq(0)" ); page.focus();

if( pageTitle.length ) {
pageTitle.focus();
}
else{
page.find( focusable ).eq( 0 ).focus();
}
} }
} }


Expand All @@ -385,32 +378,46 @@
$.mobile.changePage.apply( null, pageTransitionQueue.pop() ); $.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 for transitioning between two existing pages
function transitionPages( toPage, fromPage, transition, reverse ) { function transitionPages( toPage, fromPage, transition, reverse ) {


//get current scroll distance //get current scroll distance
var currScroll = $.support.scrollTop ? $window.scrollTop() : true, var active = $.mobile.urlHistory.getActive(),
toScroll = toPage.data( "lastScroll" ) || $.mobile.defaultHomeScroll, toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
screenHeight = getScreenHeight(); screenHeight = getScreenHeight();


//if scrolled down, scroll to top // Scroll to top
if( currScroll ){ window.scrollTo( 0, $.mobile.defaultHomeScroll );
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;
}


if( fromPage ) { 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 //trigger before show/hide events
fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } ); fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
} }
Expand All @@ -430,15 +437,12 @@
promise.done(function() { promise.done(function() {
//reset toPage height bac //reset toPage height bac
toPage.height( "" ); toPage.height( "" );


//jump to top or prev scroll, sometimes on iOS the page has not rendered yet. // Send focus to the newly shown page
if( toScroll ){ reFocus( toPage );
$.mobile.silentScroll( toScroll );
$( document ).one( "silentscroll", function() { reFocus( toPage ); } ); // Jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
} $.mobile.silentScroll( toScroll );
else{
reFocus( toPage );
}


//trigger show/hide events //trigger show/hide events
if( fromPage ) { if( fromPage ) {
Expand All @@ -463,6 +467,8 @@


return pageMin; return pageMin;
} }

$.mobile.getScreenHeight = getScreenHeight;


//simply set the active page's minimum height to screen height, depending on orientation //simply set the active page's minimum height to screen height, depending on orientation
function resetActivePageHeight(){ function resetActivePageHeight(){
Expand Down
4 changes: 3 additions & 1 deletion js/jquery.mobile.page.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ $.widget( "mobile.page", $.mobile.widget, {


this._trigger( "beforecreate" ); 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 );
} }
}); });


Expand Down
23 changes: 16 additions & 7 deletions js/jquery.mobile.vmouse.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -164,27 +164,35 @@ function clearResetTimer() {
} }


function triggerVirtualEvent( eventType, event, flags ) { function triggerVirtualEvent( eventType, event, flags ) {
var defaultPrevented = false, var ve;
ve;


if ( ( flags && flags[ eventType ] ) || if ( ( flags && flags[ eventType ] ) ||
( !flags && getClosestElementWithVirtualBinding( event.target, eventType ) ) ) { ( !flags && getClosestElementWithVirtualBinding( event.target, eventType ) ) ) {


ve = createVirtualEvent( event, eventType ); ve = createVirtualEvent( event, eventType );


$( event.target).trigger( ve ); $( event.target).trigger( ve );

defaultPrevented = ve.isDefaultPrevented();
} }


return defaultPrevented; return ve;
} }


function mouseEventCallback( event ) { function mouseEventCallback( event ) {
var touchID = $.data(event.target, touchTargetPropertyName); var touchID = $.data(event.target, touchTargetPropertyName);


if ( !blockMouseTriggers && ( !lastTouchID || lastTouchID !== touchID ) ){ 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();
}
}
} }
} }


Expand Down Expand Up @@ -264,7 +272,8 @@ function handleTouchEnd( event ) {
triggerVirtualEvent( "vmouseup", event, flags ); triggerVirtualEvent( "vmouseup", event, flags );


if ( !didScroll ) { 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 // The target of the mouse events that follow the touchend
// event don't necessarily match the target used during the // event don't necessarily match the target used during the
// touch. This means we need to rely on coordinates for blocking // touch. This means we need to rely on coordinates for blocking
Expand Down
Loading

0 comments on commit 04623c2

Please sign in to comment.