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 more comments. Created Sept. 23, 2015, 12:36 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
« static/css/index-mobile.css ('K') | « 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
3 var visibleTab; 116 var visibleTab;
4 var container; 117 var container;
5 118
6 window.toggleMore = function() 119 window.toggleMore = function()
7 { 120 {
8 if (container.className == "hidden") 121 if (container.className == "hidden")
9 container.className = visibleTab || getDefaultTab(); 122 container.className = visibleTab || getDefaultTab();
10 else 123 else
11 container.className = "hidden"; 124 container.className = "hidden";
12 } 125 }
13 126
14 window.showTab = function(button) 127 window.showTab = function(button)
15 { 128 {
16 var id = button.id.substr(5); 129 var id = button.id.substr(5);
17 container.className = id; 130 container.className = id;
18 visibleTab = id; 131 visibleTab = id;
19 } 132 }
20 133
21 function getDefaultTab() 134 function getDefaultTab()
22 { 135 {
23 var content = document.getElementById("content"); 136 var content = document.getElementById("content");
24 var ua = content.className.match(/ua\-([^\s]+)/); 137 var ua = content.className.match(/ua\-([^\s]+)/);
25 visibleTab = ua && ua[1] || "firefox"; 138 visibleTab = ua && ua[1] || "firefox";
26 return visibleTab; 139 return visibleTab;
27 } 140 }
28 141
29 function init() 142 function init()
30 { 143 {
31 container = document.getElementById("more-container"); 144 container = document.getElementById("more-container");
145 contentLoad();
32 } 146 }
33 147
34 init(); 148 init();
35 })(); 149 })();
OLDNEW
« 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