| 1 |
From 72408e8ae31ba533f26c976f8a1baca1912adfa4 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Fred Chu <[email protected]> |
| 3 |
Date: Wed, 31 Oct 2012 17:15:25 +0800 |
| 4 |
Subject: [PATCH] release 1.1.1, [bug fixed] center against window failed |
| 5 |
|
| 6 |
--- |
| 7 |
CHANGELOG.md | 6 ++++++ |
| 8 |
jquery.center.js | 33 ++++++++++++++++++++++++--------- |
| 9 |
jquery.center.min.js | 4 ++-- |
| 10 |
3 files changed, 32 insertions(+), 11 deletions(-) |
| 11 |
|
| 12 |
diff --git a/CHANGELOG.md b/CHANGELOG.md |
| 13 |
index 7fca1b2..677753a 100644 |
| 14 |
--- a/CHANGELOG.md |
| 15 |
+++ b/CHANGELOG.md |
| 16 |
@@ -1,5 +1,11 @@ |
| 17 |
# jQuery Center Plugin CHANGELOG |
| 18 |
|
| 19 |
+## 1.1.1/ 2012-10-31 |
| 20 |
+ |
| 21 |
+- [bug fix] center against window failed |
| 22 |
+ |
| 23 |
+ |
| 24 |
+ |
| 25 |
## 1.1.0 |
| 26 |
|
| 27 |
* Add center on window resize option, default to true |
| 28 |
diff --git a/jquery.center.js b/jquery.center.js |
| 29 |
index ea09e6a..922e7a5 100644 |
| 30 |
--- a/jquery.center.js |
| 31 |
+++ b/jquery.center.js |
| 32 |
@@ -1,17 +1,29 @@ |
| 33 |
/*! Copyright 2011, Ben Lin (http://dreamerslab.com/) |
| 34 |
* Licensed under the MIT License (LICENSE.txt). |
| 35 |
* |
| 36 |
-* Version: 1.1.0 |
| 37 |
+* Version: 1.1.1 |
| 38 |
* |
| 39 |
* Requires: jQuery 1.2.6+ |
| 40 |
*/ |
| 41 |
;( function( $, window ){ |
| 42 |
+ var get_win_size = function (){ |
| 43 |
+ if( window.innerWidth != undefined ){ |
| 44 |
+ return [ window.innerWidth, window.innerHeight ]; |
| 45 |
+ }else{ |
| 46 |
+ var B = document.body; |
| 47 |
+ var D = document.documentElement; |
| 48 |
+ |
| 49 |
+ return [ Math.max( D.clientWidth, B.clientWidth ), Math.max( D.clientHeight, B.clientHeight )]; |
| 50 |
+ } |
| 51 |
+ } |
| 52 |
+ |
| 53 |
$.fn.center = function( opt ){ |
| 54 |
var $w = $( window ); // cache gobal |
| 55 |
var scrollTop = $w.scrollTop(); |
| 56 |
|
| 57 |
return this.each( function(){ |
| 58 |
var $this = $( this ); // cache $( this ) |
| 59 |
+ |
| 60 |
// merge user options with default configs |
| 61 |
var configs = $.extend({ |
| 62 |
against : 'window', |
| 63 |
@@ -22,26 +34,29 @@ |
| 64 |
|
| 65 |
var centerize = function(){ |
| 66 |
var against = configs.against; |
| 67 |
+ var against_w_n_h; |
| 68 |
var $against; |
| 69 |
|
| 70 |
if( against === 'window' ){ |
| 71 |
- $against = $w; |
| 72 |
+ against_w_n_h = get_win_size(); |
| 73 |
}else if( against === 'parent' ){ |
| 74 |
- $against = $this.parent(); |
| 75 |
- scrollTop = 0; |
| 76 |
+ $against = $this.parent(); |
| 77 |
+ against_w_n_h = [ $against.width(), $against.height()]; |
| 78 |
+ scrollTop = 0; |
| 79 |
}else{ |
| 80 |
- $against = $this.parents( against ); |
| 81 |
- scrollTop = 0; |
| 82 |
+ $against = $this.parents( against ); |
| 83 |
+ against_w_n_h = [ $against.width(), $against.height()]; |
| 84 |
+ scrollTop = 0; |
| 85 |
} |
| 86 |
|
| 87 |
- var x = (( $against.width()) - ( $this.outerWidth())) * 0.5; |
| 88 |
- var y = (( $against.height()) - ( $this.outerHeight())) * configs.topPercentage + scrollTop; |
| 89 |
+ var x = (( against_w_n_h[ 0 ]) - ( $this.outerWidth())) * 0.5; |
| 90 |
+ var y = (( against_w_n_h[ 1 ]) - ( $this.outerHeight())) * configs.topPercentage + scrollTop; |
| 91 |
|
| 92 |
if( configs.top ) y = configs.top + scrollTop; |
| 93 |
|
| 94 |
$this.css({ |
| 95 |
'left' : x, |
| 96 |
- 'top' : y |
| 97 |
+ 'top' : y |
| 98 |
}); |
| 99 |
}; |
| 100 |
|
| 101 |
#diff --git a/jquery.center.min.js b/jquery.center.min.js |
| 102 |
#index c1ae70b..7c1114f 100644 |
| 103 |
#--- a/jquery.center.min.js |
| 104 |
#+++ b/jquery.center.min.js |
| 105 |
#@@ -1,8 +1,8 @@ |
| 106 |
# /*! Copyright 2011, Ben Lin (http://dreamerslab.com/) |
| 107 |
# * Licensed under the MIT License (LICENSE.txt). |
| 108 |
# * |
| 109 |
#-* Version: 1.1.0 |
| 110 |
#+* Version: 1.1.1 |
| 111 |
# * |
| 112 |
# * Requires: jQuery 1.2.6+ |
| 113 |
# */ |
| 114 |
#-;(function(b,a){b.fn.center=function(c){var d=b(a);var e=d.scrollTop();return this.each(function(){var h=b(this);var g=b.extend({against:"window",top:false,topPercentage:0.5,resize:true},c);var f=function(){var k=g.against;var j;if(k==="window"){j=d;}else{if(k==="parent"){j=h.parent();e=0;}else{j=h.parents(k);e=0;}}var i=((j.width())-(h.outerWidth()))*0.5;var l=((j.height())-(h.outerHeight()))*g.topPercentage+e;if(g.top){l=g.top+e;}h.css({left:i,top:l});};f();if(g.resize===true){d.resize(f);}});};})(jQuery,window); |
| 115 |
#\ No newline at end of file |
| 116 |
#+;(function($,window){var get_win_size=function(){if(window.innerWidth!=undefined)return[window.innerWidth,window.innerHeight];else{var B=document.body;var D=document.documentElement;return[Math.max(D.clientWidth,B.clientWidth),Math.max(D.clientHeight,B.clientHeight)]}};$.fn.center=function(opt){var $w=$(window);var scrollTop=$w.scrollTop();return this.each(function(){var $this=$(this);var configs=$.extend({against:"window",top:false,topPercentage:0.5,resize:true},opt);var centerize=function(){var against=configs.against;var against_w_n_h;var $against;if(against==="window")against_w_n_h=get_win_size();else if(against==="parent"){$against=$this.parent();against_w_n_h=[$against.width(),$against.height()];scrollTop=0}else{$against=$this.parents(against);against_w_n_h=[$against.width(),$against.height()];scrollTop=0}var x=(against_w_n_h[0]-$this.outerWidth())*0.5;var y=(against_w_n_h[1]-$this.outerHeight())*configs.topPercentage+scrollTop;if(configs.top)y=configs.top+scrollTop;$this.css({"left":x,"top":y})};centerize();if(configs.resize===true)$w.resize(centerize)})}})(jQuery,window); |
| 117 |
#\ No newline at end of file |