Personal website https://benkurtovic.com/
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.
 
 
 
 

69 lines
2.0 KiB

  1. function fix_tag_links() {
  2. $(".post-tag").attr("href", function() {
  3. return "/#" + encodeURIComponent($(this).text());
  4. });
  5. }
  6. function load_tag_filters() {
  7. var filter_posts = function() {
  8. var filter = [];
  9. $(".tag-selected").each(function() {
  10. filter.push($(this).data("tag"))
  11. });
  12. $("#post-list li").show();
  13. $("#null-post").hide();
  14. if ($(".tag-selected").length == 0)
  15. return;
  16. $("#post-list li").each(function() {
  17. var tags = $(this).data("tags").split("|");
  18. for (var i in filter) {
  19. if ($.inArray(filter[i], tags) == -1) {
  20. $(this).hide();
  21. return;
  22. }
  23. }
  24. });
  25. if ($("#post-list li:not(:hidden)").length == 0)
  26. $("#null-post").show();
  27. }
  28. if (window.location.hash) {
  29. var tags = decodeURIComponent(window.location.hash.substr(1)).split("|");
  30. $(".tag").each(function() {
  31. if ($.inArray($(this).data("tag"), tags) != -1)
  32. $(this).toggleClass("tag-selected");
  33. });
  34. filter_posts();
  35. }
  36. $(".tag").on("click", function() {
  37. var tags = [];
  38. $(this).toggleClass("tag-selected");
  39. $(".tag-selected").each(function() {
  40. tags.push($(this).data("tag"))
  41. });
  42. if (tags.length > 0)
  43. window.location.hash = encodeURIComponent(tags.join("|"));
  44. else
  45. history.pushState("", "", window.location.pathname);
  46. filter_posts();
  47. });
  48. }
  49. function load_paragraph_links() {
  50. $("#post").find("h1, h2, h3, h4, h5, h6").on("mouseenter", function() {
  51. $(this).append($("<a>")
  52. .attr("href", "#" + this.id)
  53. .attr("class", "para-link")
  54. .text("¶"));
  55. }).on("mouseleave", function() {
  56. $(this).find(".para-link").remove();
  57. });
  58. }
  59. $(document).ready(function() {
  60. fix_tag_links();
  61. load_tag_filters();
  62. load_paragraph_links();
  63. });