From a1dffa2dd7b7cbcb358ce357f9d45be2ddc82ea8 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 16 Mar 2018 15:39:21 +0000 Subject: [PATCH] Only use pre-computed measurements for position loading bar Change-Id: I5fc17a432de8030a6154c4e961ac10c73f391a79 --- .../ve.init.mw.DesktopArticleTarget.init.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js index 46afecb7fc..ec7f48622d 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js @@ -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 );