import { WebSocialShareFacebookAttributes } from '../types/web-social-share-attributes' ; import { shareEncodedUrl } from './utils' ; /**
 * Source: https://github.com/720kb/angular-socialshare/blob/master/dist/angular-socialshare.js
 */ export const shareFacebook = async ( attrs ) => { let urlString ; if ( attrs . socialShareType && attrs . socialShareType === 'feed' ) { urlString = 'https://www.facebook.com/dialog/feed?' ; if ( attrs . socialShareVia ) { urlString += '&app_id=' + encodeURIComponent ( attrs . socialShareVia ) ; } if ( attrs . socialShareRedirectUri ) { urlString += '&redirect_uri=' + encodeURIComponent ( attrs . socialShareRedirectUri ) ; } if ( attrs . socialShareUrl ) { urlString += '&link=' + shareEncodedUrl ( attrs . socialShareUrl ) ; } if ( attrs . socialShareTo ) { urlString += '&to=' + encodeURIComponent ( attrs . socialShareTo ) ; } if ( attrs . socialShareDisplay ) { urlString += '&display=' + encodeURIComponent ( attrs . socialShareDisplay ) ; } if ( attrs . socialShareRef ) { urlString += '&ref=' + encodeURIComponent ( attrs . socialShareRef ) ; } if ( attrs . socialShareFrom ) { urlString += '&from=' + encodeURIComponent ( attrs . socialShareFrom ) ; } if ( attrs . socialShareSource ) { urlString += '&source=' + encodeURIComponent ( attrs . socialShareSource ) ; } window . open ( urlString , 'Facebook' , 'toolbar=0,status=0,resizable=yes,width=' + attrs . socialSharePopupWidth + ',height=' + attrs . socialSharePopupHeight + ',top=' + ( window . innerHeight - attrs . socialSharePopupHeight ) / 2 + ',left=' + ( window . innerWidth - attrs . socialSharePopupWidth ) / 2 ) ; } else if ( attrs . socialShareType && attrs . socialShareType === 'share' ) { urlString = 'https://www.facebook.com/dialog/share?' ; if ( attrs . socialShareVia ) { urlString += '&app_id=' + encodeURIComponent ( attrs . socialShareVia ) ; } if ( attrs . socialShareRedirectUri ) { urlString += '&redirect_uri=' + encodeURIComponent ( attrs . socialShareRedirectUri ) ; } if ( attrs . socialShareUrl ) { urlString += '&href=' + shareEncodedUrl ( attrs . socialShareUrl ) ; } if ( attrs . socialShareQuote ) { urlString += '&quote=' + encodeURIComponent ( attrs . socialShareQuote ) ; } if ( attrs . socialShareDisplay ) { urlString += '&display=' + encodeURIComponent ( attrs . socialShareDisplay ) ; } if ( attrs . socialShareMobileiframe ) { urlString += '&mobile_iframe=' + encodeURIComponent ( attrs . socialShareMobileiframe ) ; } if ( attrs . socialShareHashtags ) { urlString += '&hashtag=' + encodeURIComponent ( attrs . socialShareHashtags ) ; } window . open ( urlString , 'Facebook' , 'toolbar=0,status=0,resizable=yes,width=' + attrs . socialSharePopupWidth + ',height=' + attrs . socialSharePopupHeight + ',top=' + ( window . innerHeight - attrs . socialSharePopupHeight ) / 2 + ',left=' + ( window . innerWidth - attrs . socialSharePopupWidth ) / 2 ) ; } else if ( attrs . socialShareType && attrs . socialShareType === 'send' ) { urlString = 'https://www.facebook.com/dialog/send?' ; if ( attrs . socialShareVia ) { urlString += '&app_id=' + encodeURIComponent ( attrs . socialShareVia ) ; } if ( attrs . socialShareRedirectUri ) { urlString += '&redirect_uri=' + encodeURIComponent ( attrs . socialShareRedirectUri ) ; } if ( attrs . socialShareUrl ) { urlString += '&link=' + shareEncodedUrl ( attrs . socialShareUrl ) ; } if ( attrs . socialShareTo ) { urlString += '&to=' + encodeURIComponent ( attrs . socialShareTo ) ; } if ( attrs . socialShareDisplay ) { urlString += '&display=' + encodeURIComponent ( attrs . socialShareDisplay ) ; } window . open ( urlString , 'Facebook' , 'toolbar=0,status=0,resizable=yes,width=' + attrs . socialSharePopupWidth + ',height=' + attrs . socialSharePopupHeight + ',top=' + ( window . innerHeight - attrs . socialSharePopupHeight ) / 2 + ',left=' + ( window . innerWidth - attrs . socialSharePopupWidth ) / 2 ) ; } else { window . open ( 'https://www.facebook.com/sharer/sharer.php?u=' + shareEncodedUrl ( attrs . socialShareUrl ) , 'Facebook' , 'toolbar=0,status=0,resizable=yes,width=' + attrs . socialSharePopupWidth + ',height=' + attrs . socialSharePopupHeight + ',top=' + ( window . innerHeight - attrs . socialSharePopupHeight ) / 2 + ',left=' + ( window . innerWidth - attrs . socialSharePopupWidth ) / 2 ) ; } } ;