Skip to content

Instantly share code, notes, and snippets.

@jerel
Last active November 27, 2019 23:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerel/e15288cf911a2a89f1c1 to your computer and use it in GitHub Desktop.
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.
// 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