- md5
- 07ca75af2d448b6e20d23a25d9bcb778
- sha1
- f428c205e56372bfa971ee7b1d8482f8c68daa80
- sha256
- 69677d12aedf1cf919c5a93322c417a9b4c05602ad02ab06fc07d72c7a7136d5
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
<?php
/**
* @package Joomla.Libraries
* @subpackage HTML
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Session\Session;
/**
* HTML utility class for creating a sortable table list
*
* @since 4.0.0
*/
abstract class JHtmlDraggablelist
{
/**
* Array containing information for loaded files
*
* @var array
* @since 4.0.0
*/
protected static $loaded = array();
/**
* Method to load the Dragula script and make table sortable
*
* @param string $tableId DOM id of the table
* @param string $formId DOM id of the form
* @param string $sortDir Sort direction
* @param string $saveOrderingUrl Save ordering url, ajax-load after an item dropped
* @param string $redundant Not used
* @param boolean $nestedList Set whether the list is a nested list
*
* @return void
*
* @since 4.0.0
*
* @throws InvalidArgumentException
*/
public static function draggable(string $tableId = '', string $formId = '', string $sortDir = 'asc', string $saveOrderingUrl = '',
$redundant = null, bool $nestedList = false)
{
// Only load once
if (isset(static::$loaded[__METHOD__]))
{
return;
}
$doc = Factory::getDocument();
// Please consider using data attributes instead of passing arguments here!
if (!empty($tableId) && !empty($saveOrderingUrl) && !empty($formId) && !empty($sortDir))
{
$doc->addScriptOptions(
'draggable-list',
[
'id' => '#' . $tableId . ' tbody',
'formId' => $formId,
'direction' => $sortDir,
'url' => $saveOrderingUrl . '&' . Session::getFormToken() . '=1',
'nested' => $nestedList,
]
);
}
// Depends on Joomla.getOptions()
HTMLHelper::_('behavior.core');
// Attach draggable to document
HTMLHelper::_('script', 'vendor/dragula/dragula.min.js', ['framework'=>false, 'relative'=>true]);
HTMLHelper::_('script', 'system/draggable.min.js', ['framework'=>false, 'relative'=>true]);
HTMLHelper::_('stylesheet', 'vendor/dragula/dragula.min.css', ['framework'=>false, 'relative'=>true, 'pathOnly'=>false]);
// Set static array
static::$loaded[__METHOD__] = true;
}
}
The same content is in 2 releases, Joomla 4.0.0-alpha5 to 4.0.0-alpha6. See them all, or every version of this file.