Skip to content

Commit 16f0694

Browse files
author
Gabriel Schulhof
committed
Popup: Do not reposition if the popup remains on-screen after a resize
Fixes jquery-archivegh-7862
1 parent 827292e commit 16f0694

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

js/widgets/popup.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ define( [
2626
//>>excludeEnd("jqmBuildExclude");
2727
(function( $, undefined ) {
2828

29+
function pointInRectangle( x, y, windowCoordinates ) {
30+
return ( x >= windowCoordinates.x && x <= windowCoordinates.x + windowCoordinates.cx &&
31+
y >= windowCoordinates.y && y <= windowCoordinates.y + windowCoordinates.cy );
32+
}
33+
34+
function isOutOfSight( element, windowCoordinates ) {
35+
var offset = element.offset(),
36+
width = element.outerWidth( true ),
37+
height = element.outerHeight( true );
38+
39+
return !(
40+
pointInRectangle( offset.left, offset.top, windowCoordinates ) ||
41+
pointInRectangle( offset.left + width, offset.top, windowCoordinates ) ||
42+
pointInRectangle( offset.left + width, offset.top + height, windowCoordinates ) ||
43+
pointInRectangle( offset.left, offset.top + height, windowCoordinates ) );
44+
}
45+
2946
function fitSegmentInsideSegment( windowSize, segmentSize, offset, desired ) {
3047
var returnValue = desired;
3148

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

268285
_handleWindowResize: function(/* theEvent */) {
269286
if ( this._isOpen && this._ignoreResizeTo === 0 ) {
270-
if ( ( this._expectResizeEvent() || this._orientationchangeInProgress ) &&
287+
if ( isOutOfSight( this._ui.container, getWindowCoordinates( this.window ) ) &&
288+
( this._expectResizeEvent() || this._orientationchangeInProgress ) &&
271289
!this._ui.container.hasClass( "ui-popup-hidden" ) ) {
290+
272291
// effectively rapid-close the popup while leaving the screen intact
273292
this._ui.container
274293
.addClass( "ui-popup-hidden ui-popup-truncate" )

0 commit comments

Comments
 (0)