From e006449c7f4d1d842ba4b08d6b666c64929da8ae Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 23 Mar 2015 02:32:00 +0000 Subject: [PATCH] Vertically center the progress bar within the visible part of #content On short pages which don't extend below the fold, the progress bar should center within the #content element. Change-Id: I0b99e42f5bab8177d3b4ca6dd372d6403ae9b136 --- .../targets/ve.init.mw.ViewPageTarget.init.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js index d594d0736b..dc0a726392 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js @@ -32,17 +32,15 @@ '' ); } - var $window = $( window ), - $content = $( '#content' ), - scrollTop = $window.scrollTop(), + var $content = $( '#content' ), + contentRect = $content[0].getBoundingClientRect(), offsetTop = $content.offset().top, - windowHeight = $window.height(); + windowHeight = $( window ).height(), + top = Math.max( contentRect.top, 0 ), + bottom = Math.min( contentRect.bottom, windowHeight ), + middle = ( top + bottom ) / 2; - if ( scrollTop > offsetTop ) { - init.$loading.css( 'top', ( scrollTop - offsetTop ) + ( windowHeight / 2 ) ); - } else { - init.$loading.css( 'top', ( windowHeight - ( offsetTop - scrollTop ) ) / 2 ); - } + init.$loading.css( 'top', middle - offsetTop ); $content.prepend( init.$loading ); }