Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: static/js/index.js

Issue 29322769: Issue 2844 - Create Microsoft Edge coming soon landing page (Closed)
Patch Set: Do not use IDs in HTML, consider RTL and more comments addressing. Created Sept. 24, 2015, 2:30 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« static/css/index-mobile.css ('K') | « static/img/sprite-index.png ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: static/js/index.js
===================================================================
--- a/static/js/index.js
+++ b/static/js/index.js
@@ -1,8 +1,126 @@
(function()
{
+ function addListener(obj, type, listener, useCapture)
+ {
+ 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("edge-subscription").
saroyanm 2015/09/24 14:52:04 You can assign the element to the variable and reu
+ getElementsByClassName("subscribe-textbox")[0].
+ getAttribute("placeholder");
+ }
+
+ function contentLoad()
+ {
+ var emailTextbox = document.getElementById("edge-subscription").
+ getElementsByClassName("subscribe-textbox")[0];
+
+ // 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("edge-subscription").
saroyanm 2015/09/24 14:52:05 please assign form element to variable and reuse i
+ getElementsByTagName("form")[0], "submit", function()
+ {
+ var formElement = document.getElementById("edge-subscription").
+ getElementsByTagName("form")[0];
+ if (!window.XMLHttpRequest)
+ {
+ formElement.submit();
+ return false;
+ }
+
+ var pathArray = window.location.pathname.split("/");
+ var params = emailTextbox.name + "=" + encodeURIComponent(emailTextbox.value);
+ params += "&lang=" + pathArray[1];
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
+ params += "&product=" + "edge";
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
+ 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);
+ }
+
var visibleTab;
var container;
-
+
window.toggleMore = function()
{
if (container.className == "hidden")
@@ -10,14 +128,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 +143,12 @@
visibleTab = ua && ua[1] || "firefox";
return visibleTab;
}
-
+
function init()
{
container = document.getElementById("more-container");
+ contentLoad();
}
-
+
init();
})();
« static/css/index-mobile.css ('K') | « static/img/sprite-index.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld