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: Addressing comments. Created Aug. 26, 2015, 12:17 a.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();
39 }
40
41 function getPlaceholderText()
42 {
43 return document.getElementById("subscribe-textbox").getAttribute("placeholde r");
44 }
45
46 function contentLoad()
47 {
48 var emailTextbox = document.getElementById("subscribe-textbox");
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())
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 addListener(document.getElementById("subscribe-form"), "submit", function()
72 {
73 var formElement = document.getElementById("subscribe-form");
74 if (!window.XMLHttpRequest)
75 {
76 formElement.submit();
77 return false;
78 }
79
80 var pathArray = window.location.pathname.split("/");
81 var params = emailTextbox.name + "=" + encodeURIComponent(emailTextbox.val ue);
82 params += "&lang=" + pathArray[1];
83 params += "&product=" + "edge";
84 var request = new XMLHttpRequest();
85 request.open("POST", formElement.action, true);
86 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d");
87 addListener(request, "readystatechange", function()
88 {
89 if (request.readyState == 4)
90 {
91 if (request.status >= 200 && request.status < 300)
92 {
93 formElement.setAttribute("class", "success");
94 }
95 else if (request.status == 400)
96 {
97 formElement.setAttribute("class", "invalid");
98 }
99 else
100 {
101 var errorWrapper = document.getElementById("response-error");
102 if ("textContent" in errorWrapper)
103 errorWrapper.textContent = request.statusText;
104 else // IE8
105 errorWrapper.innerText = request.statusText;
106
107 formElement.setAttribute("class", "error");
108 }
109 }
110 }, false);
111 request.send(params);
112 return false;
113 }, false);
114 }
115 addListener(document, "DOMContentLoaded", contentLoad, false);
116
117
3 var visibleTab; 118 var visibleTab;
4 var container; 119 var container;
5 120
6 window.toggleMore = function() 121 window.toggleMore = function()
7 { 122 {
8 if (container.className == "hidden") 123 if (container.className == "hidden")
9 container.className = visibleTab || getDefaultTab(); 124 container.className = visibleTab || getDefaultTab();
10 else 125 else
11 container.className = "hidden"; 126 container.className = "hidden";
12 } 127 }
13 128
14 window.showTab = function(button) 129 window.showTab = function(button)
15 { 130 {
16 var id = button.id.substr(5); 131 var id = button.id.substr(5);
17 container.className = id; 132 container.className = id;
18 visibleTab = id; 133 visibleTab = id;
19 } 134 }
20 135
21 function getDefaultTab() 136 function getDefaultTab()
22 { 137 {
23 var content = document.getElementById("content"); 138 var content = document.getElementById("content");
24 var ua = content.className.match(/ua\-([^\s]+)/); 139 var ua = content.className.match(/ua\-([^\s]+)/);
25 visibleTab = ua && ua[1] || "firefox"; 140 visibleTab = ua && ua[1] || "firefox";
26 return visibleTab; 141 return visibleTab;
27 } 142 }
28 143
29 function init() 144 function init()
30 { 145 {
31 container = document.getElementById("more-container"); 146 container = document.getElementById("more-container");
32 } 147 }
33 148
34 init(); 149 init();
35 })(); 150 })();
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