page.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. var bodyContentElementID = document.getElementById("body_cont");
  2. var loadingBarElementID = document.getElementById("loadingbar");
  3. function changeCurrentPage(fileName, extraid, a = -1)
  4. {
  5. event.preventDefault();
  6. window.stop();
  7. bodyContentElementID.innerHTML = "";
  8. const tempBodyElementID = $("#body_cont");
  9. tempBodyElementID.stop();
  10. console.log(a);
  11. if(a != -1)
  12. {
  13. const url = `/panel/${fileName}/${extraid}`;
  14. window.history.pushState(null, null, url);
  15. switch(a)
  16. {
  17. case 1:
  18. sendXHR
  19. ({
  20. type: "GET",
  21. url: "./modules/template/player/profile.php?test=" + extraid,
  22. callback: function()
  23. {
  24. console.log("newXHR readyState:"+newXHR.readyState)
  25. console.log("newXHR status"+newXHR.status)
  26. if(newXHR.readyState == 4 && newXHR.status == 200)
  27. {
  28. bodyContentElementID.innerHTML = newXHR.response;
  29. loadingBarElementID.classList.remove("active");
  30. }
  31. }
  32. });
  33. break;
  34. case 2:
  35. sendXHR
  36. ({
  37. type: "GET",
  38. url: "./modules/template/player/change_skin.php?test=" + extraid,
  39. callback: function()
  40. {
  41. if(newXHR.readyState == 4 && newXHR.status == 200)
  42. {
  43. tempBodyElementID.html(newXHR.response);
  44. loadingBarElementID.classList.remove("active");
  45. }
  46. }
  47. });
  48. break;
  49. case 3:
  50. sendXHR
  51. ({
  52. type: "GET",
  53. url: "./modules/template/player/inbox.php?test=" + extraid,
  54. callback: function()
  55. {
  56. if(newXHR.readyState == 4 && newXHR.status == 200)
  57. {
  58. bodyContentElementID.innerHTML = newXHR.response;
  59. loadingBarElementID.classList.remove("active");
  60. }
  61. }
  62. });
  63. break;
  64. case 4:
  65. sendXHR
  66. ({
  67. type: "GET",
  68. url: "./modules/template/player/applications.php?test=" + extraid,
  69. callback: function()
  70. {
  71. if(newXHR.readyState == 4 && newXHR.status == 200)
  72. {
  73. bodyContentElementID.innerHTML = newXHR.response;
  74. loadingBarElementID.classList.remove("active");
  75. }
  76. }
  77. });
  78. break;
  79. case 5:
  80. sendXHR
  81. ({
  82. type: "GET",
  83. url: "./modules/template/player/application.php?test=" + extraid,
  84. callback: function()
  85. {
  86. if(newXHR.readyState == 4 && newXHR.status == 200)
  87. {
  88. bodyContentElementID.innerHTML = newXHR.response;
  89. loadingBarElementID.classList.remove("active");
  90. }
  91. }
  92. });
  93. break;
  94. case 6:
  95. sendXHR
  96. ({
  97. type: "GET",
  98. url: "./modules/template/player/vehicle.php?test=" + extraid,
  99. callback: function()
  100. {
  101. if(newXHR.readyState == 4 && newXHR.status == 200)
  102. {
  103. bodyContentElementID.innerHTML = newXHR.response;
  104. loadingBarElementID.classList.remove("active");
  105. }
  106. }
  107. });
  108. break;
  109. case 7:
  110. sendXHR
  111. ({
  112. type: "GET",
  113. url: "./modules/template/player/faction.php?test=" + extraid,
  114. callback: function()
  115. {
  116. if(newXHR.readyState == 4 && newXHR.status == 200)
  117. {
  118. bodyContentElementID.innerHTML = newXHR.response;
  119. loadingBarElementID.classList.remove("active");
  120. }
  121. }
  122. });
  123. break;
  124. case 8:
  125. sendXHR
  126. ({
  127. type: "GET",
  128. url: "./modules/template/player/friends.php?test=" + extraid,
  129. callback: function()
  130. {
  131. if(newXHR.readyState == 4 && newXHR.status == 200)
  132. {
  133. tempBodyElementID.html(newXHR.response);
  134. loadingBarElementID.classList.remove("active");
  135. }
  136. }
  137. });
  138. break;
  139. case 9:
  140. sendXHR
  141. ({
  142. type: "GET",
  143. url: "./modules/template/player/gov.php?test=" + extraid,
  144. callback: function()
  145. {
  146. if(newXHR.readyState == 4 && newXHR.status == 200)
  147. {
  148. tempBodyElementID.html(newXHR.response);
  149. loadingBarElementID.classList.remove("active");
  150. }
  151. }
  152. });
  153. break;
  154. case 10:
  155. sendXHR
  156. ({
  157. type: "GET",
  158. url: "./modules/template/player/property.php?test=" + extraid,
  159. callback: function()
  160. {
  161. if(newXHR.readyState == 4 && newXHR.status == 200)
  162. {
  163. bodyContentElementID.innerHTML = newXHR.response;
  164. loadingBarElementID.classList.remove("active");
  165. }
  166. }
  167. });
  168. break;
  169. }
  170. }
  171. else
  172. {
  173. const oldMenu = document.getElementsByClassName("selected");
  174. if(oldMenu.length > 0)
  175. {
  176. oldMenu[0].classList.remove("selected");
  177. }
  178. const newMenu = document.getElementById(fileName);
  179. if(newMenu)
  180. {
  181. newMenu.classList.add("selected");
  182. }
  183. window.history.pushState(null, null, extraid);
  184. loadingBarElementID.classList.add("active");
  185. sendXHR
  186. ({
  187. type: "GET",
  188. url: "./modules/template/player/" + fileName + ".php",
  189. callback: function()
  190. {
  191. if(newXHR.readyState == 4 && newXHR.status == 200)
  192. {
  193. tempBodyElementID.html(newXHR.response);
  194. loadingBarElementID.classList.remove("active");
  195. }
  196. }
  197. });
  198. }
  199. }
  200. function sendXHR(options)
  201. {
  202. // (Modern browsers) OR (Internet Explorer 5 or 6).
  203. newXHR = new XMLHttpRequest() || new ActiveXObject("Microsoft.XMLHTTP");
  204. if(options.sendJSON === true)
  205. {
  206. options.contentType = "application/json; charset=utf-8";
  207. options.data = JSON.stringify(options.data);
  208. }
  209. else
  210. {
  211. options.contentType = "application/x-www-form-urlencoded";
  212. }
  213. newXHR.open(options.type, options.url, options.async || true);
  214. newXHR.setRequestHeader("Content-Type", options.contentType);
  215. newXHR.send((options.type == "POST") ? options.data : null);
  216. newXHR.onreadystatechange = options.callback; // Will execute a function when the HTTP request state changes.
  217. return newXHR;
  218. }
  219. function changeCurrentPage_A(fileName, extraid, a = -1)
  220. {
  221. event.preventDefault();
  222. window.stop();
  223. bodyContentElementID.innerHTML = "";
  224. const tempBodyElementID = $("#body_cont");
  225. tempBodyElementID.stop();
  226. if(a != -1)
  227. {
  228. const url = `/admin/${fileName}/${extraid}`;
  229. window.history.pushState(null, null, url);
  230. switch(a)
  231. {
  232. case 1:
  233. sendXHR
  234. ({
  235. type: "GET",
  236. url: "./modules/template/admin/application.php?app_id=" + extraid,
  237. callback: function()
  238. {
  239. if(newXHR.readyState == 4 && newXHR.status == 200)
  240. {
  241. tempBodyElementID.html(newXHR.response);
  242. loadingBarElementID.classList.remove("active");
  243. }
  244. }
  245. });
  246. break;
  247. case 2:
  248. sendXHR
  249. ({
  250. type: "GET",
  251. url: "./modules/template/admin/players.php?app_id=" + extraid,
  252. callback: function()
  253. {
  254. if(newXHR.readyState == 4 && newXHR.status == 200)
  255. {
  256. tempBodyElementID.html(newXHR.response);
  257. loadingBarElementID.classList.remove("active");
  258. }
  259. }
  260. });
  261. break;
  262. }
  263. }
  264. else
  265. {
  266. const oldMenu = document.getElementsByClassName("selected");
  267. if(oldMenu.length > 0)
  268. {
  269. oldMenu[0].classList.remove("selected");
  270. }
  271. const newMenu = document.getElementById(fileName);
  272. if(newMenu)
  273. {
  274. newMenu.classList.add("selected");
  275. }
  276. window.history.pushState(null, null, extraid);
  277. loadingBarElementID.classList.add("active");
  278. sendXHR
  279. ({
  280. type: "GET",
  281. url: "./modules/template/admin/" + fileName + ".php",
  282. callback: function()
  283. {
  284. if(newXHR.readyState == 4 && newXHR.status == 200)
  285. {
  286. tempBodyElementID.html(newXHR.response);
  287. loadingBarElementID.classList.remove("active");
  288. }
  289. }
  290. });
  291. }
  292. }
  293. $(window).bind("popstate", function(e)
  294. {
  295. e = e.originalEvent.state;
  296. e ? alert(e.lasturl) : alert("Use the menu to navigate.")
  297. });