jQuery.footHovzer: Fix scrolling issues
authorgladoscc <admin@glados.cc>
Fri, 2 Jan 2015 16:02:48 +0000 (03:02 +1100)
committergladoscc <admin@glados.cc>
Fri, 2 Jan 2015 17:43:35 +0000 (04:43 +1100)
Fix scrollbar appearing if the page does not fill the screen, and the
debug toolbar is enabled.

This patch also fixes an issue where the page will have a height of
~1000px if the CSS is loaded after the JS executes (display:none
isn't triggered before the outerHeight() calculation). I've only been
able to fix this by adding a setTimeout, which is a little bit hacky..
but can't figure out how to solve it any other way.

Bug: T38273
Change-Id: I1f92cb0681b7a82a5936267c120f85481a95a962

resources/src/jquery/jquery.footHovzer.js

index de745c3..e601ddb 100644 (file)
@@ -2,7 +2,7 @@
  * @class jQuery.plugin.footHovzer
  */
 ( function ( $ ) {
-       var $hovzer, footHovzer, prevHeight, newHeight;
+       var $hovzer, footHovzer, $spacer;
 
        function getHovzer() {
                if ( $hovzer === undefined ) {
                        var $body;
 
                        $body = $( 'body' );
-                       if ( prevHeight === undefined ) {
-                               prevHeight = getHovzer().outerHeight( /* includeMargin = */ true );
-                               $body.css( 'paddingBottom', '+=' + prevHeight + 'px' );
-                       } else {
-                               newHeight = getHovzer().outerHeight( true );
-                               $body.css( 'paddingBottom', ( parseFloat( $body.css( 'paddingBottom' ) ) - prevHeight ) + newHeight );
 
-                               prevHeight = newHeight;
+                       if ( $spacer === undefined ) {
+                               $spacer = $( '<div>' ).attr( 'id', 'jquery-foot-hovzer-spacer' );
+                               $spacer.appendTo( $body );
                        }
+                       // Ensure CSS is applied by browser before using .outerHeight()
+                       setTimeout( function () {
+                               $spacer.css( 'height', getHovzer().outerHeight( /* includeMargin = */ true ) );
+                       }, 0 );
                }
        };