Skip to content

Commit

Permalink
For #133, searching history items
Browse files Browse the repository at this point in the history
  • Loading branch information
a85 committed Jun 22, 2013
1 parent d517a24 commit d93404c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
24 changes: 23 additions & 1 deletion chrome/js/modules/history.js
Expand Up @@ -168,6 +168,28 @@ pm.history = {

filter: function(term) {
var requests = pm.history.requests;
return requests;
var count = requests.length;
var filteredItems = [];
for (var i = 0; i < count; i++) {
var id = requests[i].id;
var url = requests[i].url;

var filteredItem = {
id: id,
url: url,
toShow: false
};

if (url.indexOf(term) >= 0) {
filteredItem.toShow = true;
}
else {
filteredItem.toShow = false;
}

filteredItems.push(filteredItem);
}

return filteredItems;
}
};
25 changes: 24 additions & 1 deletion chrome/js/modules/search.js
Expand Up @@ -24,11 +24,34 @@ pm.search = {
}
else {
var filteredHistoryItems = pm.history.filter(term);
console.log(filteredHistoryItems);

if (filteredHistoryItems.length === 0) {

}
else {
pm.search.toggleHistoryItemVisibility(filteredHistoryItems);
}
}
},

toggleHistoryItemVisibility: function(filteredHistoryItems) {
console.log("Filter history items", filteredHistoryItems);
var count = filteredHistoryItems.length;
for(var i = 0; i < count; i++) {
var item = filteredHistoryItems[i];
var id = "#sidebar-request-" + item.id;

if(item.toShow) {
$(id).css("display", "block");
}
else {
$(id).css("display", "none");
}
}
},

revertSidebar: function() {
console.log("Reverting sidebar to original state");
$("#history-items li").css("display", "block");
}
};

0 comments on commit d93404c

Please sign in to comment.