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

script.js 3.2 KiB

6 months ago
5 months ago
6 months ago
6 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. $ ('.message-block').on ('click', function ()
  62. {
  63. const dt = $ (this).find ('.message-block-dt').text ();
  64. const chat = $ (this).find ('.message-block-chat').text ();
  65. const answer = $ (this).find ('.message-block-answer').text ();
  66. window.open (`./talk.php?dt=${dt}&chat=${chat}&answer=${answer}`);
  67. });
  68. if ($.cookie ('expand-filter') === '0')
  69. {
  70. $ ('#collapse-filter').removeClass ('show');
  71. $ ('#accordion-filter .accordion-button').addClass ('collapsed');
  72. }
  73. }
  74. static
  75. jumpTo (page)
  76. {
  77. const url = new URL (window.location.href);
  78. url.searchParams.delete ('p');
  79. url.searchParams.append ('p', page);
  80. window.location.href = url;
  81. }
  82. static
  83. setPagination ()
  84. {
  85. for (let i = 1; i <= 20; ++i)
  86. $ (`.page-${i}`).removeClass ('d-none');
  87. for (let i = 20; i > 1; --i)
  88. {
  89. if (($ ('.pagination').width () < $ ('body').width () * .8)
  90. && ($ ('.page-item:not(.d-none)').length / 2 % 2 != 0))
  91. break;
  92. $ (`.page-${i}`).addClass ('d-none');
  93. }
  94. }
  95. }
  96. Script.main ();