summaryrefslogtreecommitdiff
path: root/resources/src/jquery/jquery.footHovzer.js
blob: e601ddb1b63e908137a7254133a741c56eae0466 (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, $spacer;

	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 ( $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 );
		}
	};

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

}( jQuery ) );