_init.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 > 200 && !smallHeaderShowing) {
  15. $smallHeader.addClass('showing');
  16. smallHeaderShowing = true;
  17. }
  18. else if (top <= 200 && 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. document.addEventListener('DOMContentLoaded', function() {
  44. var calendarEl = document.getElementById('calendar');
  45. var calendar = new FullCalendar.Calendar(calendarEl, {
  46. plugins: [ 'dayGrid','timeGrid', 'googleCalendar' ],
  47. height: 'auto',
  48. header: {
  49. left: 'title',
  50. center: '',
  51. right: 'today,dayGridMonth,timeGridWeek prev,next '
  52. },
  53. views: {
  54. dayGrid: {
  55. hiddenDays: [ 0,6,7 ]
  56. },
  57. timeGrid: {
  58. minTime: '10:00:00',
  59. maxTime: '17:00:00',
  60. columnHeaderFormat: {
  61. weekday: 'short'
  62. },
  63. hiddenDays: [ 0,6,7 ]
  64. },
  65. },
  66. firstDay : 1,
  67. defaultView: 'dayGridMonth',
  68. googleCalendarApiKey: 'AIzaSyAGowGJYx6dOaQvG_vSUI73uT88VWOTcNQ',
  69. events: {
  70. googleCalendarId: 'davidawindham.com_bvrht1f8n2vgldgjenpgfdd4bk@group.calendar.google.com',
  71. className: 'gcal-event'
  72. },
  73. eventRender: function(info) {
  74. },
  75. eventClick: function(info) {
  76. info.jsEvent.preventDefault();
  77. }
  78. });
  79. calendar.render();
  80. });
  81. function why() {
  82. var index = 0,
  83. $section = $('.testimonials-section'),
  84. $testimonials = $('.br-testimonial'),
  85. $indicators = $('.indicators'),
  86. interval;
  87. function next(goTo) {
  88. $testimonials.removeClass('showing');
  89. if (index < $testimonials.length - 1)
  90. index++;
  91. else index = 0;
  92. $testimonials.eq(index).addClass('showing');
  93. $indicators.children().eq(index).addClass('current').siblings().removeClass('current');
  94. }
  95. function start() {
  96. interval = setInterval(function () {
  97. next();
  98. }, 6000);
  99. }
  100. function stop() {
  101. clearInterval(interval);
  102. }
  103. function makeIndicators() {
  104. for (var i = 0; i < $testimonials.length; i++) {
  105. var indicator = $('<span></span>');
  106. if (i === 0)
  107. indicator.addClass('current');
  108. $indicators.append(indicator);
  109. }
  110. }
  111. function advanceNow() {
  112. stop();
  113. next();
  114. start();
  115. }
  116. if ($testimonials.length) {
  117. makeIndicators();
  118. start();
  119. $section.on('mouseenter', '.br-testimonial', function () { stop(); });
  120. $section.on('mouseleave', '.br-testimonial', function () { start(); });
  121. $indicators.on('click', 'span', function () {
  122. index = $(this).index() - 1;
  123. advanceNow();
  124. });
  125. $('.next-testimonial').on('click', function () { advanceNow(); });
  126. }
  127. }
  128. function waypoints() {
  129. var waypoints = [];
  130. var $window = $(window),
  131. $body = $('body');
  132. var $headerSmall = $('.header-small');
  133. var $pages = $('.page-view');
  134. var $html = $('html'), isSmallWindow;
  135. function removeClasses($element) {
  136. $element.removeClass('viewport-above viewport-below viewport-inside');
  137. }
  138. function setClass($element, className) {
  139. removeClasses($element);
  140. $element.addClass(className);
  141. }
  142. function manageSize() {
  143. isSmallWindow = $window.width() <= 620;
  144. }
  145. function manageBackground($element) {
  146. var $colorSource = $element.prev('.background-color'),
  147. bgClass = false, hasGradient, background, gradient;
  148. if ($colorSource.length) {
  149. bgClass = $colorSource[0].hasAttribute('data-dark-bg') ? 'dark-bg' : 'light-bg';
  150. background = $colorSource.css('background-color');
  151. $body.css('background', background);
  152. $html.css('background', background);
  153. $body.attr('bg', bgClass);
  154. $headerSmall.css('color', background);
  155. }
  156. }
  157. function waypoint_init() {
  158. $pages.each(function () {
  159. var $this = $(this);
  160. var inview = new Waypoint.Inview({
  161. element: $this[0],
  162. enter: function (direction) {
  163. manageBackground($this);
  164. setClass($this, 'viewport-inside');
  165. },
  166. exited: function (direction) {
  167. if (direction == 'down')
  168. setClass($this, 'viewport-above');
  169. else setClass($this, 'viewport-below');
  170. },
  171. offset: {
  172. top: $window.height() / 2,
  173. bottom: $window.height() / 2
  174. }
  175. });
  176. waypoints.push(inview);
  177. });
  178. }
  179. function clearWaypoints() {
  180. for (var i = 0; i < waypoints.length; i++) {
  181. waypoints[i].destroy();
  182. }
  183. waypoints = [];
  184. }
  185. function handleWaypoints() {
  186. clearWaypoints();
  187. waypoint_init();
  188. }
  189. handleWaypoints();
  190. manageSize();
  191. $(window).on('resize', function () {
  192. $pages.each(function () {
  193. removeClasses($(this));
  194. });
  195. handleWaypoints();
  196. manageSize();
  197. });
  198. }
  199. function waypoint_init() {
  200. Waypoint.Inview.prototype.createWaypoints = function () {
  201. function outerHeight(el) {
  202. var height = el.offsetHeight;
  203. var style = getComputedStyle(el);
  204. height += parseInt(style.marginTop) + parseInt(style.marginBottom);
  205. return height;
  206. }
  207. var configs = {
  208. vertical: [{
  209. down: 'enter', up: 'exited',
  210. offset: function () {
  211. var _offset = this.options.offset && this.options.offset.bottom || 0;
  212. return this.options.context.innerHeight - _offset;
  213. }.bind(this)
  214. }, {
  215. down: 'entered', up: 'exit',
  216. offset: function () {
  217. var _offset = this.options.offset && this.options.offset.bottom || 0;
  218. return this.options.context.innerHeight - outerHeight(this.element) - _offset;
  219. }.bind(this)
  220. }, {
  221. down: 'exit', up: 'entered',
  222. offset: function () {
  223. var _offset = this.options.offset && this.options.offset.top || 0;
  224. return _offset;
  225. }.bind(this)
  226. }, {
  227. down: 'exited', up: 'enter',
  228. offset: function () {
  229. var _offset = this.options.offset && this.options.offset.top || 0;
  230. return _offset - outerHeight(this.element);
  231. }.bind(this)
  232. }],
  233. horizontal: [{
  234. right: 'enter',
  235. left: 'exited',
  236. offset: '100%'
  237. }, {
  238. right: 'entered',
  239. left: 'exit',
  240. offset: 'right-in-view'
  241. }, {
  242. right: 'exit',
  243. left: 'entered',
  244. offset: 0
  245. }, {
  246. right: 'exited',
  247. left: 'enter',
  248. offset: function () {
  249. return -this.adapter.outerWidth()
  250. }
  251. }]
  252. };
  253. for (var i = 0, end = configs[this.axis].length; i < end; i++) {
  254. var config = configs[this.axis][i];
  255. this.createWaypoint(config)
  256. }
  257. };
  258. $.fn.scrollEnd = function (callback, timeout) {
  259. $(this).scroll(function () {
  260. var $this = $(this);
  261. if ($this.data('scrollTimeout')) {
  262. clearTimeout($this.data('scrollTimeout'));
  263. }
  264. $this.data('scrollTimeout', setTimeout(callback, timeout));
  265. });
  266. };
  267. }