PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/assets/layout/unify-v1.9.1/Blog-Magazine/assets/js/app.js

https://gitlab.com/augustocbx/grimes
JavaScript | 170 lines | 133 code | 17 blank | 20 comment | 13 complexity | 22d6b7cdf386a2475bf48c26aa2c76f6 MD5 | raw file
  1. /*
  2. * Template Name: Unify - Responsive Bootstrap Template
  3. * Author: @htmlstream
  4. * Website: http://htmlstream.com
  5. */
  6. var App = function() {
  7. // We extend jQuery by method hasAttr
  8. $.fn.hasAttr = function(name) {
  9. return this.attr(name) !== undefined;
  10. };
  11. // Fixed Header
  12. function handleHeader() {
  13. jQuery(window).scroll(function() {
  14. if (jQuery(window).scrollTop() > 100) {
  15. jQuery('.header-fixed .header-sticky').addClass('header-fixed-shrink');
  16. } else {
  17. jQuery('.header-fixed .header-sticky').removeClass('header-fixed-shrink');
  18. }
  19. });
  20. }
  21. // Search Box
  22. function handleSearch() {
  23. $('.blog-topbar .search-btn').on('click', function() {
  24. if (jQuery('.topbar-search-block').hasClass('topbar-search-visible')) {
  25. jQuery('.topbar-search-block').slideUp();
  26. jQuery('.topbar-search-block').removeClass('topbar-search-visible');
  27. } else {
  28. jQuery('.topbar-search-block').slideDown();
  29. jQuery('.topbar-search-block').addClass('topbar-search-visible');
  30. }
  31. });
  32. $('.blog-topbar .search-close').on('click', function() {
  33. jQuery('.topbar-search-block').slideUp();
  34. jQuery('.topbar-search-block').removeClass('topbar-search-visible');
  35. });
  36. jQuery(window).scroll(function() {
  37. jQuery('.topbar-search-block').slideUp();
  38. jQuery('.topbar-search-block').removeClass('topbar-search-visible');
  39. });
  40. }
  41. // TopBar
  42. function handleTopBar() {
  43. $('.topbar-toggler').on('click', function() {
  44. if (jQuery('.topbar-toggler').hasClass('topbar-list-visible')) {
  45. jQuery('.topbar-menu').slideUp();
  46. jQuery(this).removeClass('topbar-list-visible');
  47. } else {
  48. jQuery('.topbar-menu').slideDown();
  49. jQuery(this).addClass('topbar-list-visible');
  50. }
  51. });
  52. }
  53. // TopBar SubMenu
  54. function handleTopBarSubMenu() {
  55. $('.topbar-list > li').on('click', function(e) {
  56. if (jQuery(this).children('ul').hasClass('topbar-dropdown')) {
  57. if (jQuery(this).children('ul').hasClass('topbar-dropdown-visible')) {
  58. jQuery(this).children('.topbar-dropdown').slideUp();
  59. jQuery(this).children('.topbar-dropdown').removeClass('topbar-dropdown-visible');
  60. } else {
  61. jQuery(this).children('.topbar-dropdown').slideDown();
  62. jQuery(this).children('.topbar-dropdown').addClass('topbar-dropdown-visible');
  63. }
  64. }
  65. //e.preventDefault();
  66. });
  67. }
  68. // More Articles
  69. function handleMoreArticles() {
  70. var is_box_visible = true;
  71. var distance_from_top = $('.outside-more-articles').attr('data-scrollTop');
  72. $(window).scroll(function() {
  73. if (($(window).scrollTop() > distance_from_top)&&(is_box_visible === true)) {
  74. $('.outside-more-articles').addClass('outside-more-articles--show');
  75. } else {
  76. $('.outside-more-articles').removeClass('outside-more-articles--show');
  77. }
  78. });
  79. $('.outside-more-articles__close').on('click', function(e) {
  80. $('.outside-more-articles').removeClass('outside-more-articles--show');
  81. is_box_visible = false;
  82. });
  83. }
  84. // Please Wait
  85. function handlePleaseWait() {
  86. var is_box_visible = true;
  87. $(document).mouseleave(function(e){
  88. if ((e.clientY < 0)&&(is_box_visible === true)) {
  89. $('.g-popup-wrapper').show();
  90. if ($('.g-popup-wrapper').is(':visible')) $('body').addClass('g-blur');
  91. }
  92. });
  93. $('.g-popup__close').on('click', function(e) {
  94. $('.g-popup-wrapper').hide();
  95. $('body').removeClass('g-blur');
  96. is_box_visible = false;
  97. });
  98. }
  99. // Hover Selector
  100. function handleHoverSelector() {
  101. $('.hoverSelector').on('hover', function(e) {
  102. $('.hoverSelectorBlock', this).toggleClass('show');
  103. e.stopPropagation();
  104. });
  105. }
  106. // Bootstrap Tooltips and Popovers
  107. function handleBootstrap() {
  108. /* Bootstrap Carousel */
  109. jQuery('.carousel').carousel({
  110. interval: 15000,
  111. pause: 'hover'
  112. });
  113. /* Tooltips */
  114. jQuery('.tooltips').tooltip();
  115. jQuery('.tooltips-show').tooltip('show');
  116. jQuery('.tooltips-hide').tooltip('hide');
  117. jQuery('.tooltips-toggle').tooltip('toggle');
  118. jQuery('.tooltips-destroy').tooltip('destroy');
  119. /* Popovers */
  120. jQuery('.popovers').popover();
  121. jQuery('.popovers-show').popover('show');
  122. jQuery('.popovers-hide').popover('hide');
  123. jQuery('.popovers-toggle').popover('toggle');
  124. jQuery('.popovers-destroy').popover('destroy');
  125. }
  126. return {
  127. init: function() {
  128. handleSearch();
  129. handleTopBar();
  130. handleHeader();
  131. handleBootstrap();
  132. handleHoverSelector();
  133. handleTopBarSubMenu();
  134. handleMoreArticles();
  135. handlePleaseWait();
  136. },
  137. // Scroll Bar
  138. initScrollBar: function() {
  139. jQuery('.mCustomScrollbar').mCustomScrollbar({
  140. theme: 'minimal',
  141. scrollInertia: 300,
  142. scrollEasing: 'linear'
  143. });
  144. },
  145. // Counters
  146. initCounter: function() {
  147. jQuery('.counter').counterUp({
  148. delay: 10,
  149. time: 1000
  150. });
  151. },
  152. };
  153. }();