0
+/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
0
+ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
0
+ * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
0
+ * $LastChangedDate: 2007-12-20 08:46:55 -0600 (Thu, 20 Dec 2007) $
0
+ * Requires: jQuery 1.2+
0
+// Create innerHeight, innerWidth, outerHeight and outerWidth methods
0
+$.each( [ 'Height', 'Width' ], function(i, name){
0
+ // innerHeight and innerWidth
0
+ $.fn[ 'inner' + name ] = function() {
0
+ var torl = name == 'Height' ? 'Top' : 'Left', // top or left
0
+ borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
0
+ return this.is(':visible') ? this[0]['client' + name] : num( this, name.toLowerCase() ) + num(this, 'padding' + torl) + num(this, 'padding' + borr);
0
+ // outerHeight and outerWidth
0
+ $.fn[ 'outer' + name ] = function(options) {
0
+ var torl = name == 'Height' ? 'Top' : 'Left', // top or left
0
+ borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
0
+ options = $.extend({ margin: false }, options || {});
0
+ var val = this.is(':visible') ?
0
+ this[0]['offset' + name] :
0
+ num( this, name.toLowerCase() )
0
+ + num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
0
+ + num(this, 'padding' + torl) + num(this, 'padding' + borr);
0
+ return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
0
+// Create scrollLeft and scrollTop methods
0
+$.each( ['Left', 'Top'], function(i, name) {
0
+ $.fn[ 'scroll' + name ] = function(val) {
0
+ return val != undefined ?
0
+ // Set the scroll offset
0
+ this.each(function() {
0
+ this == window || this == document ?
0
+ name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
0
+ name == 'Top' ? val : $(window)[ 'scrollTop' ]()
0
+ this[ 'scroll' + name ] = val;
0
+ // Return the scroll offset
0
+ this[0] == window || this[0] == document ?
0
+ self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
0
+ $.boxModel && document.documentElement[ 'scroll' + name ] ||
0
+ document.body[ 'scroll' + name ] :
0
+ this[0][ 'scroll' + name ];
0
+ position: function() {
0
+ var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
0
+ // Get *real* offsetParent
0
+ offsetParent = this.offsetParent();
0
+ // Get correct offsets
0
+ offset = this.offset();
0
+ parentOffset = offsetParent.offset();
0
+ // Subtract element margins
0
+ offset.top -= num(elem, 'marginTop');
0
+ offset.left -= num(elem, 'marginLeft');
0
+ // Add offsetParent borders
0
+ parentOffset.top += num(offsetParent, 'borderTopWidth');
0
+ parentOffset.left += num(offsetParent, 'borderLeftWidth');
0
+ // Subtract the two offsets
0
+ top: offset.top - parentOffset.top,
0
+ left: offset.left - parentOffset.left
0
+ offsetParent: function() {
0
+ var offsetParent = this[0].offsetParent;
0
+ while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
0
+ offsetParent = offsetParent.offsetParent;
0
+ return $(offsetParent);
0
+function num(el, prop) {
0
+ return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;
Comments
No one has commented yet.