1 | /* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net) |
---|
2 | * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) |
---|
3 | * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. |
---|
4 | * |
---|
5 | * $LastChangedDate: 2007-12-20 08:43:48 -0600 (Thu, 20 Dec 2007) $ |
---|
6 | * $Rev: 4257 $ |
---|
7 | * |
---|
8 | * $LastChangedDate: 2010-10-23 08:43:48 -0600 (Thu, 20 Dec 2007) $ |
---|
9 | * By cljosse |
---|
10 | * Version: 1.2 |
---|
11 | * |
---|
12 | * Requires: jQuery 1.2+ |
---|
13 | * |
---|
14 | */ |
---|
15 | (function (jQuery) { |
---|
16 | jQuery.dimensions = { version: '1.3' }; |
---|
17 | /* |
---|
18 | * Interception Height, Width |
---|
19 | */ |
---|
20 | jQuery.each(['Height', 'Width'], |
---|
21 | function (i, name) { |
---|
22 | jQuery.fn['inner' + name] = function () { |
---|
23 | if (!this[0]) return; |
---|
24 | var torl = name == 'Height' ? 'Top' : 'Left', |
---|
25 | borr = name == 'Height' ? 'Bottom' : 'Right'; |
---|
26 | return this.is(':visible') ? this[0]['client' + name] : num(this, name.toLowerCase()) + num(this, 'padding' + torl) + num(this, 'padding' + borr); |
---|
27 | }; |
---|
28 | |
---|
29 | jQuery.fn['outer' + name] = function (options) { |
---|
30 | if (!this[0]) return; |
---|
31 | var torl = name == 'Height' ? 'Top' : 'Left', |
---|
32 | borr = name == 'Height' ? 'Bottom' : 'Right'; |
---|
33 | options = options || false; |
---|
34 | options = jQuery.extend({ margin: options }); |
---|
35 | |
---|
36 | var val = this.is(':visible') ? this[0]['offset' + name] : |
---|
37 | num(this, |
---|
38 | name.toLowerCase()) + |
---|
39 | num(this, 'border' + torl + 'Width') + |
---|
40 | num(this, 'border' + borr + 'Width') + |
---|
41 | num(this, 'padding' + torl) + |
---|
42 | num(this, 'padding' + borr) |
---|
43 | |
---|
44 | ; |
---|
45 | return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0); |
---|
46 | }; |
---|
47 | }); |
---|
48 | /* |
---|
49 | * |
---|
50 | */ |
---|
51 | jQuery.each(['Left', 'Top'], |
---|
52 | function (i, name) { |
---|
53 | jQuery.fn['scroll' + name] = function (val) { |
---|
54 | if (!this[0]) return; |
---|
55 | return val != undefined ? this.each(function () { |
---|
56 | this == window || this == document ? window.scrollTo(name == 'Left' ? val : $(window)['scrollLeft'](), |
---|
57 | name == 'Top' ? val : $(window)['scrollTop']()) : this['scroll' + name] = val; |
---|
58 | }) : this[0] == window || this[0] == document ? self[(name == 'Left' ? 'pageXOffset' : 'pageYOffset')] || jQuery.boxModel && document.documentElement['scroll' + name] || document.body['scroll' + name] : this[0]['scroll' + name]; |
---|
59 | }; |
---|
60 | |
---|
61 | }); |
---|
62 | jQuery.fn.extend({ |
---|
63 | |
---|
64 | infos: function () { |
---|
65 | var width = 0, height = 0; |
---|
66 | var elem = jQuery(this).get(0); |
---|
67 | |
---|
68 | |
---|
69 | var Left = 0, Top = 0, offset, parentOffset, offsetParent, results; |
---|
70 | var borderwidth = { width: "0 0 0 0", |
---|
71 | top: 0, |
---|
72 | left: 0, |
---|
73 | right: 0, |
---|
74 | bottom: 0 |
---|
75 | } |
---|
76 | var padding = { padding: "0 0 0 0", |
---|
77 | top: 0, |
---|
78 | left: 0, |
---|
79 | right: 0, |
---|
80 | bottom: 0 |
---|
81 | }; |
---|
82 | var margin = { margin: "0 0 0 0", |
---|
83 | top: 0, |
---|
84 | left: 0, |
---|
85 | right: 0, |
---|
86 | bottom: 0 |
---|
87 | }; |
---|
88 | //===================================================================== |
---|
89 | myposition = ""; |
---|
90 | results = { |
---|
91 | position: "", |
---|
92 | top: 0, |
---|
93 | left: 0, |
---|
94 | width: 0, |
---|
95 | height: 0, |
---|
96 | right: 0, |
---|
97 | bottom: 0, |
---|
98 | borderwidth: borderwidth, |
---|
99 | padding: padding, |
---|
100 | margin: margin, id: "", nodeName: "" |
---|
101 | }; |
---|
102 | ; |
---|
103 | if (elem) { |
---|
104 | id = ""; nodeName = ""; |
---|
105 | if (elem.id) id = elem.id; |
---|
106 | if (elem.nodeName) nodeName = elem.nodeName; |
---|
107 | |
---|
108 | |
---|
109 | if (elem == window) { |
---|
110 | |
---|
111 | myposition = ""; |
---|
112 | width = jQuery(elem).width(); |
---|
113 | height = jQuery(elem).height(); |
---|
114 | } else { |
---|
115 | Css = jQuery(elem).getStyles(elem); |
---|
116 | myposition = Css.position || ""; |
---|
117 | width = jQuery(elem).outerWidth(); |
---|
118 | height = jQuery(elem).outerHeight(); |
---|
119 | |
---|
120 | |
---|
121 | borderwidth.left = jQuery(elem).Get_Val_int(Css.borderLeftWidth); |
---|
122 | borderwidth.right = jQuery(elem).Get_Val_int(Css.borderRightWidth); |
---|
123 | borderwidth.top = jQuery(elem).Get_Val_int(Css.borderTopWidth); |
---|
124 | borderwidth.bottom = jQuery(elem).Get_Val_int(Css.borderBottomWidth); |
---|
125 | try { |
---|
126 | borderwidth.width = Css.borderWidth; |
---|
127 | } catch (e) { |
---|
128 | borderwidth.width = '"' + borderwidth.left + ' ' + borderwidth.top + ' ' + borderwidth.right + ' ' + borderwidth.bottom + '"'; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | margin.left = jQuery(elem).Get_Val_int(Css.marginLeft); |
---|
134 | margin.right = jQuery(elem).Get_Val_int(Css.marginRight); |
---|
135 | margin.top = jQuery(elem).Get_Val_int(Css.marginTop); |
---|
136 | margin.bottom = jQuery(elem).Get_Val_int(Css.marginBottom); |
---|
137 | try { |
---|
138 | margin.margin = Css.margin; |
---|
139 | } catch (e) { |
---|
140 | margin.margin = '"' + margin.left + ' ' + margin.top + ' ' + margin.right + ' ' + margin.bottom + '"'; |
---|
141 | } |
---|
142 | |
---|
143 | padding.left = jQuery(elem).Get_Val_int(Css.paddingLeft); |
---|
144 | padding.right = jQuery(elem).Get_Val_int(Css.paddingRight); |
---|
145 | padding.top = jQuery(elem).Get_Val_int(Css.paddingTop); |
---|
146 | padding.bottom = jQuery(elem).Get_Val_int(Css.paddingBottom); |
---|
147 | try { |
---|
148 | padding.padding = Css.padding; |
---|
149 | } catch (e) { |
---|
150 | padding.padding = '"' + padding.left + ' ' + padding.top + ' ' + padding.right + ' ' + padding.bottom + '"'; |
---|
151 | } |
---|
152 | } |
---|
153 | if (elem == window) { |
---|
154 | Cl_Position = { Top: 0, Left: 0 }; |
---|
155 | } else { |
---|
156 | Cl_Position = jQuery(elem).position(); |
---|
157 | } |
---|
158 | Left = Cl_Position.left; |
---|
159 | Top = Cl_Position.top; |
---|
160 | |
---|
161 | results = { |
---|
162 | position: myposition, |
---|
163 | top: Top, |
---|
164 | left: Left, |
---|
165 | width: width, |
---|
166 | height: height, |
---|
167 | right: Left + width, |
---|
168 | bottom: Top + height, |
---|
169 | borderwidth: borderwidth, |
---|
170 | margin: margin, |
---|
171 | padding: padding, |
---|
172 | id: id, |
---|
173 | nodeName: nodeName |
---|
174 | }; |
---|
175 | |
---|
176 | return results |
---|
177 | } return results; |
---|
178 | }, |
---|
179 | /* |
---|
180 | * Cl_Position de l'object elem |
---|
181 | */ |
---|
182 | position: function () { |
---|
183 | var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results; |
---|
184 | |
---|
185 | if (elem) { |
---|
186 | offsetParent = this.offsetParent(); |
---|
187 | offset = this.offset(); |
---|
188 | |
---|
189 | if (offsetParent) { |
---|
190 | if (elem == window) { |
---|
191 | parentOffset = { top: 0, left: 0 }; |
---|
192 | } else if (typeof (offsetParent.offset) != "undefined") |
---|
193 | parentOffset = offsetParent.offset(); |
---|
194 | else |
---|
195 | parentOffset = { top: 0, left: 0 }; |
---|
196 | |
---|
197 | if (!offset) |
---|
198 | offset = { top: 0, left: 0 }; |
---|
199 | |
---|
200 | offset.top -= num(elem, 'marginTop'); |
---|
201 | offset.left -= num(elem, 'marginLeft'); |
---|
202 | |
---|
203 | if (offsetParent.length > 0) { |
---|
204 | parentOffset.top += num(offsetParent, 'borderTopWidth'); |
---|
205 | parentOffset.left += num(offsetParent, 'borderLeftWidth'); |
---|
206 | } else { |
---|
207 | parentOffset = { top: 0, left: 0 }; |
---|
208 | |
---|
209 | } |
---|
210 | } else { |
---|
211 | parentOffset = { top: 0, left: 0 }; |
---|
212 | } |
---|
213 | |
---|
214 | results = { |
---|
215 | top: Math.ceil(offset.top - parentOffset.top), left: Math.ceil(offset.left - parentOffset.left) |
---|
216 | }; |
---|
217 | } return results; |
---|
218 | }, |
---|
219 | /* |
---|
220 | * offsetParent |
---|
221 | */ |
---|
222 | offsetParent: function () { |
---|
223 | var offsetParent = this[0].offsetParent; |
---|
224 | while (offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static')) |
---|
225 | offsetParent = offsetParent.offsetParent; |
---|
226 | return jQuery(offsetParent); |
---|
227 | }, |
---|
228 | // getStyles(Obj) Récupérer la valeur CSS |
---|
229 | getStyles: function (elt) { |
---|
230 | var element = elt; |
---|
231 | if (window.getComputedStyle) // Mozilla Firefox & cie |
---|
232 | { |
---|
233 | var propriete = window.getComputedStyle(element, null); |
---|
234 | } |
---|
235 | else if (element.currentStyle) // Microsoft Internet Explorer |
---|
236 | { |
---|
237 | |
---|
238 | var propriete = element.currentStyle; |
---|
239 | } |
---|
240 | return propriete; |
---|
241 | }, |
---|
242 | /* |
---|
243 | * Get_val_int |
---|
244 | * params: element,valeur maxi |
---|
245 | * return: valeur entiere |
---|
246 | */ |
---|
247 | |
---|
248 | Get_Val_int: function (myObj, Maxi_val, Mini_val) { |
---|
249 | var val = 0; |
---|
250 | Maxi_val = parseInt(Maxi_val || "0"); |
---|
251 | |
---|
252 | /* |
---|
253 | - numérique suivie de px ou % ou pt ou em, |
---|
254 | - thin, bordure mince, |
---|
255 | - medium, bordure moyenne (valeur par défaut), |
---|
256 | - thick, bordure épaisse, |
---|
257 | - inherit, hérite de son parent (css2). |
---|
258 | */ |
---|
259 | |
---|
260 | if (!myObj) { |
---|
261 | return Maxi_val; |
---|
262 | } |
---|
263 | |
---|
264 | if (typeof (myObj) == "string") { |
---|
265 | |
---|
266 | if (myObj == "none") return Maxi_val; |
---|
267 | var reg1 = new RegExp("auto", "g") |
---|
268 | if (myObj.match(reg1)) { |
---|
269 | return Maxi_val; |
---|
270 | } |
---|
271 | reg1 = new RegExp("px", "g") |
---|
272 | if (myObj.match(reg1)) { |
---|
273 | |
---|
274 | myObj = parseInt(myObj); |
---|
275 | |
---|
276 | } |
---|
277 | else { |
---|
278 | reg1 = new RegExp("%", "g") |
---|
279 | if (myObj.match(reg1)) { |
---|
280 | val = Math.ceil(myObj * Maxi_val / 100); |
---|
281 | return val; |
---|
282 | } |
---|
283 | } |
---|
284 | |
---|
285 | if (Mini_val) |
---|
286 | if (myObj < Mini_val) return Maxi_val; |
---|
287 | |
---|
288 | switch (myObj) { |
---|
289 | case 'thin': |
---|
290 | return 1; |
---|
291 | break; |
---|
292 | case 'medium': |
---|
293 | return 2; |
---|
294 | break; |
---|
295 | case 'thick': |
---|
296 | return 4; |
---|
297 | break; |
---|
298 | case 'inherit': |
---|
299 | break; |
---|
300 | default: |
---|
301 | break; |
---|
302 | } |
---|
303 | |
---|
304 | |
---|
305 | |
---|
306 | val = parseInt(myObj); |
---|
307 | |
---|
308 | } else { |
---|
309 | val = parseInt(myObj); |
---|
310 | } |
---|
311 | if (typeof (val) == "NaN") return Maxi_val; |
---|
312 | return val; |
---|
313 | } |
---|
314 | }); |
---|
315 | /* |
---|
316 | * |
---|
317 | */ |
---|
318 | function num(el, prop) { |
---|
319 | return parseInt(jQuery.curCSS(el.jquery ? el[0] : el, prop, true)) || 0; |
---|
320 | }; |
---|
321 | |
---|
322 | myjQuery = jQuery; |
---|
323 | my$ = $; |
---|
324 | |
---|
325 | })(jQuery); |
---|