summaryrefslogtreecommitdiff
path: root/resources/jquery/jquery.footHovzer.js
blob: 56fc32d49226d38b224464fb6621ca93db72797f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
 * Utility to stack stuff in an overlay fixed on the bottom of the page.
 *
 * Usage:
 * <code>
 *     var hovzer = $.getFootHovzer();
 *     hovzer.$.append( $myCollection );
 *     hovzer.update();
 * </code>
 *
 * @author Timo Tijhof, 2012
 */
( function ( $ ) {
	var $hovzer, footHovzer, prevHeight, newHeight;

	function getHovzer() {
		if ( $hovzer === undefined ) {
			$hovzer = $( '<div id="jquery-foot-hovzer"></div>' ).appendTo( 'body' );
		}
		return $hovzer;
	}

	footHovzer = {
		update: function () {
			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;
			}
		}
	};

	$.getFootHovzer = function () {
		footHovzer.$ = getHovzer();
		return footHovzer;
	};

}( jQuery ) );