Difference between revisions of "Template:Waterloo/JS/header.js"
m (Testing title in sub navbar) |
|||
Line 4: | Line 4: | ||
String.prototype.capitalize = function() { | String.prototype.capitalize = function() { | ||
return this.charAt(0).toUpperCase() + this.slice(1); | return this.charAt(0).toUpperCase() + this.slice(1); | ||
− | } | + | }; |
// detects scroll for top resizing and lower nav show | // detects scroll for top resizing and lower nav show | ||
Line 11: | Line 11: | ||
$('.main-nav').addClass('shrink'); | $('.main-nav').addClass('shrink'); | ||
if ($('#inner-page-links').children().length > 0) { | if ($('#inner-page-links').children().length > 0) { | ||
− | $('.navbar-lower').removeClass('hide-lower') | + | $('.navbar-lower').removeClass('hide-lower'); |
} | } | ||
} else { | } else { | ||
$('.main-nav').removeClass('shrink'); | $('.main-nav').removeClass('shrink'); | ||
− | $('.navbar-lower').addClass('hide-lower') | + | $('.navbar-lower').addClass('hide-lower'); |
} | } | ||
}); | }); | ||
Line 22: | Line 22: | ||
$(document).ready(function(){ | $(document).ready(function(){ | ||
$('.accordion-heading').addClass('link'); | $('.accordion-heading').addClass('link'); | ||
− | $('.link').each(function(i, obj) { | + | $('.link a').each(function(i, obj) { |
− | $("#inner-page-links").append('<li><a href="#" class="scroll-link">'+obj. | + | $("#inner-page-links").append('<li><a href="#" class="scroll-link">'+obj.innerHTML.capitalize()+'</a></li>'); |
}); | }); | ||
$(".scroll-link").each(function(i, obj) { | $(".scroll-link").each(function(i, obj) { | ||
Line 31: | Line 31: | ||
}); | }); | ||
if ($('#inner-page-links').children().length < 1) { | if ($('#inner-page-links').children().length < 1) { | ||
− | $('.navbar-lower').addClass('hide-lower') | + | $('.navbar-lower').addClass('hide-lower'); |
} | } | ||
}); | }); | ||
Line 38: | Line 38: | ||
function scrollToAnchor(aid){ | function scrollToAnchor(aid){ | ||
var aTag = $('#'+aid); | var aTag = $('#'+aid); | ||
− | if(aTag.length){ | + | if(aTag.length){ |
$('html, body').animate({scrollTop:$(aTag).position().top}, 'slow'); | $('html, body').animate({scrollTop:$(aTag).position().top}, 'slow'); | ||
} | } | ||
} | } |
Revision as of 07:07, 25 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) { $('.main-nav').addClass('shrink'); if ($('#inner-page-links').children().length > 0) { $('.navbar-lower').removeClass('hide-lower'); } } else { $('.main-nav').removeClass('shrink'); $('.navbar-lower').addClass('hide-lower'); }
});
// fills in lower nav with inner page links $(document).ready(function(){
$('.accordion-heading').addClass('link'); $('.link a').each(function(i, obj) {$("#inner-page-links").append('
}); $(".scroll-link").each(function(i, obj) { $(obj).click(function() { scrollToAnchor(obj.text.toLowerCase()); }); }); if ($('#inner-page-links').children().length < 1) { $('.navbar-lower').addClass('hide-lower'); }
});
// for smooth scrolling function scrollToAnchor(aid){
var aTag = $('#'+aid); if(aTag.length){ $('html, body').animate({scrollTop:$(aTag).position().top}, 'slow'); }
}