5 lines
3.0 KiB
JavaScript
5 lines
3.0 KiB
JavaScript
import u from"joomla.dialog";/**
|
|
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
*/if(!window.Joomla)throw new Error("Joomla API is not properly initialised");Joomla.addShortcut=(o,t)=>{hotkeys(o,"joomla",e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),t.call()})},Joomla.addClickShortcut=(o,t)=>{Joomla.addShortcut(o,()=>{const e=document.querySelector(t);e&&e.click()})},Joomla.addFocusShortcut=(o,t)=>{Joomla.addShortcut(o,()=>{const e=document.querySelector(t);e&&e.focus()})},Joomla.addLinkShortcut=(o,t)=>{Joomla.addShortcut(o,()=>{window.location.href=t})};const S=()=>{hotkeys.filter=o=>{const t=o.target||o.srcElement,{tagName:e}=t;return t.type==="checkbox"?!0:t.classList.contains("tox-textarea-wrap")&&t.closest(".joomla-highlighter-dialog")?!1:!(t.isContentEditable||e==="INPUT"||e==="SELECT"||e==="TEXTAREA")}},f=()=>{hotkeys("J",o=>{hotkeys.getScope()!=="joomla"&&(o.preventDefault(),o.stopPropagation(),o.stopImmediatePropagation(),hotkeys.setScope("joomla"),setTimeout(()=>{hotkeys.setScope(!1)},Joomla.getOptions("plg_system_shortcut.timeout",2e3)))})},E=()=>{const o=document.querySelector(".com_cpanel .container-main");if(o){const t=document.createElement("section");t.className="content pt-4",t.insertAdjacentHTML("beforeend",Joomla.Text._("PLG_SYSTEM_SHORTCUT_OVERVIEW_HINT")),o.appendChild(t)}},n=(o,t="",e=[])=>{const s=document.createElement(o);return s.textContent=t,e&&e.length&&s.classList.add(...e),s};let a;const T=o=>{if(a)return a;const t=new Map;Object.values(o).forEach(r=>{if(!r.shortcut||!r.title)return;let c=[];t.has(r.shortcut)?(c=t.get(r.shortcut),c.push(r.title)):c=[r.title],t.set(r.shortcut,c)});const e=n("dl");t.forEach((r,c)=>{const d=n("div"),i=n("dt","",["d-inline-block"]);d.appendChild(i),i.appendChild(n("kbd","J")),c.split("+").forEach(h=>{i.appendChild(n("span",Joomla.Text._("PLG_SYSTEM_SHORTCUT_THEN"),["px-1"])),i.appendChild(n("kbd",h))}),r.forEach(h=>{const m=n("dd","",["d-inline-block","ps-1"]);m.innerHTML=Joomla.sanitizeHtml(h),d.appendChild(m)}),e.appendChild(d)});const s=n("p");s.innerHTML=Joomla.sanitizeHtml(Joomla.Text._("PLG_SYSTEM_SHORTCUT_OVERVIEW_DESC"),{kbd:"*"});const p=n("div");p.appendChild(e);const l=n("div","",["p-3"]);return l.appendChild(s),l.appendChild(p),a=new u({textHeader:Joomla.Text._("PLG_SYSTEM_SHORTCUT_OVERVIEW_TITLE"),textClose:Joomla.Text._("JCLOSE"),popupContent:l,width:"600px",height:"fit-content"}),a},C=o=>{T(o).show()};document.addEventListener("DOMContentLoaded",()=>{const o=Joomla.getOptions("plg_system_shortcut.shortcuts");Object.values(o).forEach(t=>{!t.shortcut||!t.selector||(t.selector.startsWith("/")||t.selector.startsWith("http://")||t.selector.startsWith("www.")?Joomla.addLinkShortcut(t.shortcut,t.selector):t.selector.includes("input")?Joomla.addFocusShortcut(t.shortcut,t.selector):Joomla.addClickShortcut(t.shortcut,t.selector))}),document.querySelector("nav")&&(hotkeys("X","joomla",()=>{C(o)}),E()),S(),f()});
|