main.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. $(".navigator-action").on("click", function () {
  2. let url = $(this).attr("action");
  3. console.log("URL: " + url);
  4. window.location.href = url;
  5. var elems = document.querySelectorAll(".navigator-action");
  6. [].forEach.call(elems, function (el) {
  7. el.classList.remove("active");
  8. });
  9. $(this).addClass("active");
  10. })
  11. // for avatar
  12. //$('#user_avatar').change(function (e) {
  13. // e.preventDefault();
  14. // console.log("user_avatar");
  15. // var fileLoad = document.getElementById("user_avatar").files[0];
  16. // var fileExt = fileLoad.name.match(/(.*)\??/i).shift().replace(/\?.*/, '').split('.').pop();
  17. // if (fileExt != "png" && fileExt != "jpg" && fileExt != "jpeg" && fileExt != "PNG" && fileExt != "JPG" && fileExt != "JPEG") {
  18. // toastr.error("Only PNG or JPG type are accepted");
  19. // } else if (fileLoad.size >= 5 * 1024 * 1024 || fileLoad.size < 10) {
  20. // toastr.error("Please check your image size");
  21. // } else {
  22. // var oFReader = new FileReader();
  23. // oFReader.readAsDataURL(fileLoad);
  24. // oFReader.onload = function (oFREvent) {
  25. // document.getElementById("image-user").src = oFREvent.target.result;
  26. // };
  27. // var control = $("#user_avatar");
  28. // control.replaceWith(control = control.clone(true));
  29. // }
  30. //});
  31. // Get the input field
  32. var input = document.getElementById("search");
  33. if (input != null) {
  34. // Execute a function when the user releases a key on the keyboard
  35. input.addEventListener("keyup", function (event) {
  36. // Number 13 is the "Enter" key on the keyboard
  37. if (event.keyCode === 13) {
  38. // Cancel the default action, if needed
  39. event.preventDefault();
  40. // Trigger the button element with a click
  41. let keySearch = $("#search").val();
  42. let subDomain = $("#subDomain").val();
  43. window.location.href = subDomain + '/Home/Search?key=' + keySearch;
  44. }
  45. });
  46. }
  47. // When the user scrolls the page, execute myFunction
  48. window.onscroll = function () { myFunction() };
  49. // Get the header
  50. var header = document.getElementById("myHeader");
  51. var sticky;
  52. if (header != null) {
  53. sticky = header.offsetTop;
  54. }
  55. // Get the offset position of the navbar
  56. var topToShow = 200;
  57. // Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
  58. function myFunction() {
  59. let checkHomeHide = $("#myHeader").hasClass("home");
  60. let checkGameHide = $("#myHeader").hasClass("game");
  61. if (header != null) {
  62. if (checkHomeHide) {
  63. if (window.pageYOffset > topToShow) {
  64. header.classList.add("sticky");
  65. header.classList.remove("hide");
  66. } else {
  67. header.classList.remove("sticky");
  68. header.classList.add("hide");
  69. }
  70. }
  71. else if (checkGameHide) {
  72. if (window.pageYOffset > topToShow) {
  73. header.classList.add("sticky");
  74. header.classList.remove("hide");
  75. } else {
  76. header.classList.remove("sticky");
  77. header.classList.add("hide");
  78. }
  79. }
  80. else {
  81. if (window.pageYOffset > sticky) {
  82. header.classList.add("sticky");
  83. } else {
  84. header.classList.remove("sticky");
  85. }
  86. }
  87. }
  88. }
  89. // for avatar
  90. $('#user_avatar').change(function (e) {
  91. e.preventDefault();
  92. //console.log("user_avatar");
  93. var fileLoad = document.getElementById("user_avatar").files[0];
  94. var fileExt = fileLoad.name.match(/(.*)\??/i).shift().replace(/\?.*/, '').split('.').pop();
  95. if (fileExt != "png" && fileExt != "jpg" && fileExt != "jpeg") {
  96. $.ajax({
  97. type: "POST",
  98. url: "/Partial/Response",
  99. data: {
  100. "message": "Only PNG or JPG type are accepted",
  101. },
  102. success: function (data) {
  103. $('#informModel').html(data);
  104. $('#myInform').modal({ "backdrop": "static", keyboard: true });
  105. $('#myInform').modal('show');
  106. },
  107. failure: function (data) {
  108. console.log(data);
  109. },
  110. error: function (data) {
  111. console.log(data);
  112. }
  113. });
  114. } else if (fileLoad.size >= 5 * 1024 * 1024 || fileLoad.size < 10) {
  115. $.ajax({
  116. type: "POST",
  117. url: "/Partial/Response",
  118. data: {
  119. "message": "Please check your image size",
  120. },
  121. success: function (data) {
  122. $('#informModel').html(data);
  123. $('#myInform').modal({ "backdrop": "static", keyboard: true });
  124. $('#myInform').modal('show');
  125. },
  126. failure: function (data) {
  127. console.log(data);
  128. },
  129. error: function (data) {
  130. console.log(data);
  131. }
  132. });
  133. } else {
  134. var oFReader = new FileReader();
  135. oFReader.readAsDataURL(fileLoad);
  136. oFReader.onload = function (oFREvent) {
  137. document.getElementById("personal-picture").src = oFREvent.target.result;
  138. //$("#checkAvatar").val("1");
  139. //$("#upload_avatar").submit();
  140. var formData = new FormData();
  141. formData.append('__RequestVerificationToken', $('input[name=__RequestVerificationToken]').val());
  142. formData.append('user_avatar', fileLoad);
  143. $.ajax({
  144. type: "POST",
  145. url: "/Account/UploadAvatar",
  146. headers: {
  147. 'RequestVerificationToken': $('input[name=__RequestVerificationToken]').val(),
  148. 'Accept': 'application/json'
  149. },
  150. data: formData,
  151. processData: false,
  152. contentType: false,
  153. success: function (data) {
  154. location.reload();
  155. },
  156. failure: function (data) {
  157. console.log(data);
  158. },
  159. error: function (data) {
  160. console.log(data);
  161. }
  162. });
  163. };
  164. var control = $("#user_avatar");
  165. control.replaceWith(control = control.clone(true));
  166. }
  167. });
  168. $(".open-or-close-eye").on("click", function () {
  169. console.log("open close eye");
  170. if ($(".open-eye").hasClass("hide")) {
  171. $(".open-eye").removeClass("hide");
  172. $(".close-eye").addClass("hide");
  173. } else {
  174. $(".open-eye").addClass("hide");
  175. $(".close-eye").removeClass("hide");
  176. }
  177. })