In a custom J4 site I am using the Shack Locations (previously Focalpoint) core extension that displays a dynamically generated legend of location types on the front end, but it is listing the nine types randomly. I carefully created the location types in the order in which I wanted them to appear. I also used Joomla's ordering facility to no avail. So, I created an override which brings in the location type IDs as a class for each li item (by default there is no 'li' class), so on the front-end the html now shows this (although each also has an 'a' link, but that's not relevant here):
<li class="28">No meeting</li>
<li class="22">Tuesday afternoon</li>
<li class="23">Tuesday evening</li>
<li class="25">Wednesday evening</li>
<li class="27">Thursday evening</li>
<li class="20">Monday afternoon</li>
<li class="24">Wednesday afternoon</li>
<li class="26">Thursday afternoon</li>
<li class="21">Monday evening</li>
For what I hope are obvious reasons, I want the list to display like this:
<li class="20">Monday afternoon</li>
<li class="21">Monday evening</li>
<li class="22">Tuesday afternoon</li>
<li class="23">Tuesday evening</li>
<li class="24">Wednesday afternoon</li>
<li class="25">Wednesday evening</li>
<li class="26">Thursday afternoon</li>
<li class="27">Thursday evening</li>
<li class="28">No meeting</li>
The PHP for this element is
<?php
defined('_JEXEC') or die();
$markers = $this->chunkLegends($this->item->markerdata);
$html = [];
$subtitle = '';
$lastLegend = null;
foreach ($markers as $legend) {
if ($lastLegend && $lastLegend != $legend->alias) {
$html[] = '</ul>';
$html[] = '</div>';
}
$subtitle = $legend->subtitle ? sprintf('<small>%s</small>', $legend->subtitle) : '';
$html[] = sprintf(
'<div class="%s"><h4>%s%s</h4>',
$legend->alias,
$legend->title,
$subtitle
);
$html[] = '<ul class="sidebar">';
foreach ($legend->markers as $marker) {
$html[] = sprintf(
'<li class="%s"><a data-marker-type="%s" class="active markertoggles markers-%s" href="#">%s</a></li>',
$marker->locationtype_id,
$marker->locationtype_id,
$marker->locationtypealias,
$marker->locationtype
);
}
$html[] = '</ul>';
$html[] = '</div>';
}
$html[] = $this->loadTemplate('legend_buttons');
echo join("\n", $html);
Can I sort the li
items by their class, either by adding something to the PHP file, or writing vanilla JavaScript? No jQuery, please. TIA.