Commit 0296e765 authored by Mike Gabriel's avatar Mike Gabriel

New upstream version 1.1.0+dfsg1

parents
.DS_Store
# jQuery Center Plugin CHANGELOG
## 1.1.0
* Add center on window resize option, default to true
## 1.0.3
* Add package.json for new jquery plugin site
## 1.0.2
* Fix bug on undefined variable against ( thanks to Nick Inhofe )
## 1.0.1
* Fix jQuery conflict
## 1.0.0
* First stable release
\ No newline at end of file
Copyright 2011, Ben Lin (http://dreamerslab.com/)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
# jQuery Center Plugin
A jQuery plugin that centralizes DOM element.
## Description
This simple plugin helps you centralize your DOM element against their parent element or the window. You can also specify the top of the DOM element by passing customized settings.
## Demo
- Please see demo.html
- Live demo please take a look at [this](http://dreamerslab.com/demos/centralize-html-dom-element-with-jquery-center-plugin)
## Documentation
- There is a syntax highlight version, please see [this post](http://dreamerslab.com/blog/en/centralize-html-dom-element-with-jquery-center-plugin/)
- For chinese version please go [here](http://dreamerslab.com/blog/tw/centralize-html-dom-element-with-jquery-center-plugin/)
## Requires
- jQuery 1.2.6+
## Browser Compatibility
- [Firefox](http://mzl.la/RNaI) 2.0+
- [Internet Explorer](http://bit.ly/9fMgIQ) 6+
- [Safari](http://bit.ly/gMhzVR) 3+
- [Opera](http://bit.ly/fWJzaC) 10.6+
- [Chrome](http://bit.ly/ePHvYZ) 8+
## Installation
- First, make sure you are using valid [DOCTYPE](http://bit.ly/hQK1Rk)
- Include nessesary JS files
<!-- -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="path-to-file/jquery.center.js"></script>
## Options
#### against
- description: the element that the DOM element centralize against to
- data type: string
- default value: 'window'
- possible value: 'window', 'parent', or '.someTarget'
#### top
- description: you can specify the top of the target element
- data type: integer
- default value: false
- possible value: 13, 20, 36 ... any number you want
#### topPercentage
- description: or specify the top in percentage of the target element
- data type: float
- default value: 0.5
- possible value: 0.1, 0.4, 0.8 ...
#### resize
- description: center on window resize
- data type: boolean
- default value: true
- possible value: true | false
## Usage
> Example code:
// centralize #some-element against the window
$( '#some-element' ).center();
// centralize .some-element against its parent element
$( '.some-element' ).center({
against : 'parent',
top : 10
});
// centralize .some-element against '.some-target-element'
// !IMPORTANT '.some-target-element' must be ".some-element"'s parents
$( '.some-element' ).center({
against : '.some-target-element',
topPercentage : 0.4
});
## License
The expandable plugin is licensed under the MIT License (LICENSE.txt).
Copyright (c) 2011 [Ben Lin](http://dreamerslab.com)
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Center Plugin Demo</title>
<style type="text/css">
h1{
text-align : center;
}
#wrap{
width: 880px;
margin: 0 auto 50px;
}
#info{
text-align: center;
margin: 50px 0 0;
}
#play-ground1{
height: 150px;
}
#play-ground2{
height: 220px;
position: relative;
}
.spacer{
height: 50px;
}
.parent{
width: 200px;
height: 200px;
position: relative;
background: #cccccc;
display: inline;
float: left;
margin: 0 20px 0 0;
}
.some-element{
width: 100px;
height: 100px;
position: absolute;
background: #333333;
color: white;
}
.btn{
background: #cccccc;
float: left;
display: inline;
font-family: arial;
font-size: 12px;
font-weight: bolder;
padding: 3px 7px;
margin: 0 8px 0 0;
cursor: pointer;
}
</style>
</head>
<body>
<div id="wrap">
<h1>
jQuery Center Plugin Demo
</h1>
<p>
Try clicking the buttons to see how they works :)
</p>
<h2>
centralize #some-element against the window
</h2>
<div id="sample1" class="spacer">
<div id="btn1" class="btn">Centralize</div>
<div class="btn restore">Restore</div>
</div>
<div id="play-ground1">
<div id="some-element" class="some-element">
#some-element
</div>
</div>
<h2>
centralize .some-element against its parent
</h2>
<div id="sample2" class="spacer">
<div id="btn2" class="btn">Centralize</div>
<div class="btn restore">Restore</div>
</div>
<div id="play-ground2">
<div class="parent">
.parent
<div class="some-element">
.some-element
</div>
</div>
<div class="parent">
.parent
<div class="some-element">
.some-element
</div>
</div>
<div class="parent">
.parent
<div class="some-element">
.some-element
</div>
</div>
<div class="parent">
.parent
<div class="some-element">
.some-element
</div>
</div>
</div>
<h3 id="info">
Demo provides by <a href="http://dreamerslab.com/">DreamersLab</a>
</h3>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript" src="jquery.center.min.js"></script>
<script type="text/javascript" charset="utf-8">
// wrap everything in document ready event
$( function(){
// cache jquery obj
var $el = $( '#some-element' );
var $pg2el = $( '#play-ground2' ).find( '.some-element' );
// centerize '#some-element' against the window on clicking #btn1
$( '#btn1' ).bind( 'click', function(){
$el.center();
});
// restore '#some-element' position on clicking '.restore'
$( '#sample1' ).find( '.restore' ).bind( 'click', function(){
$el.attr( 'style', '' );
});
// centerize each '.some-element' against its parent on clicking #btn2
$( '#btn2' ).bind( 'click', function(){
$pg2el.center({ against: 'parent' });
});
// restore '.some-element' position on clicking '.restore'
$( '#sample2' ).find( '.restore' ).bind( 'click', function(){
$pg2el.attr( 'style', '' );
});
});
</script>
<script type="text/javascript" charset="utf-8">
// google analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20960410-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>
\ No newline at end of file
/*! Copyright 2011, Ben Lin (http://dreamerslab.com/)
* Licensed under the MIT License (LICENSE.txt).
*
* Version: 1.1.0
*
* Requires: jQuery 1.2.6+
*/
;( function( $, window ){
$.fn.center = function( opt ){
var $w = $( window ); // cache gobal
var scrollTop = $w.scrollTop();
return this.each( function(){
var $this = $( this ); // cache $( this )
// merge user options with default configs
var configs = $.extend({
against : 'window',
top : false,
topPercentage : 0.5,
resize : true
}, opt );
var centerize = function(){
var against = configs.against;
var $against;
if( against === 'window' ){
$against = $w;
}else if( against === 'parent' ){
$against = $this.parent();
scrollTop = 0;
}else{
$against = $this.parents( against );
scrollTop = 0;
}
var x = (( $against.width()) - ( $this.outerWidth())) * 0.5;
var y = (( $against.height()) - ( $this.outerHeight())) * configs.topPercentage + scrollTop;
if( configs.top ) y = configs.top + scrollTop;
$this.css({
'left' : x,
'top' : y
});
};
// apply centerization
centerize();
if( configs.resize === true ) $w.resize( centerize );
});
};
})( jQuery, window );
\ No newline at end of file
{
"name" : "center",
"version" : "1.1.0",
"title" : "jQuery Center Plugin",
"author" : "dreamerslab <ben@dreamerslab.com>",
"licenses": [{
"type": "MIT",
"url" : "LICENSE.txt"
}],
"dependencies": {
"jquery": ">=1.2.6"
},
"description": "This simple plugin helps you centralize your DOM element against their parent element or the window. You can also specify the top of the DOM element by passing customized settings.",
"keywords": [
"center", "centralize", "alignment", "layout", "layouts"
],
"homepage": "http://dreamerslab.com/blog/centralize-html-dom-element-with-jquery-center-plugin/"
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment