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

Side by Side Diff: static/js/scripts.js

Issue 29335113: Issue 2675 - Implemented responsive header for web.eyeo.com (Closed)
Patch Set: Fixed minor css style issues Created June 16, 2016, 6:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 jQuery(function() 1 (function(){
2 { 2
saroyanm 2016/06/22 07:54:20 Detail: compared to our other JS codes we do not h
juliandoucette 2016/06/23 17:25:42 Done.
3 var toTop = jQuery("#to-top"); 3 function addListener(target, event, callback)
4 toTop.click(function ()
5 { 4 {
6 jQuery("body,html").animate({ 5 if (target.addEventListener)
7 scrollTop: 0
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 { 6 {
saroyanm 2016/06/22 07:54:23 I couldn't find the rule in our coding style wheth
juliandoucette 2016/06/23 17:25:42 Done.
25 header.css("top", -height); 7 return target.addEventListener(event, callback, false);
26 header.animate({top: 0},function()
27 {
28 header.css("top", "");
29 });
30 header.addClass("fixed");
31 } 8 }
32 else 9 else
33 header.removeClass("fixed"); 10 {
11 return target.attachEvent("on" + event, callback);
12 }
34 } 13 }
35 14
36 // Display "to top" button 15 function onLoad(callback)
37 var toTop = jQuery("#to-top"); 16 {
38 toTop.css("opacity", scrollTop > 100 ? 1 : 0) 17 if (document.addEventListener)
39 }); 18 {
19 return addListener(document, "DOMContentLoaded", callback);
20 }
21 else
22 {
23 return addListener(window, "load", callback);
24 }
25 }
26
27 onLoad(function()
28 {
29 // expand & contract fixed header
30
saroyanm 2016/06/22 07:54:19 Detail: Same as above comment about new lines, sam
juliandoucette 2016/06/23 17:25:42 Done.
31 var header = document.getElementById("header");
32 var headerPadding = 13;
33
saroyanm 2016/06/22 07:54:23 Detail: no new line needed here as well
juliandoucette 2016/06/23 17:25:43 Done.
34 addListener(window, "scroll", function()
35 {
36 var scrollY = window.scrollY || document.documentElement.scrollTop;
37
38 if (scrollY < headerPadding)
39 {
40 header.className = "top";
41 }
42 else
43 {
44 header.className = "";
45 }
46 });
47
48 // open & close header menu (on small screens)
49
50 var menu = document.getElementById("menu");
51 var menuButton = document.getElementById("header-hamburger");
52
53 addListener(menuButton, "click", function()
54 {
55 if (menu.className === "open")
56 {
57 menu.className = "";
58 menu.setAttribute("aria-expanded", false);
59 }
60 else
61 {
62 menu.className = "open";
63 menu.setAttribute("aria-expanded", true);
64 }
65 });
66 });
67
68 }());
saroyanm 2016/06/22 07:54:19 Detail: According to our coding styles "Newline at
juliandoucette 2016/06/23 17:25:42 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld