home.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. timeForReload = false;
  136. document.getElementById("mybeep").addEventListener("ended", function() {
  137. if (timeForReload) {
  138. refresh();
  139. }
  140. timeForReload = false;
  141. }, true);
  142. function checkServer() {
  143. $.ajax({
  144. method: "POST",
  145. async: false,
  146. url: "/pushmessages",
  147. dataType: "json",
  148. jsonp: false,
  149. data: {
  150. userHint: $("input#userHint").val()
  151. },
  152. success: function( data ) {
  153. // Handle 'no match' indicated by [ "" ] response
  154. //response( data.length === 1 && data[0].length === 0 ? [] : data );
  155. if (data.length === 2 && data[0] === 200) {
  156. if ($("input#last_message").val() !== data[1]) {
  157. $("#myPlayButton").click();
  158. timeForReload = true;
  159. }
  160. }
  161. },
  162. error: function (responseData, textStatus, errorThrown) {
  163. //alert('POST failed: ' + errorThrown);
  164. }
  165. });
  166. }
  167. function readyToType() {
  168. maxY = document.getElementById("Console").scrollHeight;
  169. document.getElementById("Console").scrollTop=maxY;
  170. }
  171. function setContentPos() {
  172. if (window.innerWidth<650) {
  173. $("#ahome").attr("href","/");
  174. $("#agithub").css("display","none");
  175. $("#afeedback").css("display","none");
  176. $("#asupport").css("display","none");
  177. $("#pwd2").css("display","inline");
  178. $("#sidebar").css("display","none");
  179. $("#burger-menu").css("display","inline");
  180. $("#messagebar").css("width","100%");
  181. $("#logo-hmm").css("display","none");
  182. } else {
  183. $("#ahome").attr("href","http://homomm.org");
  184. $("#agithub").css("display","inline");
  185. $("#afeedback").css("display","inline");
  186. $("#asupport").css("display","inline");
  187. $("#pwd2").css("display","none");
  188. $("#sidebar").css("display","inline");
  189. $("#burger-menu").css("display","none");
  190. $("#messagebar").css("width","75%");
  191. $("#logo-hmm").css("display","inline");
  192. }
  193. hideBurgerMenu();
  194. hideIcons();
  195. if (window.innerWidth<900) {
  196. $("#MessageL").css("width","97%");
  197. $("#MessageK").css("width","89%");
  198. //$("#del-attach").css("top","-42px");
  199. } else {
  200. $("#MessageL").css("width","100%");
  201. $("#MessageK").css("width","93%");
  202. //$("#del-attach").css("top","-34px");
  203. }
  204. if (window.innerWidth<650) {
  205. $("#MessageL").css("width", parseInt(window.innerWidth-65) + "px");
  206. } else {
  207. consoleRect=document.getElementById("Console").getBoundingClientRect();
  208. $("#MessageL").css("width", parseInt(consoleRect.width-33) + "px");
  209. }
  210. newConsoleHeight = parseInt(window.innerHeight-250);
  211. if (newConsoleHeight>288) {
  212. $("#Console").css("height", newConsoleHeight + "px");
  213. }
  214. //$("#Messagep").css("top", (newConsoleHeight - 433) + "px");
  215. msgKrect=document.getElementById("MessageK").getBoundingClientRect();
  216. msgLineRect=document.getElementById("MessageLine").getBoundingClientRect();
  217. $("#MessageS").css("height",parseInt(msgLineRect.height));
  218. $("#MessageS").css("max-height",parseInt(msgLineRect.height));
  219. $("#MessageLine").css("width", parseInt(msgKrect.width - 115) + "px");
  220. window.scroll(0, 0);
  221. $(document.body).css("overflow-y", "hidden");
  222. }
  223. function setFooterPos() {
  224. //if (document.getElementById("footerCont")) {
  225. //if ($("#Password").val() === "") {
  226. // tollerance = 48;
  227. //} else {
  228. tollerance = 15;
  229. //}
  230. if (window.innerWidth<450) {
  231. $(".no-sm").css("display", "none");
  232. } else {
  233. $(".no-sm").css("display", "inline");
  234. }
  235. $("#footerCont").css("top", parseInt( window.innerHeight - $("#footerCont").height() - tollerance ) + "px");
  236. $("#footer").css("top", parseInt( window.innerHeight - $("#footer").height() - tollerance ) + "px");
  237. //}
  238. }
  239. function showEncodedPassword() {
  240. if ($("#Password").val() === "") {
  241. $("#Password").addClass("emptyfield");
  242. return;
  243. }
  244. if ($("#Salt").val() === "") {
  245. $("#Salt").addClass("emptyfield");
  246. return;
  247. }
  248. passw = encryptSha2( $("#Password").val() + $("#Salt").val());
  249. msg = "Please set your hash in the config file with this value:";
  250. alert(msg + "\n\n" + passw);
  251. }
  252. $("input#files").on("change", function(e) {
  253. if (!document.getElementById("files").files) {
  254. $("#del-attach").css("display", "none");
  255. } else {
  256. $("#del-attach").css("display", "inline");
  257. }
  258. //frmHC.submit();
  259. });
  260. function clearUpload() {
  261. $("#upload-cont").html("<input id='files' name='files[]' type='file' accept='.gif,.png,.jpg,.jpeg' style='visibility: hidden;' multiple>");
  262. $("#del-attach").css("display", "none");
  263. }
  264. $("#Password").on("keydown", function(e){
  265. $("#Password").removeClass("emptyfield");
  266. });
  267. $("#Salt").on("keydown", function(e){
  268. $("#Salt").removeClass("emptyfield");
  269. });
  270. window.addEventListener("load", function() {
  271. if ($("#frmHC").css("display")==="none") {
  272. setTimeout("setContentPos()", 5200);
  273. setTimeout("setFooterPos()", 5300);
  274. setTimeout("readyToType()", 5400);
  275. } else {
  276. setTimeout("setContentPos()", 1000);
  277. setTimeout("setFooterPos()", 2000);
  278. setTimeout("readyToType()", 2100);
  279. }
  280. }, true);
  281. window.addEventListener("resize", function() {
  282. if ($("#frmHC").css("display")==="none") {
  283. setTimeout("setContentPos()", 5200);
  284. setTimeout("setFooterPos()", 5300);
  285. setTimeout("readyToType()", 5400);
  286. } else {
  287. setTimeout("setContentPos()", 1000);
  288. setTimeout("setFooterPos()", 2000);
  289. setTimeout("readyToType()", 2100);
  290. }
  291. }, true);