Created
June 4, 2010 13:38
-
-
Save caisui/425419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://code.google.com/p/vimperator-labs/source/browse/common/content/buffer.js?spec=svna58ba2909452326de623a7a978799a44dcf92150&r=ba0d0f68dea50aa115e0d7f27be19c95f1f6ac54#1058 | |
//1058,1090 | |
findScrollable: function findScrollable(dir, horizontal) { | |
let pos = "scrollTop", size = "clientHeight", max = "scrollHeight", layoutSize = "offsetHeight", | |
overflow = "overflowX", border1 = "borderTopWidth", border2 = "borderBottomWidth"; | |
if (horizontal) | |
pos = "scrollLeft", size = "clientWidth", max = "scrollWidth", layoutSize = "offsetWidth", | |
overflow = "overflowX", border1 = "borderLeftWidth", border2 = "borderRightWidth"; | |
function find(elem) { | |
for (; elem && elem.parentNode instanceof Element; elem = elem.parentNode) { | |
let style = util.computedStyle(elem); | |
let borderSize = parseInt(style[border1]) + parseInt(style[border2]); | |
let realSize = elem[size]; | |
// Stupid Gecko eccentricities. May fail for quirks mode documents. | |
if (elem[size] + borderSize == elem[max] || elem[size] == 0) // Stupid, fallible heuristic. | |
continue; | |
if (style[overflow] == "hidden") | |
realSize += borderSize; | |
if (dir < 0 && elem[pos] > 0 || dir > 0 && elem[pos] + realSize < elem[max]) | |
break; | |
} | |
return elem; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment