Bug Tracker

Changeset 5345

Show
Ignore:
Timestamp:
04/29/08 03:26:06 (8 months ago)
Author:
brandon.aaron
Message:

Merged dimensions with core

Location:
trunk/jquery
Files:
2 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/build.xml

    r4244 r5345  
    4141            <fileset dir="${SRC_DIR}" includes="fx.js" /> 
    4242            <fileset dir="${SRC_DIR}" includes="offset.js" /> 
     43            <fileset dir="${SRC_DIR}" includes="dimensions.js" /> 
    4344            <fileset dir="${SRC_DIR}" includes="outro.js" /> 
    4445        </concat> 
  • trunk/jquery/Makefile

    r4549 r5345  
    1414    ${SRC_DIR}/ajax.js\ 
    1515    ${SRC_DIR}/fx.js\ 
    16     ${SRC_DIR}/offset.js 
     16    ${SRC_DIR}/offset.js\ 
     17    ${SRC_DIR}/dimensions.js 
    1718 
    1819PLUGINS = ${PLUG_DIR}/button/*\ 
  • trunk/jquery/src/offset.js

    r5275 r5345  
    9999}; 
    100100 
    101 // Create innerHeight, innerWidth, outerHeight and outerWidth methods 
    102 jQuery.each(["Height", "Width"], function(i, name){ 
    103101 
    104     var tl = name == "Height" ? "Top"    : "Left",  // top or left 
    105         br = name == "Height" ? "Bottom" : "Right"; // bottom or right 
     102jQuery.fn.extend({ 
     103    position: function() { 
     104        var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results; 
     105         
     106        if (elem) { 
     107            // Get *real* offsetParent 
     108            offsetParent = this.offsetParent(); 
     109             
     110            // Get correct offsets 
     111            offset       = this.offset(); 
     112            parentOffset = offsetParent.offset(); 
     113             
     114            // Subtract element margins 
     115            offset.top  -= parseInt( jQuery.curCSS(elem, 'marginTop', true) ) || 0; 
     116            offset.left -= parseInt( jQuery.curCSS(elem, 'marginLeft', true) ) || 0; 
     117             
     118            // Add offsetParent borders 
     119            parentOffset.top  += parseInt( jQuery.curCSS(offsetParent[0], 'borderTopWidth', true) ) || 0; 
     120            parentOffset.left += parseInt( jQuery.curCSS(offsetParent[0], 'borderLeftWidth', true) ) || 0; 
     121             
     122            // Subtract the two offsets 
     123            results = { 
     124                top:  offset.top  - parentOffset.top, 
     125                left: offset.left - parentOffset.left 
     126            }; 
     127        } 
     128         
     129        return results; 
     130    }, 
    106131     
    107     // innerHeight and innerWidth 
    108     jQuery.fn["inner" + name] = function(){ 
    109         return this[ name.toLowerCase() ]() +  
    110             num(this, "padding" + tl) +  
    111             num(this, "padding" + br); 
    112     }; 
    113      
    114     // outerHeight and outerWidth 
    115     jQuery.fn["outer" + name] = function(margin) { 
    116         return this["inner" + name]() +  
    117             num(this, "border" + tl + "Width") + 
    118             num(this, "border" + br + "Width") + 
    119             (!!margin ?  
    120                 num(this, "margin" + tl) + num(this, "margin" + br) : 0); 
    121     }; 
    122      
     132    offsetParent: function() { 
     133        var offsetParent = this[0].offsetParent; 
     134        while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static') ) 
     135            offsetParent = offsetParent.offsetParent; 
     136        return jQuery(offsetParent); 
     137    } 
    123138}); 
    124139 
    125 function num(elem, prop) { 
    126     elem = elem.jquery ? elem[0] : elem; 
    127     return elem && parseInt( jQuery.curCSS(elem, prop, true) ) || 0; 
    128 } 
     140 
     141// Create scrollLeft and scrollTop methods 
     142jQuery.each( ['Left', 'Top'], function(i, name) { 
     143    jQuery.fn[ 'scroll' + name ] = function(val) { 
     144        if (!this[0]) return; 
     145         
     146        return val != undefined ? 
     147         
     148            // Set the scroll offset 
     149            this.each(function() { 
     150                this == window || this == document ? 
     151                    window.scrollTo(  
     152                        name == 'Left' ? val : jQuery(window)[ 'scrollLeft' ](), 
     153                        name == 'Top'  ? val : jQuery(window)[ 'scrollTop'  ]() 
     154                    ) : 
     155                    this[ 'scroll' + name ] = val; 
     156            }) : 
     157             
     158            // Return the scroll offset 
     159            this[0] == window || this[0] == document ? 
     160                self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] || 
     161                    jQuery.boxModel && document.documentElement[ 'scroll' + name ] || 
     162                    document.body[ 'scroll' + name ] : 
     163                this[0][ 'scroll' + name ]; 
     164    }; 
     165}); 
  • trunk/jquery/test/index.html

    r4217 r5345  
    99    <script type="text/javascript" src="data/testrunner.js"></script> 
    1010    <script type="text/javascript" src="unit/core.js"></script> 
     11    <script type="text/javascript" src="unit/dimensions.js"></script> 
    1112    <script type="text/javascript" src="unit/selector.js"></script> 
    1213    <script type="text/javascript" src="unit/event.js"></script>