Skip to content

Instantly share code, notes, and snippets.

@aortbals
Last active August 29, 2015 14:07
Show Gist options
  • Save aortbals/536c57f4b97d4c01a853 to your computer and use it in GitHub Desktop.
Save aortbals/536c57f4b97d4c01a853 to your computer and use it in GitHub Desktop.
Ember Twitter Sharing Button Component
Tweet it!
{{twitter-button data-text=twitterText data-url=twitterUrl}}
/* global twittr */
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'a',
classNames: 'twitter-share-button',
attributeBindings: ['data-size', 'data-url', 'data-text', 'data-hashtags'],
/**
Twitter must reinitialize after content is rendered.
https://dev.twitter.com/web/javascript/initialization
*/
loadWidgets: function() {
window.twttr.widgets.load(this.get('element'));
}.on('didInsertElement')
});
import config from 'app/config/environment';
export default {
name: 'twitter',
initialize: function(container, application) {
Ember.debug('Initializing twitter widgets')
window.twttr = (function (d, s, id) {
var t, js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
return window.twttr || (t = { _e: [], ready: function (f) { t._e.push(f) } });
}(document, "script", "twitter-wjs"));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment