UNPKG

web-social-share

Version:

A Web Component to share urls and text on social networks

24 lines (23 loc) 872 B
import { staticOpenNewWindow, isMobile, shareEncodedUrl } from './utils'; export const whatsapp = async (attrs) => { const mobile = isMobile(); let urlString = mobile ? 'https://api.whatsapp.com/send?text=' : 'https://web.whatsapp.com/send?text='; if (attrs.socialShareText) { urlString += encodeURIComponent(attrs.socialShareText) + '%0A'; } //default to the current page if a URL isn't specified urlString += shareEncodedUrl(attrs.socialShareUrl); if (mobile) { staticOpenNewWindow(urlString); } else { window.open(urlString, 'WhatsApp', 'toolbar=0,status=0,resizable=yes,width=' + attrs.socialSharePopupWidth + ',height=' + attrs.socialSharePopupHeight + ',top=' + (window.innerHeight - attrs.socialSharePopupHeight) / 2 + ',left=' + (window.innerWidth - attrs.socialSharePopupWidth) / 2); } };