PageSourceSearch

https://www.c2es.org/wp-content/themes/c2es/resources/js/embed-image.js

js c2es.org collected 2026-09-24 08:34:04 UTC 2,901 bytes, 82 lines download raw bytes

1document.addEventListener('DOMContentLoaded', () => {
2
3  // Event listener for embed-image buttons
4  document.querySelectorAll('.embed-image').forEach(button => {
5    button.addEventListener('click', function (e) {
6      const url = this.dataset.image;
7      const embedHtml = `<img src="${url}" alt="">`;
8
9      navigator.clipboard.writeText(embedHtml).then(() => {
10        // Remove any existing message
11        const existing = this.parentNode.querySelector('.embed-success-message');
12        if (existing) existing.remove();
13
14        // Create a new message element
15        const message = document.createElement('div');
16        message.className = 'embed-success-message';
17        message.textContent = 'Embed HTML copied!';
18        this.parentNode.appendChild(message);
19      }).catch((err) => {
20        console.error('Error copying embed HTML:', err);
21      });
22    });
23  });
24
25  // Event listener for download-image buttons
26  document.querySelectorAll('.download-image').forEach(button => {
27    button.addEventListener('click', function (e) {
28      if (e.target.classList.contains('download-image')) {
29      const url = e.target.dataset.image;
30      const filename = url.split('/').pop();
31
32      fetch(url, { mode: 'cors' })
33        .then(res => {
34          if (!res.ok) throw new Error(`HTTP ${res.status}`);
35            return res.blob();
36          })
37        .then(blob => {
38          const blobUrl = URL.createObjectURL(blob);
39          const link = document.createElement('a');
40          link.href = blobUrl;
41          link.download = filename;
42          document.body.appendChild(link);
43          link.click();
44          document.body.removeChild(link);
45          URL.revokeObjectURL(blobUrl);
46        })
47        .catch(err => {
48          // Fallback when fetch fails (CORS, network, etc.)
49          console.warn('Fetch download failed, using direct download:', err);
50          const a = document.createElement('a');
51          a.href = url;
52          a.download = filename;
53          a.target = '_blank'; // Opens in new tab if download attr not supported
54          document.body.appendChild(a);
55          a.click();
56          document.body.removeChild(a);
57        });
58      }
59    });
60  });
61
62  const captions = document.querySelectorAll('.wp-caption');
63
64  captions.forEach(caption => {
65    const captionText = caption.querySelector('.wp-caption-text');
66    const imageButtons = caption.querySelector('.image-buttons');
67
68    // Only proceed if both elements exist
69    if (captionText && imageButtons) {
70      // Create wrapper div
71      const wrapper = document.createElement('div');
72      wrapper.className = 'image-meta';
73
74      // Insert wrapper before captionText
75      captionText.parentNode.insertBefore(wrapper, captionText);
76
77      // Move captionText and imageButtons inside wrapper
78      wrapper.appendChild(captionText);
79      wrapper.appendChild(imageButtons);
80    }
81  });
82});

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.