Skip to content

Instantly share code, notes, and snippets.

@stephandesouza
Last active September 6, 2016 13:36
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 stephandesouza/2fc18738dd5483e9f5ac5b5bcf4a2426 to your computer and use it in GitHub Desktop.
Save stephandesouza/2fc18738dd5483e9f5ac5b5bcf4a2426 to your computer and use it in GitHub Desktop.
jQuery Sharer
<!--
Para o caso do Pinterest DEVEMOS informar se estamos no escopo de um single, ou archive (caso não usado Wordpress),
pois no modo Archive ele deve considerar somente a foto informada no data-thumb, enquanto no single ele pode aceitar
qualquer imagem do conteúdo (ver JS)
-->
<body class="single">
<ul class="nav nav-sharing"
data-thumb="{{thumb}}"
data-url="{{url]}"
data-title="{{title}}"
data-description="{{description}}">
<li>
<a role="button" class="btn btn-facebook">
<i class="fa fa-facebook" aria-hidden="true"></i>
<span class="sr-only">Compartilhar no Facebook</span>
</a>
</li>
<li>
<a role="button" class="btn btn-twitter">
<i class="fa fa-twitter" aria-hidden="true"></i>
<span class="sr-only">Compartilhar no Twitter</span>
</a>
</li>
<!-- Negamos Google Plus no Mobile -->
<li class="hidden-xs">
<a role="button" class="btn btn-googleplus"><i class="fa fa-google-plus" aria-hidden="true"></i>
<span class="sr-only">Compartilhar no Google Plus</span>
</a>
</li>
<li>
<a role="button" class="btn btn-pinterest">
<i class="fa fa-pinterest" aria-hidden="true"></i>
<span class="sr-only">Compartilhar no Pinterest</span>
</a>
</li>
<!-- Whatsapp Somente no Mobile -->
<li class="visible-xs">
<a role="button" class="btn btn-whatsapp">
<i class="fa fa-whatsapp" aria-hidden="true"></i>
<span class="sr-only">Compartilhar no Whatsapp</span>
</a>
</li>
</ul>
function onClickShare(e) {
e.preventDefault();
var $link = $(e.currentTarget),
$nav = $(e.delegateTarget),
network = '(not set)',
pageTitle = $nav.data('title'),
shareUrl = $nav.data('url'),
thumb = $nav.data('thumb');
if ($link.hasClass('btn-facebook')) {
network = 'facebook';
if (window.FB && window.FB.ui) {
window.FB.ui({
method: 'share',
href: shareUrl
});
} else {
window.open('https://www.facebook.com/sharer/sharer.php?u=' + shareUrl, '_blank', 'height=400, width=800');
}
} else if ($link.hasClass('btn-twitter')) {
network = 'twitter';
window.open('https://twitter.com/intent/tweet?text=' + pageTitle + ' - ' + shareUrl, '_blank', 'height=' + shareWindowHeight + ', width= ' + shareWindowWidth);
} else if ($link.hasClass('btn-googleplus')) {
network = 'googleplus';
window.open('https://plus.google.com/share?url=' + shareUrl, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');
} else if ($link.hasClass('btn-whatsapp')) {
network = 'whatsapp';
window.open('whatsapp://send?text=' + pageTitle + ' - ' + shareUrl);
} else if ($link.hasClass('btn-pinterest')) {
network = 'pinterest';
if (window.PinUtils) {
if ($body.hasClass('single')) {
PinUtils.pinAny();
} else {
PinUtils.pinOne({
media: thumb,
url: shareUrl,
description: pageTitle
});
}
} else {
window.open('http://pinterest.com/pin/create/button/?url=' + shareUrl + '&media=' + thumb + '&description=' + pageTitle, '_blank', 'height=' + shareWindowHeight + ', width= ' + shareWindowWidth);
}
}
if (window.dataLayer) {
window.dataLayer.push({
event: 'pc_share_url',
network: network,
shareUrl: shareUrl,
pageTitle: pageTitle
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment