JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr{ gilour

File "share-link-socially.ts"

Full Path: /home/markqprx/iniasli.pro/resources/client/utils/urls/share-link-socially.ts
File size: 1.63 KB
MIME-type: text/plain
Charset: utf-8

export type ShareableNetworks =
  | 'facebook'
  | 'twitter'
  | 'pinterest'
  | 'tumblr'
  | 'blogger'
  | 'mail';

export function shareLinkSocially(
  network: ShareableNetworks,
  link: string,
  name?: string,
  image?: string
) {
  const url = generateShareUrl(network, link, name, image);

  if (network === 'mail') {
    window.location.href = url;
  } else {
    openNewWindow(url);
  }
}

function openNewWindow(url: string) {
  const width = 575,
    height = 400,
    left = (window.innerWidth - width) / 2,
    top = (window.innerHeight - height) / 2,
    opts =
      'status=1, scrollbars=1' +
      ',width=' +
      width +
      ',height=' +
      height +
      ',top=' +
      top +
      ',left=' +
      left;

  window.open(url, 'share', opts);
}

function generateShareUrl(
  type: ShareableNetworks,
  link: string,
  name?: string,
  image?: string
): string {
  switch (type) {
    case 'facebook':
      return 'https://www.facebook.com/sharer/sharer.php?u=' + link;
    case 'twitter':
      return `https://twitter.com/intent/tweet?text=${name}&url=${link}`;
    case 'pinterest':
      return (
        'https://pinterest.com/pin/create/button/?url=' +
        link +
        '&media=' +
        image
      );
    case 'tumblr':
      const base =
        'https://www.tumblr.com/widgets/share/tool?shareSource=legacy&canonicalUrl=&posttype=photo&title=&caption=';
      return base + name + '&content=' + image + '&url=' + link;
    case 'blogger':
      return (
        'https://www.blogger.com/blog_this.pyra?t&u=' + link + '&n=' + name
      );
    case 'mail':
      return `mailto:?subject=Check out this link.&body=${link}`;
  }
}