Difference between revisions of "Template:Waterloo/JS/header.js"

Line 18: Line 18:
 
   }
 
   }
 
});
 
});
 
//set lower navbar
 
// $('.navbar-lower').affix({
 
//  offset: {top: 200}
 
// });
 
  
 
// fills in lower nav with inner page links
 
// fills in lower nav with inner page links
Line 28: Line 23:
 
   $('.accordion-heading').addClass('link');
 
   $('.accordion-heading').addClass('link');
 
   $('.link').each(function(i, obj) {
 
   $('.link').each(function(i, obj) {
     $("#inner-page-links").append('<li><a href="#'+obj.id+'">'+obj.id.capitalize()+'</a></li>');
+
     $("#inner-page-links").append('<li><a href="#" id="'+obj.id+'" class="scroll-link">'+obj.id.capitalize()+'</a></li>');
 
   });
 
   });
 
   if ($('#inner-page-links').children().length < 1) {
 
   if ($('#inner-page-links').children().length < 1) {
Line 36: Line 31:
  
 
// for smooth scrolling
 
// for smooth scrolling
// $(function() {
+
function scrollToAnchor(aid){
//  $('a[href*=#]:not([href=#])').click(function() {
+
     var aTag = $("a[name='"+ aid +"']");
//     if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
+
    $('html,body').animate({scrollTop: aTag.offset().top},'slow');
//      var target = $(this.hash);
+
}
//      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
+
 
//      if (target.length) {
+
$(".scroll-link").click(function(obj) {
//        $('html,body').animate({
+
  scrollToAnchor(obj.id);
//          scrollTop: target.offset().top
+
});
//        }, 500);
+
//        return false;
+
//      }
+
//    }
+
//  });
+
// });
+

Revision as of 21:31, 21 August 2015

// scripts for header

// for capitalizing id String.prototype.capitalize = function() {

   return this.charAt(0).toUpperCase() + this.slice(1);

}

// detects scroll for top resizing and lower nav show $(window).scroll(function() {

 if ($(document).scrollTop() > 50) {
   $('.navbar-fixed-top').addClass('shrink');
   if ($('#inner-page-links').children().length > 0) {
     $('.navbar-lower').removeClass('hide-lower')
   }
 } else {
   $('.navbar-fixed-top').removeClass('shrink');
   $('.navbar-lower').addClass('hide-lower')
 }

});

// fills in lower nav with inner page links $(document).ready(function(){

 $('.accordion-heading').addClass('link');
 $('.link').each(function(i, obj) {
$("#inner-page-links").append('
  • <a href="#" id="'+obj.id+'" class="scroll-link">'+obj.id.capitalize()+'</a>
  • ');
     });
     if ($('#inner-page-links').children().length < 1) {
       $('.navbar-lower').addClass('hide-lower')
     }
    

    });

    // for smooth scrolling function scrollToAnchor(aid){

       var aTag = $("a[name='"+ aid +"']");
       $('html,body').animate({scrollTop: aTag.offset().top},'slow');
    

    }

    $(".scroll-link").click(function(obj) {

      scrollToAnchor(obj.id);
    

    });