home.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. $("#chatHint").val("");
  33. if (key===13) {
  34. e.preventDefault();
  35. frmHC.submit();
  36. } else {
  37. $("#Password2").val($(this).val());
  38. //e.preventDefault();
  39. }
  40. });
  41. $("#Password2").on("keydown",function(e){
  42. key = e.which;
  43. //alert(key);
  44. $("#chatHint").val("");
  45. if (key===13) {
  46. e.preventDefault();
  47. $("#Password").val("");
  48. frmHC.submit();
  49. } else {
  50. //e.preventDefault();
  51. }
  52. });
  53. $("#MessageLine").on("keydown",function(e){
  54. key = e.which;
  55. //alert(key);
  56. if (key===13) {
  57. //e.preventDefault();
  58. //sendMessage()
  59. } else {
  60. //e.preventDefault();
  61. }
  62. });
  63. });
  64. $("#burger-menu").on("click",function(){
  65. if (!bBurgerMenuVisible) {
  66. $(".friend-header").css("display", "table");
  67. } else {
  68. $(".friend-header").css("display", "none");
  69. }
  70. bBurgerMenuVisible=!bBurgerMenuVisible;
  71. });
  72. function hideBurgerMenu() {
  73. $(".friend-header").css("display", "none");
  74. bBurgerMenuVisible=false;
  75. }
  76. function changeChat(user) {
  77. $("#chatHint").val(user);
  78. frmHC.submit();
  79. }
  80. $("#pop-icons").on("click", function() {
  81. if (!bIconsVisible) {
  82. tollerance = 450 / window.scrollY;
  83. msgLineRect = document.getElementById("MessageLine").getBoundingClientRect();
  84. //mytop = parseInt(msgLineRect.top - window.scrollY - 350 - tollerance) + "px";
  85. left = parseInt(msgLineRect.left + msgLineRect.width - 260) + "px";
  86. if (window.innerWidth < 650) {
  87. left = parseInt(msgLineRect.left + msgLineRect.width - 0) + "px";
  88. }
  89. //$("#emoticons").css("top", mytop);
  90. $("#emoticons").css("left", left);
  91. $("#emoticons").css("display", "inline");
  92. $("#emoticons").css("z-index", "99999");
  93. } else {
  94. $("#emoticons").css("display", "none");
  95. }
  96. bIconsVisible = !bIconsVisible;
  97. });
  98. function hideIcons() {
  99. $("#emoticons").css("display", "none");
  100. IconsVisible = false;
  101. }
  102. function insertEmotIcon(icon) {
  103. $("#MessageLine").val($("#MessageLine").val() + icon);
  104. }
  105. function closeSplash() {
  106. $("#hideSplash").val("1");
  107. $("#splash").hide();
  108. }
  109. function refresh() {
  110. $("#CommandLine").val("refreshbrd");
  111. frmHC.submit();
  112. }
  113. function closePlayer() {
  114. refresh();
  115. }
  116. function sendMessage() {
  117. //if ($("#MessageLine").val()==="") {
  118. // alert("First, write your message!");
  119. // return;
  120. //}
  121. $("#CommandLine").val("sendmsg");
  122. frmHC.submit();
  123. }
  124. function deletePic(pic) {
  125. $("#CommandLine").val("delpic " + pic);
  126. frmHC.submit();
  127. }
  128. function deleteMsg(msg) {
  129. $("#CommandLine").val("delmsg " + msg);
  130. frmHC.submit();
  131. }
  132. function openPic(pic) {
  133. $("#CommandLine").val("openpic " + pic);
  134. frmHC.submit();
  135. }
  136. timeForReload = false;
  137. document.getElementById("mybeep").addEventListener("ended", function() {
  138. if (timeForReload) {
  139. refresh();
  140. }
  141. timeForReload = false;
  142. }, true);
  143. function checkServer() {
  144. $.ajax({
  145. method: "POST",
  146. async: false,
  147. url: "/pushmessages",
  148. dataType: "json",
  149. jsonp: false,
  150. data: {
  151. chatHint: $("input#chatHint").val()
  152. },
  153. success: function( data ) {
  154. // Handle 'no match' indicated by [ "" ] response
  155. //response( data.length === 1 && data[0].length === 0 ? [] : data );
  156. if (data.length === 2 && data[0] === 200) {
  157. if ($("input#last_message").val() !== data[1]) {
  158. if ($("#MessageLine").val()==="") {
  159. $("#myPlayButton").click();
  160. timeForReload = true;
  161. }
  162. }
  163. }
  164. },
  165. error: function (responseData, textStatus, errorThrown) {
  166. //alert('POST failed: ' + errorThrown);
  167. }
  168. });
  169. }
  170. function readyToType() {
  171. maxY = document.getElementById("Console").scrollHeight;
  172. document.getElementById("Console").scrollTop=maxY;
  173. }
  174. function setContentPos() {
  175. if (window.innerWidth<650) {
  176. $("#ahome").attr("href","/");
  177. $("#agithub").css("display","none");
  178. $("#afeedback").css("display","none");
  179. $("#asupport").css("display","none");
  180. $("#pwd2").css("display","inline");
  181. $("#sidebar").css("display","none");
  182. $("#burger-menu").css("display","inline");
  183. $("#messagebar").css("width","100%");
  184. $("#logo-hmm").css("display","none");
  185. } else {
  186. $("#ahome").attr("href","http://homomm.org");
  187. $("#agithub").css("display","inline");
  188. $("#afeedback").css("display","inline");
  189. $("#asupport").css("display","inline");
  190. $("#pwd2").css("display","none");
  191. $("#sidebar").css("display","inline");
  192. $("#burger-menu").css("display","none");
  193. $("#messagebar").css("width","75%");
  194. $("#logo-hmm").css("display","inline");
  195. }
  196. hideBurgerMenu();
  197. hideIcons();
  198. if (window.innerWidth<900) {
  199. $("#MessageL").css("width","97%");
  200. $("#MessageK").css("width","89%");
  201. //$("#del-attach").css("top","-42px");
  202. } else {
  203. $("#MessageL").css("width","100%");
  204. $("#MessageK").css("width","93%");
  205. //$("#del-attach").css("top","-34px");
  206. }
  207. if (window.innerWidth<650) {
  208. $("#MessageL").css("width", parseInt(window.innerWidth-65) + "px");
  209. } else {
  210. consoleRect=document.getElementById("Console").getBoundingClientRect();
  211. $("#MessageL").css("width", parseInt(consoleRect.width-33) + "px");
  212. }
  213. newConsoleHeight = parseInt(window.innerHeight-250);
  214. if (newConsoleHeight>288) {
  215. $("#Console").css("height", newConsoleHeight + "px");
  216. }
  217. //$("#Messagep").css("top", (newConsoleHeight - 433) + "px");
  218. msgKrect=document.getElementById("MessageK").getBoundingClientRect();
  219. msgLineRect=document.getElementById("MessageLine").getBoundingClientRect();
  220. $("#MessageS").css("height",parseInt(msgLineRect.height));
  221. $("#MessageS").css("max-height",parseInt(msgLineRect.height));
  222. $("#MessageLine").css("width", parseInt(msgKrect.width - 115) + "px");
  223. window.scroll(0, 0);
  224. $(document.body).css("overflow-y", "hidden");
  225. }
  226. function setFooterPos() {
  227. //if (document.getElementById("footerCont")) {
  228. //if ($("#Password").val() === "") {
  229. // tollerance = 48;
  230. //} else {
  231. tollerance = 15;
  232. //}
  233. if (window.innerWidth<450) {
  234. $(".no-sm").css("display", "none");
  235. } else {
  236. $(".no-sm").css("display", "inline");
  237. }
  238. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  239. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance ) + "px");
  240. //}
  241. }
  242. function showEncodedPassword() {
  243. if ($("#Password").val() === "") {
  244. $("#Password").addClass("emptyfield");
  245. return;
  246. }
  247. if ($("#Salt").val() === "") {
  248. $("#Salt").addClass("emptyfield");
  249. return;
  250. }
  251. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  252. msg = "Please set your hash in the config file with this value:";
  253. alert(msg + "\n\n" + passw);
  254. }
  255. $("input#files").on("change", function(e) {
  256. if (!document.getElementById("files").files) {
  257. $("#del-attach").css("display", "none");
  258. } else {
  259. $("#del-attach").css("display", "inline");
  260. }
  261. //frmHC.submit();
  262. });
  263. function clearUpload() {
  264. $("#upload-cont").html("<input id='files' name='files[]' type='file' accept='.gif,.png,.jpg,.jpeg' style='visibility: hidden;' multiple>");
  265. $("#del-attach").css("display", "none");
  266. }
  267. $("#Password").on("keydown", function(e){
  268. $("#Password").removeClass("emptyfield");
  269. });
  270. $("#Salt").on("keydown", function(e){
  271. $("#Salt").removeClass("emptyfield");
  272. });
  273. window.addEventListener("load", function() {
  274. if ($("#frmHC").css("display")==="none") {
  275. setTimeout("setContentPos()", 5200);
  276. setTimeout("setFooterPos()", 5300);
  277. setTimeout("readyToType()", 5400);
  278. } else {
  279. setTimeout("setContentPos()", 1000);
  280. setTimeout("setFooterPos()", 2000);
  281. setTimeout("readyToType()", 2100);
  282. }
  283. }, true);
  284. window.addEventListener("resize", function() {
  285. if ($("#frmHC").css("display")==="none") {
  286. setTimeout("setContentPos()", 5200);
  287. setTimeout("setFooterPos()", 5300);
  288. setTimeout("readyToType()", 5400);
  289. } else {
  290. setTimeout("setContentPos()", 1000);
  291. setTimeout("setFooterPos()", 2000);
  292. setTimeout("readyToType()", 2100);
  293. }
  294. }, true);