Created
February 26, 2020 08:37
-
-
Save ankedsgn/77b18845434250e06557eb3e2cc3d9dc to your computer and use it in GitHub Desktop.
History path / breadcrumbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$( document ).ready(function() { | |
/** | |
* breadcrumbs / history path | |
*/ | |
breadcrumbStateSaver(document.location.href, document.title); | |
showBreadCrumb(); | |
)}; | |
//breadcrumbs -> https://stackoverflow.com/questions/18998797/create-breadcrumbs-dynamically-on-client-side-using-javascript | |
function bindEventToNavigation(){ | |
$.each($("#primary-menu li a"), function(index, element){ | |
$(element).click(function(event){ | |
breadcrumbStateSaver($(this).attr('href'), $(this).text()); | |
showBreadCrumb(); | |
}); | |
}); | |
} | |
function breadcrumbStateSaver(link, text) { | |
if (typeof (Storage) != "undefined") { | |
text = text.split('|')[0]; | |
var items = []; | |
if (sessionStorage.breadcrumb) { | |
items = JSON.parse(sessionStorage.breadcrumb); | |
} | |
items.push("<a href='" + link + "'>" + text + "</a>"); | |
sessionStorage.breadcrumb = JSON.stringify(items); | |
} | |
} | |
function showBreadCrumb(){ | |
var breadcrumbs = JSON.parse(sessionStorage.breadcrumb); | |
$("#breadcrumbs").html(breadcrumbs.slice(-4,-1).join(' » ')); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# breadcrumbs via JS #} | |
<div id="breadcrumbs" class="breadcrumbs"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment