common.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2016, 2024, 5 Mode
  3. * All rights reserved.
  4. *
  5. * This file is part of Puzzleu.
  6. *
  7. * Puzzleu is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Puzzleu is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Puzzleu. If not, see <https://www.gnu.org/licenses/>.
  19. * config.inc
  20. *
  21. * Puzzleu common javascript code.
  22. *
  23. * @author Daniele Bonini <my25mb@aol.com>
  24. * @copyrights (c) 2021, 2024, 5 Mode
  25. */
  26. function closeMe(tthis) {
  27. $(tthis).parent().hide();
  28. }
  29. /**
  30. * Encrypt the given string
  31. *
  32. * @param {string} string - The string to encrypt
  33. * @returns {string} the encrypted string
  34. */
  35. function encryptSha2(string) {
  36. var jsSHAo = new jsSHA("SHA-256", "TEXT", 1);
  37. jsSHAo.update(string);
  38. return jsSHAo.getHash("HEX");
  39. }
  40. /**
  41. * Get the height of the whole document
  42. *
  43. * @param {none}
  44. * @returns {int} the document height
  45. */
  46. function getDocHeight() {
  47. var D = document;
  48. return Math.max(
  49. D.body.scrollHeight, D.documentElement.scrollHeight,
  50. D.body.offsetHeight, D.documentElement.offsetHeight,
  51. D.body.clientHeight, D.documentElement.clientHeight
  52. );
  53. }
  54. function getDocHeight2() {
  55. var D = document;
  56. var scrollMaxY;
  57. if (window.scrollMaxY) {
  58. scrollMaxY = window.scrollMaxY;
  59. } else {
  60. scrollMaxY = D.documentElement.scrollHeight;
  61. }
  62. var height = Math.max(
  63. D.body.scrollHeight, scrollMaxY,
  64. D.body.offsetHeight, D.documentElement.offsetHeight,
  65. D.body.clientHeight, D.documentElement.clientHeight
  66. );
  67. return height;
  68. }
  69. /**
  70. * Get the width of the whole document
  71. *
  72. * @param {none}
  73. * @returns {int} the document width
  74. */
  75. function getDocWidth() {
  76. var D = document;
  77. return Math.max(
  78. D.body.scrollWidth, D.documentElement.scrollWidth,
  79. D.body.offsetWidth, D.documentElement.offsetWidth,
  80. D.body.clientWidth, D.documentElement.clientWidth
  81. );
  82. }
  83. function getDocWidth2() {
  84. var D = document;
  85. var scrollMaxX;
  86. if (window.scrollMaxX) {
  87. scrollMaxX = window.scrollMaxX;
  88. } else {
  89. scrollMaxX = D.documentElement.scrollWidth;
  90. }
  91. return Math.max(
  92. D.body.scrollWidth, scrollMaxX,
  93. D.body.offsetWidth, D.documentElement.offsetWidth,
  94. D.body.clientWidth, D.documentElement.clientWidth
  95. );
  96. }
  97. function rnd(min, max) {
  98. min = Math.ceil(min);
  99. max = Math.floor(max);
  100. return Math.floor(Math.random() * (max - min +1)) + min;
  101. }
  102. /**
  103. * Open a link from any event handler
  104. *
  105. * @param {string} href the link to open
  106. * @param {string} target the frame target
  107. * @returns {none}
  108. */
  109. function openLink(href, target) {
  110. window.open(href, target);
  111. }