tizen beta release
[framework/web/web-ui-fw.git] / libs / js / jlayout / jquery.sizes.js
1 /*!
2  * JSizes - JQuery plugin v0.33
3  *
4  * Licensed under the revised BSD License.
5  * Copyright 2008-2010 Bram Stein
6  * All rights reserved.
7  */
8 /*global jQuery*/
9 (function ($) {
10         var num = function (value) {
11                         return parseInt(value, 10) || 0;
12                 };
13
14         /**
15          * Sets or gets the values for min-width, min-height, max-width
16          * and max-height.
17          */
18         $.each(['min', 'max'], function (i, name) {
19                 $.fn[name + 'Size'] = function (value) {
20                         var width, height;
21                         if (value) {
22                                 if (value.width !== undefined) {
23                                         this.css(name + '-width', value.width);
24                                 }
25                                 if (value.height !== undefined) {
26                                         this.css(name + '-height', value.height);
27                                 }
28                                 return this;
29                         }
30                         else {
31                                 width = this.css(name + '-width');
32                                 height = this.css(name + '-height');
33                                 // Apparently:
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)};
38                         }
39                 };
40         });
41
42         /**
43          * Returns whether or not an element is visible.
44          */
45         $.fn.isVisible = function () {
46                 return this.is(':visible');
47         };
48
49         /**
50          * Sets or gets the values for border, margin and padding.
51          */
52         $.each(['border', 'margin', 'padding'], function (i, name) {
53                 $.fn[name] = function (value) {
54                         if (value) {
55                                 if (value.top !== undefined) {
56                                         this.css(name + '-top' + (name === 'border' ? '-width' : ''), value.top);
57                                 }
58                                 if (value.bottom !== undefined) {
59                                         this.css(name + '-bottom' + (name === 'border' ? '-width' : ''), value.bottom);
60                                 }
61                                 if (value.left !== undefined) {
62                                         this.css(name + '-left' + (name === 'border' ? '-width' : ''), value.left);
63                                 }
64                                 if (value.right !== undefined) {
65                                         this.css(name + '-right' + (name === 'border' ? '-width' : ''), value.right);
66                                 }
67                                 return this;
68                         }
69                         else {
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' : '')))};
74                         }
75                 };
76         });
77 })(jQuery);