init.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. jQuery(document).ready(function($) {
  2. var wide = 768;
  3. if ($(window).width() > wide) {
  4. var headerHeight = $('.navbar').height();
  5. $(window).on('scroll', {
  6. previousTop: 0
  7. },
  8. function() {
  9. var currentTop = $(window).scrollTop();
  10. if (currentTop < this.previousTop) {
  11. if (currentTop > 0 && $('.navbar').hasClass('fixed')) {
  12. $('.navbar').addClass('visible');
  13. } else {
  14. $('.navbar').removeClass('visible fixed');
  15. }
  16. } else {
  17. $('.navbar').removeClass('visible');
  18. if (currentTop > headerHeight && !$('.navbar').hasClass('fixed')) $('.navbar').addClass('fixed');
  19. }
  20. this.previousTop = currentTop;
  21. });
  22. }
  23. var commentsDiv = $('#comments');
  24. if (commentsDiv.length) {
  25. $(commentsDiv).hide();
  26. $('.toggle-comments').on('click', function(e) {
  27. e.preventDefault();
  28. $(commentsDiv).toggle('slow', function() {
  29. var anchor = $('.toggle-comments');
  30. var anchorText = anchor.text() == 'Hide Comments' ? 'Show Comments' : 'Hide Comments';
  31. $(anchor).text(anchorText);
  32. });
  33. });
  34. }
  35. });