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.

126 lines
3.6 KiB

  1. $(document).ready(function() {
  2. vis.createBreadcrumbs($(".container.full").first());
  3. vis.initSiteSearch();
  4. vis.initKeywords();
  5. });
  6. // namespace
  7. var vis = {};
  8. /**
  9. * Adds a breadcrumb as first child to the specified container.
  10. *
  11. * @author felixhayashi
  12. */
  13. vis.createBreadcrumbs = function(container) {
  14. // use the url to infer the path
  15. var crumbs = location.pathname.split('/');
  16. // number of ancestor directories
  17. var stepbackIndex = crumbs.length-1;
  18. var breadcrumbs = $.map(crumbs, function(crumb, i) {
  19. // first and last element of the split
  20. if(!crumb) return;
  21. stepbackIndex--;
  22. if(/\.html$/.test(crumb)) {
  23. // strip the .html to make it look prettier
  24. return "<span>" + crumb.replace(/\.html$/, "") + "</span>";
  25. } else {
  26. // calculate the relative url
  27. for(var ref=crumb+"/", j=0; j<stepbackIndex; j++, ref="../"+ref);
  28. return "<a href='" + ref + "'>" + crumb + "</a>";
  29. }
  30. }).join("") || "Home";
  31. // insert into the container at the beginning.
  32. $(container).prepend("<div id=\"breadcrumbs\">" + breadcrumbs + "</div>");
  33. };
  34. /**
  35. * Will load tipue search field.
  36. * If the search has already begun, we also display the results.
  37. *
  38. * For information how it works:
  39. * @see https://github.com/almende/vis/issues/909#issuecomment-120119414
  40. * @see https://github.com/almende/vis/issues/909#issuecomment-120397562
  41. *
  42. * @author felixhayashi
  43. */
  44. vis.initSiteSearch = function() {
  45. $("#tipue_search_input").tipuesearch({
  46. "mode": "live",
  47. "show": 3,
  48. });
  49. var hasSearchMessage = $("#tipue_search_content").children().length > 0;
  50. if(hasSearchMessage) {
  51. // show result panel
  52. $("#search-results-wrapper").css("display", "block");
  53. // encode the keywords that were entered by the user
  54. var keywords = $("#tipue_search_input").val().replace(/\s/g, ",");
  55. // add keywords to result-urls
  56. $(".tipue_search_content_url a, .tipue_search_content_title a").each(function() {
  57. $(this).attr("href", $(this).attr("href") + "?keywords=" + keywords);
  58. });
  59. } else {
  60. $("#search-results-wrapper").css("display", "none");
  61. }
  62. };
  63. /**
  64. * Will highlight the keywords that are passed as url get-parameters.
  65. * All keywords are higlighted and a panel is displayed to jump to the
  66. * first keyword found.
  67. *
  68. * For information how it works:
  69. * @see https://github.com/almende/vis/issues/909#issuecomment-120119414
  70. * @see https://github.com/almende/vis/issues/909#issuecomment-120397562
  71. *
  72. * @author felixhayashi
  73. */
  74. vis.initKeywords = function() {
  75. // extract keywords from get-variable
  76. var keywords = url("?keywords");
  77. if(keywords) {
  78. // highlighting all keywords
  79. keywords = keywords.split(",");
  80. for(var i = 0; i < keywords.length; i++) {
  81. $("body").highlight(keywords[i]);
  82. }
  83. // nasty hack: programmatically open full options tab
  84. // because no browser allows scrolling to hidden elements!
  85. $("[role=presentation][targetnode=fullOptions]").click();
  86. $("tr.toggle:not(collapsible)").click();
  87. // init keyword info panel
  88. $("#keyword-info").css("display", "block");
  89. $("#keyword-count").text($(".highlight").length);
  90. $("#keyword-jumper-button").on('click', function(event) {
  91. event.preventDefault();
  92. // do not cache hits outside the handler; creates problems with prettyfy lib
  93. // we use the first visible(!) hit at the time the button is clicked
  94. var firstHit = $(".highlight:visible").first();
  95. if(firstHit) {
  96. $("html, body").animate({ scrollTop: $(firstHit).offset().top }, 2000);
  97. }
  98. });
  99. }
  100. };