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
Expand Up @@ -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",
Expand Down
16 changes: 9 additions & 7 deletions js/jquery.mobile.event.js
Expand Up @@ -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 );
}

Expand All @@ -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 );
});
}
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.mobile.forms.select.custom.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 1 addition & 8 deletions js/jquery.mobile.forms.slider.js
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion js/jquery.mobile.media.classes.js
Expand Up @@ -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 ) {
Expand Down
82 changes: 44 additions & 38 deletions js/jquery.mobile.navigation.js
Expand Up @@ -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();
}
}

Expand All @@ -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 } );
}
Expand All @@ -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 ) {
Expand All @@ -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(){
Expand Down
4 changes: 3 additions & 1 deletion js/jquery.mobile.page.js
Expand Up @@ -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 );
}
});

Expand Down
23 changes: 16 additions & 7 deletions js/jquery.mobile.vmouse.js
Expand Up @@ -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();
}
}
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 04623c2

Please sign in to comment.