Skip to content

Instantly share code, notes, and snippets.

@jdcauley
Last active August 29, 2015 14:07
Show Gist options
  • Save jdcauley/cc5a01a31a12065d1e6e to your computer and use it in GitHub Desktop.
Save jdcauley/cc5a01a31a12065d1e6e to your computer and use it in GitHub Desktop.
li Sort
function alphabatizeMenu(target){
var continent = document.getElementById('tab_' + target);
if(continent){
var listParent = document.getElementById(target + '-offices');
var listItems = continent.getElementsByClassName('in-' + target);
var listItemText = [];
for(var i = 0; i < listItems.length; i++){
listItemText.push({
country: listItems[i].textContent,
item: listItems[i]
});
}
listItemText.sort(function (a, b) {
var countryA = a.country;
var countryB = b.country;
return countryA.localeCompare(countryB);
});
for(var n = 0; n < listItemText.length; n++){
listParent.appendChild(listItemText[n].item);
}
}
}
if($('body').hasClass('page-template-template-purchase-php')){
alphabatizeMenu('europe');
alphabatizeMenu('north-america');
alphabatizeMenu('south-america');
alphabatizeMenu('asia');
alphabatizeMenu('africa');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment