Created
July 14, 2015 21:30
-
-
Save kirqe/487f413da79d7c8c93f0 to your computer and use it in GitHub Desktop.
Async twitter widget with rails turbolinks
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
<!-- before: --> | |
<a class="twitter-timeline" | |
href="https://twitter.com/twitterapi" | |
data-widget-id="YOUR-WIDGET-ID">Tweets by @twitterapi</a> | |
<!-- after: --> | |
<div class="twiiter-timeline-container" | |
data-widget-id="YOUR-WIDGET-ID" | |
data-widget-options="<%= { borderColor: '#abcdef' }.to_json %>"> | |
</div> | |
//app/assets/javascripts/twitter.js.coffee | |
$ -> | |
loadTwitterSDK() | |
$(document).on 'page:change', renderTimelines | |
loadTwitterSDK = -> | |
$.getScript "//platform.twitter.com/widgets.js", -> | |
renderTimelines() | |
renderTimelines = -> | |
$('.twitter-timeline-container').each -> | |
$container = $(this) | |
widgetId = $container.data 'widget-id' | |
widgetOptions = $container.data 'widget-options' | |
$container.empty() | |
twttr?.widgets.createTimeline widgetId, $container[0], null, widgetOptions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you have an updated version of this one?