/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net) * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * * $LastChangedDate: 2007-12-20 08:43:48 -0600 (Thu, 20 Dec 2007) $ * $Rev: 4257 $ * * $LastChangedDate: 2010-10-23 08:43:48 -0600 (Thu, 20 Dec 2007) $ * By cljosse * Version: 1.3 * * Requires: jQuery 1.2+ * */ (function (jQuery) { jQuery.dimensions = { version: '1.3' }; /* * Interception Height, Width */ jQuery.each(['Height', 'Width'], function (i, name) { jQuery.fn['inner' + name] = function () { if (!this[0]) return; var torl = name == 'Height' ? 'Top' : 'Left', borr = name == 'Height' ? 'Bottom' : 'Right'; return this.is(':visible') ? this[0]['client' + name] : num(this, name.toLowerCase()) + num(this, 'padding' + torl) + num(this, 'padding' + borr); }; jQuery.fn['outer' + name] = function (options) { if (!this[0]) return; var torl = name == 'Height' ? 'Top' : 'Left', borr = name == 'Height' ? 'Bottom' : 'Right'; options = options || false; options = jQuery.extend({ margin: options }); Maxi_val = this.parent().width(); var val = this.is(':visible') ? this[0]['offset' + name] : num(this, name.toLowerCase()) + num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width') + num(this, 'padding' + torl) + num(this, 'padding' + borr) ; return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0); }; }); /* * */ jQuery.each(['Left', 'Top', 'Right', 'Bottom', 'All'], function (i, name) { //========== scroll ================= jQuery.fn['scroll' + name] = function (val) { if (!this[0]) return; return val != undefined ? this.each(function () { this == window || this == document ? window.scrollTo(name == 'Left' ? val : $(window)['scrollLeft'](), name == 'Top' ? val : $(window)['scrollTop']()) : this['scroll' + name] = val; }) : 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]; }; //========= Absolute ===================== jQuery.fn['absolute' + name] = function (Args) { if (!this[0]) return 0; a = jQuery(this[0]); m = { Left: 0, Top: 0, Right: 0, Bottom: 0, All: { Left: 0, Top: 0, Right: 0, Bottom: 0 } }; pos = jQuery(this).offset(); pos.top = Math.ceil(pos.top); pos.left = Math.ceil(pos.left); size = { width: jQuery(this).outerWidth(), height: jQuery(this).outerHeight() }; if (name == "All") { m[name]['Left'] = pos.left; m[name]['Top'] = pos.top; m[name]['Right'] = pos.left + size.width; m[name]['Bottom'] = pos.top + size.height; } else { if (name == 'Left' || name == 'Top') { m[name] = name == 'Left' ? pos.left : (pos.top); } else { m[name] = name == 'Right' ? pos.left + size.width : pos.top + size.height; } } return m[name]; }; }); //===================================================== jQuery.fn.extend({ infos: function (Arguments) { if (Arguments) { if (Arguments == true) { Args = { absolute: true || false, externe: Arguments.externe || false }; } else { Args = { absolute: Arguments.absolute || false, externe: Arguments.externe || false }; } } else { Args = { absolute: false, externe: false }; } var width = 0, height = 0; var elem = jQuery(this).get(0); var Left = 0, Top = 0, results; var borderwidth = { width: "0 0 0 0", top: 0, left: 0, right: 0, bottom: 0 }; var padding = { padding: "0 0 0 0", top: 0, left: 0, right: 0, bottom: 0 }; var margin = { margin: "0 0 0 0", top: 0, left: 0, right: 0, bottom: 0 }; //===================================================================== myposition = ""; results = { visible: false, position: "", top: 0, left: 0, width: 0, height: 0, right: 0, bottom: 0, borderwidth: borderwidth, padding: padding, margin: margin, out: { width: 0, height: 0, right: 0, bottom: 0 }, exterieur: { width: 0, height: 0, right: 0, bottom: 0 }, general: { width: 0, height: 0, right: 0, bottom: 0, marges: { height: 0, top: 0, bottom: 0, width: 0, left: 0, right: 0 } }, src: "", useMap: "", id: "", nodeName: "" }; ; if (elem) { id = ""; nodeName = ""; if (elem.id) id = elem.id; if (elem.nodeName) nodeName = elem.nodeName; width = jQuery(elem).width(); height = jQuery(elem).height(); if (elem == window) { myposition = ""; var myWidth = 0, myHeight = 0; var x2Height = jQuery(window).height(); if (typeof (window.innerWidth) == 'number') { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } if (myHeight != x2Height) { width = myWidth; } width = myWidth; height = myHeight; out_width = myWidth; out_height = myHeight; in_width = myWidth; ; in_height = myHeight; } else { Css = jQuery(elem).getStyles(elem); myposition = Css.position.toString() || ""; out_width = jQuery(elem).outerWidth(); out_height = jQuery(elem).outerHeight(); in_width = jQuery(elem).innerWidth(); in_height = jQuery(elem).innerHeight(); elem_parent = elem.parentElement; if (typeof elem_parent == "undefined") { elem_parent = window; } if (typeof Css.width != "undefined") width = Get_Val_int(Css.width, jQuery(elem_parent).width(), 0); if (typeof Css.height != "undefined") height = Get_Val_int(Css.height, jQuery(elem_parent).height(), 0); borderwidth.left = Get_Val_int(Css.borderLeftWidth, "", "", { elem: elem, prop: 'borderLeftWidth' }); borderwidth.right = Get_Val_int(Css.borderRightWidth, "", "", { elem: elem, prop: 'borderRightWidth' }); borderwidth.top = Get_Val_int(Css.borderTopWidth, "", "", { elem: elem, prop: 'borderTopWidth' }); borderwidth.bottom = Get_Val_int(Css.borderBottomWidth, "", "", { elem: elem, prop: 'borderBottomWidth' }); try { borderwidth.width = Css.borderWidth; } catch (e) { borderwidth.width = '"' + borderwidth.left + ' ' + borderwidth.top + ' ' + borderwidth.right + ' ' + borderwidth.bottom + '"'; } margin.left = Get_Val_int(Css.marginLeft, "", "", { elem: elem, prop: 'marginLeft' }); margin.right = Get_Val_int(Css.marginRight, "", "", { elem: elem, prop: 'marginRight' }); margin.top = Get_Val_int(Css.marginTop, "", "", { elem: elem, prop: 'marginTop' }); margin.bottom = Get_Val_int(Css.marginBottom, "", "", { elem: elem, prop: 'marginBottom' }); try { margin.margin = Css.margin; } catch (e) { margin.margin = '"' + margin.left + ' ' + margin.top + ' ' + margin.right + ' ' + margin.bottom + '"'; } padding.left = Get_Val_int(Css.paddingLeft, "", "", { elem: elem, prop: 'paddingLeft' }); padding.right = Get_Val_int(Css.paddingRight, "", "", { elem: elem, prop: 'paddingRight' }); padding.top = Get_Val_int(Css.paddingTop, "", "", { elem: elem, prop: 'paddingTop' }); padding.bottom = Get_Val_int(Css.paddingBottom, "", "", { elem: elem, prop: 'paddingBottom' }); try { padding.padding = Css.padding; } catch (e) { padding.padding = '"' + padding.left + ' ' + padding.top + ' ' + padding.right + ' ' + padding.bottom + '"'; } } if (elem == window) { Cl_Position = { top: 0, left: 0 }; } else { Cl_Position = jQuery(elem).d_position(); /* margin: 5px; border: 10px ; padding: 20px; */ s_elem = elem; Left = Cl_Position.left; // 291 Top = Cl_Position.top; // 812 if (Args.absolute == true) { all = jQuery(elem).absoluteAll(); Top = all.Top; Left = all.Left; Args.externe = false; } if (Args.externe == true) { if (elem.tagName != "BODY") { nodeName = nodeName || ""; L1 = jQuery(elem).position(); // sans les marges ; L2 = jQuery(elem).position(true); // 296 x 817 Left = L1.left; Top = L1.top; } } elem = s_elem; } visible = jQuery(elem).is(':visible'); results = { useMap: elem.useMap || "none", src: elem.src || "none", visible: visible || false, position: myposition, top: Top, left: Left, width: width, // valeur interieur height: height, right: Left + width, bottom: Top + height, padding: padding, out: { width: in_width, height: in_height, right: Left + in_width, bottom: Top + in_height }, borderwidth: borderwidth, exterieur: { width: out_width, height: out_height, right: Left + out_width, bottom: Top + out_height }, margin: margin, general: { width: out_width + margin.left + margin.right, height: out_height + margin.top + margin.bottom, right: Left + out_width + margin.left + margin.right, bottom: Top + out_height + margin.top + margin.bottom, marges: { height: margin.top + borderwidth.top + padding.top + margin.bottom + borderwidth.bottom + padding.bottom, top: margin.top + borderwidth.top + padding.top, bottom: margin.bottom + borderwidth.bottom + padding.bottom, width: margin.left + borderwidth.left + padding.left + margin.right + borderwidth.right + padding.right, left: margin.left + borderwidth.left + padding.left, right: margin.right + borderwidth.right + padding.right } }, id: id, nodeName: nodeName || "" }; return results; } return results; }, /* * Cl_Position de l'object elem */ d_position: function () { var elem = this[0], offset, parentOffset, offsetParent, results=null; l1 = jQuery(elem).css("left"); if (elem) { offsetParent = this.offsetParent(); offset = this.offset(); offset_j = jQuery(this).offset(); if (offsetParent) { if (elem == window) { parentOffset = { top: 0, left: 0 }; } else if (typeof (offsetParent.offset) != "undefined") parentOffset = offsetParent.offset(); else parentOffset = { top: 0, left: 0 }; if (!offset) offset = { top: 0, left: 0 }; offset.top -= num(elem, 'marginTop'); offset.left -= num(elem, 'marginLeft'); if (offsetParent.length > 0) { parentOffset.top += num(offsetParent, 'borderTopWidth'); parentOffset.left += num(offsetParent, 'borderLeftWidth'); } else { parentOffset = { top: 0, left: 0 }; } } else { parentOffset = { top: 0, left: 0 }; } results = { top: Math.ceil(offset.top - parentOffset.top), left: Math.ceil(offset.left - parentOffset.left) }; } return results; }, /* * offsetParent */ offsetParent: function () { var offsetParent = null; if (this[0] == window) return; try { n1 = this[0].nodeName; offsetParent = this[0].offsetParent; while (offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static')) offsetParent = offsetParent.offsetParent; return jQuery(offsetParent); } catch (e) { jQuery(offsetParent); } }, // getStyles(Obj) Récupérer la valeur CSS getStyles: function (elt) { var element = jQuery(elt).get(0); propriete = []; try { if (jQuery(element).length > 0) if (window.getComputedStyle) // Mozilla Firefox & cie { propriete = window.getComputedStyle(element, null); } else if (element.currentStyle) // Microsoft Internet Explorer { propriete = element.currentStyle; } } catch (e) { } return propriete; }, Get_Val_int: function (myObj, Maxi_val, Mini_val, prop) { return Get_Val_int(myObj, Maxi_val, Mini_val, prop); } }); /************************** * Get_val_int * params: element,valeur maxi * return: valeur entiere ******************************/ Get_Val_int = function (myObj, Maxi_val, Mini_val, prop) { var val = 0; Maxi_val = parseInt(Maxi_val || "0"); /* - numérique suivie de px ou % ou pt ou em, - thin, bordure mince, - medium, bordure moyenne (valeur par défaut), - thick, bordure épaisse, - inherit, hérite de son parent (css2). */ if (!myObj) { return Maxi_val; } if (typeof (myObj) == "string") { switch (myObj) { case 'thin': return 1; break; case 'medium': return 2; break; case 'thick': return 4; break; case 'inherit': break; case 'none': return Maxi_val; break; default: break; } var reg1 = new RegExp("auto", "g"); if (myObj.match(reg1)) { return Maxi_val; } if (prop) { myObj = num(prop.elem, prop.prop); } else { reg1 = new RegExp("px", "g"); if (myObj.match(reg1)) { myObj = Parse_Int(myObj); } else { reg1 = new RegExp("%", "g"); if (myObj.match(reg1)) { myObj = myObj.replace(reg1, ""); val = Math.ceil(myObj * Maxi_val / 100); return val; } } } if (Mini_val) if (myObj < Mini_val) return Maxi_val; val = Parse_Int(myObj); } else { val = Parse_Int(myObj); } if (typeof (val) == "NaN") return Maxi_val; return val; }; /* * */ function Parse_Int(valeur_num) { if (!jQuery.isNumeric(valeur_num)) { valeur_num = valeur_num.toString(); reg1 = new RegExp("px", "gi"); if (valeur_num.match(reg1)) { valeur_num = valeur_num.replace(reg1, ""); } if (valeur_num.match(RegExp("%", "gi"))) { valeur_num = valeur_num.replace(reg1, ""); valeur_num = Math.ceil(valeur_num * Maxi_val / 100); } else { valeur_num = valeur_num.replace(reg1, ""); } } valeur_num = Math.ceil(valeur_num)|| 0; return valeur_num ; } function num(el, prop) { valeur_num = jQuery.css(el.jquery ? el[0] : el, prop, true); return Parse_Int(valeur_num); }; // myjQuery = jQuery; // my$ = $; })(jQuery);