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.

143 lines
4.2 KiB

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