Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions administrator/language/en-GB/en-GB.plg_system_shortcuts.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; Joomla! Project
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_SHORTCUTS="System - Keyboard Shortcuts"
PLG_SYSTEM_SHORTCUTS_SECTION="Site Section"
PLG_SYSTEM_SHORTCUTS_SECTION_ADMIN="Administrator (Backend)"
PLG_SYSTEM_SHORTCUTS_SECTION_BOTH="Both"
PLG_SYSTEM_SHORTCUTS_SECTION_SITE="Site (Frontend)"
PLG_SYSTEM_SHORTCUTS_XML_DESCRIPTION="Adds keyboard shortcuts to Joomla."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_SHORTCUTS="System - Keyboard Shortcuts"
PLG_SYSTEM_SHORTCUTS_XML_DESCRIPTION="Adds keyboard shortcuts to Joomla."
77 changes: 77 additions & 0 deletions build/media_source/plg_system_shortcuts/js/shortcuts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

document.onkeyup = function(e) {

/*
* Form Controls
*
* these shortcuts are available for any Joomla admin form
* that uses the standard Joomla toolbar.
*/

// Save - Alt/Opt S
if (e.altKey && e.which == 83) {
var toolbar = document.getElementById("toolbar-apply");
toolbar.getElementsByClassName("button-apply")[0].click();
};
// Save & Close - Shift + Alt/Opt S
if (e.shiftKey && e.altKey && e.which == 83) {
var toolbar = document.getElementById("toolbar-save");
toolbar.getElementsByClassName("button-save")[0].click();
};
// Save & New - Shift + Alt/Opt N
if (e.shiftKey && e.altKey && e.which == 78) {
var toolbar = document.getElementById("save-group-children-save-new");
toolbar.getElementsByClassName("button-save-new")[0].click();
};
// Save as Copy - Shift + Alt/Opt C
if (e.shiftKey && e.altKey && e.which == 67) {
var toolbar = document.getElementById("save-group-children-save-copy");
toolbar.getElementsByClassName("button-save-copy")[0].click();
};
// Cancel/Close - Alt/Opt X
if (e.altKey && e.which == 88) {
var toolbar = document.getElementById("toolbar-cancel");
toolbar.getElementsByClassName("button-cancel")[0].click();
};

/*
* Item Controls
*
* these shortcuts are available for any Joomla admin view
* that uses the standard Joomla toolbar for letting users
* create new items.
*/

// New - Alt/Opt N
if (e.altKey && e.which == 78) {
var toolbar = document.getElementById("toolbar-new");
toolbar.getElementsByClassName("button-new")[0].click();
};

// Help - Alt/Opt H
if (e.altKey && e.which == 72) {
var toolbar = document.getElementById("toolbar-help");
toolbar.getElementsByClassName("button-help")[0].click();
};

// Options - Alt/Opt O
if (e.altKey && e.which == 79) {
var toolbar = document.getElementById("toolbar-options");
toolbar.getElementsByClassName("button-options")[0].click();
};

}

/*
* Admin Shortcuts
*
* these shortcuts are available in the Joomla administrator
* application on any page.
*/



80 changes: 80 additions & 0 deletions plugins/system/shortcuts/shortcuts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage System.shortcuts
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;

/**
* Mousetrap plugin to add keyboard shortcuts to the administrator template.
*
* @since __DEPLOY_VERSION__
*/
class PlgSystemShortcuts extends CMSPlugin
{
/**
* If true, language files will be loaded automatically.
*
* @var boolean
* @since 4.0.0
*/
protected $autoloadLanguage = true;

/**
* Application object.
*
* @var JApplicationCms
* @since 4.0.0
*/
protected $app;

/**
* Add the javascript for the shortcuts
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onBeforeCompileHead()
{
$section = (int) $this->params->get('section_shortcuts', 2);
$current_section = 0;

// Get the document object.
$document = Factory::getDocument();

try
{
$app = Factory::getApplication();

if ($app->isClient('administrator'))
{
$current_section = 2;
}
elseif ($app->isClient('site'))
{
$current_section = 1;
}
}
catch (Exception $exc)
{
$current_section = 0;
}

if (!($current_section & $section))
{
return false;
}

HTMLHelper::_('script', 'plg_system_shortcuts/shortcuts.js', array('version' => 'auto', 'relative' => true), ['defer' => true]);
}
}
36 changes: 36 additions & 0 deletions plugins/system/shortcuts/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="4.0" type="plugin" group="system" method="upgrade">
<name>plg_system_shortcuts</name>
<author>Joomla! Project</author>
<creationDate>2019-2-27</creationDate>
<copyright>(C) 2005 - 2019 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>4.0.0</version>
<description>PLG_SYSTEM_SHORTCUTS_XML_DESCRIPTION</description>
<files>
<filename plugin="shortcuts">shortcuts.php</filename>
</files>
<languages>
<language tag="en-GB">language/en-GB/en-GB.plg_system_shortcuts.ini</language>
<language tag="en-GB">language/en-GB/en-GB.plg_system_shortcuts.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field
name="section_shortcuts"
type="list"
label="PLG_SYSTEM_SHORTCUTS_SECTION"
default="2"
filter="integer"
>
<option value="1">PLG_SYSTEM_SHORTCUTS_SECTION_SITE</option>
<option value="2">PLG_SYSTEM_SHORTCUTS_SECTION_ADMIN</option>
<option value="3">PLG_SYSTEM_SHORTCUTS_SECTION_BOTH</option>
</field>
</fieldset>
</fields>
</config>
</extension>