Skip to content

Commit

Permalink
Some cleanup of Element:getOffsetParent.
Browse files Browse the repository at this point in the history
  • Loading branch information
timwienk authored and cpojer committed Oct 27, 2010
1 parent 92a0d19 commit 0b855f1
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions Source/Element/Element.Dimensions.js
Expand Up @@ -65,29 +65,31 @@ Element.implement({
var isOffset = function(el){
return styleString(el, 'position') != 'static' || isBody(el);
};

var isOffsetStatic = function(el){
return isOffset(el) || (/^(?:table|td|th)$/i).test(el.tagName);
};
return function(){

return (brokenOffsetParent) ? function(){
var element = this;
if (isBody(element) || styleString(element, 'position') == 'fixed') return null;
if (!brokenOffsetParent){
// orphan nodes on ie8 fire exception while accessing offsetParent
try {
return element.offsetParent;
} catch(e) {
return null;
}
}


var isOffsetCheck = (styleString(element, 'position') == 'static') ? isOffsetStatic : isOffset;

while ((element = element.parentNode)){
if (isOffsetCheck(element)) return element;
}

return null;
} : function(){
var element = this;
if (isBody(element) || styleString(element, 'position') == 'fixed') return null;

try {
return element.offsetParent;
} catch(e) {
return null;
}
};
})(),

Expand Down

0 comments on commit 0b855f1

Please sign in to comment.