Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 (function() | 1 (function() |
2 { | 2 { |
3 function addListener(obj, type, listener, useCapture) | 3 function addListener(obj, type, listener, useCapture) |
saroyanm
2015/09/22 13:15:46
Should be redundant if we doesn't expect IE8 users
Oleksandr
2015/09/23 00:37:57
We still support IE8.
saroyanm
2015/09/23 12:44:20
Fare enough, just ignore the IE8 related comments.
| |
4 { | 4 { |
5 if ("addEventListener" in obj) | 5 if ("addEventListener" in obj) |
6 { | 6 { |
7 obj.addEventListener(type, function(ev) | 7 obj.addEventListener(type, function(ev) |
8 { | 8 { |
9 if (listener(ev) === false) | 9 if (listener(ev) === false) |
10 ev.preventDefault(); | 10 ev.preventDefault(); |
11 }, useCapture); | 11 }, useCapture); |
12 } | 12 } |
13 else | 13 else |
(...skipping 14 matching lines...) Expand all Loading... | |
28 else | 28 else |
29 { | 29 { |
30 obj[type] = listener; | 30 obj[type] = listener; |
31 } | 31 } |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 function addPlaceholder(textbox) | 35 function addPlaceholder(textbox) |
36 { | 36 { |
37 textbox.setAttribute("class", "placeholder"); | 37 textbox.setAttribute("class", "placeholder"); |
38 textbox.value = getPlaceholderText(); | 38 textbox.value = getPlaceholderText(textbox); |
39 } | 39 } |
40 | 40 |
41 function getPlaceholderText() | 41 function getPlaceholderText(textbox) |
42 { | 42 { |
43 return document.getElementById("subscribe-textbox").getAttribute("placeholde r"); | 43 return textbox.getAttribute("placeholder"); |
44 } | 44 } |
45 | 45 |
46 function contentLoad() | 46 function initSubscriptionForm(subscriptionElement) |
47 { | 47 { |
48 var emailTextbox = document.getElementById("subscribe-textbox"); | 48 var emailTextbox = subscriptionElement.querySelectorAll(".subscribe-textbox" )[0]; |
49 | 49 |
50 // IE9 + Safari iOS | 50 // IE9 + Safari iOS |
51 if (!("placeholder" in document.createElement("input")) | 51 if (!("placeholder" in document.createElement("input")) |
52 && !emailTextbox.value) | 52 && !emailTextbox.value) |
53 { | 53 { |
54 addPlaceholder(emailTextbox); | 54 addPlaceholder(emailTextbox); |
55 addListener(emailTextbox, "focus", function() | 55 addListener(emailTextbox, "focus", function() |
56 { | 56 { |
57 if (emailTextbox.value == getPlaceholderText()) | 57 if (emailTextbox.value == getPlaceholderText(emailTextbox)) |
58 { | 58 { |
59 emailTextbox.value = ""; | 59 emailTextbox.value = ""; |
60 emailTextbox.setAttribute("class", ""); | 60 emailTextbox.setAttribute("class", ""); |
61 } | 61 } |
62 }, false); | 62 }, false); |
63 | 63 |
64 addListener(emailTextbox, "blur", function() | 64 addListener(emailTextbox, "blur", function() |
65 { | 65 { |
66 if (!emailTextbox.value) | 66 if (!emailTextbox.value) |
67 addPlaceholder(emailTextbox); | 67 addPlaceholder(emailTextbox); |
68 }, false); | 68 }, false); |
69 } | 69 } |
70 | 70 |
71 addListener(document.getElementById("subscribe-form"), "submit", function() | 71 var formElement = subscriptionElement.getElementsByTagName("form")[0]; |
72 addListener(formElement, "submit", function() | |
72 { | 73 { |
73 var formElement = document.getElementById("subscribe-form"); | |
74 if (!window.XMLHttpRequest) | 74 if (!window.XMLHttpRequest) |
75 { | 75 { |
76 formElement.submit(); | 76 formElement.submit(); |
77 return false; | 77 return false; |
78 } | 78 } |
79 | 79 |
80 var pathArray = window.location.pathname.split("/"); | 80 var inputs = formElement.getElementsByTagName("input"); |
81 var params = emailTextbox.name + "=" + encodeURIComponent(emailTextbox.val ue); | 81 var params = ""; |
82 params += "&lang=" + pathArray[1]; | 82 for (var i = 0; i < inputs.length; i++) |
83 params += "&product=" + "edge"; | 83 { |
84 if (params) | |
85 params += "&"; | |
86 params += inputs[i].name + "=" + encodeURIComponent(inputs[i].value); | |
87 } | |
84 var request = new XMLHttpRequest(); | 88 var request = new XMLHttpRequest(); |
85 request.open("POST", formElement.action, true); | 89 request.open("POST", "/submitEmail", true); |
86 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d"); | 90 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d"); |
87 addListener(request, "readystatechange", function() | 91 addListener(request, "readystatechange", function() |
88 { | 92 { |
89 if (request.readyState == 4) | 93 if (request.readyState == 4) |
90 { | 94 { |
91 if (request.status >= 200 && request.status < 300) | 95 if (request.status >= 200 && request.status < 300) |
92 { | 96 { |
93 formElement.setAttribute("class", "success"); | 97 formElement.setAttribute("class", "success"); |
94 } | 98 } |
95 else if (request.status == 400) | 99 else if (request.status == 400) |
96 { | 100 { |
97 formElement.setAttribute("class", "invalid"); | 101 formElement.setAttribute("class", "invalid"); |
98 } | 102 } |
99 else | 103 else |
100 { | 104 { |
101 var errorWrapper = document.getElementById("response-error"); | 105 var errorWrapper = document.getElementById("response-error"); |
102 if ("textContent" in errorWrapper) | 106 if ("textContent" in errorWrapper) |
103 errorWrapper.textContent = request.statusText; | 107 errorWrapper.textContent = request.statusText; |
104 else // IE8 | 108 else // IE8 |
105 errorWrapper.innerText = request.statusText; | 109 errorWrapper.innerText = request.statusText; |
106 | 110 |
107 formElement.setAttribute("class", "error"); | 111 formElement.setAttribute("class", "error"); |
108 } | 112 } |
109 } | 113 } |
110 }, false); | 114 }, false); |
111 request.send(params); | 115 request.send(params); |
112 return false; | 116 return false; |
113 }, false); | 117 }, false); |
114 } | 118 } |
115 addListener(document, "DOMContentLoaded", contentLoad, false); | |
saroyanm
2015/09/22 13:15:46
Script is called after the content is loaded, so t
| |
116 | |
117 | 119 |
118 var visibleTab; | 120 var visibleTab; |
119 var container; | 121 var container; |
120 | 122 |
121 window.toggleMore = function() | 123 window.toggleMore = function() |
122 { | 124 { |
123 if (container.className == "hidden") | 125 if (container.className == "hidden") |
124 container.className = visibleTab || getDefaultTab(); | 126 container.className = visibleTab || getDefaultTab(); |
125 else | 127 else |
126 container.className = "hidden"; | 128 container.className = "hidden"; |
(...skipping 10 matching lines...) Expand all Loading... | |
137 { | 139 { |
138 var content = document.getElementById("content"); | 140 var content = document.getElementById("content"); |
139 var ua = content.className.match(/ua\-([^\s]+)/); | 141 var ua = content.className.match(/ua\-([^\s]+)/); |
140 visibleTab = ua && ua[1] || "firefox"; | 142 visibleTab = ua && ua[1] || "firefox"; |
141 return visibleTab; | 143 return visibleTab; |
142 } | 144 } |
143 | 145 |
144 function init() | 146 function init() |
145 { | 147 { |
146 container = document.getElementById("more-container"); | 148 container = document.getElementById("more-container"); |
149 initSubscriptionForm(document.getElementById("edge-subscription")); | |
147 } | 150 } |
148 | 151 |
149 init(); | 152 init(); |
150 })(); | 153 })(); |
LEFT | RIGHT |