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

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

Issue 29630614: [Demo] Issue 6047 - Missing background on uninstallation page (Closed) Base URL: https://hg.adblockplus.org/web.adblockplus.org
Patch Set: Created Dec. 5, 2017, 10:25 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/css/uninstalled.css ('k') | templates/default.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 (function()
2 {
3 var adblockersList = null;
4 function toggleView(element)
5 {
6 var targetId = element.getAttribute("data-toggle-view");
7 if (targetId)
8 document.getElementById(targetId).classList.toggle("hidden");
9 }
10
11 function checkSelectedAdblocker()
12 {
13 var selectedOption = adblockersList[adblockersList.selectedIndex];
14 var element = selectedOption.getAttribute("data-show-element");
15 if (element)
16 document.getElementById(element).classList.remove("hidden");
17 else
18 {
19 element = selectedOption.getAttribute("data-hide-element");
20 document.getElementById(element).classList.add("hidden");
21 }
22 }
23
24 function init()
25 {
26 var form = document.getElementById("reasons-form");
27
28 // Create hidden input for GET parameters
29 window.location.search.substr(1).split("&").forEach(function(param)
30 {
31 if (!/.=./.test(param))
32 return;
33
34 var paramSplit = param.split("=");
35 var input = document.createElement("input");
36 input.setAttribute("type", "hidden");
37 input.setAttribute("name", decodeURIComponent(paramSplit[0]));
38 input.setAttribute("value", decodeURIComponent(paramSplit[1]));
39 form.appendChild(input);
40 });
41
42 // Randomly add reasons
43 var reasonsContainer = document.getElementById("reasons");
44 var reasons = document.querySelectorAll("#reasons > li");
45 reasons = Array.prototype.slice.call(reasons);
46 reasonsContainer.innerHTML = "";
47 while (reasons.length)
48 {
49 var randomIndex = Math.floor(Math.random() * (reasons.length -1));
50 var reasonElement = reasons.splice(randomIndex, 1)[0];
51 reasonsContainer.appendChild(reasonElement);
52 var checkbox = reasonElement.querySelector("input[type=checkbox]");
53 if (checkbox.checked)
54 toggleView(checkbox);
55
56 checkbox.addEventListener("change", function(event)
57 {
58 toggleView(event.target);
59 }, false);
60 }
61
62 adblockersList = document.querySelector("#adblockers select");
63 adblockersList.addEventListener("change", function()
64 {
65 checkSelectedAdblocker();
66 }, false);
67 checkSelectedAdblocker();
68
69 var reasonOtherInput = document.getElementById("reason-other-input");
70 var maxLength = reasonOtherInput.getAttribute("maxlength");
71 var charCounter = document.getElementById("characters-countdown");
72 charCounter.textContent = maxLength;
73 reasonOtherInput.addEventListener("keyup", function()
74 {
75 charCounter.textContent = maxLength - reasonOtherInput.value.length;
76 }, false);
77
78 var submitButton = document.getElementById("reason-submit");
79 submitButton.addEventListener("click", function(event)
80 {
81 if (!document.querySelector("ul input:checked"))
82 {
83 event.preventDefault();
84 form.setAttribute("class", "error");
85 }
86 else
87 {
88 form.submit();
89 }
90 }, false);
91 }
92 document.addEventListener("DOMContentLoaded", init, false);
93 })();
OLDNEW
« no previous file with comments | « static/css/uninstalled.css ('k') | templates/default.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld