Skip to content

Commit

Permalink
Add an observer to make sure the hide class is removed when necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Aug 12, 2015
1 parent ccc1fb0 commit c2ef507
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
27 changes: 23 additions & 4 deletions data/trello-counter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

self.port.on("cardCounterRefresh", function() {
function showCounters() {
var list = document.getElementsByClassName("list-header-num-cards");
if (list === null) setTimeout(showCounters, 100);
for (var i = 0; i < list.length; i++) {
list[i].classList.remove("hide");
if (list[i].classList.contains("hide")) {
list[i].classList.remove("hide");
}
}
});
}

function setupObserver() {
console.debug('Init observers');
var observer = new MutationObserver(function(mutations) {
console.debug("Mutation detected on num cards headers");
showCounters();
});
var list = document.querySelector('.list-header-num-cards');
if (list === null) setTimeout(setupObserver, 100);
observer.observe(list, {
attributes: true,
characterData: true
});
}

self.port.on("setupObserver", setupObserver);
self.port.on("cardCounterRefresh", showCounters);
1 change: 1 addition & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pageMod.PageMod({
include: "https://trello.com/b/*",
contentScriptFile: self.data.url("trello-counter.js"),
onAttach: function(worker) {
worker.port.emit("setupObserver");
worker.port.emit("cardCounterRefresh");
tabs.on('activate', function () {
worker.port.emit("cardCounterRefresh");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"description": "Display Trello list number of cards",
"author": "Rémy HUBSCHER <[email protected]>",
"license": "MPL 2.0",
"version": "0.2"
"version": "0.3"
}

0 comments on commit c2ef507

Please sign in to comment.