Skip to content

Instantly share code, notes, and snippets.

@dmikey
Created July 17, 2014 21:43
Show Gist options
  • Save dmikey/5e4c2a1a9b9f5f4f0559 to your computer and use it in GitHub Desktop.
Save dmikey/5e4c2a1a9b9f5f4f0559 to your computer and use it in GitHub Desktop.
Enyo control, that displays a ShareThis button. Requires use of enyo.Once (https://gist.github.com/dmikey/600ebf57cc11e085d13c) , see it in action: http://jsfiddle.net/toxigenicpoem/YE2LJ/show
(function(enyo, scope){
//load share this on the page
var loadShareThis = enyo.Once(function(callback) {
enyo.load('//w.sharethis.com/button/buttons.js',
callback
);
});
var checkShareThis = function(callback) {
//poll to see if sharethis was loaded on the page
loadShareThis(callback);
var pollShareThisId = setTimeout(function pollShareThis(){
if(typeof stWidget === 'object'){
clearTimeout(pollShareThisId);
callback();
}else {
setTimeout(pollShareThis, 1000)
};
}, 1000);
};
//share this kind for use in other controls
enyo.kind({
name: 'ShareThis',
components: [
{name:'shareThisContainer'}
],
hasExternalLoaded: false,
observers:{
'observeExternalLoaded': ['hasExternalLoaded']
},
opts: {
"service":"sharethis",
"url":"http://sharethis.com/3",
"title":"sharethis",
"type":"large",
"text":"ShareThis" ,
"image":"http://icons.iconarchive.com/icons/iconshock/high-detail-social/256/sharethis-icon.png",
"summary":"this is description3"
},
observeExternalLoaded: function(){
this.opts.element = document.getElementById(this.$.shareThisContainer.id);
stWidget.addEntry(this.opts);
},
constructor: function() {
this.inherited(arguments);
var loadCallback = enyo.bind(this, function(){
this.set('hasExternalLoaded', true);
});
checkShareThis(loadCallback);
}
});
}(enyo, this))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment