Skip to content

Commit 04623c2

Browse files
committed
Merge branch 'master' into changepage-prevent
2 parents 6aa8c8f + d0fe757 commit 04623c2

11 files changed

+238
-107
lines changed

js/jquery.mobile.core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
defaultPageTransition: "slide",
3737

3838
// Minimum scroll distance that will be remembered when returning to a page
39-
minScrollBack: screen.height / 2,
39+
minScrollBack: 250,
4040

4141
// Set default dialog transition - 'none' for no transitions
4242
defaultDialogTransition: "pop",

js/jquery.mobile.event.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,19 @@ $.event.special.tap = {
7878
return false;
7979
}
8080

81-
var touching = true,
82-
origTarget = event.target,
81+
var origTarget = event.target,
8382
origEvent = event.originalEvent,
8483
timer;
8584

85+
function clearTapTimer() {
86+
clearTimeout( timer );
87+
}
88+
8689
function clearTapHandlers() {
87-
touching = false;
88-
clearTimeout(timer);
90+
clearTapTimer();
8991

9092
$this.unbind( "vclick", clickHandler )
93+
.unbind( "vmouseup", clearTapTimer )
9194
.unbind( "vmousecancel", clearTapHandlers );
9295
}
9396

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

104107
$this.bind( "vmousecancel", clearTapHandlers )
108+
.bind( "vmouseup", clearTapTimer )
105109
.bind( "vclick", clickHandler );
106110

107111
timer = setTimeout(function() {
108-
if ( touching ) {
109-
triggerCustomEvent( thisObject, "taphold", event );
110-
}
112+
triggerCustomEvent( thisObject, "taphold", $.Event( "taphold" ) );
111113
}, 750 );
112114
});
113115
}

js/jquery.mobile.forms.select.custom.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
.delegate( ".ui-li>a", "focusout", function() {
104104
$( this ).attr( "tabindex", "-1" );
105105
})
106-
.delegate( "li:not(.ui-disabled, .ui-li-divider)", "vclick", function( event ) {
106+
.delegate( "li:not(.ui-disabled, .ui-li-divider)", "click", function( event ) {
107107

108108
// index of option tag to be selected
109109
var oldIndex = self.select[ 0 ].selectedIndex,
@@ -174,7 +174,7 @@
174174
// If enter or space is pressed, trigger click
175175
case 13:
176176
case 32:
177-
target.trigger( "vclick" );
177+
target.trigger( "click" );
178178

179179
return false;
180180
break;

js/jquery.mobile.forms.slider.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,9 @@ $.widget( "mobile.slider", $.mobile.widget, {
140140

141141
if ( !self.userModified ) {
142142
//tap occurred, but value didn't change. flip it!
143+
handle.addClass( "ui-slider-handle-snapping" );
143144
self.refresh( !self.beforeStart ? 1 : 0 );
144145
}
145-
var curval = val();
146-
var snapped = Math.round( curval / ( max - min ) * 100 );
147-
handle
148-
.addClass( "ui-slider-handle-snapping" )
149-
.css( "left", snapped + "%" )
150-
.animationComplete( function() {
151-
handle.removeClass( "ui-slider-handle-snapping" );
152-
});
153146
}
154147
return false;
155148
}

js/jquery.mobile.media.classes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ $( document ).bind( "mobileinit.htmlclass", function() {
7777

7878
var ev = $.support.orientation;
7979

80-
$window.bind( "orientationchange.htmlclass throttledResize.htmlclass", function( event ) {
80+
$window.bind( "orientationchange.htmlclass throttledresize.htmlclass", function( event ) {
8181

8282
// add orientation class to HTML element on flip/resize.
8383
if ( event.orientation ) {

js/jquery.mobile.navigation.js

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -354,20 +354,13 @@
354354

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

359-
if( lastClicked && lastClicked.length ) {
360-
lastClicked.focus();
359+
if( pageTitle.length ) {
360+
pageTitle.focus();
361361
}
362-
else {
363-
var pageTitle = page.find( ".ui-title:eq(0)" );
364-
365-
if( pageTitle.length ) {
366-
pageTitle.focus();
367-
}
368-
else{
369-
page.find( focusable ).eq( 0 ).focus();
370-
}
362+
else{
363+
page.focus();
371364
}
372365
}
373366

@@ -385,32 +378,46 @@
385378
$.mobile.changePage.apply( null, pageTransitionQueue.pop() );
386379
}
387380
}
381+
382+
// Save the last scroll distance per page, before it is hidden
383+
var getLastScroll = (function( lastScrollEnabled ){
384+
return function(){
385+
if( !lastScrollEnabled ){
386+
lastScrollEnabled = true;
387+
return;
388+
}
389+
390+
lastScrollEnabled = false;
391+
392+
var active = $.mobile.urlHistory.getActive();
393+
394+
if( active ){
395+
var lastScroll = $( window ).scrollTop();
396+
397+
// Set active page's lastScroll prop.
398+
// If the Y location we're scrolling to is less than minScrollBack, let it go.
399+
active.lastScroll = lastScroll < $.mobile.minScrollBack ? $.mobile.defaultHomeScroll : lastScroll;
400+
}
401+
};
402+
})( true );
403+
404+
// to get last scroll, we need to get scrolltop before the page change
405+
// using beforechangepage or popstate/hashchange (whichever comes first)
406+
$( document ).bind( "beforechangepage", getLastScroll );
407+
$( window ).bind( $.support.pushState ? "popstate" : "hashchange", getLastScroll );
388408

389409
//function for transitioning between two existing pages
390410
function transitionPages( toPage, fromPage, transition, reverse ) {
391411

392412
//get current scroll distance
393-
var currScroll = $.support.scrollTop ? $window.scrollTop() : true,
394-
toScroll = toPage.data( "lastScroll" ) || $.mobile.defaultHomeScroll,
413+
var active = $.mobile.urlHistory.getActive(),
414+
toScroll = active.lastScroll || $.mobile.defaultHomeScroll,
395415
screenHeight = getScreenHeight();
396416

397-
//if scrolled down, scroll to top
398-
if( currScroll ){
399-
window.scrollTo( 0, $.mobile.defaultHomeScroll );
400-
}
401-
402-
//if the Y location we're scrolling to is less than 10px, let it go for sake of smoothness
403-
if( toScroll < $.mobile.minScrollBack ){
404-
toScroll = 0;
405-
}
417+
// Scroll to top
418+
window.scrollTo( 0, $.mobile.defaultHomeScroll );
406419

407420
if( fromPage ) {
408-
//set as data for returning to that spot
409-
fromPage
410-
.height( screenHeight + currScroll )
411-
.jqmData( "lastScroll", currScroll )
412-
.jqmData( "lastClicked", $activeClickedLink );
413-
414421
//trigger before show/hide events
415422
fromPage.data( "page" )._trigger( "beforehide", null, { nextPage: toPage } );
416423
}
@@ -430,15 +437,12 @@
430437
promise.done(function() {
431438
//reset toPage height bac
432439
toPage.height( "" );
433-
434-
//jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
435-
if( toScroll ){
436-
$.mobile.silentScroll( toScroll );
437-
$( document ).one( "silentscroll", function() { reFocus( toPage ); } );
438-
}
439-
else{
440-
reFocus( toPage );
441-
}
440+
441+
// Send focus to the newly shown page
442+
reFocus( toPage );
443+
444+
// Jump to top or prev scroll, sometimes on iOS the page has not rendered yet.
445+
$.mobile.silentScroll( toScroll );
442446

443447
//trigger show/hide events
444448
if( fromPage ) {
@@ -463,6 +467,8 @@
463467

464468
return pageMin;
465469
}
470+
471+
$.mobile.getScreenHeight = getScreenHeight;
466472

467473
//simply set the active page's minimum height to screen height, depending on orientation
468474
function resetActivePageHeight(){

js/jquery.mobile.page.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ $.widget( "mobile.page", $.mobile.widget, {
1717

1818
this._trigger( "beforecreate" );
1919

20-
this.element.addClass( "ui-page ui-body-" + this.options.theme );
20+
this.element
21+
.attr( "tabindex", "0" )
22+
.addClass( "ui-page ui-body-" + this.options.theme );
2123
}
2224
});
2325

js/jquery.mobile.vmouse.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,27 +164,35 @@ function clearResetTimer() {
164164
}
165165

166166
function triggerVirtualEvent( eventType, event, flags ) {
167-
var defaultPrevented = false,
168-
ve;
167+
var ve;
169168

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

173172
ve = createVirtualEvent( event, eventType );
174173

175174
$( event.target).trigger( ve );
176-
177-
defaultPrevented = ve.isDefaultPrevented();
178175
}
179176

180-
return defaultPrevented;
177+
return ve;
181178
}
182179

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

186183
if ( !blockMouseTriggers && ( !lastTouchID || lastTouchID !== touchID ) ){
187-
triggerVirtualEvent( "v" + event.type, event );
184+
var ve = triggerVirtualEvent( "v" + event.type, event );
185+
if ( ve ) {
186+
if ( ve.isDefaultPrevented() ) {
187+
event.preventDefault();
188+
}
189+
if ( ve.isPropagationStopped() ) {
190+
event.stopPropagation();
191+
}
192+
if ( ve.isImmediatePropagationStopped() ) {
193+
event.stopImmediatePropagation();
194+
}
195+
}
188196
}
189197
}
190198

@@ -264,7 +272,8 @@ function handleTouchEnd( event ) {
264272
triggerVirtualEvent( "vmouseup", event, flags );
265273

266274
if ( !didScroll ) {
267-
if ( triggerVirtualEvent( "vclick", event, flags ) ) {
275+
var ve = triggerVirtualEvent( "vclick", event, flags );
276+
if ( ve && ve.isDefaultPrevented() ) {
268277
// The target of the mouse events that follow the touchend
269278
// event don't necessarily match the target used during the
270279
// touch. This means we need to rely on coordinates for blocking

0 commit comments

Comments
 (0)