vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

  1. $(document).ready(function() {
  2. vis.createBreadcrumbs($(".container.full").first());
  3. });
  4. // namespace
  5. var vis = {};
  6. /**
  7. * Adds a breadcrumb as first child to the specified container.
  8. *
  9. * @author felixhayashi
  10. */
  11. vis.createBreadcrumbs = function(container) {
  12. // use the url to infer the path
  13. var crumbs = location.pathname.split('/');
  14. // number of ancestor directories
  15. var stepbackIndex = crumbs.length-1;
  16. var breadcrumbs = $.map(crumbs, function(crumb, i) {
  17. // first and last element of the split
  18. if(!crumb) return;
  19. stepbackIndex--;
  20. if(/\.html$/.test(crumb)) {
  21. // strip the .html to make it look prettier
  22. return "<span>" + crumb.replace(/\.html$/, "") + "</span>";
  23. } else {
  24. // calculate the relative url
  25. for(var ref=crumb+"/", j=0; j<stepbackIndex; j++, ref="../"+ref);
  26. return "<a href='" + ref + "'>" + crumb + "</a>";
  27. }
  28. }).join("") || "Home";
  29. // insert into the container at the beginning.
  30. $(container).prepend("<div id=\"breadcrumbs\">" + breadcrumbs + "</div>");
  31. };