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.
 
 
 
 

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