| Index: static/js/index.js |
| =================================================================== |
| --- a/static/js/index.js |
| +++ b/static/js/index.js |
| @@ -1,8 +1,123 @@ |
| (function() |
| { |
| + 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.
|
| + { |
| + if ("addEventListener" in obj) |
| + { |
| + obj.addEventListener(type, function(ev) |
| + { |
| + if (listener(ev) === false) |
| + ev.preventDefault(); |
| + }, useCapture); |
| + } |
| + else |
| + { |
| + // IE 8 |
| + if (type == "DOMContentLoaded") |
| + type = "readystatechange"; |
| + |
| + type = "on" + type; |
| + if ("attachEvent" in obj) |
| + { |
| + obj.attachEvent(type, function() |
| + { |
| + if (document.readyState == "complete" && listener(event) === false) |
| + event.returnValue = false; |
| + }); |
| + } |
| + else |
| + { |
| + obj[type] = listener; |
| + } |
| + } |
| + } |
| + |
| + function addPlaceholder(textbox) |
| + { |
| + textbox.setAttribute("class", "placeholder"); |
| + textbox.value = getPlaceholderText(); |
| + } |
| + |
| + function getPlaceholderText() |
| + { |
| + return document.getElementById("subscribe-textbox").getAttribute("placeholder"); |
| + } |
| + |
| + function contentLoad() |
| + { |
| + var emailTextbox = document.getElementById("subscribe-textbox"); |
| + |
| + // IE9 + Safari iOS |
| + if (!("placeholder" in document.createElement("input")) |
| + && !emailTextbox.value) |
| + { |
| + addPlaceholder(emailTextbox); |
| + addListener(emailTextbox, "focus", function() |
| + { |
| + if (emailTextbox.value == getPlaceholderText()) |
| + { |
| + emailTextbox.value = ""; |
| + emailTextbox.setAttribute("class", ""); |
| + } |
| + }, false); |
| + |
| + addListener(emailTextbox, "blur", function() |
| + { |
| + if (!emailTextbox.value) |
| + addPlaceholder(emailTextbox); |
| + }, false); |
| + } |
| + |
| + addListener(document.getElementById("subscribe-form"), "submit", function() |
| + { |
| + var formElement = document.getElementById("subscribe-form"); |
| + if (!window.XMLHttpRequest) |
| + { |
| + formElement.submit(); |
| + return false; |
| + } |
| + |
| + var pathArray = window.location.pathname.split("/"); |
| + var params = emailTextbox.name + "=" + encodeURIComponent(emailTextbox.value); |
| + params += "&lang=" + pathArray[1]; |
| + params += "&product=" + "edge"; |
| + var request = new XMLHttpRequest(); |
| + request.open("POST", formElement.action, true); |
| + request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
| + addListener(request, "readystatechange", function() |
| + { |
| + if (request.readyState == 4) |
| + { |
| + if (request.status >= 200 && request.status < 300) |
| + { |
| + formElement.setAttribute("class", "success"); |
| + } |
| + else if (request.status == 400) |
| + { |
| + formElement.setAttribute("class", "invalid"); |
| + } |
| + else |
| + { |
| + var errorWrapper = document.getElementById("response-error"); |
| + if ("textContent" in errorWrapper) |
| + errorWrapper.textContent = request.statusText; |
| + else // IE8 |
| + errorWrapper.innerText = request.statusText; |
| + |
| + formElement.setAttribute("class", "error"); |
| + } |
| + } |
| + }, false); |
| + request.send(params); |
| + return false; |
| + }, false); |
| + } |
| + addListener(document, "DOMContentLoaded", contentLoad, false); |
|
saroyanm
2015/09/22 13:15:46
Script is called after the content is loaded, so t
|
| + |
| + |
| var visibleTab; |
| var container; |
| - |
| + |
| window.toggleMore = function() |
| { |
| if (container.className == "hidden") |
| @@ -10,14 +125,14 @@ |
| else |
| container.className = "hidden"; |
| } |
| - |
| + |
| window.showTab = function(button) |
| { |
| var id = button.id.substr(5); |
| container.className = id; |
| visibleTab = id; |
| } |
| - |
| + |
| function getDefaultTab() |
| { |
| var content = document.getElementById("content"); |
| @@ -25,11 +140,11 @@ |
| visibleTab = ua && ua[1] || "firefox"; |
| return visibleTab; |
| } |
| - |
| + |
| function init() |
| { |
| container = document.getElementById("more-container"); |
| } |
| - |
| + |
| init(); |
| })(); |