1(function (Drupal, once) { 2 "use strict"; 3 4 function getPageUrl(btn) { 5 if (btn && btn.dataset && btn.dataset.copyUrl) return btn.dataset.copyUrl; 6 if (btn && btn.dataset && btn.dataset.copy === "canonical") { 7 var c = document.querySelector('link[rel="canonical"]'); 8 if (c && c.href) return c.href; 9 } 10 return window.location.href; 11 } 12 13 function copyWithFallback(text) { 14 try { 15 var ta = document.createElement("textarea"); 16 ta.value = text; 17 ta.setAttribute("readonly", ""); 18 ta.style.position = "absolute"; 19 ta.style.left = "-9999px"; 20 document.body.appendChild(ta); 21 ta.select(); 22 var ok = document.execCommand("copy"); 23 document.body.removeChild(ta); 24 return ok ? Promise.resolve() : Promise.reject(); 25 } catch (e) { 26 return Promise.reject(e); 27 } 28 } 29 30 function copyToClipboard(text) { 31 if (navigator.clipboard && navigator.clipboard.writeText) { 32 return navigator.clipboard.writeText(text); 33 } 34 return copyWithFallback(text); 35 } 36 37 function showMsg(btn, ok) { 38 var msgEl = null, p = btn.parentElement; 39 while (p && !msgEl) { msgEl = p.querySelector(".copy-msg"); p = p.parentElement; } 40 if (!msgEl) msgEl = document.querySelector(".copy-msg"); 41 if (!msgEl) return; 42 var copied = btn.dataset.copiedLabel ? Drupal.t(btn.dataset.copiedLabel) : Drupal.t("Kopyalandı"); 43 var failed = btn.dataset.copyErrorLabel ? Drupal.t(btn.dataset.copyErrorLabel) : Drupal.t("Kopyalanamadı"); 44 var text = ok ? copied : failed; 45 msgEl.textContent = text; 46 msgEl.classList.remove("d-none"); 47 msgEl.classList.toggle("is-copy-error", !ok); 48 window.clearTimeout(msgEl._t); 49 msgEl._t = window.setTimeout(function () { 50 msgEl.classList.add("d-none"); 51 msgEl.classList.remove("is-copy-error"); 52 }, 1600); 53 } 54 55 Drupal.behaviors.copyPageUrl = { 56 attach: function (context) { 57 once("copyPageUrl", ".btn-copy", context).forEach(function (btn) { 58 btn.addEventListener("click", function (e) { 59 e.preventDefault(); 60 var url = getPageUrl(btn); 61 copyToClipboard(url).then(function () { showMsg(btn, true); }).catch(function () { showMsg(btn, false); }); 62 }); 63 }); 64 }, 65 }; 66})(Drupal, once);
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.