Index: background.js |
=================================================================== |
--- a/background.js |
+++ b/background.js |
@@ -292,16 +292,67 @@ |
iconAnimation.update(activeNotification.severity); |
} |
+function notificationWindowClick() { |
Thomas Greiner
2014/02/17 10:02:41
Nit: Bracket on next line
saroyanm
2014/02/18 10:25:08
Done.
|
+ if (activeNotification.links) |
+ { |
+ activeNotification.links.forEach(function(link) |
+ { |
+ chrome.tabs.create({ url: Utils.getDocLink(link) }); |
Thomas Greiner
2014/02/17 10:02:41
This is Chrome-specific. We do have an "openTab" m
saroyanm
2014/02/18 10:25:08
Done.
|
+ }); |
+ } |
+ prepareNotificationIconAndPopup(); |
+} |
+ |
+function notificationButtonClick(id, index) { |
Thomas Greiner
2014/02/17 10:02:41
Nit: Bracket on next line
saroyanm
2014/02/18 10:25:08
Done.
|
+ chrome.tabs.create({url: Utils.getDocLink(activeNotification.links[index])}); |
Thomas Greiner
2014/02/17 10:02:41
This is Chrome-specific. We do have an "openTab" m
saroyanm
2014/02/18 10:25:08
Done.
|
+ prepareNotificationIconAndPopup(); |
+} |
+ |
function showNotification(notification) |
{ |
activeNotification = notification; |
- |
- if (activeNotification.severity === "critical" |
- && typeof webkitNotifications !== "undefined") |
+ if (activeNotification.severity === "critical") |
{ |
- var notification = webkitNotifications.createHTMLNotification("notification.html"); |
- notification.show(); |
- notification.addEventListener("close", prepareNotificationIconAndPopup); |
+ var isWebkit = typeof webkitNotifications !== "undefined"; |
Thomas Greiner
2014/02/17 10:02:41
All browsers based on this repository use WebKit s
saroyanm
2014/02/18 10:25:08
Done.
|
+ if (isWebkit && "createHTMLNotification" in webkitNotifications) |
+ { |
+ notification = webkitNotifications.createHTMLNotification("notification.html"); |
+ notification.show(); |
+ notification.addEventListener("close", prepareNotificationIconAndPopup); |
+ return; |
+ } |
+ |
+ var texts = Notification.getLocalizedTexts(notification); |
+ var title = texts.title ? texts.title : ""; |
+ var message = texts.message ? texts.message : ""; |
+ var iconUrl = "icons/abp-128.png"; |
+ if ("notifications" in chrome) |
Thomas Greiner
2014/02/17 10:02:41
This is Chrome-specific but the adblockpluschrome
saroyanm
2014/02/18 10:25:08
Thanks, for pointing this, now I see what is under
Thomas Greiner
2014/02/18 14:26:17
That's OK for now. We can add a Safari-specific im
|
+ { |
+ var buttons = []; |
+ var links = notification.links; |
+ links.forEach(function(link, index){ |
Thomas Greiner
2014/02/17 10:02:41
Nit: Missing space after closing bracket.
|
+ buttons.push({"title": link.replace(new RegExp("_", 'g'), " ")}); |
Thomas Greiner
2014/02/17 10:02:41
The link texts can actually be extracted from the
saroyanm
2014/02/18 10:25:08
Maybe it make sense also to remove anchors with th
|
+ }); |
+ var opt = { |
+ type: "basic", |
+ title: title, |
+ message: message, |
+ iconUrl: iconUrl, |
Thomas Greiner
2014/02/17 10:02:41
You can directly inline "title", "message" and "ic
Thomas Greiner
2014/02/17 10:02:41
Use |ext.getURL("icons/abp-128.png")| as the icon
saroyanm
2014/02/18 10:25:08
while I've added also else case I'm using that var
Thomas Greiner
2014/02/18 14:26:17
Right, that's fine then. Although you could write
|
+ buttons: buttons |
+ }; |
+ notification = chrome.notifications; |
Thomas Greiner
2014/02/17 10:02:41
Avoid creating global variables by adding "var".
saroyanm
2014/02/18 10:25:08
Done.
|
+ notification.create("", opt, function(){}); |
Thomas Greiner
2014/02/17 10:02:41
Nit: Missing space after closing bracket.
saroyanm
2014/02/18 10:25:08
Done.
|
+ notification.onClosed.addListener(prepareNotificationIconAndPopup); |
+ notification.onClicked.addListener(notificationWindowClick); |
+ notification.onButtonClicked.addListener(notificationButtonClick); |
+ } |
+ else if (isWebkit && "createNotification" in webkitNotifications) |
+ { |
+ notification = webkitNotifications.createNotification(iconUrl, title, message); |
+ notification.show(); |
+ notification.addEventListener("close", prepareNotificationIconAndPopup); |
Thomas Greiner
2014/02/17 10:02:41
Nit: Add third parameter
saroyanm
2014/02/18 10:25:08
Done.
|
+ notification.addEventListener("click", notificationWindowClick); |
Thomas Greiner
2014/02/17 10:02:41
Nit: Add third parameter
saroyanm
2014/02/18 10:25:08
Done.
|
+ } |
Thomas Greiner
2014/02/17 10:02:41
What about the "else" case here?
saroyanm
2014/02/18 10:25:08
Added also confirm dialog for else case, thanks fo
|
} |
else |
prepareNotificationIconAndPopup(); |