This is our way of sorting and adding new links to the navigation drop-down. You can add this on “_head.tpl” of your current theme directory in the custom of course.
Feel free to comment on how to improve this further.
<script type="text/javascript">
jQuery(document).ready(function(){
$.each( $('.topnav') , function( x, i ){
var salesreport = $( "ul.navbar-nav li:last-child ul.dropdown-menu" ).find("#salesreport");
//adding custom link to the navigation dropdown
if(salesreport.length === 0){
$( "ul.navbar-nav li:nth-last-child(2) ul.dropdown-menu" ).append('<li><a href="index.php?module=Leads&action=salesreport" id="salesreport">Sales Report</a></li>');
$( "ul.navbar-nav li:last-child ul.dropdown-menu" ).append('<li><a href="index.php?module=Leads&action=salesreport" id="salesreport">Sales Report</a></li>');
}
//sort the dropdown alphabetically
sortIt( $(this) );
});
function sortIt( list ){
var mylist = list.find('.dropdown-menu');
var listitems = mylist.children('li').get();
listitems.sort(function(a, b) {
return $(a).find('a').text().toUpperCase().localeCompare($(b).find('a').text().toUpperCase());
})
$.each(listitems, function(idx, itm) { mylist.append(itm); });
}
})
</script>