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

Unified Diff: popup.js

Issue 29338491: Issue 3823 - Split up message responder code (Closed)
Patch Set: Implement getPort() Created March 21, 2016, 3:25 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« lib/messaging.js ('K') | « metadata.common ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: popup.js
===================================================================
--- a/popup.js
+++ b/popup.js
@@ -23,6 +23,7 @@
var Prefs = require("prefs").Prefs;
var checkWhitelisted = require("whitelisting").checkWhitelisted;
var getDecodedHostname = require("url").getDecodedHostname;
+var getPort = require("messaging").getPort;
Wladimir Palant 2016/03/21 15:50:13 I'd really go with: var port = require("messagi
Sebastian Noack 2016/03/21 17:15:42 Well, the code below only runs once if at all. So
Wladimir Palant 2016/03/21 18:05:22 Why not call require only in that case then?
Sebastian Noack 2016/03/21 19:54:13 I lend towards having all imports at the beginning
var page = null;
@@ -37,7 +38,14 @@
page.url.protocol != "https:"))
document.body.classList.add("local");
else if (!backgroundPage.htmlPages.has(page))
+ {
document.body.classList.add("nohtml");
+ getPort(window).on("composer.ready", function(message, sender)
+ {
+ if (sender.page.id == page.id)
+ document.body.classList.remove("nohtml");
+ });
+ }
// Ask content script whether clickhide is active. If so, show cancel button.
// If that isn't the case, ask background.html whether it has cached filters. If so,
@@ -56,8 +64,6 @@
}
});
- // Attach event listeners
- ext.onMessage.addListener(onMessage);
document.getElementById("enabled").addEventListener("click", toggleEnabled, false);
document.getElementById("clickhide").addEventListener("click", activateClickHide, false);
document.getElementById("clickhide-cancel").addEventListener("click", cancelClickHide, false);
@@ -77,17 +83,6 @@
}
}
-function onUnload()
-{
- ext.onMessage.removeListener(onMessage);
-}
-
-function onMessage(message, sender, callback)
-{
- if (message.type == "composer.ready" && sender.page.id == page.id)
- document.body.classList.remove("nohtml");
-}
-
function toggleEnabled()
{
var disabled = document.body.classList.toggle("disabled");
@@ -145,4 +140,3 @@
}
document.addEventListener("DOMContentLoaded", onLoad, false);
-window.addEventListener("unload", onUnload, false);
« lib/messaging.js ('K') | « metadata.common ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld