/* 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-10-06 20:11:15 +0200 (sa, 06 okt 2007) $ * $rev: 3581 $ * * version: @version * * requires: jquery 1.2+ */ (function($){ $.dimensions = { version: '@version' }; // create innerheight, innerwidth, outerheight and outerwidth methods $.each( [ 'height', 'width' ], function(i, name){ // innerheight and innerwidth $.fn[ 'inner' + name ] = function() { if (!this[0]) return; var torl = name == 'height' ? 'top' : 'left', // top or left borr = name == 'height' ? 'bottom' : 'right'; // bottom or right return num( this, name.tolowercase() ) + num(this, 'padding' + torl) + num(this, 'padding' + borr); }; // outerheight and outerwidth $.fn[ 'outer' + name ] = function(options) { if (!this[0]) return; var torl = name == 'height' ? 'top' : 'left', // top or left borr = name == 'height' ? 'bottom' : 'right'; // bottom or right options = $.extend({ margin: false }, options || {}); return num( this, name.tolowercase() ) + num(this, 'border' + torl + 'width') + num(this, 'border' + borr + 'width') + num(this, 'padding' + torl) + num(this, 'padding' + borr) + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0); }; }); // create scrollleft and scrolltop methods $.each( ['left', 'top'], function(i, name) { $.fn[ 'scroll' + name ] = function(val) { if (!this[0]) return; return val != undefined ? // set the scroll offset this.each(function() { this == window || this == document ? window.scrollto( name == 'left' ? val : $(window)[ 'scrollleft' ](), name == 'top' ? val : $(window)[ 'scrolltop' ]() ) : this[ 'scroll' + name ] = val; }) : // return the scroll offset this[0] == window || this[0] == document ? self[ (name == 'left' ? 'pagexoffset' : 'pageyoffset') ] || $.boxmodel && document.documentelement[ 'scroll' + name ] || document.body[ 'scroll' + name ] : this[0][ 'scroll' + name ]; }; }); $.fn.extend({ position: function() { var left = 0, top = 0, elem = this[0], offset, parentoffset, offsetparent, results; if (elem) { // get *real* offsetparent offsetparent = this.offsetparent(); // get correct offsets offset = this.offset(); parentoffset = offsetparent.offset(); // subtract element margins offset.top -= num(elem, 'margintop'); offset.left -= num(elem, 'marginleft'); // add offsetparent borders parentoffset.top += num(offsetparent, 'bordertopwidth'); parentoffset.left += num(offsetparent, 'borderleftwidth'); // subtract the two offsets results = { top: offset.top - parentoffset.top, left: offset.left - parentoffset.left }; } return results; }, offsetparent: function() { var offsetparent = this[0].offsetparent; while ( offsetparent && (!/^body|html$/i.test(offsetparent.tagname) && $.css(offsetparent, 'position') == 'static') ) offsetparent = offsetparent.offsetparent; return $(offsetparent); } }); function num(el, prop) { return parseint($.css(el.jquery?el[0]:el,prop))||0; }; })(jquery);