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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. }
  51. static
  52. jumpTo (page)
  53. {
  54. const url = new URL (window.location.href);
  55. url.searchParams.delete ('p');
  56. url.searchParams.append ('p', page);
  57. window.location.href = url;
  58. }
  59. }
  60. Script.main ();