source: extensions/Autosize/js/jquery.dimensions.js @ 7899

Last change on this file since 7899 was 7899, checked in by cljosse, 13 years ago

[cl_conflit] fix conflict with rv_gmaps

File size: 11.4 KB
Line 
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 = jQuery.extend({ margin: false },
34                                                options || {});
35                    var val = this.is(':visible') ? this[0]['offset' + name] :
36                        num(this,
37                        name.toLowerCase()) +
38                        num(this, 'border' + torl + 'Width') +
39                        num(this, 'border' + borr + 'Width') +
40                        num(this, 'padding' + torl) +
41                        num(this, 'padding' + borr);
42                    return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
43                };
44            });
45    /*
46    *
47    */
48    jQuery.each(['Left', 'Top'],
49      function (i, name) {
50          jQuery.fn['scroll' + name] = function (val) {
51              if (!this[0]) return;
52              return val != undefined ? this.each(function () {
53                  this == window || this == document ? window.scrollTo(name == 'Left' ? val : $(window)['scrollLeft'](),
54           name == 'Top' ? val : $(window)['scrollTop']()) : this['scroll' + name] = val;
55              }) : 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];
56          };
57
58      });
59    jQuery.fn.extend({
60
61        infos: function () {
62            var width = 0, height = 0;
63            var elem = jQuery(this).get(0);
64
65
66            var Left = 0, Top = 0, offset, parentOffset, offsetParent, results;
67            var borderwidth = { width: "0 0 0 0",
68                top: 0,
69                left: 0,
70                right: 0,
71                bottom: 0
72            }
73            var padding = { padding: "0 0 0 0",
74                top: 0,
75                left: 0,
76                right: 0,
77                bottom: 0
78            };
79            var margin = { margin: "0 0 0 0",
80                top: 0,
81                left: 0,
82                right: 0,
83                bottom: 0
84            };
85            //=====================================================================
86            myposition = "";
87            results = {
88                position: "",
89                top: 0,
90                left: 0,
91                width: 0,
92                height: 0,
93                right: 0,
94                bottom: 0,
95                borderwidth: borderwidth,
96                padding: padding,
97                margin: margin, id: "", nodeName: ""
98            };
99            ;
100            if (elem) {
101                id = ""; nodeName = "";
102                if (elem.id) id = elem.id;
103                if (elem.nodeName) nodeName = elem.nodeName;
104
105
106                if (elem == window) {
107
108                    myposition = jQuery(this).attr("position") || "";
109                    width = jQuery(elem).width();
110                    height = jQuery(elem).height();
111                } else {
112                    myposition = jQuery(this).css("position") || "";
113                    width = jQuery(elem).outerWidth();
114                    height = jQuery(elem).outerHeight();
115
116
117                    borderwidth.left = jQuery(elem).Get_Val_int(jQuery(elem).css("borderLeftWidth"));
118                    borderwidth.right = jQuery(elem).Get_Val_int(jQuery(elem).css("borderRightWidth"));
119                    borderwidth.top = jQuery(elem).Get_Val_int(jQuery(elem).css("borderTopWidth"));
120                    borderwidth.bottom = jQuery(elem).Get_Val_int(jQuery(elem).css("borderBottomWidth"));
121                    try {
122                        borderwidth.width = jQuery(elem).Get_Val_int(jQuery(elem).css("borderWidth"));
123                    } catch (e) {
124                        borderwidth.width = '"' + borderwidth.left + ' ' + borderwidth.top + ' ' + borderwidth.right + ' ' + borderwidth.bottom + '"';
125                    }
126
127
128                    margin.left = jQuery(elem).Get_Val_int(jQuery(elem).css("marginLeft"));
129                    margin.right = jQuery(elem).Get_Val_int(jQuery(elem).css("marginRight"));
130                    margin.top = jQuery(elem).Get_Val_int(jQuery(elem).css("marginTop"));
131                    margin.bottom = jQuery(elem).Get_Val_int(jQuery(elem).css("marginBottom"));
132                    try {
133                        margin.margin = jQuery(elem).Get_Val_int(jQuery(elem).css("margin"));
134                    } catch (e) {
135                        margin.margin = '"' + margin.left + ' ' + margin.top + ' ' + margin.right + ' ' + margin.bottom + '"';
136                    }
137
138                    padding.left = jQuery(elem).Get_Val_int(jQuery(elem).css("paddingLeft"));
139                    padding.right = jQuery(elem).Get_Val_int(jQuery(elem).css("paddingRight"));
140                    padding.top = jQuery(elem).Get_Val_int(jQuery(elem).css("paddingTop"));
141                    padding.bottom = jQuery(elem).Get_Val_int(jQuery(elem).css("paddingBottom"));
142                    try { padding.padding = jQuery(elem).Get_Val_int(jQuery(elem).css("padding")); } catch (e) {
143                        padding.padding = '"' + padding.left + ' ' + padding.top + ' ' + padding.right + ' ' + padding.bottom + '"';
144                    }
145                }
146                if (elem == window) {
147                    Cl_Position = { Top: 0, Left: 0 };
148                } else {
149                    Cl_Position = jQuery(elem).position();
150                }
151                Left = Cl_Position.left;
152                Top = Cl_Position.top;
153
154                results = {
155                    position: myposition,
156                    top: Top,
157                    left: Left,
158                    width: width,
159                    height: height,
160                    right: Left + width,
161                    bottom: Top + height,
162                    borderwidth: borderwidth,
163                    margin: margin,
164                    padding: padding,
165                    id: id,
166                    nodeName: nodeName
167                };
168
169                return results
170            } return results;
171        },
172        /*
173        * Cl_Position de l'object elem
174        */
175        position: function () {
176            var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
177
178            if (elem) {
179                offsetParent = this.offsetParent();
180                offset = this.offset();
181
182                if (offsetParent) {
183                    if (elem == window) {
184                        parentOffset = { top: 0, left: 0 };
185                    } else if (typeof (offsetParent.offset) != "undefined")
186                        parentOffset = offsetParent.offset();
187                    else
188                        parentOffset = { top: 0, left: 0 };
189
190                    if (!offset)
191                        offset = { top: 0, left: 0 };
192
193                    offset.top -= num(elem, 'marginTop');
194                    offset.left -= num(elem, 'marginLeft');
195
196                    if (offsetParent.length > 0) {
197                        parentOffset.top += num(offsetParent, 'borderTopWidth');
198                        parentOffset.left += num(offsetParent, 'borderLeftWidth');
199                    } else {
200                        parentOffset = { top: 0, left: 0 };
201
202                    }
203                } else {
204                    parentOffset = { top: 0, left: 0 };
205                }
206
207                results = {
208                    top: Math.ceil(offset.top - parentOffset.top), left: Math.ceil(offset.left - parentOffset.left)
209                };
210            } return results;
211        },
212        /*
213        * offsetParent
214        */
215        offsetParent: function () {
216            var offsetParent = this[0].offsetParent;
217            while (offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static'))
218                offsetParent = offsetParent.offsetParent;
219            return jQuery(offsetParent);
220        },
221        /*
222        * Get_val_int
223        * params: element,valeur maxi
224        * return: valeur entiere
225        */
226
227        Get_Val_int: function (myObj, Maxi_val, Mini_val) {
228            var val = 0;
229
230            Maxi_val = parseInt(Maxi_val || "0");
231
232            /*
233            - numérique suivie de px ou % ou pt ou em,
234            - thin, bordure mince,
235            - medium, bordure moyenne (valeur par défaut),
236            - thick, bordure épaisse,
237            - inherit, hérite de son parent (css2).
238            */
239
240            if (!myObj) {
241                return Maxi_val;
242            }
243
244            if (typeof (myObj) == "string") {
245                if (myObj == "none") return Maxi_val;
246                if (myObj == "auto") return Maxi_val;
247                var reg1 = new RegExp("px", "g")
248                if (myObj.match(reg1)) {
249
250                    myObj = parseInt(myObj);
251
252                }
253                else {
254                    reg1 = new RegExp("%", "g")
255                    if (myObj.match(reg1)) {
256                        val = Math.ceil(myObj * Maxi_val / 100);
257                        return val;
258                    }
259                }
260
261                if (Mini_val)
262                    if (myObj < Mini_val) return Maxi_val;
263
264                switch (myObj) {
265                    case 'thin':
266                        return 1;
267                        break;
268                    case 'medium':
269                        return 2;
270                        break;
271                    case 'thick':
272                        return 4;
273                        break;
274                    case 'inherit':
275                        break;
276                    default:
277                        break;
278                }
279
280
281
282                val = parseInt(myObj);
283
284            } else {
285                val = parseInt(myObj);
286            }
287            if (typeof (val) == "NaN") return Maxi_val;
288            return val;
289        }
290    });
291    /*
292    *
293    */
294    function num(el, prop) {
295        return parseInt(jQuery.curCSS(el.jquery ? el[0] : el, prop, true)) || 0;
296    };
297
298
299
300})(jQuery);
Note: See TracBrowser for help on using the repository browser.