| 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 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("edge-subscription"). | 43 return textbox.getAttribute("placeholder"); |
|
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 } | 44 } |
| 47 | 45 |
| 48 function contentLoad() | 46 function initSubscriptionForm(subscriptionElement) |
| 49 { | 47 { |
| 50 var emailTextbox = document.getElementById("edge-subscription"). | 48 var emailTextbox = subscriptionElement.querySelectorAll(".subscribe-textbox" )[0]; |
| 51 getElementsByClassName("subscribe-textbox")[0]; | |
| 52 | 49 |
| 53 // IE9 + Safari iOS | 50 // IE9 + Safari iOS |
| 54 if (!("placeholder" in document.createElement("input")) | 51 if (!("placeholder" in document.createElement("input")) |
| 55 && !emailTextbox.value) | 52 && !emailTextbox.value) |
| 56 { | 53 { |
| 57 addPlaceholder(emailTextbox); | 54 addPlaceholder(emailTextbox); |
| 58 addListener(emailTextbox, "focus", function() | 55 addListener(emailTextbox, "focus", function() |
| 59 { | 56 { |
| 60 if (emailTextbox.value == getPlaceholderText()) | 57 if (emailTextbox.value == getPlaceholderText(emailTextbox)) |
| 61 { | 58 { |
| 62 emailTextbox.value = ""; | 59 emailTextbox.value = ""; |
| 63 emailTextbox.setAttribute("class", ""); | 60 emailTextbox.setAttribute("class", ""); |
| 64 } | 61 } |
| 65 }, false); | 62 }, false); |
| 66 | 63 |
| 67 addListener(emailTextbox, "blur", function() | 64 addListener(emailTextbox, "blur", function() |
| 68 { | 65 { |
| 69 if (!emailTextbox.value) | 66 if (!emailTextbox.value) |
| 70 addPlaceholder(emailTextbox); | 67 addPlaceholder(emailTextbox); |
| 71 }, false); | 68 }, false); |
| 72 } | 69 } |
| 73 | 70 |
| 74 addListener(document.getElementById("edge-subscription"). | 71 var formElement = subscriptionElement.getElementsByTagName("form")[0]; |
|
saroyanm
2015/09/24 14:52:05
please assign form element to variable and reuse i
| |
| 75 getElementsByTagName("form")[0], "submit", function() | 72 addListener(formElement, "submit", function() |
| 76 { | 73 { |
| 77 var formElement = document.getElementById("edge-subscription"). | |
| 78 getElementsByTagName("form")[0]; | |
| 79 if (!window.XMLHttpRequest) | 74 if (!window.XMLHttpRequest) |
| 80 { | 75 { |
| 81 formElement.submit(); | 76 formElement.submit(); |
| 82 return false; | 77 return false; |
| 83 } | 78 } |
| 84 | 79 |
| 85 var pathArray = window.location.pathname.split("/"); | 80 var inputs = formElement.getElementsByTagName("input"); |
| 86 var params = emailTextbox.name + "=" + encodeURIComponent(emailTextbox.val ue); | 81 var params = ""; |
| 87 params += "&lang=" + pathArray[1]; | 82 for (var i = 0; i < inputs.length; i++) |
|
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"; | 83 { |
|
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
| |
| 84 if (params) | |
| 85 params += "&"; | |
| 86 params += inputs[i].name + "=" + encodeURIComponent(inputs[i].value); | |
| 87 } | |
| 89 var request = new XMLHttpRequest(); | 88 var request = new XMLHttpRequest(); |
| 90 request.open("POST", formElement.action, true); | 89 request.open("POST", "/submitEmail", true); |
| 91 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d"); | 90 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d"); |
| 92 addListener(request, "readystatechange", function() | 91 addListener(request, "readystatechange", function() |
| 93 { | 92 { |
| 94 if (request.readyState == 4) | 93 if (request.readyState == 4) |
| 95 { | 94 { |
| 96 if (request.status >= 200 && request.status < 300) | 95 if (request.status >= 200 && request.status < 300) |
| 97 { | 96 { |
| 98 formElement.setAttribute("class", "success"); | 97 formElement.setAttribute("class", "success"); |
| 99 } | 98 } |
| 100 else if (request.status == 400) | 99 else if (request.status == 400) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 { | 139 { |
| 141 var content = document.getElementById("content"); | 140 var content = document.getElementById("content"); |
| 142 var ua = content.className.match(/ua\-([^\s]+)/); | 141 var ua = content.className.match(/ua\-([^\s]+)/); |
| 143 visibleTab = ua && ua[1] || "firefox"; | 142 visibleTab = ua && ua[1] || "firefox"; |
| 144 return visibleTab; | 143 return visibleTab; |
| 145 } | 144 } |
| 146 | 145 |
| 147 function init() | 146 function init() |
| 148 { | 147 { |
| 149 container = document.getElementById("more-container"); | 148 container = document.getElementById("more-container"); |
| 150 contentLoad(); | 149 initSubscriptionForm(document.getElementById("edge-subscription")); |
| 151 } | 150 } |
| 152 | 151 |
| 153 init(); | 152 init(); |
| 154 })(); | 153 })(); |
| LEFT | RIGHT |