forked from bitovi/jquerypp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdimensions.js
More file actions
192 lines (183 loc) · 5.94 KB
/
dimensions.js
File metadata and controls
192 lines (183 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
steal('jquery', 'jquerypp/dom/styles', function($) {
var
//margin is inside border
weird = /button|select/i,
getBoxes = {},
checks = {
width: ["Left", "Right"],
height: ['Top', 'Bottom'],
oldOuterHeight: $.fn.outerHeight,
oldOuterWidth: $.fn.outerWidth,
oldInnerWidth: $.fn.innerWidth,
oldInnerHeight: $.fn.innerHeight
},
supportsSetter = $.fn.jquery >= '1.8.0';
$.each({
/**
* @function jQuery.fn.outerWidth
* @parent jQuery.dimensions
*
* `jQuery.fn.outerWidth([value], [includeMargins])` lets you set
* the outer width of an object where:
*
* outerWidth = width + padding + border + (margin)
*
* And can be used like:
*
* $("#foo").outerWidth(100); //sets outer width
* $("#foo").outerWidth(100, true); // uses margins
* $("#foo").outerWidth(); //returns outer width
* $("#foo").outerWidth(true); //returns outer width + margins
*
* When setting the outerWidth, it adjusts the width of the element.
* If *includeMargin* is set to `true` margins will also be included.
* It is also possible to animate the outer width:
*
* $('#foo').animate({ outerWidth: 200 });
*
* @param {Number} [width] The width to set
* @param {Boolean} [includeMargin=false] Makes setting the outerWidth adjust
* for margins.
* @return {jQuery|Number} Returns the outer width or the jQuery wrapped elements
* if you are setting the outer width.
*/
width:
/**
* @function jQuery.fn.innerWidth
* @parent jQuery.dimensions
*
* `jQuery.fn.innerWidth([value])` lets you set the inner width of an element where
*
* innerWidth = width + padding
*
* Use it like:
*
* $("#foo").innerWidth(100); //sets inner width
* $("#foo").outerWidth(); // returns inner width
*
* Or in an animation like:
*
* $('#foo').animate({ innerWidth : 200 });
*
* Setting inner width adjusts the width of the element.
*
* @param {Number} [width] The inner width to set
* @return {jQuery|Number} Returns the inner width or the jQuery wrapped elements
* if you are setting the inner width.
*/
"Width",
/**
* @function jQuery.fn.outerHeight
* @parent jQuery.dimensions
*
* `jQuery.fn.outerHeight([value], [includeMargins])` lets
* you set the outer height of an object where:
*
* outerHeight = height + padding + border + (margin)
*
* And can be used like:
*
* $("#foo").outerHeight(100); //sets outer height
* $("#foo").outerHeight(100, true); // uses margins
* $("#foo").outerHeight(); //returns outer height
* $("#foo").outerHeight(true); //returns outer height + margins
*
* When setting the outerHeight, it adjusts the height of the element.
* If *includeMargin* is set to `true` margins will also be included.
* It is also possible to animate the outer heihgt:
*
* $('#foo').animate({ outerHeight : 200 });
*
* @param {Number} [height] The height to set
* @param {Boolean} [includeMargin=false] Makes setting the outerHeight adjust
* for margins.
* @return {jQuery|Number} Returns the outer height or the jQuery wrapped elements
* if you are setting the outer height.
*/
height:
/**
* @function jQuery.fn.innerHeight
* @parent jQuery.dimensions
*
* `jQuery.fn.innerHeight([value])` lets you set the inner height of an element where
*
* innerHeight = height + padding
*
* Use it like:
*
* $("#foo").innerHeight(100); //sets inner height
* $("#foo").outerHeight(); // returns inner height
*
* Or in an animation like:
*
* $('#foo').animate({ innerHeight : 200 });
*
* Setting inner height adjusts the height of the element.
*
* @param {Number} [height] The inner height to set
* @return {jQuery|Number} Returns the inner height or the jQuery wrapped elements
* if you are setting the inner height.
*/
// for each 'height' and 'width'
"Height" }, function(lower, Upper) {
//used to get the padding and border for an element in a given direction
getBoxes[lower] = function(el, boxes) {
var val = 0;
if (!weird.test(el.nodeName)) {
//make what to check for ....
var myChecks = [];
$.each(checks[lower], function() {
var direction = this;
$.each(boxes, function(name, val) {
if (val)
myChecks.push(name + direction+ (name == 'border' ? "Width" : "") );
})
})
$.each($.styles(el, myChecks), function(name, value) {
val += (parseFloat(value) || 0);
})
}
return val;
}
//getter / setter
if(!supportsSetter) {
$.fn["outer" + Upper] = function(v, margin) {
var first = this[0];
if (typeof v == 'number') {
// Setting the value
first && this[lower](v - getBoxes[lower](first, {padding: true, border: true, margin: margin}))
return this;
} else {
// Return the old value
return first ? checks["oldOuter" + Upper].apply(this, arguments) : null;
}
}
$.fn["inner" + Upper] = function(v) {
var first = this[0];
if (typeof v == 'number') {
// Setting the value
first&& this[lower](v - getBoxes[lower](first, { padding: true }))
return this;
} else {
// Return the old value
return first ? checks["oldInner" + Upper].apply(this, arguments) : null;
}
}
}
//provides animations
var animate = function(boxes){
// Return the animation function
return function(fx){
if (fx[supportsSetter ? 'pos' : 'state'] == 0) {
fx.start = $(fx.elem)[lower]();
fx.end = fx.end - getBoxes[lower](fx.elem,boxes);
}
fx.elem.style[lower] = (fx.pos * (fx.end - fx.start) + fx.start) + "px"
}
}
$.fx.step["outer" + Upper] = animate({padding: true, border: true})
$.fx.step["outer" + Upper+"Margin"] = animate({padding: true, border: true, margin: true})
$.fx.step["inner" + Upper] = animate({padding: true})
})
return $;
})