Guest User

Untitled

a guest
Mar 18th, 2019
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.51 KB | None | 0 0
  1. // footer custom script
  2. function wpdocs_dequeue_script() {
  3. wp_dequeue_script( 'spicepress-menu-js' );
  4. }
  5. add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );
  6.  
  7. function spicepress_custom_menu_script()
  8. { ?>
  9. <script>
  10. jQuery(document).ready(function ( jQuery ) {
  11.  
  12. /* ---------------------------------------------- /*
  13. * Scroll top
  14. /* ---------------------------------------------- */
  15.  
  16. jQuery(window).scroll(function() {
  17. if (jQuery(this).scrollTop() > 100) {
  18. jQuery('.scroll-up').fadeIn();
  19. } else {
  20. jQuery('.scroll-up').fadeOut();
  21. }
  22. });
  23.  
  24. jQuery('.scroll-up').click(function () {
  25. jQuery("html, body").animate({
  26. scrollTop: 0
  27. }, 700);
  28. return false;
  29. });
  30.  
  31.  
  32. /* ---------------------------------------------- /*
  33. * Initialization General Scripts for all pages
  34. /* ---------------------------------------------- */
  35.  
  36. var homeSection = jQuery('.home-section'),
  37. navbar = jQuery('.navbar-custom'),
  38. navHeight = navbar.height(),
  39. // worksgrid = jQuery('#works-grid'),
  40. width = Math.max(jQuery(window).width(), window.innerWidth),
  41. mobileTest = false;
  42.  
  43. if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
  44. mobileTest = true;
  45. }
  46.  
  47. buildHomeSection(homeSection);
  48. navbarAnimation(navbar, homeSection, navHeight);
  49. navbarSubmenu(width);
  50. hoverDropdown(width, mobileTest);
  51.  
  52. jQuery(window).resize(function() {
  53. var width = Math.max(jQuery(window).width(), window.innerWidth);
  54. buildHomeSection(homeSection);
  55. hoverDropdown(width, mobileTest);
  56. });
  57.  
  58. /* ---------------------------------------------- /*
  59. * Home section height
  60. /* ---------------------------------------------- */
  61.  
  62. function buildHomeSection(homeSection) {
  63. if (homeSection.length > 0) {
  64. if (homeSection.hasClass('home-full-height')) {
  65. homeSection.height(jQuery(window).height());
  66. } else {
  67. homeSection.height(jQuery(window).height() * 0.85);
  68. }
  69. }
  70. }
  71.  
  72.  
  73. /* ---------------------------------------------- /*
  74. * Transparent navbar animation
  75. /* ---------------------------------------------- */
  76.  
  77. function navbarAnimation(navbar, homeSection, navHeight) {
  78. var topScroll = jQuery(window).scrollTop();
  79. if (navbar.length > 0 && homeSection.length > 0) {
  80. if(topScroll >= navHeight) {
  81. navbar.removeClass('navbar-transparent');
  82. } else {
  83. navbar.addClass('navbar-transparent');
  84. }
  85. }
  86. }
  87.  
  88. /* ---------------------------------------------- /*
  89. * Navbar submenu
  90. /* ---------------------------------------------- */
  91.  
  92. function navbarSubmenu(width) {
  93. if (width > 1100) {
  94. jQuery('.navbar-custom .navbar-nav > li.dropdown').hover(function() {
  95. var MenuLeftOffset = jQuery('.dropdown-menu', jQuery(this)).offset().left;
  96. var Menu1LevelWidth = jQuery('.dropdown-menu', jQuery(this)).width();
  97. if (width - MenuLeftOffset < Menu1LevelWidth * 2) {
  98. jQuery(this).children('.dropdown-menu').addClass('leftauto');
  99. } else {
  100. jQuery(this).children('.dropdown-menu').removeClass('leftauto');
  101. }
  102. if (jQuery('.dropdown', jQuery(this)).length > 0) {
  103. var Menu2LevelWidth = jQuery('.dropdown-menu', jQuery(this)).width();
  104. if (width - MenuLeftOffset - Menu1LevelWidth < Menu2LevelWidth) {
  105. jQuery(this).children('.dropdown-menu').addClass('left-side');
  106. } else {
  107. jQuery(this).children('.dropdown-menu').removeClass('left-side');
  108. }
  109. }
  110. });
  111. }
  112. }
  113.  
  114. /* ---------------------------------------------- /*
  115. * Navbar hover dropdown on desctop
  116. /* ---------------------------------------------- */
  117.  
  118. function hoverDropdown(width, mobileTest) {
  119. if ((width > 1100) && (mobileTest !== true)) {
  120. jQuery('.navbar-custom').removeClass('open');
  121. var delay = 0;
  122. var setTimeoutConst;
  123. jQuery('.navbar-custom .navbar-nav > li.dropdown, .navbar-custom li.dropdown > ul > li.dropdown').hover(function() {
  124. var jQuerythis = jQuery(this);
  125. setTimeoutConst = setTimeout(function() {
  126. jQuerythis.addClass('open');
  127. jQuerythis.find('.dropdown-toggle').addClass('disabled');
  128. }, delay);
  129. },
  130. function() {
  131. clearTimeout(setTimeoutConst);
  132. jQuery(this).removeClass('open');
  133. jQuery(this).find('.dropdown-toggle').removeClass('disabled');
  134. });
  135. } else {
  136. jQuery('.navbar-custom .navbar-nav > li.dropdown, .navbar-custom li.dropdown > ul > li.dropdown').unbind('mouseenter mouseleave');
  137. jQuery('.navbar-custom [data-toggle=dropdown]').not('.binded').addClass('binded').on('click', function(event) {
  138. event.preventDefault();
  139. event.stopPropagation();
  140. jQuery(this).parent().siblings().removeClass('open');
  141. jQuery(this).parent().siblings().find('[data-toggle=dropdown]').parent().removeClass('open');
  142. jQuery(this).parent().toggleClass('open');
  143. });
  144. }
  145. }
  146.  
  147. /* ---------------------------------------------- /*
  148. * Navbar collapse on click
  149. /* ---------------------------------------------- */
  150.  
  151. jQuery(document).on('click','.navbar-collapse.in',function(e) {
  152. if( jQuery(e.target).is('a') && jQuery(e.target).attr('class') != 'dropdown-toggle' ) {
  153. jQuery(this).collapse('hide');
  154. }
  155. });
  156.  
  157.  
  158. if( jQuery(window).width() > 1100) {
  159. jQuery('.nav li.dropdown').hover(function() {
  160. jQuery(this).addClass('open');
  161.  
  162. }, function() {
  163. jQuery(this).removeClass('open');
  164. });
  165. jQuery('.nav li.dropdown-submenu').hover(function() {
  166. jQuery(this).addClass('open');
  167. }, function() {
  168. jQuery(this).removeClass('open');
  169. });
  170. }
  171.  
  172. jQuery('li.dropdown').find('.fa-angle-down').each(function(){
  173. jQuery(this).on('click', function(){
  174. if( jQuery(window).width() < 1100) {
  175. jQuery(this).parent().next().slideToggle();
  176. }
  177. return false;
  178. });
  179. });
  180.  
  181. if(jQuery(window).width() >= 1100){
  182. //For header fix
  183. jQuery(window).bind('scroll', function () {
  184. if (jQuery(window).scrollTop() > 100) {
  185. jQuery('.navbar-overlapped.navigation').addClass('stiky-header');
  186. } else {
  187. jQuery('.navbar-overlapped.navigation').removeClass('stiky-header');
  188. }
  189. });
  190.  
  191. }
  192.  
  193.  
  194. });
  195. </script>
  196. <?php
  197. }
  198. add_action('wp_footer','spicepress_custom_menu_script');
Add Comment
Please, Sign In to add comment