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

Side by Side Diff: notification.js

Issue 29570774: Issue 5593 - Merge notification.js and stats.js into popup.js (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Rename ev to event Created Oct. 10, 2017, 5: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 | « ext/popup.js ('k') | popup.html » ('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 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 /* global setPref */
19
20 "use strict";
21
22 function getDocLinks(notification)
23 {
24 if (!notification.links)
25 return Promise.resolve([]);
26
27 return Promise.all(
28 notification.links.map(link =>
29 {
30 return new Promise((resolve, reject) =>
31 {
32 chrome.runtime.sendMessage({
33 type: "app.get",
34 what: "doclink",
35 link
36 }, resolve);
37 });
38 })
39 );
40 }
41
42 function insertMessage(element, text, links)
43 {
44 let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(text);
45 if (!match)
46 {
47 element.appendChild(document.createTextNode(text));
48 return;
49 }
50
51 let before = match[1];
52 let tagName = match[2];
53 let value = match[3];
54 let after = match[4];
55
56 insertMessage(element, before, links);
57
58 let newElement = document.createElement(tagName);
59 if (tagName == "a" && links && links.length)
60 newElement.href = links.shift();
61 insertMessage(newElement, value, links);
62 element.appendChild(newElement);
63
64 insertMessage(element, after, links);
65 }
66
67 window.addEventListener("load", () =>
68 {
69 chrome.runtime.sendMessage({
70 type: "notifications.get",
71 displayMethod: "popup"
72 }, notification =>
73 {
74 if (!notification)
75 return;
76
77 let titleElement = document.getElementById("notification-title");
78 let messageElement = document.getElementById("notification-message");
79
80 titleElement.textContent = notification.texts.title;
81
82 getDocLinks(notification).then(docLinks =>
83 {
84 insertMessage(messageElement, notification.texts.message, docLinks);
85
86 messageElement.addEventListener("click", event =>
87 {
88 let link = event.target;
89 while (link && link != messageElement && link.localName != "a")
90 link = link.parentNode;
91 if (!link)
92 return;
93 event.preventDefault();
94 event.stopPropagation();
95 chrome.tabs.create({url: link.href});
96 });
97 });
98
99 let notificationElement = document.getElementById("notification");
100 notificationElement.className = notification.type;
101 notificationElement.hidden = false;
102 notificationElement.addEventListener("click", event =>
103 {
104 if (event.target.id == "notification-close")
105 notificationElement.classList.add("closing");
106 else if (event.target.id == "notification-optout" ||
107 event.target.id == "notification-hide")
108 {
109 if (event.target.id == "notification-optout")
110 setPref("notifications_ignoredcategories", true);
111
112 notificationElement.hidden = true;
113 notification.onClicked();
114 }
115 }, true);
116 });
117 }, false);
OLDNEW
« no previous file with comments | « ext/popup.js ('k') | popup.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld