Last active
August 29, 2015 14:07
-
-
Save jdcauley/cc5a01a31a12065d1e6e to your computer and use it in GitHub Desktop.
li Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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