| OLD | NEW |
| 1 (function(){ | 1 (function(){ |
| 2 document.addEventListener("DOMContentLoaded", function() | 2 document.addEventListener("DOMContentLoaded", function() |
| 3 { | 3 { |
| 4 /************************************************************************** | 4 /************************************************************************** |
| 5 * General | 5 * General |
| 6 **************************************************************************/ | 6 **************************************************************************/ |
| 7 | 7 |
| 8 document.documentElement.classList.add("js"); | 8 document.documentElement.classList.add("js"); |
| 9 document.documentElement.classList.remove("no-js"); | 9 document.documentElement.classList.remove("no-js"); |
| 10 // the class "open" was added just in case it's a no-js state | 10 // the class "open" was added just in case it's a no-js state |
| 11 document.getElementById("sidebar").classList.remove("open"); | 11 document.getElementById("sidebar").classList.remove("open"); |
| 12 | 12 |
| 13 /************************************************************************** | 13 /************************************************************************** |
| 14 * Sidebar | 14 * Sidebar |
| 15 **************************************************************************/ | 15 **************************************************************************/ |
| 16 | 16 |
| 17 var sidebar = document.getElementById("sidebar"); | |
| 18 var sidebarOpen = document.getElementById("sidebar-open"); | 17 var sidebarOpen = document.getElementById("sidebar-open"); |
| 19 var sidebarClose = document.getElementById("sidebar-close"); | 18 var sidebarClose = document.getElementById("sidebar-close"); |
| 19 var root = document.documentElement; |
| 20 | 20 |
| 21 sidebarOpen.addEventListener("click", function() | 21 sidebarOpen.addEventListener("click", function() |
| 22 { | 22 { |
| 23 sidebar.classList.add("open"); | 23 root.classList.add("open-sidebar"); |
| 24 }, false); | 24 }, false); |
| 25 | 25 |
| 26 sidebarClose.addEventListener("click", function() | 26 sidebarClose.addEventListener("click", function() |
| 27 { | 27 { |
| 28 sidebar.classList.remove("open"); | 28 root.classList.remove("open-sidebar"); |
| 29 }, false); | 29 }, false); |
| 30 | 30 |
| 31 | 31 |
| 32 /************************************************************************** | 32 /************************************************************************** |
| 33 * Youtube Embed | 33 * Youtube Embed |
| 34 **************************************************************************/ | 34 **************************************************************************/ |
| 35 | 35 |
| 36 function YoutubeEmbed(container) | 36 function YoutubeEmbed(container) |
| 37 { | 37 { |
| 38 this.container = container; | 38 this.container = container; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 else | 73 else |
| 74 { | 74 { |
| 75 this.container.classList.add("show-disclaimer"); | 75 this.container.classList.add("show-disclaimer"); |
| 76 this.timeClickedVideo = new Date().getTime(); | 76 this.timeClickedVideo = new Date().getTime(); |
| 77 } | 77 } |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 if (document.querySelector(".youtube-embed")) | 80 if (document.querySelector(".youtube-embed")) |
| 81 new YoutubeEmbed(document.querySelector(".youtube-embed")); | 81 new YoutubeEmbed(document.querySelector(".youtube-embed")); |
| 82 | 82 |
| 83 /*************************************************************************
* |
| 84 * Header disappears on scroll down and re-appears on scroll up in small s
creens |
| 85 *************************************************************************
*/ |
| 86 |
| 87 function initNavbarToggle() |
| 88 { |
| 89 var sidebarHeight = document.getElementById("sidebar").offsetHeight; |
| 90 var scrollHandled = false; |
| 91 var lastScrollTop = 0; |
| 92 var desktopBreakpoint = 1199; |
| 93 |
| 94 // IE9 does not support offsetHeight when element is fixed |
| 95 if (!sidebarHeight) |
| 96 return; |
| 97 |
| 98 window.addEventListener("scroll", (function() |
| 99 { |
| 100 scrollHandled = false; |
| 101 })); |
| 102 |
| 103 setInterval(function() |
| 104 { |
| 105 if (window.innerWidth <= desktopBreakpoint) |
| 106 { |
| 107 root.classList.add("mobile"); |
| 108 if (!root.classList.contains("open-sidebar") && !scrollHandled) |
| 109 { |
| 110 scrollHandled = handleScroll(); |
| 111 } |
| 112 } |
| 113 else |
| 114 { |
| 115 root.classList.remove("mobile"); |
| 116 } |
| 117 }, 250); |
| 118 |
| 119 function handleScroll() |
| 120 { |
| 121 var currentScroll = window.pageYOffset; |
| 122 if (currentScroll > lastScrollTop) |
| 123 { |
| 124 root.classList.add("scrollDown"); |
| 125 } |
| 126 else |
| 127 { |
| 128 root.classList.remove("scrollDown"); |
| 129 } |
| 130 lastScrollTop = currentScroll; |
| 131 return true; |
| 132 } |
| 133 } |
| 134 |
| 135 initNavbarToggle(); |
| 136 |
| 83 }, false); | 137 }, false); |
| 138 |
| 84 }()); | 139 }()); |
| OLD | NEW |