diff --git a/js/widgets/pagecontainer.js b/js/widgets/pagecontainer.js index 6960652db58..d31fec5492c 100644 --- a/js/widgets/pagecontainer.js +++ b/js/widgets/pagecontainer.js @@ -21,6 +21,7 @@ define( [ "jquery", "../core", + "jquery-ui/core", "../navigation/path", "../navigation/base", "../events/navigate", @@ -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 @@ -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 diff --git a/js/widgets/popup.js b/js/widgets/popup.js index e8fe82c3bae..afdeb62b047 100644 --- a/js/widgets/popup.js +++ b/js/widgets/popup.js @@ -29,6 +29,7 @@ // AMD. Register as an anonymous module. define( [ "jquery", + "jquery-ui/core", "../widget", "../support", "../events/navigate", @@ -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(); @@ -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;