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

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

Issue 29330735: Issue 3346 - Remove edge subscription form (Closed)
Patch Set: Add replacement message Created Nov. 25, 2015, 5:11 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/css/index-mobile.css ('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.querySelectorAll(".subscribe-textbox" )[0];
49 var reset = subscriptionElement.querySelectorAll(".reset-form")[0];
50
51 // IE9 + Safari iOS
52 if (!("placeholder" in document.createElement("input"))
53 && !emailTextbox.value)
54 {
55 addPlaceholder(emailTextbox);
56 addListener(emailTextbox, "focus", function()
57 {
58 if (emailTextbox.value == getPlaceholderText(emailTextbox))
59 {
60 emailTextbox.value = "";
61 emailTextbox.setAttribute("class", "");
62 }
63 }, false);
64
65 addListener(emailTextbox, "blur", function()
66 {
67 if (!emailTextbox.value)
68 addPlaceholder(emailTextbox);
69 }, false);
70 }
71
72 var formElement = subscriptionElement.getElementsByTagName("form")[0];
73 addListener(formElement, "submit", function()
74 {
75 if (!window.XMLHttpRequest)
76 {
77 formElement.submit();
78 return false;
79 }
80
81 var inputs = formElement.getElementsByTagName("input");
82 var params = "";
83 for (var i = 0; i < inputs.length; i++)
84 {
85 if (params)
86 params += "&";
87 params += inputs[i].name + "=" + encodeURIComponent(inputs[i].value);
88 }
89 var request = new XMLHttpRequest();
90 request.open("POST", "/submitEmail", true);
91 request.setRequestHeader("Content-Type", "application/x-www-form-urlencode d");
92 addListener(request, "readystatechange", function()
93 {
94 if (request.readyState == 4)
95 {
96 if (request.status >= 200 && request.status < 300)
97 {
98 formElement.setAttribute("class", "success");
99 }
100 else if (request.status == 400)
101 {
102 formElement.setAttribute("class", "invalid");
103 }
104 else
105 {
106 var errorWrapper = document.getElementById("response-error");
107 if ("textContent" in errorWrapper)
108 errorWrapper.textContent = request.statusText;
109 else // IE8
110 errorWrapper.innerText = request.statusText;
111
112 formElement.setAttribute("class", "error");
113 }
114 }
115 }, false);
116 request.send(params);
117 return false;
118 }, false);
119
120 addListener(reset, "click", function()
121 {
122 formElement.removeAttribute("class");
123 return false;
124 }, false);
125 }
126
127 var visibleTab; 3 var visibleTab;
128 var container; 4 var container;
129 5
130 window.toggleMore = function() 6 window.toggleMore = function()
131 { 7 {
132 if (container.className == "hidden") 8 if (container.className == "hidden")
133 container.className = visibleTab || getDefaultTab(); 9 container.className = visibleTab || getDefaultTab();
134 else 10 else
135 container.className = "hidden"; 11 container.className = "hidden";
136 } 12 }
137 13
138 window.showTab = function(button) 14 window.showTab = function(button)
139 { 15 {
140 var id = button.id.substr(5); 16 var id = button.id.substr(5);
141 container.className = id; 17 container.className = id;
142 visibleTab = id; 18 visibleTab = id;
143 } 19 }
144 20
145 function getDefaultTab() 21 function getDefaultTab()
146 { 22 {
147 var content = document.getElementById("content"); 23 var content = document.getElementById("content");
148 var ua = content.className.match(/ua\-([^\s]+)/); 24 var ua = content.className.match(/ua\-([^\s]+)/);
149 visibleTab = ua && ua[1] || "firefox"; 25 visibleTab = ua && ua[1] || "firefox";
150 return visibleTab; 26 return visibleTab;
151 } 27 }
152 28
153 function init() 29 function init()
154 { 30 {
155 container = document.getElementById("more-container"); 31 container = document.getElementById("more-container");
156 initSubscriptionForm(document.getElementById("edge-subscription"));
157 } 32 }
158 33
159 init(); 34 init();
160 })(); 35 })();
OLDNEW
« no previous file with comments | « static/css/index-mobile.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld