CoreFiles by mySites.guru
sortablelist.php84 lines, 2,486 bytes, from Joomla_4.0.0-alpha7-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha6
md5
b872062e4b03c1a5d691ee6d3431c342
sha1
15eda48ee7f85312506998bf70585c917bc43691
sha256
6ca233d6627426e7b821b883fe5bfd37bb7f73b95efd32cb2e6024f5bd94d6df
<?php
/**
 * @package     Joomla.Libraries
 * @subpackage  HTML
 *
 * @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('JPATH_PLATFORM') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;

/**
 * HTML utility class for creating a sortable table list
 *
 * @since  3.0
 */
abstract class JHtmlSortablelist
{
	/**
	 * @var    array  Array containing information for loaded files
	 * @since  3.0
	 */
	protected static $loaded = array();

	/**
	 * Method to load the Sortable 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   boolean  $proceedSaveOrderButton  Set whether a save order button is displayed
	 * @param   boolean  $nestedList              Set whether the list is a nested list
	 *
	 * @return  void
	 *
	 * @since   3.0
	 *
	 * @throws  InvalidArgumentException
	 */
	public static function sortable($tableId, $formId, $sortDir = 'asc', $saveOrderingUrl = null, $proceedSaveOrderButton = true, $nestedList = false)
	{
		// Only load once
		if (isset(static::$loaded[__METHOD__]))
		{
			return;
		}

		// Note: $i is required but has to be an optional argument in the function call due to argument order
		if ($saveOrderingUrl === null)
		{
			throw new InvalidArgumentException(sprintf('$saveOrderingUrl is a required argument in %s()', __METHOD__));
		}

		// Depends on Joomla.getOptions()
		HTMLHelper::_('behavior.core');

		// Depends on jQuery UI
		HTMLHelper::_('jquery.ui', array('core', 'sortable'));

		HTMLHelper::_('script', 'legacy/sortablelist.min.js', ['version' => 'auto', 'relative' => true]);
		HTMLHelper::_('stylesheet', 'legacy/sortablelist.css', ['version' => 'auto', 'relative' => true]);

		// Attach sortable to document
		Factory::getDocument()->addScriptOptions(
			'sortable-list',
			array(
				'id'         => '#' . $tableId . ' tbody',
				'formId'     => $formId,
				'direction'  => $sortDir,
				'url'        => $saveOrderingUrl,
				'options'    => '',
				'nestedList' => $nestedList,
				'button'     => $proceedSaveOrderButton
			)
		);

		// Set static array
		static::$loaded[__METHOD__] = true;
	}
}

The same content is in 6 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha12. See them all, or every version of this file.