first commit
This commit is contained in:
28
layouts/joomla/editors/buttons.php
Normal file
28
layouts/joomla/editors/buttons.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage Layout
|
||||
*
|
||||
* @copyright (C) 2014 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\Language\Text;
|
||||
|
||||
$buttons = $displayData;
|
||||
|
||||
?>
|
||||
<div class="editor-xtd-buttons" role="toolbar" aria-label="<?php echo Text::_('JTOOLBAR'); ?>">
|
||||
<?php if ($buttons) : ?>
|
||||
<?php foreach ($buttons as $button) :
|
||||
$options = (array) $button->get('options');
|
||||
$legacyModal = $button->get('modal');
|
||||
?>
|
||||
<?php echo $this->sublayout('button', $button); ?>
|
||||
<?php echo $legacyModal ? $this->sublayout('modal', $button) : ''; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
74
layouts/joomla/editors/buttons/button.php
Normal file
74
layouts/joomla/editors/buttons/button.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage Layout
|
||||
*
|
||||
* @copyright (C) 2014 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\Factory;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
/** @var \Joomla\CMS\Editor\Button\Button $button */
|
||||
$button = $displayData;
|
||||
|
||||
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
|
||||
$btnAsset = 'editor-button.' . $button->getButtonName();
|
||||
|
||||
// Enable the button assets if any
|
||||
if ($wa->assetExists('style', $btnAsset)) {
|
||||
$wa->useStyle($btnAsset);
|
||||
}
|
||||
if ($wa->assetExists('script', $btnAsset)) {
|
||||
$wa->useScript($btnAsset);
|
||||
}
|
||||
|
||||
$class = 'btn btn-secondary';
|
||||
$class .= $button->get('class') ? ' ' . $button->get('class') : null;
|
||||
$class .= $button->get('modal') ? ' modal-button' : null;
|
||||
$href = '#' . $button->get('editor') . '_' . strtolower($button->get('name', '')) . '_modal';
|
||||
$link = $button->get('link');
|
||||
$onclick = $button->get('onclick') ? ' onclick="' . $button->get('onclick') . '"' : '';
|
||||
$title = $button->get('title') ? $button->get('title') : $button->get('text', '');
|
||||
$icon = $button->get('icon');
|
||||
$action = $button->get('action', '');
|
||||
$options = (array) $button->get('options');
|
||||
|
||||
// Correct the link, check for legacy with & in it, and prepend a base Uri
|
||||
if ($link && $link[0] !== '#') {
|
||||
$link = str_contains($link, '&') ? htmlspecialchars_decode($link) : $link;
|
||||
$link = Uri::base(true) . '/' . $link;
|
||||
$options['src'] = $options['src'] ?? $link;
|
||||
}
|
||||
|
||||
// Detect a legacy BS modal, and set action to "modal" for legacy buttons, when possible
|
||||
$legacyModal = $button->get('modal');
|
||||
|
||||
// Prepare default values for modal
|
||||
if ($action === 'modal') {
|
||||
$wa->useScript('joomla.dialog');
|
||||
$legacyModal = false;
|
||||
|
||||
$options['popupType'] = $options['popupType'] ?? 'iframe';
|
||||
$options['textHeader'] = $options['textHeader'] ?? $title;
|
||||
$options['iconHeader'] = $options['iconHeader'] ?? 'icon-' . $icon;
|
||||
}
|
||||
|
||||
$optStr = $options && $action ? json_encode($options, JSON_UNESCAPED_SLASHES) : '';
|
||||
|
||||
?>
|
||||
|
||||
<button type="button" data-joomla-editor-button-action="<?php echo $this->escape($action); ?>" data-joomla-editor-button-options="<?php echo $this->escape($optStr); ?>"
|
||||
class="xtd-button btn btn-secondary <?php echo $class; ?>" title="<?php echo $this->escape($title); ?>" <?php echo $onclick; ?>
|
||||
<?php echo $legacyModal ? 'data-bs-toggle="modal" data-bs-target="' . $href . '"' : '' ?>>
|
||||
<?php if ($icon) : ?>
|
||||
<span class="icon-<?php echo $icon; ?>" aria-hidden="true"></span>
|
||||
<?php endif; ?>
|
||||
<?php echo $button->get('text'); ?>
|
||||
</button>
|
||||
|
||||
60
layouts/joomla/editors/buttons/modal.php
Normal file
60
layouts/joomla/editors/buttons/modal.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage Layout
|
||||
*
|
||||
* @copyright (C) 2016 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\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
/** @var \Joomla\CMS\Editor\Button\Button $button */
|
||||
$button = $displayData;
|
||||
|
||||
if (!$button->get('modal')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$class = ($button->get('class')) ? $button->get('class') : null;
|
||||
$class .= ($button->get('modal')) ? ' modal-button' : null;
|
||||
$href = '#' . $button->get('editor') . '_' . strtolower($button->get('name')) . '_modal';
|
||||
$link = ($button->get('link')) ? Uri::base() . $button->get('link') : null;
|
||||
$onclick = ($button->get('onclick')) ? ' onclick="' . $button->get('onclick') . '"' : '';
|
||||
$title = ($button->get('title')) ? $button->get('title') : $button->get('text');
|
||||
$options = $button->getOptions();
|
||||
|
||||
$confirm = '';
|
||||
|
||||
if (is_array($button->get('options')) && isset($options['confirmText']) && isset($options['confirmCallback'])) {
|
||||
$confirm = '<button type="button" class="btn btn-success" data-bs-dismiss="modal" onclick="' . $options['confirmCallback'] . '">'
|
||||
. $options['confirmText'] . ' </button>';
|
||||
}
|
||||
|
||||
if (null !== $button->get('id')) {
|
||||
$id = str_replace(' ', '', $button->get('id'));
|
||||
} else {
|
||||
$id = $button->get('editor') . '_' . strtolower($button->get('name')) . '_modal';
|
||||
}
|
||||
|
||||
// @todo: J4: Move Make buttons fullscreen on smaller devices per https://github.com/joomla/joomla-cms/pull/23091
|
||||
// Create the modal
|
||||
echo HTMLHelper::_(
|
||||
'bootstrap.renderModal',
|
||||
$id,
|
||||
[
|
||||
'url' => $link,
|
||||
'title' => $title,
|
||||
'height' => array_key_exists('height', $options) ? $options['height'] : '400px',
|
||||
'width' => array_key_exists('width', $options) ? $options['width'] : '800px',
|
||||
'bodyHeight' => array_key_exists('bodyHeight', $options) ? $options['bodyHeight'] : '70',
|
||||
'modalWidth' => array_key_exists('modalWidth', $options) ? $options['modalWidth'] : '80',
|
||||
'footer' => $confirm . '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">'
|
||||
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>'
|
||||
]
|
||||
);
|
||||
Reference in New Issue
Block a user