Plugin Directory

Changeset 609830


Ignore:
Timestamp:
10/09/2012 12:23:23 AM (13 years ago)
Author:
codeblab
Message:

Trying another absoluteXY.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • glass/trunk/glass.js

    r495408 r609830  
    160160function glassAddSupMargins(obj)
    161161{
    162   var mleft;
    163   var mtop;
     162  var mleft ='0px';
     163  var mtop = '0px';
    164164  var o = obj;
    165165  var computedStyle;
     
    191191        mtop   = computedStyle.marginTop;
    192192      }
    193      
     193      else {
     194    mleft = '0px';
     195    mtop = '0px';
     196      }
     197
    194198      if (mleft && mtop && (mleft != '0px' || mtop != '0px')) { 
    195199        // Use dummyImg to convert the strings to pixel counts.
     
    235239// Hence this function.
    236240//
    237 function glassAddAbsoluteXY(obj)
     241function glassAddAbsoluteXY__old(obj)
     242{
     243  o = obj; // Loop var.
     244  obj.absoluteX  = 0;
     245  obj.absoluteY  = 0;
     246  absoluteAncestor = false;
     247  computedStyle =
     248    (document.defaultView && document.defaultView.getComputedStyle);
     249  currentStyle = (element.currentStyle);
     250
     251  while (element.offsetParent) {
     252    obj.absoluteX += element.offsetLeft
     253    obj.absoluteY  += element.offsetTop
     254    element = element.offsetParent;
     255    //if the element hasLayout (IE-only property)
     256    if (currentStyle && element.currentStyle.hasLayout && (element.nodeName.toLowerCase() != 'html')) {
     257      //add the width of the left border
     258      obj.absoluteX += element.clientLeft;
     259      obj.absoluteY += element.clientTop;
     260      // and if it's absolutely positioned,
     261      // flag that we've got an absolutely positioned ancestor
     262      if (element.currentStyle['position'] == 'absolute')
     263        absoluteAncestor = true;
     264      // otherwise, if it's a browser that supports
     265      // computedStyle & the element is absolutely positioned
     266    } else if (computedStyle && document.defaultView.getComputedStyle(element, "").getPropertyValue('position') == 'absolute') {
     267      //add the left border of the element
     268      obj.absoluteX += parseInt(document.defaultView.getComputedStyle(element, "").getPropertyValue('border-left-width'));
     269      obj.absoluteY += parseInt(document.defaultView.getComputedStyle(element, "").getPropertyValue('border-top-width'));
     270      //and flag that we've got an absolutely positioned ancestor
     271      absoluteAncestor = true;
     272    }
     273  }
     274  // if the browser supports currentStyle (i.e. is IE)
     275  // and we found an absolutely positioned ancestor,
     276  // add any left margin on the BODY
     277  if (!absoluteAncestor && currentStyle) {
     278    obj.absoluteX += document.getElementsByTagName('BODY')[0].offsetLeft;
     279    obj.absoluteY  += document.getElementsByTagName('BODY')[0].offsetTop;
     280  }
     281  // otherwise, if we found an absolutely positioned ancestor
     282  // and the browser supports computed style add any left border from the BODY
     283  else if (!absoluteAncestor && computedStyle) {
     284    obj.absoluteX += parseInt(document.defaultView.getComputedStyle(document.getElementsByTagName('BODY')[0], "").getPropertyValue('border-left-width'));
     285    obj.absoluteY  += parseInt(document.defaultView.getComputedStyle(document.getElementsByTagName('BODY')[0], "").getPropertyValue('border-top-width'));
     286  }
     287}
     288
     289
     290// GlassAddAbsoluteXY: Add absoluteX and Y to properties of object.
     291//
     292// The absolute document position should be standard. It is not
     293// Hence this function.
     294//
     295function glassAddAbsoluteXY__old(obj)
    238296{
    239297  o = obj; // Loop var.
Note: See TracChangeset for help on using the changeset viewer.