Skip to content

Instantly share code, notes, and snippets.

@slav123
Created March 15, 2013 00:06
Show Gist options
  • Save slav123/5166418 to your computer and use it in GitHub Desktop.
Save slav123/5166418 to your computer and use it in GitHub Desktop.
$(".social a",ifrm.contentWindow.document).social();
// social Buttons
// When a user clicks an item this function determines how to create a social button from it.
$.fn.social = function(){
//Add popup functionality for share buttons
return $(this).each(function(){
var service = this.className.match(/social_([a-z]+)/);
if(!service) return;
service = service[1];
var image = window.location.protocol+"//"+window.location.host+"/" +$("meta[property='og:image']").attr("content");
var share_url_short = '';
var share_url = '';
// Determine the service
var url = {
google : "https://plus.google.com/share?url=" + share_url,
facebook : "http://www.facebook.com/sharer.php?s=100&p[title]=Commonwealth%20Bank%20Signals&p[url]="+share_url+"&p[summary]=Did%20you%20know%20that%20for%20almost%20a%20quarter%20of%20parents%2C%20childcare%20costs%20are%20equal%20to%2C%20or%20greater%20than%2C%20wages%20earned%20per%20parent%20returning%20to%20work%3F%20Find%20out%20more%20on%20the%20cost%20of%20childcare%20here%3A.&p[images][0]=" + image,
twitter : "http://www.twitter.com/share?text=For+almost+1%2F4+of+parents%2C+childcare+costs+outweigh+wages+earned+per+parent+returning+to+work.+Find+out+more+here&url="+share_url_short,
pinterest : "http://pinterest.com/pin/create/button/?url="+share_url+"&media=http%3A%2F%2Flocalhost%2Fcba-signals-app%2Fcba-signals-app%2Fassets%2Fimg%2Fsocial%2Fsocial_pinterest.png&description=A%20look%20at%20the%20spending%20habits%20of%20Australians%20just%20like%20me.%20%23commbankSignals",
rss : "http://blog.commbank.com.au/feed",
commbank : "http://blog.commbank.com.au/"
}[service];
if(!url){
return;
}
$(this).attr({
href:url,
target:'_blank',
title: service[0].toUpperCase() + service.slice(1)
});
// Dont add popups to these
if(!!~'commbank,rss'.indexOf(service)){
return;
}
$(this).on('click', function(e){
e.preventDefault();
var width = 575,
height = 400,
left = ($(window).width() - width) / 2,
top = ($(window).height() - height) / 2,
opts = 'status=1' +
',width=' + width +
',height=' + height +
',top=' + top +
',left=' + left;
window.open(url, 'twitter', opts);
switch(service){
case "google":
_gaq.push(['_trackSocial', 'Google', 'Share']);
break;
case "twitter":
_gaq.push(['_trackSocial', 'Twitter', 'Tweet']);
break;
case "facebook":
_gaq.push(['_trackSocial', 'Facebook', 'Like']);
break;
case "pinterest":
_gaq.push(['_trackSocial', 'Pintrest', 'Pin']);
break;
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment