first commit
This commit is contained in:
46
plugins/system/shortcut/services/provider.php
Normal file
46
plugins/system/shortcut/services/provider.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage System.shortcut
|
||||
*
|
||||
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Extension\PluginInterface;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\System\Shortcut\Extension\Shortcut;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = new Shortcut(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('system', 'shortcut')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
40
plugins/system/shortcut/shortcut.xml
Normal file
40
plugins/system/shortcut/shortcut.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="system" method="upgrade">
|
||||
<name>plg_system_shortcut</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2022-06</creationDate>
|
||||
<copyright>(C) 2022 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>4.2.0</version>
|
||||
<description>PLG_SYSTEM_SHORTCUT_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\System\Shortcut</namespace>
|
||||
<media destination="plg_system_shortcut" folder="media">
|
||||
<folder>js</folder>
|
||||
</media>
|
||||
<files>
|
||||
<folder plugin="shortcut">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_system_shortcut.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_system_shortcut.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="timeout"
|
||||
type="number"
|
||||
label="PLG_SYSTEM_SHORTCUT_TIMEOUT_LABEL"
|
||||
description="PLG_SYSTEM_SHORTCUT_TIMEOUT_DESC"
|
||||
required="true"
|
||||
start="1"
|
||||
step="1"
|
||||
default="2000"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
136
plugins/system/shortcut/src/Extension/Shortcut.php
Normal file
136
plugins/system/shortcut/src/Extension/Shortcut.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage System.shortcut
|
||||
*
|
||||
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\System\Shortcut\Extension;
|
||||
|
||||
use Joomla\CMS\Event\GenericEvent;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Event\Event;
|
||||
use Joomla\Event\SubscriberInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Shortcut plugin to add accessible keyboard shortcuts to the administrator templates.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*/
|
||||
final class Shortcut extends CMSPlugin implements SubscriberInterface
|
||||
{
|
||||
/**
|
||||
* Returns an array of events this subscriber will listen to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* - The method name to call (priority defaults to 0)
|
||||
* - An array composed of the method name to call and the priority
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
'onBeforeCompileHead' => 'initialize',
|
||||
'onLoadShortcuts' => 'addShortcuts',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the javascript for the shortcuts
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
if (!$this->getApplication()->isClient('administrator')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load translations
|
||||
$this->loadLanguage();
|
||||
|
||||
$context = $this->getApplication()->getInput()->get('option') . '.' . $this->getApplication()->getInput()->get('view');
|
||||
|
||||
$shortcuts = [];
|
||||
|
||||
$event = new GenericEvent(
|
||||
'onLoadShortcuts',
|
||||
[
|
||||
'context' => $context,
|
||||
'shortcuts' => $shortcuts,
|
||||
]
|
||||
);
|
||||
|
||||
$this->getDispatcher()->dispatch('onLoadShortcuts', $event);
|
||||
|
||||
$shortcuts = $event->getArgument('shortcuts');
|
||||
|
||||
Text::script('PLG_SYSTEM_SHORTCUT_OVERVIEW_HINT');
|
||||
Text::script('PLG_SYSTEM_SHORTCUT_OVERVIEW_TITLE');
|
||||
Text::script('PLG_SYSTEM_SHORTCUT_OVERVIEW_DESC');
|
||||
Text::script('PLG_SYSTEM_SHORTCUT_THEN');
|
||||
Text::script('JCLOSE');
|
||||
|
||||
$document = $this->getApplication()->getDocument();
|
||||
$wa = $document->getWebAssetManager();
|
||||
$wa->useScript('bootstrap.modal');
|
||||
$wa->registerAndUseScript('script', 'plg_system_shortcut/shortcut.min.js', ['dependencies' => ['hotkeysjs']]);
|
||||
|
||||
$timeout = $this->params->get('timeout', 2000);
|
||||
|
||||
$document->addScriptOptions('plg_system_shortcut.shortcuts', $shortcuts);
|
||||
$document->addScriptOptions('plg_system_shortcut.timeout', $timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add default shortcuts to the document
|
||||
*
|
||||
* @param Event $event The event
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public function addShortcuts(Event $event)
|
||||
{
|
||||
$shortcuts = $event->getArgument('shortcuts', []);
|
||||
|
||||
$shortcuts = array_merge(
|
||||
$shortcuts,
|
||||
[
|
||||
'applyKey' => (object) ['selector' => 'joomla-toolbar-button .button-apply', 'shortcut' => 'A', 'title' => $this->getApplication()->getLanguage()->_('JAPPLY')],
|
||||
'saveKey' => (object) ['selector' => 'joomla-toolbar-button .button-save', 'shortcut' => 'S', 'title' => $this->getApplication()->getLanguage()->_('JTOOLBAR_SAVE')],
|
||||
'cancelKey' => (object) ['selector' => 'joomla-toolbar-button .button-cancel', 'shortcut' => 'Q', 'title' => $this->getApplication()->getLanguage()->_('JCANCEL')],
|
||||
'newKey' => (object) ['selector' => 'joomla-toolbar-button .button-new', 'shortcut' => 'N', 'title' => $this->getApplication()->getLanguage()->_('JTOOLBAR_NEW')],
|
||||
'searchKey' => (object) ['selector' => 'input[placeholder=' . $this->getApplication()->getLanguage()->_('JSEARCH_FILTER') . ']', 'shortcut' => 'F', 'title' => $this->getApplication()->getLanguage()->_('JSEARCH_FILTER')],
|
||||
'optionKey' => (object) ['selector' => 'joomla-toolbar-button .button-options', 'shortcut' => 'O', 'title' => $this->getApplication()->getLanguage()->_('JOPTIONS')],
|
||||
'helpKey' => (object) ['selector' => 'joomla-toolbar-button .button-help', 'shortcut' => 'H', 'title' => $this->getApplication()->getLanguage()->_('JHELP')],
|
||||
'toggleMenu' => (object) ['selector' => '#menu-collapse', 'shortcut' => 'M', 'title' => $this->getApplication()->getLanguage()->_('JTOGGLE_SIDEBAR_MENU')],
|
||||
'dashboard' => (object) ['selector' => (string) new Uri(Route::_('index.php?')), 'shortcut' => 'D', 'title' => $this->getApplication()->getLanguage()->_('JHOMEDASHBOARD')],
|
||||
]
|
||||
);
|
||||
|
||||
$event->setArgument('shortcuts', $shortcuts);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user