PageSourceSearch

https://photohuman.space/wp-content/themes/photohuman/source/js/modules/shareHelpers.js

js photohuman.space collected 2026-09-28 08:54:48 UTC 2,043 bytes, 78 lines download raw bytes

1export const copyToClipboard = async (text) => {
2  if (navigator.clipboard?.writeText) {
3    await navigator.clipboard.writeText(text);
4    return true;
5  }
6
7  const textarea = document.createElement('textarea');
8  textarea.value = text;
9  textarea.setAttribute('readonly', '');
10  textarea.style.position = 'fixed';
11  textarea.style.left = '-9999px';
12  document.body.appendChild(textarea);
13  textarea.select();
14
15  let copied = false;
16
17  try {
18    copied = document.execCommand('copy');
19  } catch (error) {
20    copied = false;
21  }
22
23  textarea.remove();
24  return copied;
25};
26
27let hideTooltipTimer = null;
28
29export const showCopiedFeedback = (button, defaultLabel = 'Поделиться') => {
30  let tooltip = button.querySelector('.share-product-tooltip');
31
32  if (!tooltip) {
33    tooltip = document.createElement('span');
34    tooltip.className = 'share-product-tooltip';
35    tooltip.setAttribute('role', 'status');
36    tooltip.textContent = 'Ссылка скопирована';
37    button.appendChild(tooltip);
38  }
39
40  if (hideTooltipTimer) {
41    window.clearTimeout(hideTooltipTimer);
42  }
43
44  tooltip.classList.add('_show');
45  button.setAttribute('aria-label', 'Ссылка скопирована');
46
47  hideTooltipTimer = window.setTimeout(() => {
48    tooltip.classList.remove('_show');
49    button.setAttribute('aria-label', defaultLabel);
50    hideTooltipTimer = null;
51  }, 2200);
52};
53
54export const shareUrl = async (button, url, options = {}) => {
55  const title = options.title || document.title;
56  const text = options.text || title;
57  const defaultLabel = options.defaultLabel || 'Поделиться';
58
59  if (navigator.share) {
60    try {
61      await navigator.share({ title, text, url });
62      return true;
63    } catch (error) {
64      if (error?.name === 'AbortError') {
65        return false;
66      }
67    }
68  }
69
70  const copied = await copyToClipboard(url);
71
72  if (copied) {
73    showCopiedFeedback(button, defaultLabel);
74    return true;
75  }
76
77  return false;
78};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.