Last active
November 27, 2019 23:24
-
-
Save jerel/e15288cf911a2a89f1c1 to your computer and use it in GitHub Desktop.
Making the default Twitter tweet widgets work in an EmberJS application. This adds the twitter widget script after the tweets are in the DOM.
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
// Method 1 | |
// add the twitter widget library to the bottom of app/index.html (after your Ember app) | |
<script src="//platform.twitter.com/widgets.js" charset="utf-8"></script> | |
// initialize it after the content is in the DOM | |
import Ember from 'ember'; | |
export default Ember.View.extend({ | |
didInsertElement: function() { | |
window.twttr.widgets.load(); | |
} | |
}); | |
// Method 2 | |
import Ember from 'ember'; | |
export default Ember.View.extend({ | |
didInsertElement: function() { | |
var script = window.document.createElement('script'); | |
script.id = 'twitter-script'; | |
script.src = '//platform.twitter.com/widgets.js'; | |
script.charset = 'utf-8'; | |
window.$('body').append(script); | |
}, | |
willDestroyElement: function() { | |
window.$('#twitter-script', 'body').remove(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment