Files
Shaarli_bm_theme/shaarli-pro/dist/bulk-actions.min.js
T
bruno 5d7255cc22
CI / build (push) Failing after 4m54s
Add built JS assets to distributable
2026-08-09 21:14:35 -04:00

1 line
5.0 KiB
JavaScript

document.addEventListener("DOMContentLoaded",()=>{"use strict";const e=window.ShaarliProI18n||{t:function(e){return e}},t=document.getElementById("select-mode-btn"),n=document.getElementById("bulk-actions-bar"),l=document.getElementById("bulk-count"),i=document.getElementById("bulk-select-all"),o=document.getElementById("bulk-cancel"),c=document.getElementById("bulk-delete"),a=document.getElementById("bulk-public"),s=document.getElementById("bulk-private"),d=document.getElementById("bulk-confirm-modal"),r=document.getElementById("bulk-modal-title"),u=document.getElementById("bulk-modal-subtitle"),m=document.getElementById("bulk-modal-list"),k=document.getElementById("bulk-modal-confirm"),b=document.getElementById("bulk-modal-cancel"),f=document.getElementById("bulk-modal-close");let p=!1,E=new Set,y=null,h=null;const v=window.ShaarliProA11y||{focusFirst:function(){},trapFocus:function(){return function(){}}},g={delete:{title:t=>e.t("Are you sure to delete {count} link{plural}?",{count:t,plural:t>1?"s":""}),subtitle:e.t("The following links will be irretrievably deleted:"),confirm:t=>e.t("DELETE {count} LINK{plural}",{count:t,plural:t>1?"S":""}).toUpperCase(),confirmClass:"bulk-confirm-delete"},public:{title:t=>e.t("Are you sure to set {count} link{plural} public?",{count:t,plural:t>1?"s":""}),subtitle:e.t("The following links will be set as public:"),confirm:t=>e.t("SET {count} LINK{plural} PUBLIC",{count:t,plural:t>1?"S":""}).toUpperCase(),confirmClass:"bulk-confirm-public"},private:{title:t=>e.t("Are you sure to set {count} link{plural} private?",{count:t,plural:t>1?"s":""}),subtitle:e.t("The following links will be set as private:"),confirm:t=>e.t("SET {count} LINK{plural} PRIVATE",{count:t,plural:t>1?"S":""}).toUpperCase(),confirmClass:"bulk-confirm-private"}};function L(){l&&(l.textContent=E.size),document.querySelectorAll(".link-outer").forEach(e=>{const t=e.dataset.id;E.has(t)?e.classList.add("selected"):e.classList.remove("selected")}),document.querySelectorAll(".link-checkbox").forEach(e=>{e.checked=E.has(e.dataset.id)})}function w(){p=!0,document.body.classList.add("selection-mode"),n?.classList.add("show"),t?.classList.add("active")}function I(){p=!1,E.clear(),document.body.classList.remove("selection-mode"),n?.classList.remove("show"),t?.classList.remove("active"),L()}function C(e){E.has(e)?E.delete(e):E.add(e),E.size>0&&!p?w():0===E.size&&p&&I(),L()}function B(){return Array.from(E)}function S(t){if(!d||0===E.size)return;const n=g[t];if(!n)return;const l=B();y=t,r&&(r.textContent=n.title(l.length)),u&&(u.textContent=n.subtitle),k&&(k.textContent=n.confirm(l.length),k.className=`bulk-modal-btn bulk-modal-confirm ${n.confirmClass}`),function(t){m&&(m.innerHTML="",t.forEach(t=>{const n=document.querySelector(`.link-outer[data-id="${t}"]`),l=n?.querySelector(".link-title")?.textContent?.trim()||n?.querySelector(".link-url")?.textContent?.trim()||e.t("Untitled link"),i=document.createElement("div");i.className="bulk-modal-item";const o=document.createElement("span");o.className="bulk-modal-item-id",o.textContent=`#${t}`;const c=document.createElement("span");c.className="bulk-modal-item-title",c.textContent=l,i.appendChild(o),i.appendChild(c),m.appendChild(i)}))}(l),d.classList.add("show"),d.setAttribute("aria-hidden","false"),document.body.style.overflow="hidden",v.focusFirst(d),h=v.trapFocus(d)}function A(){d&&(y=null,d.classList.remove("show"),d.setAttribute("aria-hidden","true"),document.body.style.overflow="","function"==typeof h&&(h(),h=null))}t?.addEventListener("click",()=>{p?I():w()}),o?.addEventListener("click",I),i?.addEventListener("click",()=>{document.querySelectorAll(".link-outer").forEach(e=>{e.dataset.id&&E.add(e.dataset.id)}),!p&&E.size>0&&w(),L()}),document.addEventListener("change",e=>{e.target.classList.contains("link-checkbox")&&C(e.target.dataset.id)}),document.addEventListener("click",e=>{if(!p)return;const t=e.target.closest(".link-outer");if(t&&t.dataset.id){if(e.target.closest(".link-actions")||e.target.closest(".link-hover-actions")||"A"===e.target.tagName||"INPUT"===e.target.tagName||e.target.closest("label"))return;C(t.dataset.id)}}),c?.addEventListener("click",()=>{0!==E.size&&S("delete")}),a?.addEventListener("click",()=>{0!==E.size&&S("public")}),s?.addEventListener("click",()=>{0!==E.size&&S("private")}),k?.addEventListener("click",function(){if(!y||0===E.size)return;const t=B(),n=(window.shaarli?.token||"").trim()||document.querySelector('input[name="token"]')?.value||"";if(!n)return void alert(e.t("Missing security token. Please refresh the page and try again."));const l=window.shaarli?.basePath||"",i=function(e){return e.map(e=>encodeURIComponent(e)).join("+")}(t);let o="";if("delete"===y)o=`${l}/admin/shaare/delete?id=${i}&token=${encodeURIComponent(n)}`;else{const e="public"===y?"public":"private";o=`${l}/admin/shaare/visibility?token=${encodeURIComponent(n)}&newVisibility=${e}&id=${i}`}A(),window.location.href=o}),b?.addEventListener("click",A),f?.addEventListener("click",A),d?.addEventListener("click",e=>{e.target===d&&A()}),document.addEventListener("keydown",e=>{"Escape"===e.key&&d?.classList.contains("show")&&A()})});