Tiggles ツ of Speak Creative
6/21/2019 - 3:50 AM

Locator Map Alpha Sorting

The default sorting for the Locator Map Page part lists the locations by nearness to the "center" point. This script will take the list, and sort them alphabetically by the Location Name.

ie: http://cloud.madebyspeak.com/be89bdc7e58d

// for performance, so that our script does not run on every single page
if ($("body.arboretum-page").length) {
 
  // the location list does not populate when dom is ready - this will ensure our script only runs once the list is populated
  function checkForItem(elementName) {
    if ($(elementName).length >= 1) {
        clearInterval(elementChecker);
        var mylist = $('ol.places-app-location-list');
        var listitems = mylist.children("li");
        listitems.sort(function(a, b) {
          var compA = $(a).text().toUpperCase();
          var compB = $(b).text().toUpperCase();
          return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
        })
        $(mylist).append(listitems);
    }
  }
  var elementChecker = setInterval(function() { checkForItem(".places-app-location-name"); }, 500);
}