_init.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. $(function () {
  2. header();
  3. hamburger();
  4. waypoint_init();
  5. waypoints();
  6. why();
  7. });
  8. function header() {
  9. var $window = $(window),
  10. $smallHeader = $('.header-small'),
  11. smallHeaderShowing = false;
  12. function small_header() {
  13. var top = $window.scrollTop();
  14. if (top > 80 && !smallHeaderShowing) {
  15. $smallHeader.addClass('showing');
  16. smallHeaderShowing = true;
  17. }
  18. else if (top <= 80 && smallHeaderShowing) {
  19. $smallHeader.removeClass('showing');
  20. smallHeaderShowing = false;
  21. }
  22. }
  23. $window.scroll(small_header);
  24. small_header();
  25. }
  26. function hamburger() {
  27. var isOpen = false,
  28. $hamburger = $('.hamburger'),
  29. $headerSmall = $('.header-small');
  30. $hamburger.on('click', function () {
  31. isOpen = !isOpen;
  32. $hamburger.toggleClass('is-active');
  33. $headerSmall.toggleClass('menu-open');
  34. });
  35. $(window).on('scroll', function(){
  36. if(isOpen){
  37. $hamburger.removeClass('is-active');
  38. $headerSmall.removeClass('menu-open');
  39. isOpen = false;
  40. }
  41. });
  42. }
  43. function why() {
  44. var index = 0,
  45. $section = $('.testimonials-section'),
  46. $testimonials = $('.br-testimonial'),
  47. $indicators = $('.indicators'),
  48. interval;
  49. function next(goTo) {
  50. $testimonials.removeClass('showing');
  51. if (index < $testimonials.length - 1)
  52. index++;
  53. else index = 0;
  54. $testimonials.eq(index).addClass('showing');
  55. $indicators.children().eq(index).addClass('current').siblings().removeClass('current');
  56. }
  57. function start() {
  58. interval = setInterval(function () {
  59. next();
  60. }, 6000);
  61. }
  62. function stop() {
  63. clearInterval(interval);
  64. }
  65. function makeIndicators() {
  66. for (var i = 0; i < $testimonials.length; i++) {
  67. var indicator = $('<span></span>');
  68. if (i === 0)
  69. indicator.addClass('current');
  70. $indicators.append(indicator);
  71. }
  72. }
  73. function advanceNow() {
  74. stop();
  75. next();
  76. start();
  77. }
  78. if ($testimonials.length) {
  79. makeIndicators();
  80. start();
  81. $section.on('mouseenter', '.br-testimonial', function () { stop(); });
  82. $section.on('mouseleave', '.br-testimonial', function () { start(); });
  83. $indicators.on('click', 'span', function () {
  84. index = $(this).index() - 1;
  85. advanceNow();
  86. });
  87. $('.next-testimonial').on('click', function () { advanceNow(); });
  88. }
  89. }
  90. function waypoints() {
  91. var waypoints = [];
  92. var $window = $(window),
  93. $body = $('body');
  94. var $headerSmall = $('.header-small');
  95. var $pages = $('.page-view');
  96. var $html = $('html'), isSmallWindow;
  97. function removeClasses($element) {
  98. $element.removeClass('viewport-above viewport-below viewport-inside');
  99. }
  100. function setClass($element, className) {
  101. removeClasses($element);
  102. $element.addClass(className);
  103. }
  104. function manageSize() {
  105. isSmallWindow = $window.width() <= 620;
  106. }
  107. function manageBackground($element) {
  108. var $colorSource = $element.prev('.background-color'),
  109. bgClass = false, hasGradient, background, gradient;
  110. if ($colorSource.length) {
  111. bgClass = $colorSource[0].hasAttribute('data-dark-bg') ? 'dark-bg' : 'light-bg';
  112. background = $colorSource.css('background-color');
  113. $body.css('background', background);
  114. $html.css('background', background);
  115. $body.attr('bg', bgClass);
  116. $headerSmall.css('color', background);
  117. }
  118. }
  119. function waypoint_init() {
  120. $pages.each(function () {
  121. var $this = $(this);
  122. var inview = new Waypoint.Inview({
  123. element: $this[0],
  124. enter: function (direction) {
  125. manageBackground($this);
  126. setClass($this, 'viewport-inside');
  127. },
  128. exited: function (direction) {
  129. if (direction == 'down')
  130. setClass($this, 'viewport-above');
  131. else setClass($this, 'viewport-below');
  132. },
  133. offset: {
  134. top: $window.height() / 2,
  135. bottom: $window.height() / 2
  136. }
  137. });
  138. waypoints.push(inview);
  139. });
  140. }
  141. function clearWaypoints() {
  142. for (var i = 0; i < waypoints.length; i++) {
  143. waypoints[i].destroy();
  144. }
  145. waypoints = [];
  146. }
  147. function handleWaypoints() {
  148. clearWaypoints();
  149. waypoint_init();
  150. }
  151. handleWaypoints();
  152. manageSize();
  153. $(window).on('resize', function () {
  154. $pages.each(function () {
  155. removeClasses($(this));
  156. });
  157. handleWaypoints();
  158. manageSize();
  159. });
  160. }
  161. function waypoint_init() {
  162. Waypoint.Inview.prototype.createWaypoints = function () {
  163. function outerHeight(el) {
  164. var height = el.offsetHeight;
  165. var style = getComputedStyle(el);
  166. height += parseInt(style.marginTop) + parseInt(style.marginBottom);
  167. return height;
  168. }
  169. var configs = {
  170. vertical: [{
  171. down: 'enter', up: 'exited',
  172. offset: function () {
  173. var _offset = this.options.offset && this.options.offset.bottom || 0;
  174. return this.options.context.innerHeight - _offset;
  175. }.bind(this)
  176. }, {
  177. down: 'entered', up: 'exit',
  178. offset: function () {
  179. var _offset = this.options.offset && this.options.offset.bottom || 0;
  180. return this.options.context.innerHeight - outerHeight(this.element) - _offset;
  181. }.bind(this)
  182. }, {
  183. down: 'exit', up: 'entered',
  184. offset: function () {
  185. var _offset = this.options.offset && this.options.offset.top || 0;
  186. return _offset;
  187. }.bind(this)
  188. }, {
  189. down: 'exited', up: 'enter',
  190. offset: function () {
  191. var _offset = this.options.offset && this.options.offset.top || 0;
  192. return _offset - outerHeight(this.element);
  193. }.bind(this)
  194. }],
  195. horizontal: [{
  196. right: 'enter',
  197. left: 'exited',
  198. offset: '100%'
  199. }, {
  200. right: 'entered',
  201. left: 'exit',
  202. offset: 'right-in-view'
  203. }, {
  204. right: 'exit',
  205. left: 'entered',
  206. offset: 0
  207. }, {
  208. right: 'exited',
  209. left: 'enter',
  210. offset: function () {
  211. return -this.adapter.outerWidth()
  212. }
  213. }]
  214. };
  215. for (var i = 0, end = configs[this.axis].length; i < end; i++) {
  216. var config = configs[this.axis][i];
  217. this.createWaypoint(config)
  218. }
  219. };
  220. $.fn.scrollEnd = function (callback, timeout) {
  221. $(this).scroll(function () {
  222. var $this = $(this);
  223. if ($this.data('scrollTimeout')) {
  224. clearTimeout($this.data('scrollTimeout'));
  225. }
  226. $this.data('scrollTimeout', setTimeout(callback, timeout));
  227. });
  228. };
  229. }