File size: 1,988 Bytes
187ef74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Source-shaped event sharing without production social-network effects.
// The official page opens a "Share with friends" dialog; this protected
// preview keeps that interaction local and only copies its own event URL.
(function () {
  "use strict";

  var trigger = document.querySelector("[data-share-trigger]");
  var dialog = document.querySelector("#share-event-dialog");
  if (!trigger || !dialog) return;

  var close = dialog.querySelector("[data-share-close]");
  var copy = dialog.querySelector("[data-share-copy]");
  var input = dialog.querySelector("[data-share-url]");
  var status = dialog.querySelector("[data-share-status]");

  function eventUrl() {
    return window.location.origin + window.location.pathname;
  }

  function openDialog() {
    input.value = eventUrl();
    status.textContent = "";
    trigger.setAttribute("aria-expanded", "true");
    if (dialog.showModal) dialog.showModal();
    else dialog.setAttribute("open", "");
    copy.focus();
  }

  function closeDialog() {
    trigger.setAttribute("aria-expanded", "false");
    if (dialog.close) dialog.close();
    else dialog.removeAttribute("open");
    trigger.focus();
  }

  function fallbackSelect() {
    input.focus();
    input.select();
    status.textContent = "Link selected. Press Ctrl+C or Command+C to copy.";
  }

  trigger.addEventListener("click", openDialog);
  close.addEventListener("click", closeDialog);
  dialog.addEventListener("close", function () {
    trigger.setAttribute("aria-expanded", "false");
  });
  dialog.addEventListener("click", function (event) {
    if (event.target === dialog) closeDialog();
  });
  copy.addEventListener("click", function () {
    var value = eventUrl();
    input.value = value;
    if (!navigator.clipboard || !navigator.clipboard.writeText) {
      fallbackSelect();
      return;
    }
    navigator.clipboard.writeText(value).then(function () {
      status.textContent = "Link copied!";
    }).catch(fallbackSelect);
  });
})();