Skip to content

Commit

Permalink
Popup: Do not reposition if the popup remains on-screen after a resize
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed Jan 27, 2015
1 parent 827292e commit 31f6bb0
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion js/widgets/popup.js
Expand Up @@ -26,6 +26,23 @@ define( [
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

function pointInRectangle( x, y, windowCoordinates ) {
return ( x >= windowCoordinates.x && x <= windowCoordinates.x + windowCoordinates.cx &&
y >= windowCoordinates.y && y <= windowCoordinates.y + windowCoordinates.cy );
}

function isOutOfSight( element, windowCoordinates ) {
var offset = element.offset(),
width = element.outerWidth( true ),
height = element.outerHeight( true );

return !(
pointInRectangle( offset.left, offset.top, windowCoordinates ) ||
pointInRectangle( offset.left + width, offset.top, windowCoordinates ) ||
pointInRectangle( offset.left + width, offset.top + height, windowCoordinates ) ||
pointInRectangle( offset.left, offset.top + height, windowCoordinates ) );
}

function fitSegmentInsideSegment( windowSize, segmentSize, offset, desired ) {
var returnValue = desired;

Expand Down Expand Up @@ -267,8 +284,10 @@ $.widget( "mobile.popup", {

_handleWindowResize: function(/* theEvent */) {
if ( this._isOpen && this._ignoreResizeTo === 0 ) {
if ( ( this._expectResizeEvent() || this._orientationchangeInProgress ) &&
if ( isOutOfSight( this._ui.container, getWindowCoordinates( this.window ) ) &&
( this._expectResizeEvent() || this._orientationchangeInProgress ) &&
!this._ui.container.hasClass( "ui-popup-hidden" ) ) {

// effectively rapid-close the popup while leaving the screen intact
this._ui.container
.addClass( "ui-popup-hidden ui-popup-truncate" )
Expand Down

0 comments on commit 31f6bb0

Please sign in to comment.