Created
June 25, 2012 05:00
-
-
Save Haroperi/2986632 to your computer and use it in GitHub Desktop.
パンくずリスト with js
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
// 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 += " > "; | |
} | |
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