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

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

Issue 29322769: Issue 2844 - Create Microsoft Edge coming soon landing page (Closed)
Patch Set: Remove unneeded CSS rules. Reoganize the CSS. Improve readability of JS. Created Sept. 25, 2015, 12:35 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« includes/index.tmpl ('K') | « static/img/sprite-index.png ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function() 1 (function()
2 { 2 {
3 function addListener(obj, type, listener, useCapture)
4 {
5 if ("addEventListener" in obj)
6 {
7 obj.addEventListener(type, function(ev)
8 {
9 if (listener(ev) === false)
10 ev.preventDefault();
11 }, useCapture);
12 }
13 else
14 {
15 // IE 8
16 if (type == "DOMContentLoaded")
17 type = "readystatechange";
18
19 type = "on" + type;
20 if ("attachEvent" in obj)
21 {
22 obj.attachEvent(type, function()
23 {
24 if (document.readyState == "complete" && listener(event) === false)
25 event.returnValue = false;
26 });
27 }
28 else
29 {
30 obj[type] = listener;
31 }
32 }
33 }
34
35 function addPlaceholder(textbox)
36 {
37 textbox.setAttribute("class", "placeholder");
38 textbox.value = getPlaceholderText(textbox);
39 }
40
41 function getPlaceholderText(textbox)
42 {
43 return textbox.getAttribute("placeholder");
44 }
45
46 function contentLoad()
saroyanm 2015/09/29 09:58:40 Please rename the function, in general the content
47 {
48 var edgeSubscription = document.getElementById("edge-subscription");
saroyanm 2015/09/29 09:58:40 This will be redundant after the suggested impleme
49 var emailTextbox = edgeSubscription.getElementsByClassName("subscribe-textbo x")[0];
saroyanm 2015/09/29 09:58:40 In general I'd be fan of using queryselector becau
Oleksandr 2015/09/30 08:17:03 To me the querySelector wouldn't be any more under
50
51 // IE9 + Safari iOS
52 if (!("placeholder" in document.createElement("input"))
53 && !emailTextbox.value)
54 {
55 addPlaceholder(emailTextbox);
56 addListener(emailTextbox, "focus", function()
57 {
58 if (emailTextbox.value == getPlaceholderText(textbox))
59 {
60 emailTextbox.value = "";
61 emailTextbox.setAttribute("class", "");
62 }
63 }, false);
64
65 addListener(emailTextbox, "blur", function()
66 {
67 if (!emailTextbox.value)
68 addPlaceholder(emailTextbox);
69 }, false);
70 }
71
72 var subscriptionForm = document.getElementById("edge-subscription").
saroyanm 2015/09/29 09:58:39 You have the "edge-subscription" element already,
73 getElementsByTagName("form")[0];
74 addListener(subscriptionForm, "submit", function()
75 {
76 var formElement = subscriptionForm;
saroyanm 2015/09/29 09:58:40 I think this assignment is redundant.
77 if (!window.XMLHttpRequest)
78 {
79 formElement.submit();
80 return false;
81 }
82
83 var pathArray = window.location.pathname.split("/");
84 var params = emailTextbox.name + "=" + encodeURIComponent(emailTextbox.val ue);
saroyanm 2015/09/29 09:58:40 After implementing the changes in index.tmpl you c
85 params += "&lang=" + pathArray[1];
86 params += "&product=" + "edge";
87 var request = new XMLHttpRequest();
88 request.open("POST", "/submitEmail", true);
89 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d");
90 addListener(request, "readystatechange", function()
91 {
92 if (request.readyState == 4)
93 {
94 if (request.status >= 200 && request.status < 300)
95 {
96 formElement.setAttribute("class", "success");
97 }
98 else if (request.status == 400)
99 {
100 formElement.setAttribute("class", "invalid");
101 }
102 else
103 {
104 var errorWrapper = document.getElementById("response-error");
105 if ("textContent" in errorWrapper)
106 errorWrapper.textContent = request.statusText;
107 else // IE8
108 errorWrapper.innerText = request.statusText;
109
110 formElement.setAttribute("class", "error");
111 }
112 }
113 }, false);
114 request.send(params);
115 return false;
116 }, false);
117 }
118
3 var visibleTab; 119 var visibleTab;
4 var container; 120 var container;
5 121
6 window.toggleMore = function() 122 window.toggleMore = function()
7 { 123 {
8 if (container.className == "hidden") 124 if (container.className == "hidden")
9 container.className = visibleTab || getDefaultTab(); 125 container.className = visibleTab || getDefaultTab();
10 else 126 else
11 container.className = "hidden"; 127 container.className = "hidden";
12 } 128 }
13 129
14 window.showTab = function(button) 130 window.showTab = function(button)
15 { 131 {
16 var id = button.id.substr(5); 132 var id = button.id.substr(5);
17 container.className = id; 133 container.className = id;
18 visibleTab = id; 134 visibleTab = id;
19 } 135 }
20 136
21 function getDefaultTab() 137 function getDefaultTab()
22 { 138 {
23 var content = document.getElementById("content"); 139 var content = document.getElementById("content");
24 var ua = content.className.match(/ua\-([^\s]+)/); 140 var ua = content.className.match(/ua\-([^\s]+)/);
25 visibleTab = ua && ua[1] || "firefox"; 141 visibleTab = ua && ua[1] || "firefox";
26 return visibleTab; 142 return visibleTab;
27 } 143 }
28 144
29 function init() 145 function init()
30 { 146 {
31 container = document.getElementById("more-container"); 147 container = document.getElementById("more-container");
148 contentLoad();
32 } 149 }
33 150
34 init(); 151 init();
35 })(); 152 })();
OLDNEW
« includes/index.tmpl ('K') | « static/img/sprite-index.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld