list.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. "use strict";
  2. var filterizd;
  3. var isMobile = false, isTablet = false, isLaptop = false;
  4. (function ($) {
  5. jQuery(document).ready(function () {
  6. function detectDevice() {
  7. if (window.innerWidth <= 425) {
  8. isMobile = true;
  9. isTablet = false;
  10. isLaptop = false;
  11. } else if (window.innerWidth <= 768) {
  12. isMobile = false;
  13. isTablet = true;
  14. isLaptop = false;
  15. } else {
  16. isMobile = false;
  17. isTablet = false;
  18. isLaptop = true;
  19. }
  20. }
  21. detectDevice();
  22. // ======= Adjust height of the post cards =============
  23. function adjustPostCardsHeight() {
  24. if (!isMobile) { // no need to adjust height for mobile devices
  25. let postCardHolder = document.getElementById("post-cards");
  26. if (postCardHolder == null ){
  27. return
  28. }
  29. let el = postCardHolder.children;
  30. let maxHeight = 0;
  31. for (let i = 0; i < el.length; i++) {
  32. if (el[i].children[1].clientHeight > maxHeight) {
  33. maxHeight = el[i].children[1].clientHeight;
  34. }
  35. }
  36. for (let i = 0; i < el.length; i++) {
  37. el[i].children[1].setAttribute("style", "min-height: " + maxHeight + "px;")
  38. }
  39. }
  40. }
  41. adjustPostCardsHeight();
  42. // ============= Sidebar Tree ================
  43. function buildSidebarMenu() {
  44. var openedClass = "fa-minus-circle";
  45. var closedClass = "fa-plus-circle";
  46. // initialize top level
  47. var tree = $("#tree");
  48. // add expand icon to those li who has ul as children
  49. tree.find("li").has("ul").each(function () {
  50. var branch = $(this);
  51. branch.prepend('<i class="fas ' + closedClass + '"></i>');
  52. branch.on('click', function (e) {
  53. if (this.children[1] == e.target) {
  54. // toggle "expand" class and icon
  55. branch.toggleClass("expand");
  56. var icon = $(this).children('i:first');
  57. icon.toggleClass(openedClass + " " + closedClass);
  58. }
  59. });
  60. });
  61. // remove "expnad" class from siblings of the clicked item
  62. tree.find("li").on("click", function () {
  63. var item = $(this);
  64. var shiblings = item.siblings().each(function () {
  65. var sibling = $(this);
  66. if (sibling.hasClass("expand")) {
  67. sibling.removeClass("expand");
  68. var icon = sibling.children('i:first');
  69. icon.toggleClass(openedClass + " " + closedClass);
  70. }
  71. });
  72. });
  73. // focus the cliked item
  74. tree.find("a").on("click", function () {
  75. // clear other focused link
  76. tree.find("a.focused").each(function () {
  77. $(this).removeClass("focused");
  78. });
  79. // focus cliked link
  80. $(this).addClass("focused");
  81. });
  82. }
  83. buildSidebarMenu();
  84. // initialize filterizr
  85. filterizd = $(".filtr-container").filterizr({ layout: 'sameWidth' });
  86. });
  87. })(jQuery);
  88. // toggle sidebar on click
  89. function toggleSidebar() {
  90. document.getElementById("sidebar").classList.toggle("hide");
  91. document.getElementById("content").classList.toggle("overley");
  92. // if it is mobile device. then scroll to top.
  93. if (isMobile && $("#sidebar").hasClass("hide")) {
  94. document.body.scrollTop = 0;
  95. document.documentElement.scrollTop = 0;
  96. }
  97. setTimeout(function () {
  98. filterizd.filterizr('sort');
  99. }, 300);
  100. }