From 26d53cd07e2c77f99254a33f8b07b27fa9acb7e1 Mon Sep 17 00:00:00 2001 From: Amanpreet Singh Date: Mon, 11 Jul 2016 01:14:56 +0530 Subject: [PATCH] Panel: ScrollTop only when ui-content is out of view Fixes #6767 Closes #8483 --- js/helpers.js | 18 ++++++++++++++++++ js/widgets/panel.js | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/js/helpers.js b/js/helpers.js index 63f067f5d1b..f26a1d45f7a 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -255,6 +255,24 @@ $.extend( $.mobile, { this.loading._widget = loader; return returnValue; + }, + + isElementCurrentlyVisible: function( el ) { + el = typeof el === "string" ? $( el )[ 0 ] : el[ 0 ]; + + if( !el ) { + return true; + } + + var rect = el.getBoundingClientRect(); + + return ( + rect.bottom > 0 && + rect.right > 0 && + rect.top < + ( window.innerHeight || document.documentElement.clientHeight ) && + rect.left < + ( window.innerWidth || document.documentElement.clientWidth ) ); } } ); diff --git a/js/widgets/panel.js b/js/widgets/panel.js index efa7a0381c1..5e99a4dea16 100644 --- a/js/widgets/panel.js +++ b/js/widgets/panel.js @@ -216,7 +216,8 @@ return $.widget( "mobile.panel", { ( heightWithMargins - heightWithoutMargins ) ); } } - if ( scrollToTop === true ) { + if ( scrollToTop === true && + !$.mobile.isElementCurrentlyVisible( ".ui-content" ) ) { this.window[ 0 ].scrollTo( 0, $.mobile.defaultHomeScroll ); } } else {