common.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2016, 2024, 5 Mode
  3. * All rights reserved.
  4. *
  5. * This file is part of Simplicity.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither 5 Mode nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * Simplicity common javascript code.
  30. *
  31. * @author Daniele Bonini <my25mb@aol.com>
  32. * @copyrights (c) 2021, 2024, 5 Mode
  33. */
  34. function closeMe(tthis) {
  35. $(tthis).parent().hide();
  36. }
  37. /**
  38. * Encrypt the given string
  39. *
  40. * @param {string} string - The string to encrypt
  41. * @returns {string} the encrypted string
  42. */
  43. function encryptSha2(string) {
  44. var jsSHAo = new jsSHA("SHA-256", "TEXT", 1);
  45. jsSHAo.update(string);
  46. return jsSHAo.getHash("HEX");
  47. }
  48. /**
  49. * Get the height of the whole document
  50. *
  51. * @param {none}
  52. * @returns {int} the document height
  53. */
  54. function getDocHeight() {
  55. var D = document;
  56. return Math.max(
  57. D.body.scrollHeight, D.documentElement.scrollHeight,
  58. D.body.offsetHeight, D.documentElement.offsetHeight,
  59. D.body.clientHeight, D.documentElement.clientHeight
  60. );
  61. }
  62. function getDocHeight2() {
  63. var D = document;
  64. var scrollMaxY;
  65. if (window.scrollMaxY) {
  66. scrollMaxY = window.scrollMaxY;
  67. } else {
  68. scrollMaxY = D.documentElement.scrollHeight;
  69. }
  70. var height = Math.max(
  71. D.body.scrollHeight, scrollMaxY,
  72. D.body.offsetHeight, D.documentElement.offsetHeight,
  73. D.body.clientHeight, D.documentElement.clientHeight
  74. );
  75. return height;
  76. }
  77. /**
  78. * Get the width of the whole document
  79. *
  80. * @param {none}
  81. * @returns {int} the document width
  82. */
  83. function getDocWidth() {
  84. var D = document;
  85. return Math.max(
  86. D.body.scrollWidth, D.documentElement.scrollWidth,
  87. D.body.offsetWidth, D.documentElement.offsetWidth,
  88. D.body.clientWidth, D.documentElement.clientWidth
  89. );
  90. }
  91. function getDocWidth2() {
  92. var D = document;
  93. var scrollMaxX;
  94. if (window.scrollMaxX) {
  95. scrollMaxX = window.scrollMaxX;
  96. } else {
  97. scrollMaxX = D.documentElement.scrollWidth;
  98. }
  99. return Math.max(
  100. D.body.scrollWidth, scrollMaxX,
  101. D.body.offsetWidth, D.documentElement.offsetWidth,
  102. D.body.clientWidth, D.documentElement.clientWidth
  103. );
  104. }
  105. function rnd(min, max) {
  106. min = Math.ceil(min);
  107. max = Math.floor(max);
  108. return Math.floor(Math.random() * (max - min +1)) + min;
  109. }
  110. /**
  111. * Open a link from any event handler
  112. *
  113. * @param {string} href the link to open
  114. * @param {string} target the frame target
  115. * @returns {none}
  116. */
  117. function openLink(href, target) {
  118. window.open(href, target);
  119. }