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: Do not use IDs in HTML, consider RTL and more comments addressing. Created Sept. 24, 2015, 2:30 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
« static/css/index-mobile.css ('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();
39 }
40
41 function getPlaceholderText()
42 {
43 return document.getElementById("edge-subscription").
saroyanm 2015/09/24 14:52:04 You can assign the element to the variable and reu
44 getElementsByClassName("subscribe-textbox")[0].
45 getAttribute("placeholder");
46 }
47
48 function contentLoad()
49 {
50 var emailTextbox = document.getElementById("edge-subscription").
51 getElementsByClassName("subscribe-textbox")[0];
52
53 // IE9 + Safari iOS
54 if (!("placeholder" in document.createElement("input"))
55 && !emailTextbox.value)
56 {
57 addPlaceholder(emailTextbox);
58 addListener(emailTextbox, "focus", function()
59 {
60 if (emailTextbox.value == getPlaceholderText())
61 {
62 emailTextbox.value = "";
63 emailTextbox.setAttribute("class", "");
64 }
65 }, false);
66
67 addListener(emailTextbox, "blur", function()
68 {
69 if (!emailTextbox.value)
70 addPlaceholder(emailTextbox);
71 }, false);
72 }
73
74 addListener(document.getElementById("edge-subscription").
saroyanm 2015/09/24 14:52:05 please assign form element to variable and reuse i
75 getElementsByTagName("form")[0], "submit", function()
76 {
77 var formElement = document.getElementById("edge-subscription").
78 getElementsByTagName("form")[0];
79 if (!window.XMLHttpRequest)
80 {
81 formElement.submit();
82 return false;
83 }
84
85 var pathArray = window.location.pathname.split("/");
86 var params = emailTextbox.name + "=" + encodeURIComponent(emailTextbox.val ue);
87 params += "&lang=" + pathArray[1];
saroyanm 2015/09/24 14:52:04 Please note that this will return empty string for
Oleksandr 2015/09/25 00:35:45 I don't have a strong opinion on this either, but
saroyanm 2015/09/29 09:58:38 IMO make sense to remove it or provide correct imp
88 params += "&product=" + "edge";
saroyanm 2015/09/24 14:52:05 Where is this coming from ? I can't find reference
Oleksandr 2015/09/25 00:35:45 https://hg.adblockplus.org/sitescripts/rev/19391de
saroyanm 2015/09/29 09:58:38 Thanks for the reference, Updated the ticket accor
89 var request = new XMLHttpRequest();
90 request.open("POST", formElement.action, true);
91 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d");
92 addListener(request, "readystatechange", function()
93 {
94 if (request.readyState == 4)
95 {
96 if (request.status >= 200 && request.status < 300)
97 {
98 formElement.setAttribute("class", "success");
99 }
100 else if (request.status == 400)
101 {
102 formElement.setAttribute("class", "invalid");
103 }
104 else
105 {
106 var errorWrapper = document.getElementById("response-error");
107 if ("textContent" in errorWrapper)
108 errorWrapper.textContent = request.statusText;
109 else // IE8
110 errorWrapper.innerText = request.statusText;
111
112 formElement.setAttribute("class", "error");
113 }
114 }
115 }, false);
116 request.send(params);
117 return false;
118 }, false);
119 }
120
3 var visibleTab; 121 var visibleTab;
4 var container; 122 var container;
5 123
6 window.toggleMore = function() 124 window.toggleMore = function()
7 { 125 {
8 if (container.className == "hidden") 126 if (container.className == "hidden")
9 container.className = visibleTab || getDefaultTab(); 127 container.className = visibleTab || getDefaultTab();
10 else 128 else
11 container.className = "hidden"; 129 container.className = "hidden";
12 } 130 }
13 131
14 window.showTab = function(button) 132 window.showTab = function(button)
15 { 133 {
16 var id = button.id.substr(5); 134 var id = button.id.substr(5);
17 container.className = id; 135 container.className = id;
18 visibleTab = id; 136 visibleTab = id;
19 } 137 }
20 138
21 function getDefaultTab() 139 function getDefaultTab()
22 { 140 {
23 var content = document.getElementById("content"); 141 var content = document.getElementById("content");
24 var ua = content.className.match(/ua\-([^\s]+)/); 142 var ua = content.className.match(/ua\-([^\s]+)/);
25 visibleTab = ua && ua[1] || "firefox"; 143 visibleTab = ua && ua[1] || "firefox";
26 return visibleTab; 144 return visibleTab;
27 } 145 }
28 146
29 function init() 147 function init()
30 { 148 {
31 container = document.getElementById("more-container"); 149 container = document.getElementById("more-container");
150 contentLoad();
32 } 151 }
33 152
34 init(); 153 init();
35 })(); 154 })();
OLDNEW
« static/css/index-mobile.css ('K') | « static/img/sprite-index.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld