Created
June 4, 2010 15:03
-
-
Save caisui/425514 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
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.ownerDocument; elem = elem.parentNode) { | |
let style = util.computedStyle(elem); | |
let realSize = elem[size]; | |
// Stupid Gecko eccentricities. May fail for quirks mode documents. | |
if (style.overflow === "visible") // Stupid, fallible heuristic. | |
continue; | |
if (dir < 0 && elem[pos] > 0 || dir > 0 && elem[pos] + realSize < elem[max]) | |
break; | |
} | |
return elem; | |
} | |
let win = this.focusedWindow; | |
if (win.getSelection().rangeCount) | |
var elem = find(win.getSelection().getRangeAt(0).startContainer); | |
if (!(elem instanceof Element)) { | |
let doc = Buffer.findScrollableWindow().document; | |
elem = (doc.compatMode === "CSS1Compat" ? doc.documentElement : doc.body) || doc.getElementsByTagName("body")[0]; | |
} | |
return elem; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment