ニジカもんすたぁ!! トップ・ページ https://nizika.monster
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.
 
 
 
 

119 lines
2.8 KiB

  1. class
  2. Script
  3. {
  4. static
  5. main ()
  6. {
  7. const dateOptions = {dateFormat: 'yy-mm-dd',
  8. firstDay: 6};
  9. $ ('#filter-date-start').datepicker (dateOptions);
  10. $ ('#filter-date-end').datepicker (dateOptions);
  11. const url = new URL (window.location.href);
  12. const orderAsc = document.getElementById ('order-asc');
  13. const filterKeyword = document.getElementById ('filter-keyword');
  14. const btnFilter = document.getElementById ('btn-filter');
  15. const filter = (
  16. function (e)
  17. {
  18. let dateStart = $ ('#filter-date-start').val ();
  19. let dateEnd = $ ('#filter-date-end').val ();
  20. if ((dateStart !== '')
  21. && (dateEnd !== '')
  22. && (dateStart > dateEnd))
  23. [dateStart, dateEnd] = [dateEnd, dateStart];
  24. url.searchParams.delete ('p');
  25. url.searchParams.delete ('asc');
  26. url.searchParams.append ('asc', orderAsc.checked ? '1' : '0');
  27. url.searchParams.delete ('q');
  28. url.searchParams.append ('q', filterKeyword.value);
  29. url.searchParams.delete ('start');
  30. url.searchParams.delete ('end');
  31. if (dateStart !== '')
  32. url.searchParams.append ('start', dateStart);
  33. if (dateEnd !== '')
  34. url.searchParams.append ('end', dateEnd);
  35. window.location.href = url;
  36. });
  37. const resetFilter = (
  38. function ()
  39. {
  40. window.location.href = '/';
  41. });
  42. filterKeyword.addEventListener ('keydown',
  43. function (e)
  44. {
  45. if (e.key === 'Enter')
  46. filter (e);
  47. });
  48. btnFilter.addEventListener ('click', filter);
  49. $ ('#btn-reset').on ('click', resetFilter);
  50. $ (window).resize (this.setPagination);
  51. this.setPagination ();
  52. $ ('.pagination').removeClass ('opacity-0');
  53. $ ('#accordion-filter').on ('shown.bs.collapse', function ()
  54. {
  55. $.cookie ('expand-filter', '1');
  56. });
  57. $ ('#accordion-filter').on ('hidden.bs.collapse', function ()
  58. {
  59. $.cookie ('expand-filter', '0');
  60. });
  61. if ($.cookie ('expand-filter') === '0')
  62. {
  63. $ ('#collapse-filter').removeClass ('show');
  64. $ ('#accordion-filter .accordion-button').addClass ('collapsed');
  65. }
  66. }
  67. static
  68. jumpTo (page)
  69. {
  70. const url = new URL (window.location.href);
  71. url.searchParams.delete ('p');
  72. url.searchParams.append ('p', page);
  73. window.location.href = url;
  74. }
  75. static
  76. setPagination ()
  77. {
  78. for (let i = 1; i <= 20; ++i)
  79. $ (`.page-${i}`).removeClass ('d-none');
  80. for (let i = 20; i > 1; --i)
  81. {
  82. if (($ ('.pagination').width () < $ ('body').width () * .8)
  83. && ($ ('.page-item:not(.d-none)').length / 2 % 2 != 0))
  84. break;
  85. $ (`.page-${i}`).addClass ('d-none');
  86. }
  87. }
  88. }
  89. Script.main ();