Skip to content

Instantly share code, notes, and snippets.

@djaney
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save djaney/832531c306468162b8d9 to your computer and use it in GitHub Desktop.

Select an option

Save djaney/832531c306468162b8d9 to your computer and use it in GitHub Desktop.
angular.module('ngSocialMedia',[])
.directive('fbShare',function($window){
var fbShare = function(url, winWidth, winHeight) {
url = url || $window.location.href;
winWidth = winWidth || 520;
winHeight = winHeight || 350;
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
window.open('https://www.facebook.com/sharer.php?s=100&p[url]=' + url , 'fbSharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
}
return {
link:function(scope,elem,attrs){
elem.click(function(){
fbShare(attrs.fbShare);
});
}
}
})
.directive('twShare',function($window){
var twShare = function(content, winWidth, winHeight) {
var url = $window.location.href;
content = content || 'Join Gourmet Society to get at least 20% discount at all of our partner restaurants, plus other exclusive treats. '+url;
winWidth = winWidth || 520;
winHeight = winHeight || 350;
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
window.open('https://twitter.com/home?status=' + encodeURIComponent(content) , 'twShare', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
}
return {
link:function(scope,elem,attrs){
elem.click(function(){
twShare(attrs.twShare);
});
}
}
})
.directive('gplusShare',function($window){
var gplusShare = function(url, winWidth, winHeight) {
url = url || $window.location.href;
winWidth = winWidth || 520;
winHeight = winHeight || 350;
var winTop = (screen.height / 2) - (winHeight / 2);
var winLeft = (screen.width / 2) - (winWidth / 2);
window.open('https://plus.google.com/share?url=' + url , 'gplusShare', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width=' + winWidth + ',height=' + winHeight);
}
return {
link:function(scope,elem,attrs){
elem.click(function(){
gplusShare(attrs.gplusShare);
});
}
}
})
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment