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

Side by Side Diff: notification.js

Issue 29326181: Issue 3022 - Implemented new notification type for normal messages (Closed)
Patch Set: Created Sept. 10, 2015, 1:37 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
« lib/notificationHelper.js ('K') | « lib/notificationHelper.js ('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 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var backgroundPage = ext.backgroundPage.getWindow(); 18 var backgroundPage = ext.backgroundPage.getWindow();
19 var require = backgroundPage.require; 19 var require = backgroundPage.require;
20 20
21 var Utils = require("utils").Utils; 21 var Utils = require("utils").Utils;
22 var Notification = require("notification").Notification; 22 var Notification = require("notification").Notification;
23 var getActiveNotification = require("notificationHelper").getActiveNotification; 23 var notificationHelper = require("notificationHelper");
24 var getActiveNotification = notificationHelper.getActiveNotification;
25 var shouldDisplayNotification = notificationHelper.shouldDisplay;
24 26
25 function getDocLinks(notification) 27 function getDocLinks(notification)
26 { 28 {
27 if (!notification.links) 29 if (!notification.links)
28 return []; 30 return [];
29 31
30 var docLinks = []; 32 var docLinks = [];
31 notification.links.forEach(function(link) 33 notification.links.forEach(function(link)
32 { 34 {
33 docLinks.push(Utils.getDocLink(link)); 35 docLinks.push(Utils.getDocLink(link));
(...skipping 22 matching lines...) Expand all
56 newElement.href = links.shift(); 58 newElement.href = links.shift();
57 insertMessage(newElement, value, links); 59 insertMessage(newElement, value, links);
58 element.appendChild(newElement); 60 element.appendChild(newElement);
59 61
60 insertMessage(element, after, links); 62 insertMessage(element, after, links);
61 } 63 }
62 64
63 window.addEventListener("load", function() 65 window.addEventListener("load", function()
64 { 66 {
65 var notification = getActiveNotification(); 67 var notification = getActiveNotification();
66 if (!notification) 68 if (!notification || !shouldDisplayNotification("popup", notification.type))
67 return; 69 return;
68 70
69 var texts = Notification.getLocalizedTexts(notification); 71 var texts = Notification.getLocalizedTexts(notification);
70 var titleElement = document.getElementById("notification-title"); 72 var titleElement = document.getElementById("notification-title");
71 titleElement.textContent = texts.title; 73 titleElement.textContent = texts.title;
72 74
73 var docLinks = getDocLinks(notification); 75 var docLinks = getDocLinks(notification);
74 var messageElement = document.getElementById("notification-message"); 76 var messageElement = document.getElementById("notification-message");
75 insertMessage(messageElement, texts.message, docLinks); 77 insertMessage(messageElement, texts.message, docLinks);
76 78
77 messageElement.addEventListener("click", function(event) 79 messageElement.addEventListener("click", function(event)
78 { 80 {
79 var link = event.target; 81 var link = event.target;
80 while (link && link !== messageElement && link.localName !== "a") 82 while (link && link !== messageElement && link.localName !== "a")
81 link = link.parentNode; 83 link = link.parentNode;
82 if (!link) 84 if (!link)
83 return; 85 return;
84 event.preventDefault(); 86 event.preventDefault();
85 event.stopPropagation(); 87 event.stopPropagation();
86 ext.pages.open(link.href); 88 ext.pages.open(link.href);
87 }); 89 });
88 90
89 if (notification.type == "question")
90 {
91 document.getElementById("notification-question").addEventListener("click", f unction(event)
92 {
93 event.preventDefault();
94 event.stopPropagation();
95
96 var approved = false;
97 switch (event.target.id)
98 {
99 case "notification-yes":
100 approved = true;
101 case "notification-no":
102 Notification.triggerQuestionListeners(notification.id, approved);
103 Notification.markAsShown(notification.id);
104 notification.onClicked();
105 break;
106 }
107 window.close();
108 }, true);
109 }
110
111 var notificationElement = document.getElementById("notification"); 91 var notificationElement = document.getElementById("notification");
112 notificationElement.className = notification.type; 92 notificationElement.className = notification.type;
113 notificationElement.hidden = false; 93 notificationElement.hidden = false;
114 notificationElement.addEventListener("click", function(event) 94 notificationElement.addEventListener("click", function(event)
115 { 95 {
116 switch (event.target.id) 96 switch (event.target.id)
117 { 97 {
118 case "notification-close": 98 case "notification-close":
119 notificationElement.classList.add("closing"); 99 notificationElement.classList.add("closing");
120 break; 100 break;
121 case "notification-optout": 101 case "notification-optout":
122 Notification.toggleIgnoreCategory("*", true); 102 Notification.toggleIgnoreCategory("*", true);
123 case "notification-hide": 103 case "notification-hide":
124 notificationElement.hidden = true; 104 notificationElement.hidden = true;
125 notification.onClicked(); 105 notification.onClicked();
126 break; 106 break;
127 } 107 }
128 }, true); 108 }, true);
129 }, false); 109 }, false);
OLDNEW
« lib/notificationHelper.js ('K') | « lib/notificationHelper.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld