Created
February 5, 2019 23:25
-
-
Save tarngerine/127aaf8ed1cfb6975cbfc90990a014ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// A Huge Hack to "support" iframes for iOS devices | |
// On widget load, set iframe height manually to timeline height | |
// To support [Load More] button, adjust height on every touch/click event | |
// Using this on desktop as well to minimize areas to debug | |
let updateIframeHeight = (iframe) => { | |
let viewport = iframe.contentDocument.documentElement.getElementsByClassName("timeline-Viewport")[0]; | |
viewport.style.overflow = "hidden"; | |
let timeline = iframe.contentDocument.documentElement.getElementsByClassName("timeline-TweetList")[0]; | |
iframe.style.height = timeline.offsetHeight + 64; // Load button height | |
} | |
// There are two Twitter widget events: 'loaded' and 'rendered'. | |
// Loaded happens later, presumably after timeline loads | |
twttr.events.bind( | |
'loaded', | |
function (event) { | |
event.widgets.forEach(function (widget) { | |
updateIframeHeight(widget); | |
let delayedUpdateIframeHeight = () => { | |
setTimeout(() => updateIframeHeight(widget), 250); // Account for fast loads | |
setTimeout(() => updateIframeHeight(widget), 1000); | |
} | |
widget.contentDocument.addEventListener('touchend', delayedUpdateIframeHeight); | |
widget.contentDocument.addEventListener('click', delayedUpdateIframeHeight); | |
}); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment