From 36a70fa612811a12c600e55657bd56b9bbfbc252 Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 8 May 2015 18:07:33 +0300 Subject: [PATCH] Manager: search styles filter --- _locales/en/messages.json | 4 ++++ manage.html | 10 ++++++++++ manage.js | 40 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a5b09863..b087bb83 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -221,6 +221,10 @@ "message": "Use /re/ syntax for regexp search", "description": "Label after the search input field in the editor shown on Ctrl-F" }, + "searchStyles": { + "message": "Search contents", + "description": "Label for the search filter textbox on the Manage styles page" + }, "sectionAdd": { "message": "Add another section", "description": "Label for the button to add a section" diff --git a/manage.html b/manage.html index b4b0c34f..59134c6f 100644 --- a/manage.html +++ b/manage.html @@ -119,6 +119,15 @@ .enabled-only > .disabled, .edited-only > [style-update-url] { display: none; } + + #search { + width: calc(100% - 4px); + margin: 0.25rem 4px 0; + border-radius: 0.25rem; + padding-left: 0.25rem; + border-width: 1px; + } + @@ -134,6 +143,7 @@
+

diff --git a/manage.js b/manage.js index 84a8b871..79bd7a2d 100644 --- a/manage.js +++ b/manage.js @@ -430,8 +430,48 @@ function jsonEquals(a, b, property) { } } +function searchStyles(immediately) { + var query = document.getElementById("search").value.toLocaleLowerCase(); + if (query == (searchStyles.lastQuery || "")) { + return; + } + searchStyles.lastQuery = query; + if (immediately) { + doSearch(); + } else { + clearTimeout(searchStyles.timeout); + searchStyles.timeout = setTimeout(doSearch, 100); + } + function doSearch() { + chrome.extension.sendMessage({method: "getStyles"}, function(styles) { + styles.forEach(function(style) { + var el = document.querySelector("[style-id='" + style.id + "']"); + if (el) { + el.style.display = !query || isMatchingText(style.name) || isMatchingStyle(style) ? "" : "none"; + } + }); + }); + } + function isMatchingStyle(style) { + return style.sections.some(function(section) { + return Object.keys(section).some(function(key) { + var value = section[key]; + switch (typeof value) { + case "string": return isMatchingText(value); + case "object": return value.some(isMatchingText); + } + }); + }); + } + function isMatchingText(text) { + return text.toLocaleLowerCase().indexOf(query) >= 0; + } +} + document.getElementById("check-all-updates").addEventListener("click", checkUpdateAll, false); document.getElementById("apply-all-updates").addEventListener("click", applyUpdateAll, false); +document.getElementById("search").addEventListener("input", searchStyles); +searchStyles(true); // re-apply filtering on history Back function onFilterChange (className, event) { installed.classList.toggle(className, event.target.checked);