Skip to content
This repository was archived by the owner on Apr 19, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion administrator/includes/toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public static function apply($task = 'apply', $alt = 'JTOOLBAR_APPLY')
$bar = JToolbar::getInstance('toolbar');

// Add an apply button
$bar->appendButton('Standard', 'apply', $alt, $task, false);
$bar->appendButton('Apply', 'apply', $alt, $task, false);
}

/**
Expand Down
37 changes: 37 additions & 0 deletions layouts/joomla/toolbar/apply.php
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');
Copy link
Member

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?

}

$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>
109 changes: 109 additions & 0 deletions libraries/cms/toolbar/button/apply.php
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.0 ? Should this not be __DEPLOY_VERSION__ or 4.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

*/
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;
}
}
20 changes: 20 additions & 0 deletions media/system/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a console.log(''pressed: ' + e.keyCode + ' and ' + e.ctrlKey );
What happens when you press keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or try

if (String.fromCharCode(e.which).toLowerCase() == 's' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

British keyboards, I guess your s is mapped to some other keyCode 😄

e.preventDefault();
Joomla.submitbutton.call(button)
}
Copy link
Contributor Author

@dgrammatiko dgrammatiko Oct 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Joomla.submitbutton(button);

@C-Lodder try with the above code

}, false);

};

// Initiate the listener for the combo key
document.addEventListener( 'DOMContentLoaded', function() {
if (Joomla.getOptions( 'keySave' ) ) {
Joomla.keysave( Joomla.getOptions( 'keySave' ).task );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you insert a console.log(Joomla.getOptions( 'keySave' ).task); before this line?
what it is in the console?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

article.apply

}
});

}( Joomla, document ));
2 changes: 1 addition & 1 deletion media/system/js/core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.