Only use pre-computed measurements for position loading bar

Change-Id: I5fc17a432de8030a6154c4e961ac10c73f391a79
This commit is contained in:
Ed Sanders 2018-03-16 15:39:21 +00:00
parent 670f39790f
commit a1dffa2dd7

View file

@ -36,7 +36,7 @@
plugins = [];
function showLoading( mode ) {
var $content, contentRect, offsetTop, windowHeight, top, bottom, middle, loadingTop;
var $content, windowHeight, clientTop, top, bottom, middle;
if ( isLoading ) {
return;
@ -61,14 +61,12 @@
$content = $( '#content' );
if ( mode !== 'source' ) {
// Center within visible part of the target
contentRect = $content[ 0 ].getBoundingClientRect();
windowHeight = $( window ).height();
top = Math.max( contentRect.top, 0 );
bottom = Math.min( contentRect.bottom, windowHeight );
windowHeight = window.innerHeight;
clientTop = $content[ 0 ].offsetTop - window.pageYOffset;
top = Math.max( clientTop, 0 );
bottom = Math.min( clientTop + $content[ 0 ].offsetHeight, windowHeight );
middle = ( bottom - top ) / 2;
offsetTop = Math.max( -contentRect.top, 0 );
loadingTop = middle + offsetTop;
init.$loading.css( 'top', loadingTop );
init.$loading.css( 'top', middle + Math.max( -clientTop, 0 ) );
}
$content.prepend( init.$loading );