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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: static/js/scripts.js
===================================================================
--- a/static/js/scripts.js
+++ b/static/js/scripts.js
@@ -1,39 +1,68 @@
-jQuery(function()
-{
- var toTop = jQuery("#to-top");
- toTop.click(function ()
- {
- jQuery("body,html").animate({
- scrollTop: 0
- }, 800);
- return false;
- });
-});
-
-jQuery(window).scroll(function()
-{
- var scrollTop = jQuery(window).scrollTop();
-
- // Fix header
- var header = jQuery("#header");
- var height = header.height();
- var fixed = (scrollTop > height);
- if (fixed != header.hasClass("fixed"))
- {
- if (fixed)
- {
- header.css("top", -height);
- header.animate({top: 0},function()
- {
- header.css("top", "");
- });
- header.addClass("fixed");
- }
- else
- header.removeClass("fixed");
- }
-
- // Display "to top" button
- var toTop = jQuery("#to-top");
- toTop.css("opacity", scrollTop > 100 ? 1 : 0)
-});
+(function(){
+
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.
+ function addListener(target, event, callback)
+ {
+ if (target.addEventListener)
+ {
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.
+ return target.addEventListener(event, callback, false);
+ }
+ else
+ {
+ return target.attachEvent("on" + event, callback);
+ }
+ }
+
+ function onLoad(callback)
+ {
+ if (document.addEventListener)
+ {
+ return addListener(document, "DOMContentLoaded", callback);
+ }
+ else
+ {
+ return addListener(window, "load", callback);
+ }
+ }
+
+ onLoad(function()
+ {
+ // expand & contract fixed header
+
saroyanm 2016/06/22 07:54:19 Detail: Same as above comment about new lines, sam
juliandoucette 2016/06/23 17:25:42 Done.
+ var header = document.getElementById("header");
+ var headerPadding = 13;
+
saroyanm 2016/06/22 07:54:23 Detail: no new line needed here as well
juliandoucette 2016/06/23 17:25:43 Done.
+ addListener(window, "scroll", function()
+ {
+ var scrollY = window.scrollY || document.documentElement.scrollTop;
+
+ if (scrollY < headerPadding)
+ {
+ header.className = "top";
+ }
+ else
+ {
+ header.className = "";
+ }
+ });
+
+ // open & close header menu (on small screens)
+
+ var menu = document.getElementById("menu");
+ var menuButton = document.getElementById("header-hamburger");
+
+ addListener(menuButton, "click", function()
+ {
+ if (menu.className === "open")
+ {
+ menu.className = "";
+ menu.setAttribute("aria-expanded", false);
+ }
+ else
+ {
+ menu.className = "open";
+ menu.setAttribute("aria-expanded", true);
+ }
+ });
+ });
+
+}());
saroyanm 2016/06/22 07:54:19 Detail: According to our coding styles "Newline at
juliandoucette 2016/06/23 17:25:42 Done.

Powered by Google App Engine
This is Rietveld