Skip to content

Instantly share code, notes, and snippets.

@oscardelama
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscardelama/d6a35cf3d5908a7f8f55 to your computer and use it in GitHub Desktop.
Save oscardelama/d6a35cf3d5908a7f8f55 to your computer and use it in GitHub Desktop.
MenuHandler.prototype.buildMenu = function(menuObj, MaxLevels, currLevel, basePath) {
var menu = "", menuItem, className, extraTitle;
for (var childMenuKey in menuObj) {
menuItem = '';
className = '';
extraTitle = "";
if ( !/[^\-—–\s]/.test( menuObj[childMenuKey].menu ) )
menuItem = '---';
else {
if (childMenuKey == this.currMenuInfo.nextChildMenuKey) {
menuItem = '<a class="$class" href="#" title="$title">$menu</a>';
// className = (this.currMenuInfo.nextChildMenuKind == endPath) ? 'ui-state-disabled endPath':'inPath';
if (this.currMenuInfo.nextChildMenuKind == endPath) {
className = 'ui-state-disabled endPath' ;
extraTitle = ' (current page)';
}
else
className = 'inPath' ;
menuItem = menuItem.replace("$class", className);
}
else
menuItem = '<a href="$href" title="$title">$menu</a>';
//var menuItemPath = basePath + menuObj[childMenuKey].href + '/';
var menuItemPath = menuObj[childMenuKey].href;
menuItem = menuItem.replace("$href", menuItemPath);
menuItem = menuItem.replace("$title", menuObj[childMenuKey].title + extraTitle);
menuItem = menuItem.replace("$menu", menuObj[childMenuKey].menu);
if (menuObj[childMenuKey].children && currLevel > 0) {
var subMenu = this.buildMenu(menuObj[childMenuKey].children,
MaxLevels,
currLevel - 1,
menuItemPath );
menuItem += '<ul>' + subMenu + '</ul>';
}
}
menu += '<li>' + menuItem + '</li>';
}
return menu;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment