Here's an example code how to use the PHP class tx_jquery. The examples goes through an array of items and creates two lists, which then can be sortable.
The red lines are calls of the class tx_jquery. Green lines show configuration that will be passed to the tx_jquery functions.
First of all the tx_jquery class needs to be included:
require_once(t3lib_extMgm::extPath("jquery")."class.tx_jquery.php");
A function of our example class:
/**
* returns a html-code with two sortable lists
*/
function main($content,$conf){
// only include the scripts, that are necessary
tx_jquery::setPlugins(array('iutil','idrag','idrop','isortables'));
tx_jquery::includeLib();
$content = '';
$firstList = '<ul id=”firstlist”>' . “\n”;
$secondList = '<ul id=”secondlist”> . “\n”';
// define the list-content
$listArray = array(
'Item 1',
'Item 2',
'Item 3',
'Item 4',
'Item 5',
'Item 6',
'Item 7',
);
// the list items should be split on two lists
$fieldCount = rount(count($listArray)/2);
$counter = 0;
foreach ($listArray as $listItem){
if ($counter < $fieldCount){
$listName = 'firstList';
} else {
$listName = 'secondList';
}
$$listName .= '<li class=”sortable”>' . $listItem . '</li>' . “\n”;
}
$firstList .= '</ul>' . “\n”;
$secondList .= '/ul>' . “\n”;
$content = '<div id=”sortables”>' . “\n”
. $firstList
. $secondList
. '</div>' . “\n”;
$content .= '<script type=”text/javascript”>' . “\n”;
. '// <![CDATA[' . “\n”
. “$('#firstlist').Sortable({accept:'sortable', fit:true, tolerance:'intersect', floats:false});” . “\n”
. “$('#secondlist').Sortable({accept:'sortable', fit:true, tolerance:'intersect', floats:false});” . “\n”
. '// ]]>' . “\n”
. '</script>' . “\n”;
return $this->pi_wrapInBaseClass($content);
}
Please note that the class can be used without making an instance: tx_jquery::includeLib()