list.js 3.3 KB

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