sortablelist.php
1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @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_BASE') or die;
/**
* Layout variables
* ---------------------
*
* @var string $tableId The id of the table
* @var string $formId The id of the form
* @var string $saveOrderingUrl Save the ordering URL?
* @var string $sortDir The direction of the order (asc/desc)
* @var string $nestedList Is it nested list?
* @var string $proceedSaveOrderButton Is there a button to initiate the ordering?
*/
extract($displayData);
// Depends on jQuery UI
JHtml::_('jquery.ui', array('core', 'sortable'));
JHtml::_('script', 'jui/sortablelist.js', array('version' => 'auto', 'relative' => true));
JHtml::_('stylesheet', 'jui/sortablelist.css', array('version' => 'auto', 'relative' => true));
// Attach sortable to document
JFactory::getDocument()->addScriptDeclaration(
"
jQuery(document).ready(function ($){
var sortableList = new $.JSortableList('#"
. $tableId . " tbody','" . $formId . "','" . $sortDir . "' , '" . $saveOrderingUrl . "','','" . $nestedList . "');
});
"
);
if ($proceedSaveOrderButton)
{
JFactory::getDocument()->addScriptDeclaration(
"
jQuery(document).ready(function ($){
var saveOrderButton = $('.saveorder');
saveOrderButton.css({'opacity':'0.2', 'cursor':'default'}).attr('onclick','return false;');
var oldOrderingValue = '';
$('.text-area-order').focus(function ()
{
oldOrderingValue = $(this).attr('value');
})
.keyup(function (){
var newOrderingValue = $(this).attr('value');
if (oldOrderingValue != newOrderingValue)
{
saveOrderButton.css({'opacity':'1', 'cursor':'pointer'}).removeAttr('onclick')
}
});
});
"
);
}