2008-04-29 05:26:06 +02:00
|
|
|
// Create innerHeight, innerWidth, outerHeight and outerWidth methods
|
|
|
|
jQuery.each([ "Height", "Width" ], function(i, name){
|
|
|
|
|
2008-05-14 19:23:44 +02:00
|
|
|
var tl = i ? "Left" : "Top", // top or left
|
|
|
|
br = i ? "Right" : "Bottom"; // bottom or right
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2008-04-29 05:26:06 +02:00
|
|
|
// innerHeight and innerWidth
|
|
|
|
jQuery.fn["inner" + name] = function(){
|
2008-05-13 03:45:58 +02:00
|
|
|
return this[ name.toLowerCase() ]() +
|
|
|
|
num(this, "padding" + tl) +
|
2008-04-29 05:26:06 +02:00
|
|
|
num(this, "padding" + br);
|
|
|
|
};
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2008-04-29 05:26:06 +02:00
|
|
|
// outerHeight and outerWidth
|
|
|
|
jQuery.fn["outer" + name] = function(margin) {
|
2008-05-13 03:45:58 +02:00
|
|
|
return this["inner" + name]() +
|
2008-04-29 05:26:06 +02:00
|
|
|
num(this, "border" + tl + "Width") +
|
|
|
|
num(this, "border" + br + "Width") +
|
2008-05-14 19:23:44 +02:00
|
|
|
(margin ?
|
2008-04-29 05:26:06 +02:00
|
|
|
num(this, "margin" + tl) + num(this, "margin" + br) : 0);
|
|
|
|
};
|
2008-12-21 22:22:44 +01:00
|
|
|
|
|
|
|
var type = name.toLowerCase();
|
|
|
|
|
|
|
|
jQuery.fn[ type ] = function( size ) {
|
|
|
|
// Get window width or height
|
|
|
|
return this[0] == window ?
|
|
|
|
// Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
|
|
|
|
document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] ||
|
|
|
|
document.body[ "client" + name ] :
|
|
|
|
|
|
|
|
// Get document width or height
|
|
|
|
this[0] == document ?
|
|
|
|
// Either scroll[Width/Height] or offset[Width/Height], whichever is greater
|
|
|
|
Math.max(
|
|
|
|
document.documentElement["client" + name],
|
|
|
|
document.body["scroll" + name], document.documentElement["scroll" + name],
|
|
|
|
document.body["offset" + name], document.documentElement["offset" + name]
|
|
|
|
) :
|
|
|
|
|
|
|
|
// Get or set width or height on the element
|
|
|
|
size === undefined ?
|
|
|
|
// Get width or height on the element
|
|
|
|
(this.length ? jQuery.css( this[0], type ) : null) :
|
|
|
|
|
|
|
|
// Set the width or height on the element (default to pixels if value is unitless)
|
|
|
|
this.css( type, typeof size === "string" ? size : size + "px" );
|
|
|
|
};
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2008-05-15 14:53:07 +02:00
|
|
|
});
|