navbar.js
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Script used with the navbar to color the menu items and leave them visible
// Check if an element of the navbar is stored in the local storage or not
var collapseItem_ul = localStorage.getItem('collapseItem_ul');
var collapseItem_a = localStorage.getItem('collapseItem_a');
//
var sublink_activate = $("a[href='" + collapseItem_a + "']");
sublink_activate.addClass("sublink_activate");
$("#" + collapseItem_ul).addClass("show");
//store the id of the collapsible element
$('.main-nav').click(function () {
localStorage.setItem('collapseItem_ul', $(this).next().attr("id"));
});
$('.sub_link').click(function (e) {
localStorage.setItem('collapseItem_a', $(this).attr("href"));
})
// a click to the connection bar or 'accueil' button desactivate the localstorage
$('.link_connect').click(function() {
$("#" + collapseItem_ul).removeClass("show");
$("#" + collapseItem_ul).addClass("hide");
sublink_activate.removeClass("sublink_activate");
localStorage.removeItem('collapseItem_ul');
localStorage.removeItem('collapseItem_a');
});
$("#accueil").click(function (){
$("#" + collapseItem_ul).removeClass("show");
$("#" + collapseItem_ul).addClass("hide");
sublink_activate.removeClass("sublink_activate");
localStorage.removeItem('collapseItem_ul');
localStorage.removeItem('collapseItem_a');
});