source: extensions/cl_conflit/js/jquery.dimensions.js @ 8740

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

[cl_conflit] compatibility whith GMaps


File size: 12.2 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 = 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, "", "", 'borderLeftWidth');
122                    borderwidth.right = jQuery(elem).Get_Val_int(Css.borderRightWidth, "", "", 'borderRightWidth');
123                    borderwidth.top = jQuery(elem).Get_Val_int(Css.borderTopWidth, "", "", 'borderTopWidth');
124                    borderwidth.bottom = jQuery(elem).Get_Val_int(Css.borderBottomWidth, "", "", '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, "", "", 'marginLeft');
134                    margin.right = jQuery(elem).Get_Val_int(Css.marginRight, "", "", 'marginRight');
135                    margin.top = jQuery(elem).Get_Val_int(Css.marginTop, "", "", 'marginTop');
136                    margin.bottom = jQuery(elem).Get_Val_int(Css.marginBottom, "", "", '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
144                    padding.left = jQuery(elem).Get_Val_int(Css.paddingLeft, "", "", 'paddingLeft');
145                    padding.right = jQuery(elem).Get_Val_int(Css.paddingRight, "", "", 'paddingRight');
146                    padding.top = jQuery(elem).Get_Val_int(Css.paddingTop, "", "", 'paddingTop');
147                    padding.bottom = jQuery(elem).Get_Val_int(Css.paddingBottom, "", "", 'paddingBottom');
148                    try {
149                        padding.padding = Css.padding;
150                    } catch (e) {
151                        padding.padding = '"' + padding.left + ' ' + padding.top + ' ' + padding.right + ' ' + padding.bottom + '"';
152                    }
153                }
154                if (elem == window) {
155                    Cl_Position = { Top: 0, Left: 0 };
156                } else {
157                    Cl_Position = jQuery(elem).position();
158                }
159                Left = Cl_Position.left;
160                Top = Cl_Position.top;
161
162                results = {
163                    position: myposition,
164                    top: Top,
165                    left: Left,
166                    width: width,
167                    height: height,
168                    right: Left + width,
169                    bottom: Top + height,
170                    borderwidth: borderwidth,
171                    margin: margin,
172                    padding: padding,
173                    id: id,
174                    nodeName: nodeName
175                };
176
177                return results
178            } return results;
179        },
180        /*
181        * Cl_Position de l'object elem
182        */
183        position: function () {
184            var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
185
186            if (elem) {
187                offsetParent = this.offsetParent();
188                offset = this.offset();
189
190                if (offsetParent) {
191                    if (elem == window) {
192                        parentOffset = { top: 0, left: 0 };
193                    } else if (typeof (offsetParent.offset) != "undefined")
194                        parentOffset = offsetParent.offset();
195                    else
196                        parentOffset = { top: 0, left: 0 };
197
198                    if (!offset)
199                        offset = { top: 0, left: 0 };
200
201                    offset.top -= num(elem, 'marginTop');
202                    offset.left -= num(elem, 'marginLeft');
203
204                    if (offsetParent.length > 0) {
205                        parentOffset.top += num(offsetParent, 'borderTopWidth');
206                        parentOffset.left += num(offsetParent, 'borderLeftWidth');
207                    } else {
208                        parentOffset = { top: 0, left: 0 };
209
210                    }
211                } else {
212                    parentOffset = { top: 0, left: 0 };
213                }
214
215                results = {
216                    top: Math.ceil(offset.top - parentOffset.top), left: Math.ceil(offset.left - parentOffset.left)
217                };
218            } return results;
219        },
220        /*
221        * offsetParent
222        */
223        offsetParent: function () {
224            var offsetParent = this[0].offsetParent;
225            while (offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static'))
226                offsetParent = offsetParent.offsetParent;
227            return jQuery(offsetParent);
228        },
229        // getStyles(Obj) Récupérer la valeur CSS
230        getStyles: function (elt) {
231            var element = elt;
232            if (window.getComputedStyle) // Mozilla Firefox & cie
233            {
234                var propriete = window.getComputedStyle(element, null);
235            }
236            else if (element.currentStyle) // Microsoft Internet Explorer
237            {
238
239                var propriete = element.currentStyle;
240            }
241            return propriete;
242        },
243        /*
244        * Get_val_int
245        * params: element,valeur maxi
246        * return: valeur entiere
247        */
248
249        Get_Val_int: function (myObj, Maxi_val, Mini_val, prop) {
250            var val = 0;
251
252            Maxi_val = parseInt(Maxi_val || "0");
253
254            /*
255            - numérique suivie de px ou % ou pt ou em,
256            - thin, bordure mince,
257            - medium, bordure moyenne (valeur par défaut),
258            - thick, bordure épaisse,
259            - inherit, hérite de son parent (css2).
260            */
261
262            if (!myObj) {
263                return Maxi_val;
264            }
265
266            if (typeof (myObj) == "string") {
267                switch (myObj) {
268                    case 'thin':
269                        return 1;
270                        break;
271                    case 'medium':
272                        return 2;
273                        break;
274                    case 'thick':
275                        return 4;
276                        break;
277                    case 'inherit':
278                        break;
279                    case 'none':
280                        return Maxi_val;
281                        break;
282                    default:
283                        break;
284                }
285                el = this.get(0);
286                var reg1 = new RegExp("auto", "g")
287                if (myObj.match(reg1)) {
288                    return Maxi_val;
289                }
290                if (prop)
291                    myObj = num(el, prop);
292                else {
293                    reg1 = new RegExp("px", "g")
294                    if (myObj.match(reg1)) {
295
296                        myObj = parseInt(myObj);
297
298                    } else {
299                        reg1 = new RegExp("%", "g")
300                        if (myObj.match(reg1)) {
301                            val = Math.ceil(myObj * Maxi_val / 100);
302                            return val;
303                        }
304
305                    }
306
307                }
308
309                if (Mini_val)
310                    if (myObj < Mini_val) return Maxi_val;
311
312
313                val = parseInt(myObj);
314
315            } else {
316                val = parseInt(myObj);
317            }
318            if (typeof (val) == "NaN") return Maxi_val;
319            return val;
320        }
321    });
322    /*
323    *
324    */
325    function num(el, prop) {
326        return parseInt(jQuery.curCSS(el.jquery ? el[0] : el, prop, true)) || 0;
327    };
328
329    myjQuery = jQuery;
330    my$ = $;
331
332})(jQuery);
Note: See TracBrowser for help on using the repository browser.