Skip to content

Instantly share code, notes, and snippets.

@tunderdomb
tunderdomb / currentScript.polyfill.js
Created June 25, 2014 14:56
document.currentScript polyfill (a really barebones one)
if ( typeof document.currentScript == "undefined" && document.__defineGetter__ ) {
document.__defineGetter__("currentScript", function (){
try {
throw new Error()
}
catch ( e ) {
var qualifiedUrl = location.protocol + "//" + location.host
, srcs = e.stack.match(new RegExp(qualifiedUrl + ".*?\\.js", 'g'))
, src = srcs[srcs.length - 1]
, absoluteUrl = src.replace(qualifiedUrl, "")
@tunderdomb
tunderdomb / getScrollable
Created March 27, 2014 15:42
get the scrollable root element on the page
// get the actually scrollable element
function getScrollable( root ){
if ( !root.nodeName || !!~["iframe", "#document", "html", "body"].indexOf(root.nodeName.toLowerCase()) ) {
var doc = (root.contentWindow || root).document || root.ownerDocument || root
root = /webkit/i.test(navigator.userAgent) || doc.compatMode == "BackCompat"
? doc.body
: doc.documentElement;
}
return root
}