Skip to content

Instantly share code, notes, and snippets.

@hugofabricio
Created February 23, 2017 19:37
Show Gist options
  • Save hugofabricio/ae41c578e6c6653414d9331ca439b2d6 to your computer and use it in GitHub Desktop.
Save hugofabricio/ae41c578e6c6653414d9331ca439b2d6 to your computer and use it in GitHub Desktop.
class Share {
constructor() {
console.log('>>> Share constructor');
this.initShare();
}
initShare() {
$('.-share').click(function (e) {
e.preventDefault();
let url;
const el = $(this);
const shareUrl = encodeURIComponent(el.data('url'));
const shareTitle = encodeURIComponent(el.data('title'));
if (el.hasClass('-facebook')) {
url = `https://www.facebook.com/sharer/sharer.php?u=${shareUrl}`;
} else if (el.hasClass('-linkedin')) {
url = `https://www.linkedin.com/shareArticle?mini=true&url=${shareUrl}&title=${shareTitle}`;
} else if (el.hasClass('-twitter')) {
url = `https://twitter.com/intent/tweet?url=${shareUrl}&text=${shareTitle}&wrap_links=true`;
} else if (el.hasClass('-google')) {
url = `https://plus.google.com/share?url=${shareUrl}`;
} else if (el.hasClass('-whatsapp')) {
url = `whatsapp://send?text=${shareTitle} ${shareUrl}`;
}
window.open(url);
});
}
}
export default Share;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment