PageSourceSearch

https://www.hiit.fi/themes/custom/aalto_base/js/aalto_copy_to_clipboard.js?tltwfz

js hiit.fi collected 2026-10-01 10:35:43 UTC 1,745 bytes, 43 lines download raw bytes

1(function(Drupal) {
2  Drupal.behaviors.aalto_copy_to_clipboard = {
3    attach: function(context, settings) {
4      var copyUrlButtons = [].slice.call(document.querySelectorAll('.js-aalto-copy-url-button')); // Needs to be an array instead of NodeList for old Edge and IE 11.
5
6      if (copyUrlButtons.length) {
7        copyUrlButtons.forEach(function(button) {
8          button.addEventListener('click', copyUrl);
9        });
10      }
11    },
12  };
13
14  function copyToClipboard(el) {
15    var originalReadOnly = el.readOnly; // For iOS. Store the original read only -value from the element.
16    el.readOnly = true; // iOS wants the field to be "read only" for not to scroll to it with el.select()
17    el.select();
18    el.setSelectionRange(0, 999999); // For iOS. Because it just won't have any selection to copy without this.
19    el.readOnly = originalReadOnly; // For iOS. Put back the original read only -value.
20    try {
21      return document.execCommand('copy');
22    } catch (err) {
23      console.error(err);
24      return false;
25    }
26  }
27
28  function copyUrl(e) {
29    var copyButton = e.currentTarget;
30    var container = copyButton.closest('.aalto-some-share');
31    var el = document.createElement('textarea');
32    el.classList.add('aalto-visually-hidden');
33    el.setAttribute('aria-hidden', true);
34    el.value = window.location.href;
35    document.body.appendChild(el);
36    var isSuccessful = copyToClipboard(el);
37    if (isSuccessful === true) {
38      Drupal.behaviors.aalto_notification.showNotification(container);
39    }
40    copyButton.focus(); // Adding the fake element for selecting and copying the url loses focus. We need to set explicitly set the focus back to the copy url -button.
41    document.body.removeChild(el);
42  }
43})(Drupal);

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.