Skip to content

Instantly share code, notes, and snippets.

@Systerr
Last active August 29, 2015 14:13
Show Gist options
  • Save Systerr/b15d9470070e8d6e39d6 to your computer and use it in GitHub Desktop.
Save Systerr/b15d9470070e8d6e39d6 to your computer and use it in GitHub Desktop.
Social share
$(".social-icon").on("click",function(e){
var $this = $(this);
if ($this.hasClass("vk_en")){
Share.vkontakte(location.href);
} else if ($this.hasClass("fb")){
Share.facebook(location.href);
} else if ($this.hasClass("ok")){
Share.odnoklassniki(location.href);
} else if ($this.hasClass("g_plus")){
Share.google(location.href);
}
e.preventDefault();
})
Share = {
vkontakte: function(purl, ptitle, pimg, text) {
var url = 'http://vkontakte.ru/share.php?';
url += 'url=' + encodeURIComponent(purl);
//url += '&title=' + encodeURIComponent(ptitle);
//url += '&description=' + encodeURIComponent(text);
//url += '&image=' + encodeURIComponent(pimg);
//url += '&noparse=true';
Share.popup(url);
},
odnoklassniki: function(purl, text) {
var url = 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1';
//url += '&st.comments=' + encodeURIComponent(text);
url += '&st._surl=' + encodeURIComponent(purl);
Share.popup(url);
},
facebook: function(purl, ptitle, pimg, text) {
url = 'http://www.facebook.com/sharer.php?s=100';
//url += '&p[title]=' + encodeURIComponent(ptitle);
//url += '&p[summary]=' + encodeURIComponent(text);
url += '&p[url]=' + encodeURIComponent(purl);
//url += '&p[images][0]=' + encodeURIComponent(pimg);
Share.popup(url);
},
twitter: function(purl, ptitle) {
var url = 'http://twitter.com/share?';
//url += 'text=' + encodeURIComponent(ptitle);
url += '&url=' + encodeURIComponent(purl);
//url += '&counturl=' + encodeURIComponent(purl);
Share.popup(url);
},
mailru: function(purl, ptitle, pimg, text) {
var url = 'http://connect.mail.ru/share?';
url += 'url=' + encodeURIComponent(purl);
url += '&title=' + encodeURIComponent(ptitle);
url += '&description=' + encodeURIComponent(text);
url += '&imageurl=' + encodeURIComponent(pimg);
Share.popup(url)
},
google: function(purl){
var url = 'https://plus.google.com/share?';
url += 'url=' + encodeURIComponent(purl);
Share.popup(url)
},
popup: function(url) {
window.open(url,'','toolbar=0,status=0,width=626,height=436');
}
}
<div class="social-box">
<a href="https://www.facebook.com/" class="social-icon fb"></a>
<a href="https://plus.google.com/" class="social-icon g_plus"></a>
<a href="http://www.odnoklasnilki.ru/" class="social-icon ok"></a>
<a href="http://vk.com/" class="social-icon vk_en"></a>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment