search.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { lang } from "./lang.js";
  2. class search {
  3. #container;
  4. #hint;
  5. #input;
  6. #last_content;
  7. constructor() {
  8. this.#last_content = "";
  9. this.#container = document.createElement("div");
  10. this.#container.className = "search";
  11. this.#hint = document.createElement("div");
  12. this.#hint.className = "hint";
  13. this.#input = document.createElement("input");
  14. this.#input.type = "text";
  15. this.#input.placeholder = lang.search.type;
  16. const submit = document.createElement("input");
  17. submit.type = "submit";
  18. submit.value = lang.search.find;
  19. const form = document.createElement("form");
  20. form.addEventListener("submit", (action) => {
  21. action.preventDefault();
  22. this.find();
  23. });
  24. this.#input.addEventListener("keypress", () => {
  25. this.refresh();
  26. });
  27. this.#input.addEventListener("keyup", () => {
  28. this.refresh();
  29. });
  30. this.#input.addEventListener("change", () => {
  31. this.refresh();
  32. });
  33. form.appendChild(this.#input);
  34. form.appendChild(submit);
  35. this.#container.appendChild(form);
  36. this.#container.appendChild(this.#hint);
  37. }
  38. get content() {
  39. return this.#input.value.trim();
  40. }
  41. get changed() {
  42. if (this.content === this.#last_content) {
  43. return false;
  44. }
  45. this.#last_content = this.content;
  46. return true;
  47. }
  48. find() {
  49. if (!this.changed) {
  50. return;
  51. }
  52. console.log("UwU");
  53. }
  54. refresh() {
  55. if (!this.changed) {
  56. return;
  57. }
  58. console.log("OwO");
  59. }
  60. get ui() {
  61. return this.#container;
  62. }
  63. }
  64. export { search };