init-o.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*============================================
  2. Navigation
  3. ==============================================*/
  4. $('.nav-toggle').on('touchstart click', function(e) {
  5. e.preventDefault();
  6. $( this ).toggleClass( 'active' );
  7. });
  8. $(function dw_hidenav() {
  9. var headerHeight = $('.navbar').height();
  10. $(window).on('scroll', { previousTop: 0 },
  11. function() {
  12. var currentTop = $(window).scrollTop();
  13. if (currentTop < this.previousTop) {
  14. if (currentTop > 0 && $('.navbar').hasClass('fixed')) {
  15. $('.navbar').addClass('visible');
  16. } else {
  17. $('.navbar').removeClass('visible fixed');
  18. }
  19. }
  20. else {
  21. $('.navbar').removeClass('visible');
  22. if (currentTop > headerHeight && !$('.navbar').hasClass('fixed')) $('.navbar').addClass('fixed');
  23. }
  24. this.previousTop = currentTop;
  25. }
  26. );
  27. });
  28. /*============================================
  29. Comments
  30. ==============================================*/
  31. $('#comments').hide();
  32. $('.toggle-comments').on('touchstart click', function(e) {
  33. e.preventDefault();
  34. $('#comments').toggle('slow', function() {
  35. var anchor = $('.toggle-comments');
  36. var anchorText = anchor.text() === 'Hide Comments' ? 'Show Comments' : 'Hide Comments';
  37. $(anchor).text(anchorText);
  38. });
  39. });
  40. $('#commentform').validate({
  41. rules: {
  42. author: {
  43. required: true,
  44. minlength: 2
  45. },
  46. email: {
  47. required: true,
  48. email: true
  49. },
  50. comment: {
  51. required: true,
  52. minlength: 20
  53. }
  54. },
  55. messages: {
  56. author: 'Please enter in your name.',
  57. email: 'Please enter a valid email address.',
  58. comment: 'Nothing to Say?'
  59. },
  60. errorElement: 'div',
  61. errorPlacement: function(error, element) {
  62. element.before(error);
  63. }
  64. });
  65. /*============================================
  66. EU GDPR cookie notification
  67. ==============================================*/
  68. $( document ).ready( function() {
  69. cookieNotification();
  70. });
  71. var hideCookieNotification = function() {
  72. $( '.js-cookie-notification' ).delay(5000).fadeOut( "slow" );
  73. Cookies.set('EU-GDPR-Cookie', 'true', { expires: 365 });
  74. };
  75. var cookieNotification = function() {
  76. var setCookieNotification = function() {
  77. $( '.js-cookie-notification' ).fadeOut( "slow" );
  78. Cookies.set('EU-GDPR-Cookie', 'true', { expires: 365 });
  79. return false;
  80. };
  81. if ( Cookies.get('EU-GDPR-Cookie') === 'true' ) {
  82. console.log('EU GDPR cookie notification set');
  83. } else {
  84. console.log('EU GDPR cookie notification not set');
  85. $('.js-cookie-notification').css({ 'display' : 'block'});
  86. $('.js-cookie-notification').find('.js-cookie-notification-hide').click( setCookieNotification );
  87. };
  88. }