SHARE
TWEET

Untitled

a guest Mar 21st, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function parserMenu(html) {
  2.  
  3.     html = '<div><ul>' + html + '</ul></div>';
  4.  
  5.     var jqueryHtml = $(html);
  6.     let menu = new Object;
  7.    
  8.     jqueryHtml.children('ul').children('li').each(function( index ) {
  9.  
  10.         var nameElement = $( this ).children('a').text();
  11.        
  12.         menu[index] = new Object;
  13.         menu[index].name = nameElement;
  14.        
  15.         if ($( this ).children('ul').children('.has-sub')) {
  16.            
  17.             menu[index].submenu = parserMenu($( this ).children('ul').html());
  18.  
  19.         }
  20.  
  21.     });
  22.  
  23.     return menu;
  24.  
  25. }
  26.  
  27. function MenuToHTML(menu = new Object, idMenu = '', level = 0){
  28.  
  29.     var html = '<nav class="nav nav-pills flex-column">';
  30.     var separator = '';
  31.  
  32.     if (level > 5) {
  33.         level = 5;
  34.     }
  35.  
  36.     if (idMenu) {
  37.         separator = '-';
  38.     }
  39.  
  40.     $.each(menu, function(index, element) {
  41.  
  42.         let idElement = Number(index) + 1;
  43.         idElement = idMenu + '' + separator + '' + idElement;
  44.        
  45.         html += '<a class="nav-link ml-' + level + '" href="#item-1" id="' + idElement + '">' + element.name + '</a>';
  46.         html += MenuToHTML(element.submenu, idElement, level + 2);
  47.  
  48.     });
  49.  
  50.     html += '</nav>';
  51.  
  52.     return html;
  53.  
  54. }
  55.  
  56. function echoMenu(){
  57.     var html = $('a[href="/catalog"]').next('ul').html();
  58.     html = MenuToHTML(parserMenu(html));
  59.     html = '<nav id="navbar-example3" class="navbar navbar-light bg-light">' + html + '</nav>';
  60.     $('#navbar-example3').remove();
  61.     $('[data-viewblock="Catalogs"]').after(html);
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top