<commit_before>$(document).ready(documentReady);

var menuTree = {};
var topMenuItemTemplate;
var sideMenuItemTemplate;
var thePath;


function documentReady() {
  thePath = window.location.pathname;
  thePath = thePath.substring(1, thePath.length -1);
  console.log(thePath);

  $.get('/templates/topMenuItem.tpl', function(data) {
    topMenuItemTemplate = data;

    $.get('/templates/sideMenuItem.tpl', function(data) {
      sideMenuItemTemplate = data;
    });

    getMenuFile(menuFileLoaded);
  })

  //Scrolling
  $(function() {
    $(window).on("scroll", function() {
      if($(window).scrollTop() > 0) {
        $("#header").addClass("active");
      } else {
        //remove the background property so it comes transparent again (defined in your css)
        $("#header").removeClass("active");
      }
    });
  });

  if(thePath !== '/') {
    $("#header").addClass("always-active");
    $('.page').addClass('padding-fix');
  }
}

function getMenuFile(callback) {
  $.getJSON( '/menu.json', function(data) {
    callback(data);
  });


  $('#top-menu-items').on('click', 'a.top-menu-item', function(eventData) {
    var topMenuId = $(this).data().menuId;
    //Set in localstorage
    localStorage.setItem("vamp-mainSelected", topMenuId);
  });

  $('#side-menu').on('click', 'div.menu-item', function(eventData) {
    var sideMenuId = $(this).data().menuId;
    localStorage.setItem("vamp-sideSelected", sideMenuId);
  });
}


function menuFileLoaded(data) {
  //Building top menu
  data.children.forEach(function(topMenuItem) {
    if (topMenuItem.visible) {
      var html = Mustache.render(topMenuItemTemplate, topMenuItem);
      var renderedTopMenuItem = $.parseHTML(html);

      if(thePath.search(topMenuItem.path) !== -1) {
        $(renderedTopMenuItem).addClass('active');
        console.log(topMenuItem.children);
        topMenuItem.children && buildSideMenu(topMenuItem);
      }

      $('#top-menu-items').append(renderedTopMenuItem);
    }
  });
}

function buildSideMenu(data) {
  console.log(data);
  data.children.forEach(function(sideMenuItem) {
    if (sideMenuItem.visible) {
      var html = Mustache.render(sideMenuItemTemplate, sideMenuItem);
      var renderedSideMenuItem = $.parseHTML(html);
      $('#side-menu').append(renderedSideMenuItem);


      if(thePath.search(sideMenuItem.path) !== -1) {
        $(renderedSideMenuItem).addClass('active');
        sideMenuItem.children && buildSubSideMenu(sideMenuItem);
      }

    }
  })
}

function buildSubSideMenu(data) {
  console.log(data);
  console.log('test');
  data.children.forEach(function(subSideMenuItem) {
    if (subSideMenuItem.visible) {
      var html = Mustache.render('<a class="sub-menu-item" href="/{{path}}"><p class="text">{{text}}</p></a>', subSideMenuItem);
      var renderedSubSideMenuItem = $.parseHTML(html);

      if(thePath.search(subSideMenuItem.path) !== -1) {
        $(renderedSubSideMenuItem).addClass('active');
      }

      $('#side-menu').append(renderedSubSideMenuItem);
    }
  })
}




<commit_msg>Fixed #32<commit_after>$(document).ready(documentReady);

var menuTree = {};
var topMenuItemTemplate;
var sideMenuItemTemplate;
var thePath;


function documentReady() {
  thePath = window.location.pathname;
  thePath = thePath.substring(1, thePath.length -1);
  console.log(thePath);

  $.get('/templates/topMenuItem.tpl', function(data) {
    topMenuItemTemplate = data;

    $.get('/templates/sideMenuItem.tpl', function(data) {
      sideMenuItemTemplate = data;
    });

    getMenuFile(menuFileLoaded);
  })

  // Top menu color change
  $(function() {
    $(window).on("scroll", function() {
      if($(window).scrollTop() > 0) {
        $("#header").addClass("active");
      } else {
        //remove the background property so it comes transparent again (defined in your css)
        $("#header").removeClass("active");
      }
    });
  });

  if(thePath !== '/') {
    $("#header").addClass("always-active");
    $('.page').addClass('padding-fix');
  }


  //Set smoothscrolling

  $('a[href^="#"]').on('click',function (e) {
    e.preventDefault();

    var target = this.hash;
    var $target = $(target);

    $('html, body').stop().animate({
      'scrollTop': $target.offset().top - 100
    }, 350, 'swing', function () {
      // window.location.hash = target;
    });
  });
}

function getMenuFile(callback) {
  $.getJSON( '/menu.json', function(data) {
    callback(data);
  });


  $('#top-menu-items').on('click', 'a.top-menu-item', function(eventData) {
    var topMenuId = $(this).data().menuId;
    //Set in localstorage
    localStorage.setItem("vamp-mainSelected", topMenuId);
  });

  $('#side-menu').on('click', 'div.menu-item', function(eventData) {
    var sideMenuId = $(this).data().menuId;
    localStorage.setItem("vamp-sideSelected", sideMenuId);
  });
}


function menuFileLoaded(data) {
  //Building top menu
  data.children.forEach(function(topMenuItem) {
    if (topMenuItem.visible) {
      var html = Mustache.render(topMenuItemTemplate, topMenuItem);
      var renderedTopMenuItem = $.parseHTML(html);

      if(thePath.search(topMenuItem.path) !== -1) {
        $(renderedTopMenuItem).addClass('active');
        console.log(topMenuItem.children);
        topMenuItem.children && buildSideMenu(topMenuItem);
      }

      $('#top-menu-items').append(renderedTopMenuItem);
    }
  });
}

function buildSideMenu(data) {
  console.log(data);
  data.children.forEach(function(sideMenuItem) {
    if (sideMenuItem.visible) {
      var html = Mustache.render(sideMenuItemTemplate, sideMenuItem);
      var renderedSideMenuItem = $.parseHTML(html);
      $('#side-menu').append(renderedSideMenuItem);


      if(thePath.search(sideMenuItem.path) !== -1) {
        $(renderedSideMenuItem).addClass('active');
        sideMenuItem.children && buildSubSideMenu(sideMenuItem);
      }

    }
  })
}

function buildSubSideMenu(data) {
  console.log(data);
  console.log('test');
  data.children.forEach(function(subSideMenuItem) {
    if (subSideMenuItem.visible) {
      var html = Mustache.render('<a class="sub-menu-item" href="/{{path}}"><p class="text">{{text}}</p></a>', subSideMenuItem);
      var renderedSubSideMenuItem = $.parseHTML(html);

      if(thePath.search(subSideMenuItem.path) !== -1) {
        $(renderedSubSideMenuItem).addClass('active');
      }

      $('#side-menu').append(renderedSubSideMenuItem);
    }
  })
}





{'fraction_non_alphanumeric': 0.17708495713172254, 'fraction_numerical': 0.003117692907248636, 'mean_word_length': 3.5600568585643213, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4992609', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1944, 'n_words': 303}