LEFT | RIGHT |
1 (function() | 1 (function() |
2 { | 2 { |
3 function addListener(obj, type, listener, useCapture) | 3 function addListener(obj, type, listener, useCapture) |
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(); |
(...skipping 17 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) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 { | 139 { |
136 var content = document.getElementById("content"); | 140 var content = document.getElementById("content"); |
137 var ua = content.className.match(/ua\-([^\s]+)/); | 141 var ua = content.className.match(/ua\-([^\s]+)/); |
138 visibleTab = ua && ua[1] || "firefox"; | 142 visibleTab = ua && ua[1] || "firefox"; |
139 return visibleTab; | 143 return visibleTab; |
140 } | 144 } |
141 | 145 |
142 function init() | 146 function init() |
143 { | 147 { |
144 container = document.getElementById("more-container"); | 148 container = document.getElementById("more-container"); |
145 contentLoad(); | 149 initSubscriptionForm(document.getElementById("edge-subscription")); |
146 } | 150 } |
147 | 151 |
148 init(); | 152 init(); |
149 })(); | 153 })(); |
LEFT | RIGHT |