2 * JSizes - JQuery plugin v0.33
4 * Licensed under the revised BSD License.
5 * Copyright 2008-2010 Bram Stein
10 var num = function (value) {
11 return parseInt(value, 10) || 0;
15 * Sets or gets the values for min-width, min-height, max-width
18 $.each(['min', 'max'], function (i, name) {
19 $.fn[name + 'Size'] = function (value) {
22 if (value.width !== undefined) {
23 this.css(name + '-width', value.width);
25 if (value.height !== undefined) {
26 this.css(name + '-height', value.height);
31 width = this.css(name + '-width');
32 height = this.css(name + '-height');
34 // * Opera returns -1px instead of none
35 // * IE6 returns undefined instead of none
36 return {'width': (name === 'max' && (width === undefined || width === 'none' || num(width) === -1) && Number.MAX_VALUE) || num(width),
37 'height': (name === 'max' && (height === undefined || height === 'none' || num(height) === -1) && Number.MAX_VALUE) || num(height)};
43 * Returns whether or not an element is visible.
45 $.fn.isVisible = function () {
46 return this.is(':visible');
50 * Sets or gets the values for border, margin and padding.
52 $.each(['border', 'margin', 'padding'], function (i, name) {
53 $.fn[name] = function (value) {
55 if (value.top !== undefined) {
56 this.css(name + '-top' + (name === 'border' ? '-width' : ''), value.top);
58 if (value.bottom !== undefined) {
59 this.css(name + '-bottom' + (name === 'border' ? '-width' : ''), value.bottom);
61 if (value.left !== undefined) {
62 this.css(name + '-left' + (name === 'border' ? '-width' : ''), value.left);
64 if (value.right !== undefined) {
65 this.css(name + '-right' + (name === 'border' ? '-width' : ''), value.right);
70 return {top: num(this.css(name + '-top' + (name === 'border' ? '-width' : ''))),
71 bottom: num(this.css(name + '-bottom' + (name === 'border' ? '-width' : ''))),
72 left: num(this.css(name + '-left' + (name === 'border' ? '-width' : ''))),
73 right: num(this.css(name + '-right' + (name === 'border' ? '-width' : '')))};