Left: | ||
Right: |
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 25 matching lines...) Expand all Loading... | |
36 { | 36 { |
37 textbox.setAttribute("class", "placeholder"); | 37 textbox.setAttribute("class", "placeholder"); |
38 textbox.value = getPlaceholderText(textbox); | 38 textbox.value = getPlaceholderText(textbox); |
39 } | 39 } |
40 | 40 |
41 function getPlaceholderText(textbox) | 41 function getPlaceholderText(textbox) |
42 { | 42 { |
43 return textbox.getAttribute("placeholder"); | 43 return textbox.getAttribute("placeholder"); |
44 } | 44 } |
45 | 45 |
46 function contentLoad() | 46 function initSubscriptionForm(subscriptionElement) |
saroyanm
2015/09/29 09:58:40
Please rename the function, in general the content
| |
47 { | 47 { |
48 var edgeSubscription = document.getElementById("edge-subscription"); | 48 var emailTextbox = subscriptionElement.querySelectorAll(".subscribe-textbox" )[0]; |
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 | 49 |
51 // IE9 + Safari iOS | 50 // IE9 + Safari iOS |
52 if (!("placeholder" in document.createElement("input")) | 51 if (!("placeholder" in document.createElement("input")) |
53 && !emailTextbox.value) | 52 && !emailTextbox.value) |
54 { | 53 { |
55 addPlaceholder(emailTextbox); | 54 addPlaceholder(emailTextbox); |
56 addListener(emailTextbox, "focus", function() | 55 addListener(emailTextbox, "focus", function() |
57 { | 56 { |
58 if (emailTextbox.value == getPlaceholderText(textbox)) | 57 if (emailTextbox.value == getPlaceholderText(emailTextbox)) |
59 { | 58 { |
60 emailTextbox.value = ""; | 59 emailTextbox.value = ""; |
61 emailTextbox.setAttribute("class", ""); | 60 emailTextbox.setAttribute("class", ""); |
62 } | 61 } |
63 }, false); | 62 }, false); |
64 | 63 |
65 addListener(emailTextbox, "blur", function() | 64 addListener(emailTextbox, "blur", function() |
66 { | 65 { |
67 if (!emailTextbox.value) | 66 if (!emailTextbox.value) |
68 addPlaceholder(emailTextbox); | 67 addPlaceholder(emailTextbox); |
69 }, false); | 68 }, false); |
70 } | 69 } |
71 | 70 |
72 var subscriptionForm = document.getElementById("edge-subscription"). | 71 var formElement = subscriptionElement.getElementsByTagName("form")[0]; |
saroyanm
2015/09/29 09:58:39
You have the "edge-subscription" element already,
| |
73 getElementsByTagName("form")[0]; | 72 addListener(formElement, "submit", function() |
74 addListener(subscriptionForm, "submit", function() | |
75 { | 73 { |
76 var formElement = subscriptionForm; | |
saroyanm
2015/09/29 09:58:40
I think this assignment is redundant.
| |
77 if (!window.XMLHttpRequest) | 74 if (!window.XMLHttpRequest) |
78 { | 75 { |
79 formElement.submit(); | 76 formElement.submit(); |
80 return false; | 77 return false; |
81 } | 78 } |
82 | 79 |
83 var pathArray = window.location.pathname.split("/"); | 80 var inputs = formElement.getElementsByTagName("input"); |
84 var params = emailTextbox.name + "=" + encodeURIComponent(emailTextbox.val ue); | 81 var params = ""; |
saroyanm
2015/09/29 09:58:40
After implementing the changes in index.tmpl you c
| |
85 params += "&lang=" + pathArray[1]; | 82 for (var i = 0; i < inputs.length; i++) |
86 params += "&product=" + "edge"; | 83 { |
84 if (params) | |
85 params += "&"; | |
86 params += inputs[i].name + "=" + encodeURIComponent(inputs[i].value); | |
87 } | |
87 var request = new XMLHttpRequest(); | 88 var request = new XMLHttpRequest(); |
88 request.open("POST", "/submitEmail", true); | 89 request.open("POST", "/submitEmail", true); |
89 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d"); | 90 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d"); |
90 addListener(request, "readystatechange", function() | 91 addListener(request, "readystatechange", function() |
91 { | 92 { |
92 if (request.readyState == 4) | 93 if (request.readyState == 4) |
93 { | 94 { |
94 if (request.status >= 200 && request.status < 300) | 95 if (request.status >= 200 && request.status < 300) |
95 { | 96 { |
96 formElement.setAttribute("class", "success"); | 97 formElement.setAttribute("class", "success"); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 { | 139 { |
139 var content = document.getElementById("content"); | 140 var content = document.getElementById("content"); |
140 var ua = content.className.match(/ua\-([^\s]+)/); | 141 var ua = content.className.match(/ua\-([^\s]+)/); |
141 visibleTab = ua && ua[1] || "firefox"; | 142 visibleTab = ua && ua[1] || "firefox"; |
142 return visibleTab; | 143 return visibleTab; |
143 } | 144 } |
144 | 145 |
145 function init() | 146 function init() |
146 { | 147 { |
147 container = document.getElementById("more-container"); | 148 container = document.getElementById("more-container"); |
148 contentLoad(); | 149 initSubscriptionForm(document.getElementById("edge-subscription")); |
149 } | 150 } |
150 | 151 |
151 init(); | 152 init(); |
152 })(); | 153 })(); |
LEFT | RIGHT |