Skip to content

Instantly share code, notes, and snippets.

@Haroperi
Created June 25, 2012 05:00
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 Haroperi/2986632 to your computer and use it in GitHub Desktop.
Save Haroperi/2986632 to your computer and use it in GitHub Desktop.
パンくずリスト with js
// add following HTML to your HTML file.
// <div id="pankuz"></div>
// <script type="text/javascript" src="pankuz.js"></script>
// definition of each pages
table = {
"foo.github.ac.jp": {
"name": "foo github",
"directory": {
"name": "the title of this directory",
"directory2": {
"name": "the title of this directory",
"foo.html": "foooooooooo",
},
},
},
"bar.github.ac.jp" : {
"name": "bar github",
"profile.html" : { "name": "profile" },
"products.html": { "name": "products" },
},
}
url = "http:/"
arr = (window.location.hostname + window.location.pathname).split("/")
obj = document.getElementById("pankuz");
obj.innerHTML = "";
for(i = 0, current_node = table; i < arr.length && (current_node = current_node[arr[i]]); i++) {
if (!current_node["name"]) {
continue;
}
if (i > 0) {
obj.innerHTML += " &gt; ";
}
url += "/" + arr[i];
if (i == arr.length-1) {
obj.innerHTML += current_node["name"];
}
else {
obj.innerHTML += ("<a href=\"" + url + "\">" + current_node["name"] + "</a>");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment