[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 (function () { 2 'use strict'; 3 4 (function (document, Joomla) { 5 if (!Joomla) { 6 throw new Error('Joomla API is not properly initialised'); 7 } 8 /* global hotkeys */ 9 10 11 Joomla.addShortcut = function (hotkey, callback) { 12 hotkeys(hotkey, 'joomla', function (event) { 13 event.preventDefault(); 14 event.stopPropagation(); 15 event.stopImmediatePropagation(); 16 callback.call(); 17 }); 18 }; 19 20 Joomla.addClickShortcut = function (hotkey, selector) { 21 Joomla.addShortcut(hotkey, function () { 22 var element = document.querySelector(selector); 23 24 if (element) { 25 element.click(); 26 } 27 }); 28 }; 29 30 Joomla.addFocusShortcut = function (hotkey, selector) { 31 Joomla.addShortcut(hotkey, function () { 32 var element = document.querySelector(selector); 33 34 if (element) { 35 element.focus(); 36 } 37 }); 38 }; 39 40 Joomla.addLinkShortcut = function (hotkey, selector) { 41 Joomla.addShortcut(hotkey, function () { 42 window.location.href = selector; 43 }); 44 }; 45 46 var setShortcutFilter = function setShortcutFilter() { 47 hotkeys.filter = function (event) { 48 var target = event.target || event.srcElement; 49 var tagName = target.tagName; // Checkboxes should not block a shortcut event 50 51 if (target.type === 'checkbox') { 52 return true; 53 } // Default hotkeys filter behavior 54 55 56 return !(target.isContentEditable || tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA'); 57 }; 58 }; 59 60 var startupShortcuts = function startupShortcuts() { 61 hotkeys('J', function (event) { 62 // If we're already in the scope, it's a normal shortkey 63 if (hotkeys.getScope() === 'joomla') { 64 return; 65 } 66 67 event.preventDefault(); 68 event.stopPropagation(); 69 event.stopImmediatePropagation(); 70 hotkeys.setScope('joomla'); // Leave the scope after x milliseconds 71 72 setTimeout(function () { 73 hotkeys.setScope(false); 74 }, Joomla.getOptions('plg_system_shortcut.timeout', 2000)); 75 }); 76 }; 77 78 var addOverviewHint = function addOverviewHint() { 79 var mainContainer = document.querySelector('.com_cpanel .container-main'); 80 81 if (mainContainer) { 82 var containerElement = document.createElement('section'); 83 containerElement.className = 'content pt-4'; 84 containerElement.insertAdjacentHTML('beforeend', Joomla.Text._('PLG_SYSTEM_SHORTCUT_OVERVIEW_HINT')); 85 mainContainer.appendChild(containerElement); 86 } 87 }; 88 89 var initOverviewModal = function initOverviewModal(options) { 90 var dlItems = new Map(); 91 Object.values(options).forEach(function (value) { 92 if (!value.shortcut || !value.title) { 93 return; 94 } 95 96 var titles = []; 97 98 if (dlItems.has(value.shortcut)) { 99 titles = dlItems.get(value.shortcut); 100 titles.push(value.title); 101 } else { 102 titles = [value.title]; 103 } 104 105 dlItems.set(value.shortcut, titles); 106 }); 107 var dl = '<dl>'; 108 dlItems.forEach(function (titles, shortcut) { 109 dl += '<dt><kbd>J</kbd>'; 110 shortcut.split('+').forEach(function (key) { 111 dl += " <kbd>" + key.trim() + "</kbd>"; 112 }); 113 dl += '</dt>'; 114 titles.forEach(function (title) { 115 dl += "<dd>" + title + "</dd>"; 116 }); 117 }); 118 dl += '</dl>'; 119 var modal = "\n <div class=\"modal fade\" id=\"shortcutOverviewModal\" tabindex=\"-1\" role=\"dialog\" data-bs-backdrop=\"static\" aria-labelledby=\"shortcutOverviewModalLabel\" aria-hidden=\"true\">\n <div class=\"modal-dialog\" role=\"document\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h3 id=\"shortcutOverviewModalLabel\" class=\"modal-title\">\n " + Joomla.Text._('PLG_SYSTEM_SHORTCUT_OVERVIEW_TITLE') + "\n </h3>\n <button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"" + Joomla.Text._('JCLOSE') + "\"></button>\n </div>\n <div class=\"modal-body p-3\">\n <p>" + Joomla.Text._('PLG_SYSTEM_SHORTCUT_OVERVIEW_DESC') + "</p>\n <div class=\"mb-3\">\n " + dl + "\n </div>\n </div>\n </div>\n </div>\n </div>\n "; 120 document.body.insertAdjacentHTML('beforeend', modal); 121 var bootstrapModal = new bootstrap.Modal(document.getElementById('shortcutOverviewModal'), { 122 keyboard: true, 123 backdrop: true 124 }); 125 hotkeys('X', 'joomla', function () { 126 return bootstrapModal.show(); 127 }); 128 }; 129 130 document.addEventListener('DOMContentLoaded', function () { 131 var options = Joomla.getOptions('plg_system_shortcut.shortcuts'); 132 Object.values(options).forEach(function (value) { 133 if (!value.shortcut || !value.selector) { 134 return; 135 } 136 137 if (value.selector.startsWith('/') || value.selector.startsWith('http://') || value.selector.startsWith('www.')) { 138 Joomla.addLinkShortcut(value.shortcut, value.selector); 139 } else if (value.selector.includes('input')) { 140 Joomla.addFocusShortcut(value.shortcut, value.selector); 141 } else { 142 Joomla.addClickShortcut(value.shortcut, value.selector); 143 } 144 }); // Show hint and overview on logged in backend only (not login page) 145 146 if (document.querySelector('nav')) { 147 initOverviewModal(options); 148 addOverviewHint(); 149 } 150 151 setShortcutFilter(); 152 startupShortcuts(); 153 }); 154 })(document, Joomla); 155 156 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |