app.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* Template Name: Landrick - Saas & Software Landing Page Template
  2. Author: Shreethemes
  3. E-mail: support@shreethemes.in
  4. Created: August 2019
  5. Version: 3.5.0
  6. Updated: July 2021
  7. File Description: Main JS file of the template
  8. */
  9. /*********************************/
  10. /* INDEX */
  11. /*================================
  12. * 01. Loader *
  13. * 02. Toggle Menus *
  14. * 03. Active Menu *
  15. * 04. Clickable Menu *
  16. * 05. Back to top *
  17. * 06. Feather icon *
  18. * 06. DD Menu *
  19. * 06. Active Sidebar Menu *
  20. * 07. Contact us *
  21. ================================*/
  22. window.addEventListener('load', fn , false )
  23. // window.onload = function loader() {
  24. function fn() {
  25. // Preloader
  26. if(document.getElementById('preloader')){
  27. setTimeout(() => {
  28. document.getElementById('preloader').style.visibility = 'hidden';
  29. document.getElementById('preloader').style.opacity = '0';
  30. }, 350);
  31. }
  32. // Menus
  33. activateMenu();
  34. }
  35. //Menu
  36. // Toggle menu
  37. function toggleMenu() {
  38. document.getElementById('isToggle').classList.toggle('open');
  39. var isOpen = document.getElementById('navigation')
  40. if (isOpen.style.display === "block") {
  41. isOpen.style.display = "none";
  42. } else {
  43. isOpen.style.display = "block";
  44. }
  45. };
  46. //Menu Active
  47. function getClosest(elem, selector) {
  48. // Element.matches() polyfill
  49. if (!Element.prototype.matches) {
  50. Element.prototype.matches =
  51. Element.prototype.matchesSelector ||
  52. Element.prototype.mozMatchesSelector ||
  53. Element.prototype.msMatchesSelector ||
  54. Element.prototype.oMatchesSelector ||
  55. Element.prototype.webkitMatchesSelector ||
  56. function (s) {
  57. var matches = (this.document || this.ownerDocument).querySelectorAll(s),
  58. i = matches.length;
  59. while (--i >= 0 && matches.item(i) !== this) { }
  60. return i > -1;
  61. };
  62. }
  63. // Get the closest matching element
  64. for (; elem && elem !== document; elem = elem.parentNode) {
  65. if (elem.matches(selector)) return elem;
  66. }
  67. return null;
  68. };
  69. function activateMenu() {
  70. var menuItems = document.getElementsByClassName("sub-menu-item");
  71. if (menuItems) {
  72. var matchingMenuItem = null;
  73. for (var idx = 0; idx < menuItems.length; idx++) {
  74. if (menuItems[idx].href === window.location.href) {
  75. matchingMenuItem = menuItems[idx];
  76. }
  77. }
  78. if (matchingMenuItem) {
  79. matchingMenuItem.classList.add('active');
  80. var immediateParent = getClosest(matchingMenuItem, 'li');
  81. if (immediateParent) {
  82. immediateParent.classList.add('active');
  83. }
  84. var parent = getClosest(matchingMenuItem, '.parent-menu-item');
  85. if (parent) {
  86. parent.classList.add('active');
  87. var parentMenuitem = parent.querySelector('.menu-item');
  88. if (parentMenuitem) {
  89. parentMenuitem.classList.add('active');
  90. }
  91. var parentOfParent = getClosest(parent, '.parent-parent-menu-item');
  92. if (parentOfParent) {
  93. parentOfParent.classList.add('active');
  94. }
  95. } else {
  96. var parentOfParent = getClosest(matchingMenuItem, '.parent-parent-menu-item');
  97. if (parentOfParent) {
  98. parentOfParent.classList.add('active');
  99. }
  100. }
  101. }
  102. }
  103. }
  104. // Clickable Menu
  105. if(document.getElementById("navigation")){
  106. var elements = document.getElementById("navigation").getElementsByTagName("a");
  107. for(var i = 0, len = elements.length; i < len; i++) {
  108. elements[i].onclick = function (elem) {
  109. if(elem.target.getAttribute("href") === "javascript:void(0)") {
  110. var submenu = elem.target.nextElementSibling.nextElementSibling;
  111. submenu.classList.toggle('open');
  112. }
  113. }
  114. }
  115. }
  116. // Menu sticky
  117. function windowScroll() {
  118. const navbar = document.getElementById("topnav");
  119. if(navbar!=null){
  120. if (
  121. document.body.scrollTop >= 50 ||
  122. document.documentElement.scrollTop >= 50
  123. ) {
  124. navbar.classList.add("nav-sticky");
  125. } else {
  126. navbar.classList.remove("nav-sticky");
  127. }
  128. }
  129. }
  130. window.addEventListener('scroll', (ev) => {
  131. ev.preventDefault();
  132. windowScroll();
  133. })
  134. // back-to-top
  135. var mybutton = document.getElementById("back-to-top");
  136. window.onscroll = function () {
  137. scrollFunction();
  138. };
  139. function scrollFunction() {
  140. if(mybutton!=null){
  141. if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
  142. mybutton.style.display = "block";
  143. } else {
  144. mybutton.style.display = "none";
  145. }
  146. }
  147. }
  148. function topFunction() {
  149. document.body.scrollTop = 0;
  150. document.documentElement.scrollTop = 0;
  151. }
  152. //ACtive Sidebar
  153. (function () {
  154. var current = location.pathname.substring(location.pathname.lastIndexOf('/') + 1);;
  155. if (current === "") return;
  156. var menuItems = document.querySelectorAll('.sidebar-nav a');
  157. for (var i = 0, len = menuItems.length; i < len; i++) {
  158. if (menuItems[i].getAttribute("href").indexOf(current) !== -1) {
  159. menuItems[i].parentElement.className += " active";
  160. }
  161. }
  162. })();
  163. //Feather icon
  164. feather.replace();
  165. // dd-menu
  166. var ddmenu = document.getElementsByClassName("dd-menu");
  167. for(var i = 0, len = ddmenu.length; i < len; i++) {
  168. ddmenu[i].onclick = function (elem) {
  169. elem.stopPropagation();
  170. }
  171. }
  172. //Tooltip
  173. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  174. var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  175. return new bootstrap.Tooltip(tooltipTriggerEl)
  176. });
  177. //small menu
  178. try {
  179. var spy = new Gumshoe('#navmenu-nav a');
  180. }catch(err) {
  181. }
  182. //********************* */
  183. /* Contact us */
  184. //********************* */
  185. try {
  186. function validateForm() {
  187. var name = document.forms["myForm"]["name"].value;
  188. var email = document.forms["myForm"]["email"].value;
  189. var subject = document.forms["myForm"]["subject"].value;
  190. var comments = document.forms["myForm"]["comments"].value;
  191. document.getElementById("error-msg").style.opacity = 0;
  192. document.getElementById('error-msg').innerHTML = "";
  193. if (name == "" || name == null) {
  194. document.getElementById('error-msg').innerHTML = "<div class='alert alert-warning error_message'>*Please enter a Name*</div>";
  195. fadeIn();
  196. return false;
  197. }
  198. if (email == "" || email == null) {
  199. document.getElementById('error-msg').innerHTML = "<div class='alert alert-warning error_message'>*Please enter a Email*</div>";
  200. fadeIn();
  201. return false;
  202. }
  203. if (subject == "" || subject == null) {
  204. document.getElementById('error-msg').innerHTML = "<div class='alert alert-warning error_message'>*Please enter a Subject*</div>";
  205. fadeIn();
  206. return false;
  207. }
  208. if (comments == "" || comments == null) {
  209. document.getElementById('error-msg').innerHTML = "<div class='alert alert-warning error_message'>*Please enter a Comments*</div>";
  210. fadeIn();
  211. return false;
  212. }
  213. var xhttp = new XMLHttpRequest();
  214. xhttp.onreadystatechange = function () {
  215. if (this.readyState == 4 && this.status == 200) {
  216. document.getElementById("simple-msg").innerHTML = this.responseText;
  217. document.forms["myForm"]["name"].value = "";
  218. document.forms["myForm"]["email"].value = "";
  219. document.forms["myForm"]["subject"].value = "";
  220. document.forms["myForm"]["comments"].value = "";
  221. }
  222. };
  223. xhttp.open("POST", "php/contact.php", true);
  224. xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  225. xhttp.send("name=" + name + "&email=" + email + "&subject=" + subject + "&comments=" + comments);
  226. return false;
  227. }
  228. function fadeIn() {
  229. var fade = document.getElementById("error-msg");
  230. var opacity = 0;
  231. var intervalID = setInterval(function () {
  232. if (opacity < 1) {
  233. opacity = opacity + 0.5
  234. fade.style.opacity = opacity;
  235. } else {
  236. clearInterval(intervalID);
  237. }
  238. }, 200);
  239. }
  240. } catch (err) {
  241. }