home.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /**
  2. * Copyright 2021, 2024 5 Mode
  3. *
  4. * This file is part of Homomm.
  5. *
  6. * Homomm is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Homomm is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Homomm. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. * home.js
  20. *
  21. * JS file for Home page
  22. *
  23. * @author Daniele Bonini <my25mb@aol.com>
  24. * @copyrights (c) 2021, 2024, the Open Gallery's contributors
  25. */
  26. var bBurgerMenuVisible = false;
  27. var bIconsVisible = false;
  28. $(document).ready(function() {
  29. $("#Password").on("keydown",function(e){
  30. key = e.which;
  31. //alert(key);
  32. $("#userHint").val("");
  33. if (key===13) {
  34. e.preventDefault();
  35. frmHC.submit();
  36. } else {
  37. //e.preventDefault();
  38. }
  39. });
  40. $("#Password2").on("keydown",function(e){
  41. key = e.which;
  42. //alert(key);
  43. $("#userHint").val("");
  44. if (key===13) {
  45. e.preventDefault();
  46. $("#Password").val("");
  47. frmHC.submit();
  48. } else {
  49. //e.preventDefault();
  50. }
  51. });
  52. $("#MessageLine").on("keydown",function(e){
  53. key = e.which;
  54. //alert(key);
  55. if (key===13) {
  56. //e.preventDefault();
  57. //sendMessage()
  58. } else {
  59. //e.preventDefault();
  60. }
  61. });
  62. });
  63. $("#burger-menu").on("click",function(){
  64. if (!bBurgerMenuVisible) {
  65. $(".friend-header").css("display", "table");
  66. } else {
  67. $(".friend-header").css("display", "none");
  68. }
  69. bBurgerMenuVisible=!bBurgerMenuVisible;
  70. });
  71. function hideBurgerMenu() {
  72. $(".friend-header").css("display", "none");
  73. bBurgerMenuVisible=false;
  74. }
  75. function changeChat(user) {
  76. $("#userHint").val(user);
  77. frmHC.submit();
  78. }
  79. $("#pop-icons").on("click", function() {
  80. if (!bIconsVisible) {
  81. tollerance = 450 / window.scrollY;
  82. msgLineRect = document.getElementById("MessageLine").getBoundingClientRect();
  83. //mytop = parseInt(msgLineRect.top - window.scrollY - 350 - tollerance) + "px";
  84. left = parseInt(msgLineRect.left + msgLineRect.width - 260) + "px";
  85. if (window.innerWidth < 650) {
  86. left = parseInt(msgLineRect.left + msgLineRect.width - 0) + "px";
  87. }
  88. //$("#emoticons").css("top", mytop);
  89. $("#emoticons").css("left", left);
  90. $("#emoticons").css("display", "inline");
  91. $("#emoticons").css("z-index", "99999");
  92. } else {
  93. $("#emoticons").css("display", "none");
  94. }
  95. bIconsVisible = !bIconsVisible;
  96. });
  97. function hideIcons() {
  98. $("#emoticons").css("display", "none");
  99. IconsVisible = false;
  100. }
  101. function insertEmotIcon(icon) {
  102. $("#MessageLine").val($("#MessageLine").val() + icon);
  103. }
  104. function closeSplash() {
  105. $("#hideSplash").val("1");
  106. $("#splash").hide();
  107. }
  108. function refresh() {
  109. $("#CommandLine").val("refreshbrd");
  110. frmHC.submit();
  111. }
  112. function closePlayer() {
  113. refresh();
  114. }
  115. function sendMessage() {
  116. //if ($("#MessageLine").val()==="") {
  117. // alert("First, write your message!");
  118. // return;
  119. //}
  120. $("#CommandLine").val("sendmsg");
  121. frmHC.submit();
  122. }
  123. function deletePic(pic) {
  124. $("#CommandLine").val("delpic " + pic);
  125. frmHC.submit();
  126. }
  127. function deleteMsg(msg) {
  128. $("#CommandLine").val("delmsg " + msg);
  129. frmHC.submit();
  130. }
  131. function openPic(pic) {
  132. $("#CommandLine").val("openpic " + pic);
  133. frmHC.submit();
  134. }
  135. function checkServer() {
  136. $.ajax({
  137. method: "POST",
  138. async: false,
  139. url: "/pushmessages",
  140. dataType: "json",
  141. jsonp: false,
  142. data: {
  143. userHint: $("input#userHint").val()
  144. },
  145. success: function( data ) {
  146. // Handle 'no match' indicated by [ "" ] response
  147. //response( data.length === 1 && data[0].length === 0 ? [] : data );
  148. if (data.length === 2 && data[0] === 200) {
  149. if ($("input#last_message").val() !== data[1]) {
  150. $("#myPlayButton").click();
  151. setTimeout("refresh()", 12000);
  152. }
  153. }
  154. },
  155. error: function (responseData, textStatus, errorThrown) {
  156. alert('POST failed: ' + errorThrown);
  157. }
  158. });
  159. }
  160. function setContentPos() {
  161. if (window.innerWidth<650) {
  162. $("#ahome").attr("href","/");
  163. $("#agithub").css("display","none");
  164. $("#afeedback").css("display","none");
  165. $("#asupport").css("display","none");
  166. $("#pwd2").css("display","inline");
  167. $("#sidebar").css("display","none");
  168. $("#burger-menu").css("display","inline");
  169. $("#messagebar").css("width","100%");
  170. $("#logo-hmm").css("display","none");
  171. } else {
  172. $("#ahome").attr("href","http://homomm.org");
  173. $("#agithub").css("display","inline");
  174. $("#afeedback").css("display","inline");
  175. $("#asupport").css("display","inline");
  176. $("#pwd2").css("display","none");
  177. $("#sidebar").css("display","inline");
  178. $("#burger-menu").css("display","none");
  179. $("#messagebar").css("width","75%");
  180. $("#logo-hmm").css("display","inline");
  181. }
  182. hideBurgerMenu();
  183. hideIcons();
  184. if (window.innerWidth<900) {
  185. $("#MessageL").css("width","97%");
  186. $("#MessageK").css("width","89%");
  187. //$("#del-attach").css("top","-42px");
  188. } else {
  189. $("#MessageL").css("width","100%");
  190. $("#MessageK").css("width","93%");
  191. //$("#del-attach").css("top","-34px");
  192. }
  193. if (window.innerWidth<650) {
  194. $("#MessageL").css("width", parseInt(window.innerWidth-65) + "px");
  195. } else {
  196. consoleRect=document.getElementById("Console").getBoundingClientRect();
  197. $("#MessageL").css("width", parseInt(consoleRect.width-33) + "px");
  198. }
  199. newConsoleHeight = parseInt(window.innerHeight-250);
  200. if (newConsoleHeight>288) {
  201. $("#Console").css("height", newConsoleHeight + "px");
  202. }
  203. //$("#Messagep").css("top", (newConsoleHeight - 433) + "px");
  204. msgKrect=document.getElementById("MessageK").getBoundingClientRect();
  205. msgLineRect=document.getElementById("MessageLine").getBoundingClientRect();
  206. $("#MessageS").css("height",parseInt(msgLineRect.height));
  207. $("#MessageS").css("max-height",parseInt(msgLineRect.height));
  208. $("#MessageLine").css("width", parseInt(msgKrect.width - 115) + "px");
  209. window.scroll(0, 0);
  210. $(document.body).css("overflow-y", "hidden");
  211. }
  212. function setFooterPos() {
  213. //if (document.getElementById("footerCont")) {
  214. //if ($("#Password").val() === "") {
  215. // tollerance = 48;
  216. //} else {
  217. tollerance = 15;
  218. //}
  219. if (window.innerWidth<450) {
  220. $(".no-sm").css("display", "none");
  221. } else {
  222. $(".no-sm").css("display", "inline");
  223. }
  224. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  225. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance ) + "px");
  226. //}
  227. }
  228. function showEncodedPassword() {
  229. if ($("#Password").val() === "") {
  230. $("#Password").addClass("emptyfield");
  231. return;
  232. }
  233. if ($("#Salt").val() === "") {
  234. $("#Salt").addClass("emptyfield");
  235. return;
  236. }
  237. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  238. msg = "Please set your hash in the config file with this value:";
  239. alert(msg + "\n\n" + passw);
  240. }
  241. $("input#files").on("change", function(e) {
  242. if (!document.getElementById("files").files) {
  243. $("#del-attach").css("display", "none");
  244. } else {
  245. $("#del-attach").css("display", "inline");
  246. }
  247. //frmHC.submit();
  248. });
  249. function clearUpload() {
  250. $("#upload-cont").html("<input id='files' name='files[]' type='file' accept='.gif,.png,.jpg,.jpeg' style='visibility: hidden;' multiple>");
  251. $("#del-attach").css("display", "none");
  252. }
  253. $("#Password").on("keydown", function(e){
  254. $("#Password").removeClass("emptyfield");
  255. });
  256. $("#Salt").on("keydown", function(e){
  257. $("#Salt").removeClass("emptyfield");
  258. });
  259. window.addEventListener("load", function() {
  260. if ($("#frmHC").css("display")==="none") {
  261. setTimeout("setContentPos()", 5200);
  262. setTimeout("setFooterPos()", 5300);
  263. } else {
  264. setTimeout("setContentPos()", 1000);
  265. setTimeout("setFooterPos()", 3000);
  266. }
  267. }, true);
  268. window.addEventListener("resize", function() {
  269. if ($("#frmHC").css("display")==="none") {
  270. setTimeout("setContentPos()", 5200);
  271. setTimeout("setFooterPos()", 5300);
  272. } else {
  273. setTimeout("setContentPos()", 1000);
  274. setTimeout("setFooterPos()", 3000);
  275. }
  276. }, true);