Added search field to browser page popup

Fixes #268
This commit is contained in:
kkapsner 2018-10-09 12:59:53 +02:00
parent f5699a1bf3
commit eff86ce4ed
6 changed files with 40 additions and 7 deletions

View File

@ -46,4 +46,10 @@ div {
background-color: currentColor;
mask-size: 100%;
display: inline-block;
}
.search {
box-sizing: border-box;
padding-left: calc(0.5em + 19px + 0.25em);
cursor: initial;
}

View File

@ -79,5 +79,21 @@
actionButton.addEventListener("click", action.action);
actions.appendChild(actionButton);
});
var search = document.createElement("input");
search.placeholder = browser.i18n.getMessage("search");
search.className = "search action";
actions.appendChild(search);
search.focus();
search.addEventListener("keyup", function(event){
if ([10, 13].indexOf(event.keyCode) !== -1){
window.open(browser.extension.getURL(
"options/options.html" +
"?search=" +
encodeURIComponent(this.value)
));
}
});
});
}());

View File

@ -148,7 +148,7 @@
!browser.pageAction.openPopup
){
browser.tabs.create({
url: browser.extension.getURL("options/options.html?" + reason)
url: browser.extension.getURL("options/options.html?notice=" + reason)
});
}
}

View File

@ -57,13 +57,16 @@
window.setTimeout(() => node.focus(), 1);
let lastResults = [];
node.addEventListener("input", function(){
this.search();
});
node.search = function(){
const search = this.value;
const results = search? scope.search(search): [];
searchListeners.forEach(function(callback){
callback({search, results, lastResults});
});
lastResults = results;
});
};
return node;
};
scope.on = function(callback){

View File

@ -12,7 +12,8 @@
const settingsDisplay = require("./settingsDisplay");
const search = require("./search");
const settingStrings = require("./settingStrings");
const searchParameters = new URLSearchParams(window.location.search);
var callbacks = {
showReleaseNotes: function(){
logging.verbose("open release notes");
@ -118,8 +119,8 @@
introduction.textContent = browser.i18n.getMessage("optionsIntroduction");
head.appendChild(introduction);
if (window.location.search){
let noticeName = window.location.search.substr(1).trim() + "Notice";
if (searchParameters.has("notice")){
let noticeName = searchParameters.get("notice") + "Notice";
let notice = browser.i18n.getMessage(noticeName);
if (notice){
let bookmarkingNotice = document.createElement("div");
@ -174,16 +175,20 @@
document.body.appendChild(table);
const displayHidden = settings.getDefinition(settingsDisplay.displayHidden);
const searchInput = search.init();
table.appendChild(
optionsGui.createThead(
displayHidden,
search.init()
searchInput
)
);
const searchOnly = window.location.search === "?searchOnly";
const searchOnly = searchParameters.has("searchOnly");
if (searchOnly){
document.body.classList.add("searching");
}
if (searchParameters.has("search")){
searchInput.value = searchParameters.get("search");
}
search.on(function({search, results, lastResults}){
lastResults.forEach(function(node){
node.classList.remove("found");
@ -412,4 +417,6 @@
}
});
});
searchInput.search();
}());

View File

@ -4,6 +4,7 @@ Version 0.5.5:
new features:
- added settings sanitation page
- added search field to browser action popup
fixes:
- Google images did not work for some users