Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: static/js/scripts.js

Issue 29335113: Issue 2675 - Implemented responsive header for web.eyeo.com (Closed)
Left Patch Set: Implemented scripts in vanilla.js Created May 11, 2016, 11:25 p.m.
Right Patch Set: Fixed code style and consistancy issues Created June 23, 2016, 5:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « static/js/respond.min.js ('k') | templates/default.tmpl » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 document.addEventListener("DOMContentLoaded", function() 1 (function(){
saroyanm 2016/05/19 07:43:41 addEventListener is not supported in older version
juliandoucette 2016/05/19 12:01:45 My mistake. Will fix.
2 { 2 function addListener(target, event, callback)
3 // expand & contract fixed header 3 {
4 if (target.addEventListener)
5 return target.addEventListener(event, callback, false);
6 else
7 return target.attachEvent("on" + event, callback);
8 }
4 9
5 var header = document.getElementById("header"); 10 function onLoad(callback)
6 var headerPadding = 13; 11 {
saroyanm 2016/05/19 07:43:41 Detail: you are using the value only in 1 place so
juliandoucette 2016/05/19 12:01:45 For readability? (To give the literal value meanin
saroyanm 2016/05/23 12:39:20 Acknowledged.
12 if (document.addEventListener)
13 return addListener(document, "DOMContentLoaded", callback);
14 else
15 return addListener(window, "load", callback);
16 }
7 17
8 window.addEventListener("scroll", function() 18 onLoad(function()
9 { 19 {
10 var scrollY = window.scrollY || document.documentElement.scrollTop; 20 // expand & contract fixed header
11 if (scrollY < headerPadding) 21 var header = document.getElementById("header");
22 var headerPadding = 13;
23 addListener(window, "scroll", function()
12 { 24 {
13 header.className = "top"; 25 var scrollY = window.scrollY || document.documentElement.scrollTop;
14 } 26 if (scrollY < headerPadding)
15 else 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()
16 { 35 {
17 header.className = ""; 36 if (menu.className === "open")
18 } 37 {
19 }, false); 38 menu.className = "";
20 39 menu.setAttribute("aria-expanded", false);
21 // open & close header menu (on small screens) 40 }
22 41 else
23 var menu = document.getElementById("menu"); 42 {
saroyanm 2016/05/19 07:43:40 Detail: you can get the menu element using the "he
juliandoucette 2016/05/19 12:01:45 Yes. But that is a preference. document.getElemen
saroyanm 2016/05/23 12:39:20 I agree with you
24 var menuButton = document.getElementById("header-hamberger"); 43 menu.className = "open";
25 44 menu.setAttribute("aria-expanded", true);
26 menuButton.addEventListener("click", function() 45 }
27 { 46 });
28 if (menu.className === "open") 47 });
29 { 48 }());
30 menu.className = "";
31 menu.setAttribute("aria-expanded", false);
32 }
33 else
34 {
35 menu.className = "open";
36 menu.setAttribute("aria-expanded", true);
37 }
38 }, false);
39 }, false);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld