summaryrefslogtreecommitdiff
path: root/resources/src/jquery/jquery.footHovzer.js
blob: de745c3360fd02ad9ab7185c27399c5b7cfeccc2 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
 * @class jQuery.plugin.footHovzer
 */
( function ( $ ) {
	var $hovzer, footHovzer, prevHeight, newHeight;

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

	/**
	 * Utility to stack stuff in an overlay fixed on the bottom of the page.
	 *
	 * Usage:
	 *
	 *     var hovzer = $.getFootHovzer();
	 *     hovzer.$.append( $myCollection );
	 *     hovzer.update();
	 *
	 * @static
	 * @inheritable
	 * @return {jQuery.footHovzer}
	 */
	$.getFootHovzer = function () {
		footHovzer.$ = getHovzer();
		return footHovzer;
	};

	/**
	 * @private
	 * @class jQuery.footHovzer
	 */
	footHovzer = {

		/**
		 * @property {jQuery} $ The stack container
		 */

		/**
		 * Update dimensions of stack to account for changes in the subtree.
		 */
		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;
			}
		}
	};

	/**
	 * @class jQuery
	 * @mixins jQuery.plugin.footHovzer
	 */

}( jQuery ) );