Skip to content

Commit

Permalink
Cleaned some of the search code up
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Brosset committed Oct 20, 2014
1 parent aeecbc7 commit 515cd53
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions data/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ PageRecorderPanel.prototype = {
this.recordsEl = this.doc.querySelector(".records");
this.screenshotEl = this.doc.querySelector(".screenshots img");
this.toggleEl = this.doc.querySelector("#toggle");
this.searchBox = this.doc.querySelector("#search-input");
this.searchBoxEl = this.doc.querySelector("#search-input");

this.toggleEl.addEventListener("click", this.toggle);
this.searchBox.addEventListener("input", this.search);
this.searchBoxEl.addEventListener("input", this.search);
},

toggle() {
Expand All @@ -61,8 +61,8 @@ PageRecorderPanel.prototype = {

this.toggleEl.setAttribute("checked", "true")
this.recordsEl.innerHTML = "";
this.searchBox.value = "";
this.searchBox.disabled = true;
this.searchBoxEl.value = "";
this.searchBoxEl.disabled = true;
this.mm.sendAsyncMessage("PageRecorder:Start");
},

Expand All @@ -73,21 +73,22 @@ PageRecorderPanel.prototype = {
this.isStarted = false;

this.toggleEl.removeAttribute("checked");
this.searchBox.removeAttribute("disabled");
this.searchBoxEl.removeAttribute("disabled");
this.mm.sendAsyncMessage("PageRecorder:Stop");
},

search() {
let query = this.searchBox.value.toLowerCase();
if(!this.recordsEl.mozMatchesSelector(":empty") || !this.recordsEl.matches(":empty")) {
[].forEach.call(this.recordsEl.querySelectorAll("li"), function(el) {
if(query == "" || el.textContent.toLowerCase().indexOf(query) > -1) {
el.style.removeProperty("display");
}
else {
el.style.display = "none";
}
});
let query = this.searchBoxEl.value.toLowerCase();
if (query === "" || !this.recordsEl.children.length) {
return;
}

for (let el of this.recordsEl.querySelectorAll("li")) {
if(el.textContent.toLowerCase().indexOf(query) > -1) {
el.style.removeProperty("display");
} else {
el.style.display = "none";
}
}
},

Expand Down

0 comments on commit 515cd53

Please sign in to comment.