common.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. (() => {
  2. class Title
  3. {
  4. #stack = [];
  5. pushTitle(title) {
  6. this.#stack.push(title);
  7. this.#setTitle(title);
  8. }
  9. replaceTitle(title) {
  10. this.#stack.pop();
  11. this.pushTitle(title);
  12. }
  13. pop() {
  14. this.#stack.pop();
  15. this.#setTitle(this.#stack[this.#stack.length-1]);
  16. }
  17. #setTitle(title) {
  18. document.title = title ? `Photochamber - ${title}` : "Photochamber";
  19. }
  20. }
  21. document.Title = new Title();
  22. })();
  23. $(() => {
  24. function loadHash(md5sum) {
  25. if (md5sum && md5sum.length)
  26. LoadingTasks.push(async () => displayMediaFullPage(await MediaStorage.Instance.getMedia(md5sum)));
  27. else
  28. document.getElementById("pch-fullPageMedia").classList.add("hidden");
  29. }
  30. window.addEventListener("hashchange", x => {
  31. x.preventDefault();
  32. loadHash(document.location?.hash?.substr(1))
  33. return true;
  34. });
  35. onScrollBottom = (function () {
  36. this.lastCall= null;
  37. this.fnc = () => {
  38. if (this.lastCall !== null)
  39. return;
  40. this.lastCall = setTimeout(() => {
  41. this.lastCall = null;
  42. }, 1000);
  43. window.displayMoreMedia();
  44. };
  45. return this;
  46. })();
  47. window.addEventListener("scroll", evt => {
  48. if (window.scrollY+window.innerHeight >= document.body.clientHeight)
  49. onScrollBottom.fnc();
  50. });
  51. window.reloadServerDb = () => {
  52. $.ajax({
  53. url: "/api/database/reload",
  54. type: "POST",
  55. data: "{}"
  56. });
  57. };
  58. window.scanServerDb = () => {
  59. $.ajax({
  60. url: "/api/database/scan",
  61. type: "POST",
  62. data: "{}"
  63. });
  64. };
  65. window.rebootServer = () => {
  66. $.ajax({
  67. url: "/api/server/reboot",
  68. type: "POST",
  69. data: "{}"
  70. });
  71. };
  72. document.Title.pop();
  73. AccessManager.RebuildAccess();
  74. loadHash(document.location?.hash?.substr(1));
  75. MediaStorage.Instance.restoreMetaList();
  76. });