| OLD | NEW |
| 1 jQuery(function() | 1 (function(){ |
| 2 { | 2 function addListener(target, event, callback) |
| 3 var toTop = jQuery("#to-top"); | |
| 4 toTop.click(function () | |
| 5 { | 3 { |
| 6 jQuery("body,html").animate({ | 4 if (target.addEventListener) |
| 7 scrollTop: 0 | 5 return target.addEventListener(event, callback, false); |
| 8 }, 800); | |
| 9 return false; | |
| 10 }); | |
| 11 }); | |
| 12 | |
| 13 jQuery(window).scroll(function() | |
| 14 { | |
| 15 var scrollTop = jQuery(window).scrollTop(); | |
| 16 | |
| 17 // Fix header | |
| 18 var header = jQuery("#header"); | |
| 19 var height = header.height(); | |
| 20 var fixed = (scrollTop > height); | |
| 21 if (fixed != header.hasClass("fixed")) | |
| 22 { | |
| 23 if (fixed) | |
| 24 { | |
| 25 header.css("top", -height); | |
| 26 header.animate({top: 0},function() | |
| 27 { | |
| 28 header.css("top", ""); | |
| 29 }); | |
| 30 header.addClass("fixed"); | |
| 31 } | |
| 32 else | 6 else |
| 33 header.removeClass("fixed"); | 7 return target.attachEvent("on" + event, callback); |
| 34 } | 8 } |
| 35 | 9 |
| 36 // Display "to top" button | 10 function onLoad(callback) |
| 37 var toTop = jQuery("#to-top"); | 11 { |
| 38 toTop.css("opacity", scrollTop > 100 ? 1 : 0) | 12 if (document.addEventListener) |
| 39 }); | 13 return addListener(document, "DOMContentLoaded", callback); |
| 14 else |
| 15 return addListener(window, "load", callback); |
| 16 } |
| 17 |
| 18 onLoad(function() |
| 19 { |
| 20 // expand & contract fixed header |
| 21 var header = document.getElementById("header"); |
| 22 var headerPadding = 13; |
| 23 addListener(window, "scroll", function() |
| 24 { |
| 25 var scrollY = window.scrollY || document.documentElement.scrollTop; |
| 26 if (scrollY < headerPadding) |
| 27 header.className = "top"; |
| 28 else |
| 29 header.className = ""; |
| 30 }); |
| 31 // open & close header menu (on small screens) |
| 32 var menu = document.getElementById("menu"); |
| 33 var menuButton = document.getElementById("header-hamburger"); |
| 34 addListener(menuButton, "click", function() |
| 35 { |
| 36 if (menu.className === "open") |
| 37 { |
| 38 menu.className = ""; |
| 39 menu.setAttribute("aria-expanded", false); |
| 40 } |
| 41 else |
| 42 { |
| 43 menu.className = "open"; |
| 44 menu.setAttribute("aria-expanded", true); |
| 45 } |
| 46 }); |
| 47 }); |
| 48 }()); |
| OLD | NEW |