Skip to content

Instantly share code, notes, and snippets.

@xmalinov
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xmalinov/f131e2f471c09762c61f to your computer and use it in GitHub Desktop.
Save xmalinov/f131e2f471c09762c61f to your computer and use it in GitHub Desktop.
Social share snippet
/* Add id for divs with class "item" (vk, fb, tw, ok, mr)
** <div id="fb" class="item"></div>
** Uses jQuery
*/
$('.social-buttons>.item').click(function(e) {
var url = encodeURIComponent('http://somelink.ru');
var title = encodeURIComponent('Title');
var description = encodeURIComponent('Description');
var image = encodeURIComponent('http://somelink.ru/shared-image.jpg');
var id = $(this).attr('id');
var shareURL;
var windowTitle;
var width = 500;
var height = 500;
switch (id) {
case 'vk':
shareURL = 'http://vkontakte.ru/share.php?url=' + url + '&title=' + title + '&description=' + description + '&image=' + image + '&noparse=true';
windowTitle = 'ВКонтакте';
break;
case 'fb':
shareURL = 'http://www.facebook.com/sharer/sharer.php?u=' + url + '&t=' + title;
windowTitle = 'Facebook';
break;
case 'tw':
shareURL = 'http://twitter.com/share?text=' + title + '&url=' + url + '&counturl=' + url;
windowTitle = 'Twitter';
break;
case 'ok':
shareURL = 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1&st.comments=' + description + '&st._surl=' + url;
windowTitle = 'Одноклассники';
break;
case 'mr':
shareURL = 'http://connect.mail.ru/share?url=' + url + '&title=' + title + '&description=' + description + '&image_url=' + image;
windowTitle = 'Mail.ru';
break;
}
window.open(shareURL, windowTitle, 'status=no,scrollbars=no,resizable=yes,width=' + width + ',height=' + height + '');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment