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

Pagecontainer: Remove unnecessary $( ":focus" ) fallback on page change #8154

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions js/widgets/pagecontainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
define( [
"jquery",
"../core",
"jquery-ui/core",
"../navigation/path",
"../navigation/base",
"../events/navigate",
Expand Down Expand Up @@ -954,12 +955,8 @@ $.widget( "mobile.pagecontainer", {
},

transition: function( toPage, triggerData, settings ) {
var fromPage, url, pageUrl, fileUrl,
active, activeIsInitialPage,
historyDir, pageTitle, isDialog,
alreadyThere, newPageTitle,
params, cssTransitionDeferred,
beforeTransition;
var fromPage, url, pageUrl, fileUrl, active, activeIsInitialPage, historyDir, pageTitle,
isDialog, alreadyThere, newPageTitle, params, cssTransitionDeferred, beforeTransition;

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

// Kill the keyboard.
// XXX_jblas: We need to stop crawling the entire document to kill focus.
// Instead, we should be tracking focus with a delegate()
// handler so we already have the element in hand at this
// point.
// Wrap this in a try/catch block since IE9 throw "Unspecified error" if
// document.activeElement is undefined when we are in an IFrame.
try {
if ( document.activeElement &&
document.activeElement.nodeName.toLowerCase() !== "body" ) {

$( document.activeElement ).blur();
} else {
$( "input:focus, textarea:focus, select:focus" ).blur();
}
} catch ( e ) {}
// We blur the focused element to cause the virtual keyboard to disappear
$.ui.safeBlur( $.ui.safeActiveElement( this.document[ 0 ] ) );

// Record whether we are at a place in history where a dialog used to be -
// if so, do not add a new history entry and do not change the hash either
Expand Down
22 changes: 9 additions & 13 deletions js/widgets/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// AMD. Register as an anonymous module.
define( [
"jquery",
"jquery-ui/core",
"../widget",
"../support",
"../events/navigate",
Expand Down Expand Up @@ -365,9 +366,10 @@ $.widget( "mobile.popup", {
if ( targetElement !== ui.container[ 0 ] ) {
target = $( targetElement );
if ( !$.contains( ui.container[ 0 ], targetElement ) ) {
$( this.document[ 0 ].activeElement ).one( "focus", $.proxy( function() {
this._safelyBlur( targetElement );
}, this ) );
$( $.ui.safeActiveElement( this.document[ 0 ] ) ).one( "focus",
$.proxy( function() {
$.ui.safeBlur( targetElement );
}, this ) );
ui.focusElement.focus();
theEvent.preventDefault();
theEvent.stopImmediatePropagation();
Expand Down Expand Up @@ -700,24 +702,18 @@ $.widget( "mobile.popup", {
}
},

_safelyBlur: function( currentElement ) {
if ( currentElement !== this.window[ 0 ] &&
currentElement.nodeName.toLowerCase() !== "body" ) {
$( currentElement ).blur();
}
},

_openPrerequisitesComplete: function() {
var id = this.element.attr( "id" ),
firstFocus = this._ui.container.find( ":focusable" ).first();
firstFocus = this._ui.container.find( ":focusable" ).first(),
focusElement = $.ui.safeActiveElement( this.document[ 0 ] );

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

// Check to see if currElement is not a child of the container. If it's not, blur
if ( !$.contains( this._ui.container[ 0 ], this.document[ 0 ].activeElement ) ) {
this._safelyBlur( this.document[ 0 ].activeElement );
if ( focusElement && !$.contains( this._ui.container[ 0 ], focusElement ) ) {
$.ui.safeBlur( focusElement );
}
if ( firstFocus.length > 0 ) {
this._ui.focusElement = firstFocus;
Expand Down