Debian Codegraph @

jquery.center.js

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*! Copyright 2011, Ben Lin (http://dreamerslab.com/)
2 * Licensed under the MIT License (LICENSE.txt).
3 *
4 * Version: 1.1.0
5 *
6 * Requires: jQuery 1.2.6+
7 */
8 ;( function( $, window ){
9 $.fn.center = function( opt ){
10 var $w = $( window ); // cache gobal
11 var scrollTop = $w.scrollTop();
12
13 return this.each( function(){
14 var $this = $( this ); // cache $( this )
15 // merge user options with default configs
16 var configs = $.extend({
17 against : 'window',
18 top : false,
19 topPercentage : 0.5,
20 resize : true
21 }, opt );
22
23 var centerize = function(){
24 var against = configs.against;
25 var $against;
26
27 if( against === 'window' ){
28 $against = $w;
29 }else if( against === 'parent' ){
30 $against = $this.parent();
31 scrollTop = 0;
32 }else{
33 $against = $this.parents( against );
34 scrollTop = 0;
35 }
36
37 var x = (( $against.width()) - ( $this.outerWidth())) * 0.5;
38 var y = (( $against.height()) - ( $this.outerHeight())) * configs.topPercentage + scrollTop;
39
40 if( configs.top ) y = configs.top + scrollTop;
41
42 $this.css({
43 'left' : x,
44 'top' : y
45 });
46 };
47
48 // apply centerization
49 centerize();
50 if( configs.resize === true ) $w.resize( centerize );
51 });
52 };
53 })( jQuery, window );