common.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2016, 2024, 5 Mode
  3. * All rights reserved.
  4. *
  5. * This file is part of BoxToBox.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
  8. * and associated documentation files (the "Software"), to deal in the Software
  9. * without restriction, including without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or
  14. * substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  17. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  18. * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * BoxToBox common javascript code.
  24. *
  25. * @author Daniele Bonini <my25mb@aol.com>
  26. * @copyrights (c) 2021, 2024, 5 Mode
  27. */
  28. function BOXTOBOXcloseMe(tthis) {
  29. $(tthis).parent().hide();
  30. }
  31. /**
  32. * Encrypt the given string
  33. *
  34. * @param {string} string - The string to encrypt
  35. * @returns {string} the encrypted string
  36. */
  37. function BOXTOBOXencryptSha2(string) {
  38. var jsSHAo = new jsSHA("SHA-256", "TEXT", 1);
  39. jsSHAo.update(string);
  40. return jsSHAo.getHash("HEX");
  41. }
  42. /**
  43. * Get the height of the whole document
  44. *
  45. * @param {none}
  46. * @returns {int} the document height
  47. */
  48. function BOXTOBOXgetDocHeight() {
  49. var D = document;
  50. return Math.max(
  51. D.body.scrollHeight, D.documentElement.scrollHeight,
  52. D.body.offsetHeight, D.documentElement.offsetHeight,
  53. D.body.clientHeight, D.documentElement.clientHeight
  54. );
  55. }
  56. function BOXTOBOXgetDocHeight2() {
  57. var D = document;
  58. var scrollMaxY;
  59. if (window.scrollMaxY) {
  60. scrollMaxY = window.scrollMaxY;
  61. } else {
  62. scrollMaxY = D.documentElement.scrollHeight;
  63. }
  64. var height = Math.max(
  65. D.body.scrollHeight, scrollMaxY,
  66. D.body.offsetHeight, D.documentElement.offsetHeight,
  67. D.body.clientHeight, D.documentElement.clientHeight
  68. );
  69. return height;
  70. }
  71. /**
  72. * Get the width of the whole document
  73. *
  74. * @param {none}
  75. * @returns {int} the document width
  76. */
  77. function BOXTOBOXgetDocWidth() {
  78. var D = document;
  79. return Math.max(
  80. D.body.scrollWidth, D.documentElement.scrollWidth,
  81. D.body.offsetWidth, D.documentElement.offsetWidth,
  82. D.body.clientWidth, D.documentElement.clientWidth
  83. );
  84. }
  85. function BOXTOBOXgetDocWidth2() {
  86. var D = document;
  87. var scrollMaxX;
  88. if (window.scrollMaxX) {
  89. scrollMaxX = window.scrollMaxX;
  90. } else {
  91. scrollMaxX = D.documentElement.scrollWidth;
  92. }
  93. return Math.max(
  94. D.body.scrollWidth, scrollMaxX,
  95. D.body.offsetWidth, D.documentElement.offsetWidth,
  96. D.body.clientWidth, D.documentElement.clientWidth
  97. );
  98. }
  99. function BOXTOBOXrnd(min, max) {
  100. min = Math.ceil(min);
  101. max = Math.floor(max);
  102. return Math.floor(Math.random() * (max - min +1)) + min;
  103. }
  104. /**
  105. * Open a link from any event handler
  106. *
  107. * @param {string} href the link to open
  108. * @param {string} target the frame target
  109. * @returns {none}
  110. */
  111. function BOXTOBOXopenLink(href, target) {
  112. window.open(href, target);
  113. }