Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit d10fd0e

Browse files
author
Gabriel Schulhof
committed
Pagecontainer: Remove unnecessary $( ":focus" ) fallback on page change
Fixes gh-1560
1 parent 2837086 commit d10fd0e

File tree

2 files changed

+14
-35
lines changed

2 files changed

+14
-35
lines changed

js/widgets/pagecontainer.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
define( [
2222
"jquery",
2323
"../core",
24+
"jquery-ui/core",
2425
"../navigation/path",
2526
"../navigation/base",
2627
"../events/navigate",
@@ -954,12 +955,8 @@ $.widget( "mobile.pagecontainer", {
954955
},
955956

956957
transition: function( toPage, triggerData, settings ) {
957-
var fromPage, url, pageUrl, fileUrl,
958-
active, activeIsInitialPage,
959-
historyDir, pageTitle, isDialog,
960-
alreadyThere, newPageTitle,
961-
params, cssTransitionDeferred,
962-
beforeTransition;
958+
var fromPage, url, pageUrl, fileUrl, active, activeIsInitialPage, historyDir, pageTitle,
959+
isDialog, alreadyThere, newPageTitle, params, cssTransitionDeferred, beforeTransition;
963960

964961
// If we are in the midst of a transition, queue the current request.
965962
// We'll call changePage() once we're done with the current transition
@@ -1055,22 +1052,8 @@ $.widget( "mobile.pagecontainer", {
10551052
historyDir = settings.direction === "back" ? -1 : 1;
10561053
}
10571054

1058-
// Kill the keyboard.
1059-
// XXX_jblas: We need to stop crawling the entire document to kill focus.
1060-
// Instead, we should be tracking focus with a delegate()
1061-
// handler so we already have the element in hand at this
1062-
// point.
1063-
// Wrap this in a try/catch block since IE9 throw "Unspecified error" if
1064-
// document.activeElement is undefined when we are in an IFrame.
1065-
try {
1066-
if ( document.activeElement &&
1067-
document.activeElement.nodeName.toLowerCase() !== "body" ) {
1068-
1069-
$( document.activeElement ).blur();
1070-
} else {
1071-
$( "input:focus, textarea:focus, select:focus" ).blur();
1072-
}
1073-
} catch ( e ) {}
1055+
// We blur the focused element to cause the virtual keyboard to disappear
1056+
$.ui.safeBlur( $.ui.safeActiveElement( this.document[ 0 ] ) );
10741057

10751058
// Record whether we are at a place in history where a dialog used to be -
10761059
// if so, do not add a new history entry and do not change the hash either

js/widgets/popup.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
// AMD. Register as an anonymous module.
3030
define( [
3131
"jquery",
32+
"jquery-ui/core",
3233
"../widget",
3334
"../support",
3435
"../events/navigate",
@@ -365,9 +366,10 @@ $.widget( "mobile.popup", {
365366
if ( targetElement !== ui.container[ 0 ] ) {
366367
target = $( targetElement );
367368
if ( !$.contains( ui.container[ 0 ], targetElement ) ) {
368-
$( this.document[ 0 ].activeElement ).one( "focus", $.proxy( function() {
369-
this._safelyBlur( targetElement );
370-
}, this ) );
369+
$( $.ui.safeActiveElement( this.document[ 0 ] ) ).one( "focus",
370+
$.proxy( function() {
371+
$.ui.safeBlur( targetElement );
372+
}, this ) );
371373
ui.focusElement.focus();
372374
theEvent.preventDefault();
373375
theEvent.stopImmediatePropagation();
@@ -700,24 +702,18 @@ $.widget( "mobile.popup", {
700702
}
701703
},
702704

703-
_safelyBlur: function( currentElement ) {
704-
if ( currentElement !== this.window[ 0 ] &&
705-
currentElement.nodeName.toLowerCase() !== "body" ) {
706-
$( currentElement ).blur();
707-
}
708-
},
709-
710705
_openPrerequisitesComplete: function() {
711706
var id = this.element.attr( "id" ),
712-
firstFocus = this._ui.container.find( ":focusable" ).first();
707+
firstFocus = this._ui.container.find( ":focusable" ).first(),
708+
focusElement = $.ui.safeActiveElement( this.document[ 0 ] );
713709

714710
this._ui.container.addClass( "ui-popup-active" );
715711
this._isOpen = true;
716712
this._resizeScreen();
717713

718714
// Check to see if currElement is not a child of the container. If it's not, blur
719-
if ( !$.contains( this._ui.container[ 0 ], this.document[ 0 ].activeElement ) ) {
720-
this._safelyBlur( this.document[ 0 ].activeElement );
715+
if ( focusElement && !$.contains( this._ui.container[ 0 ], focusElement ) ) {
716+
$.ui.safeBlur( focusElement );
721717
}
722718
if ( firstFocus.length > 0 ) {
723719
this._ui.focusElement = firstFocus;

0 commit comments

Comments
 (0)