-
Notifications
You must be signed in to change notification settings - Fork 6
Map keys control+s to save command on forms #55
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Site | ||
| * @subpackage Layout | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| defined('JPATH_BASE') or die; | ||
|
|
||
|
|
||
| if (preg_match('/Joomla.submitbutton/', $displayData['doTask'])) | ||
| { | ||
| $ctrls = str_replace("Joomla.submitbutton('", '', $displayData['doTask']); | ||
| $ctrls = str_replace("')", '', $ctrls); | ||
| $ctrls = str_replace(";", '', $ctrls); | ||
|
|
||
| JHtml::_('behavior.core'); | ||
| JHtml::_('jquery.framework'); | ||
| $options = array('task' => $ctrls); | ||
| JFactory::getDocument()->addScriptOptions('keySave', $options); | ||
| } | ||
| else | ||
| { | ||
| JHtml::_('behavior.core'); | ||
| } | ||
|
|
||
| $doTask = $displayData['doTask']; | ||
| $class = $displayData['class']; | ||
| $text = $displayData['text']; | ||
| $btnClass = $displayData['btnClass']; | ||
| ?> | ||
| <button onclick="<?php echo $doTask; ?>" class="<?php echo $btnClass; ?>"> | ||
| <span class="<?php echo trim($class); ?>"></span> | ||
| <?php echo $text; ?> | ||
| </button> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| <?php | ||
| /** | ||
| * @package Joomla.Libraries | ||
| * @subpackage Toolbar | ||
| * | ||
| * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE | ||
| */ | ||
|
|
||
| defined('JPATH_PLATFORM') or die; | ||
|
|
||
| /** | ||
| * Renders an apply/save button | ||
| * | ||
| * @since 3.0 | ||
| */ | ||
| class JToolbarButtonApply extends JToolbarButton | ||
| { | ||
| /** | ||
| * Button type | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $_name = 'Apply'; | ||
|
|
||
| /** | ||
| * Fetch the HTML for the button | ||
| * | ||
| * @param string $type Unused string. | ||
| * @param string $name The name of the button icon class. | ||
| * @param string $text Button text. | ||
| * @param string $task Task associated with the button. | ||
| * @param boolean $list True to allow lists | ||
| * | ||
| * @return string HTML string for the button | ||
| * | ||
| * @since 3.0 | ||
| */ | ||
| public function fetchButton($type = 'Apply', $name = '', $text = '', $task = '', $list = true) | ||
| { | ||
| // Store all data to the options array for use with JLayout | ||
| $options = array(); | ||
| $options['text'] = JText::_($text); | ||
| $options['class'] = $this->fetchIconClass($name); | ||
| $options['doTask'] = $this->_getCommand($options['text'], $task, $list); | ||
|
|
||
| if ($name == 'apply' || $name == 'save') | ||
| { | ||
| $options['btnClass'] = 'btn btn-sm btn-success'; | ||
| $options['class'] .= ' icon-white'; | ||
| } | ||
| else | ||
| { | ||
| $options['btnClass'] = 'btn btn-sm btn-primary-outline'; | ||
| } | ||
|
|
||
| // Instantiate a new JLayoutFile instance and render the layout | ||
| $layout = new JLayoutFile('joomla.toolbar.apply'); | ||
|
|
||
| return $layout->render($options); | ||
| } | ||
|
|
||
| /** | ||
| * Get the button CSS Id | ||
| * | ||
| * @param string $type Unused string. | ||
| * @param string $name Name to be used as apart of the id | ||
| * @param string $text Button text | ||
| * @param string $task The task associated with the button | ||
| * @param boolean $list True to allow use of lists | ||
| * @param boolean $hideMenu True to hide the menu on click | ||
| * | ||
| * @return string Button CSS Id | ||
| * | ||
| * @since 3.0 | ||
| */ | ||
| public function fetchId($type = 'Apply', $name = '', $text = '', $task = '', $list = true, $hideMenu = false) | ||
| { | ||
| return $this->_parent->getName() . '-' . $name; | ||
| } | ||
|
|
||
| /** | ||
| * Get the JavaScript command for the button | ||
| * | ||
| * @param string $name The task name as seen by the user | ||
| * @param string $task The task used by the application | ||
| * @param boolean $list True is requires a list confirmation. | ||
| * | ||
| * @return string JavaScript command string | ||
| * | ||
| * @since 3.0 | ||
|
||
| */ | ||
| protected function _getCommand($name, $task, $list) | ||
| { | ||
| $message = JText::_('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'); | ||
| $message = addslashes($message); | ||
|
|
||
| if ($list) | ||
| { | ||
| $cmd = "if (document.adminForm.boxchecked.value==0){alert('$message');}else{ Joomla.submitbutton('$task')}"; | ||
| } | ||
| else | ||
| { | ||
| $cmd = "Joomla.submitbutton('$task')"; | ||
| } | ||
|
|
||
| return $cmd; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -845,4 +845,24 @@ Joomla.editors.instances = Joomla.editors.instances || {}; | |
| return xhr; | ||
| }; | ||
|
|
||
| /** | ||
| * Listener for control+s. Maps it to apply/save button | ||
| */ | ||
| Joomla.keysave = function ( button ) { | ||
| document.addEventListener("keydown", function(e) { | ||
| if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) { | ||
|
||
| e.preventDefault(); | ||
| Joomla.submitbutton.call(button) | ||
| } | ||
|
||
| }, false); | ||
|
|
||
| }; | ||
|
|
||
| // Initiate the listener for the combo key | ||
| document.addEventListener( 'DOMContentLoaded', function() { | ||
| if (Joomla.getOptions( 'keySave' ) ) { | ||
| Joomla.keysave( Joomla.getOptions( 'keySave' ).task ); | ||
|
||
| } | ||
| }); | ||
|
|
||
| }( Joomla, document )); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
behaviour core is being loaded in the if and the else can we just load it outside the if and then remove the else?