!(function(e, t) {
  "object" == typeof exports && "undefined" != typeof module
    ? (module.exports = t())
    : "function" == typeof define && define.amd
    ? define(t)
    : ((e = e || self).ShareButtons = t());
})(this, function() {
  "use strict";
  var k = window,
    w = k.document;
  var e = new (function() {
    function s(e, n) {
      return e.replace(/\{(\d+)\}/g, function(e, t) {
        return n[t] || e;
      });
    }
    function u(e) {
      return e.join(" - ");
    }
    function l(e) {
      return encodeURIComponent(e);
    }
    this.i = function() {
      for (var e = w.querySelectorAll(".share-btn"), t = e.length; t--; )
        n(e[t]);
    };
    var n = function(e) {
        for (var t = e.querySelectorAll("a"), n = t.length; n--; )
          r(t[n], { id: "", url: i(e), title: c(e), desc: o(e) });
      },
      r = function(e, t) {
        (t.id = f(e, "data-id")), t.id && (d(e, "click"), p(e, "click", t));
      },
      i = function(e) {
        return f(e, "data-url") || location.href || " ";
      },
      c = function(e) {
        return f(e, "data-title") || w.title || " ";
      },
      o = function(e) {
        var t = w.querySelector("meta[name=description]");
        return f(e, "data-desc") || (t && f(t, "content")) || " ";
      },
      a = 0,
      h = {},
      d = function(e, t) {
        var n = e.getAttribute("data-sharebtn-ref");
        n &&
          (e.removeEventListener
            ? e.removeEventListener(t, h[n])
            : e.detachEvent("on" + t, h[n + "ie"]));
      },
      p = function(e, t, n) {
        function r() {
          b(n.id, n.url, n.title, n.desc);
        }
        function i() {
          r.call(e);
        }
        var c = e.getAttribute("data-sharebtn-ref");
        c || ((c = ++a), e.setAttribute("data-sharebtn-ref", c)),
          (h[c] = r),
          (h[c + "ie"] = i),
          e.addEventListener
            ? e.addEventListener(t, r)
            : e.attachEvent("on" + t, i);
      },
      f = function(e, t) {
        return e.getAttribute(t);
      },
      b = function(e, t, n, r) {
        var i = l(t),
          c = l(r),
          o = l(n),
          a = o || c || "";
        switch (e) {
          case "fb":
            m(
              s("https://www.facebook.com/sharer/sharer.php?u={0}&quote={1}", [
                i,
                o
              ]),
              n
            );
            break;
          case "vk":
            m(
              s("https://vk.com/share.php?url={0}&title={1}", [i, u([o, c])]),
              n
            );
            break;
          case "tw":
            m(
              s("https://twitter.com/intent/tweet?url={0}&text={1}", [
                i,
                u([o, c])
              ]),
              n
            );
            break;
          case "tg":
            m(s("https://t.me/share/url?url={0}&text={1}", [i, u([o, c])]), n);
            break;
          case "pk":
            m(
              s("https://getpocket.com/edit?url={0}&title={1}", [i, u([o, c])]),
              n
            );
            break;
          case "re":
            m(s("https://reddit.com/submit?url={0}&title={1}", [i, o]), n);
            break;
          case "ev":
            m(
              s("https://www.evernote.com/clip.action?url={0}&t={1}", [i, o]),
              n
            );
            break;
          case "in":
            m(
              s(
                "https://www.linkedin.com/shareArticle?mini=true&url={0}&title={1}&summary={2}&source={0}",
                [i, o, u([o, c])]
              ),
              n
            );
            break;
          case "pi":
            m(
              s(
                "https://pinterest.com/pin/create/button/?url={0}&media={0}&description={1}",
                [i, u([o, c])]
              ),
              n
            );
            break;
          case "sk":
            m(
              s("https://web.skype.com/share?url={0}&source=button&text={1}", [
                i,
                u([o, c])
              ]),
              n
            );
            break;
          case "wa":
            m(s("https://wa.me/?text={0}%20{1}", [u([o, c]), i]), n);
            break;
          case "ok":
            m(
              s(
                "https://connect.ok.ru/dk?st.cmd=WidgetSharePreview&service=odnoklassniki&st.shareUrl={0}",
                [i]
              ),
              n
            );
            break;
          case "tu":
            m(
              s(
                "https://www.tumblr.com/widgets/share/tool?posttype=link&title={0}&caption={0}&content={1}&canonicalUrl={1}&shareSource=tumblr_share_button",
                [u([o, c]), i]
              ),
              n
            );
            break;
          case "hn":
            m(
              s("https://news.ycombinator.com/submitlink?t={0}&u={1}", [
                u([o, c]),
                i
              ]),
              n
            );
            break;
          case "xi":
            m(
              s("https://www.xing.com/app/user?op=share;url={0};title={1}", [
                i,
                u([o, c])
              ]),
              n
            );
            break;
          case "mail":
            0 < o.length && 0 < c.length && (a = u([o, c])),
              0 < i.length && (a = a + " / " + i),
              (location.href = s("mailto:?subject={0}&body={1}", [o, a]));
            break;
          case "print":
            window.print();
        }
      },
      m = function(e, t) {
        var n = void 0 !== k.screenLeft ? k.screenLeft : screen.left,
          r = void 0 !== k.screenTop ? k.screenTop : screen.top,
          i = k.innerWidth || w.documentElement.clientWidth || screen.width,
          c = k.innerHeight || w.documentElement.clientHeight || screen.height,
          n = k.open(
            e,
            "",
            s(
              "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width={0},height={1},top={2},left={3}",
              [600, 400, c / 3 - 400 / 3 + r, i / 2 - 300 + n]
            )
          );
        null !== n && n.focus && n.focus();
      };
  })();
  return (
    e.i(),
    {
      update: function() {
        e.i();
      }
    }
  );
});
