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

Side by Side Diff: static/js/index.js

Issue 29322769: Issue 2844 - Create Microsoft Edge coming soon landing page (Closed)
Patch Set: Reorganize some CSS rules. Created Sept. 30, 2015, 2:29 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « static/img/sprite-index.png ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function() 1 (function()
2 { 2 {
3 function addListener(obj, type, listener, useCapture)
4 {
5 if ("addEventListener" in obj)
6 {
7 obj.addEventListener(type, function(ev)
8 {
9 if (listener(ev) === false)
10 ev.preventDefault();
11 }, useCapture);
12 }
13 else
14 {
15 // IE 8
16 if (type == "DOMContentLoaded")
17 type = "readystatechange";
18
19 type = "on" + type;
20 if ("attachEvent" in obj)
21 {
22 obj.attachEvent(type, function()
23 {
24 if (document.readyState == "complete" && listener(event) === false)
25 event.returnValue = false;
26 });
27 }
28 else
29 {
30 obj[type] = listener;
31 }
32 }
33 }
34
35 function addPlaceholder(textbox)
36 {
37 textbox.setAttribute("class", "placeholder");
38 textbox.value = getPlaceholderText(textbox);
39 }
40
41 function getPlaceholderText(textbox)
42 {
43 return textbox.getAttribute("placeholder");
44 }
45
46 function initSubscriptionForm(subscriptionElement)
47 {
48 var emailTextbox = subscriptionElement.getElementsByClassName("subscribe-tex tbox")[0];
49
50 // IE9 + Safari iOS
51 if (!("placeholder" in document.createElement("input"))
52 && !emailTextbox.value)
53 {
54 addPlaceholder(emailTextbox);
55 addListener(emailTextbox, "focus", function()
56 {
57 if (emailTextbox.value == getPlaceholderText(textbox))
58 {
59 emailTextbox.value = "";
60 emailTextbox.setAttribute("class", "");
61 }
62 }, false);
63
64 addListener(emailTextbox, "blur", function()
65 {
66 if (!emailTextbox.value)
67 addPlaceholder(emailTextbox);
68 }, false);
69 }
70
71 var formElement = subscriptionElement.getElementsByTagName("form")[0];
72 addListener(formElement, "submit", function()
73 {
74 if (!window.XMLHttpRequest)
75 {
76 formElement.submit();
77 return false;
78 }
79
80 var inputs = formElement.getElementsByTagName("input");
81 var params = "";
82 for (var i = 0; i < inputs.length; i++)
83 {
84 if (params)
85 params += "&";
86 params += inputs[i].name + "=" + encodeURIComponent(inputs[i].value);
87 }
88 var request = new XMLHttpRequest();
89 request.open("POST", "/submitEmail", true);
90 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d");
91 addListener(request, "readystatechange", function()
92 {
93 if (request.readyState == 4)
94 {
95 if (request.status >= 200 && request.status < 300)
96 {
97 formElement.setAttribute("class", "success");
98 }
99 else if (request.status == 400)
100 {
101 formElement.setAttribute("class", "invalid");
102 }
103 else
104 {
105 var errorWrapper = document.getElementById("response-error");
106 if ("textContent" in errorWrapper)
107 errorWrapper.textContent = request.statusText;
108 else // IE8
109 errorWrapper.innerText = request.statusText;
110
111 formElement.setAttribute("class", "error");
112 }
113 }
114 }, false);
115 request.send(params);
116 return false;
117 }, false);
118 }
119
3 var visibleTab; 120 var visibleTab;
4 var container; 121 var container;
5 122
6 window.toggleMore = function() 123 window.toggleMore = function()
7 { 124 {
8 if (container.className == "hidden") 125 if (container.className == "hidden")
9 container.className = visibleTab || getDefaultTab(); 126 container.className = visibleTab || getDefaultTab();
10 else 127 else
11 container.className = "hidden"; 128 container.className = "hidden";
12 } 129 }
13 130
14 window.showTab = function(button) 131 window.showTab = function(button)
15 { 132 {
16 var id = button.id.substr(5); 133 var id = button.id.substr(5);
17 container.className = id; 134 container.className = id;
18 visibleTab = id; 135 visibleTab = id;
19 } 136 }
20 137
21 function getDefaultTab() 138 function getDefaultTab()
22 { 139 {
23 var content = document.getElementById("content"); 140 var content = document.getElementById("content");
24 var ua = content.className.match(/ua\-([^\s]+)/); 141 var ua = content.className.match(/ua\-([^\s]+)/);
25 visibleTab = ua && ua[1] || "firefox"; 142 visibleTab = ua && ua[1] || "firefox";
26 return visibleTab; 143 return visibleTab;
27 } 144 }
28 145
29 function init() 146 function init()
30 { 147 {
31 container = document.getElementById("more-container"); 148 container = document.getElementById("more-container");
149 initSubscriptionForm(document.getElementById("edge-subscription"));
32 } 150 }
33 151
34 init(); 152 init();
35 })(); 153 })();
OLDNEW
« no previous file with comments | « static/img/sprite-index.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld