mirror of
https://github.com/Kornstalx/5etools-mirror-2.github.io.git
synced 2026-01-14 05:47:50 -06:00
v1.204.0
This commit is contained in:
35
js/search.js
35
js/search.js
@@ -13,6 +13,23 @@ class SearchPage {
|
||||
this._render();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
static _PARAM_QUERY = "q";
|
||||
static _PARAM_LUCKY = "lucky";
|
||||
|
||||
static _getSearchParams () {
|
||||
const params = new URLSearchParams(location.search);
|
||||
return Object.fromEntries(params);
|
||||
}
|
||||
|
||||
static _setSearchParams (obj) {
|
||||
const params = new URLSearchParams(obj);
|
||||
location.search = params.toString();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
static _render_$getBtnToggleFilter (
|
||||
{
|
||||
propOmnisearch,
|
||||
@@ -43,11 +60,13 @@ class SearchPage {
|
||||
if (evt.key !== "Enter") return;
|
||||
$btnSearch.click();
|
||||
})
|
||||
.val(decodeURIComponent(location.search.slice(1).replace(/\+/g, " ")));
|
||||
.val(this._getSearchParams()[this._PARAM_QUERY]);
|
||||
|
||||
const $btnSearch = $(`<button class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>`)
|
||||
.click(() => {
|
||||
location.search = encodeURIComponent($iptSearch.val().trim().toLowerCase());
|
||||
this._setSearchParams({
|
||||
[this._PARAM_QUERY]: $iptSearch.val().trim().toLowerCase(),
|
||||
});
|
||||
});
|
||||
|
||||
const $btnHelp = $(`<button class="btn btn-default mr-2 mobile__hidden" title="Help"><span class="glyphicon glyphicon-info-sign"></span></button>`)
|
||||
@@ -146,12 +165,14 @@ class SearchPage {
|
||||
}
|
||||
SearchPage._rowMetas = [];
|
||||
|
||||
if (!location.search.slice(1)) {
|
||||
const params = this._getSearchParams();
|
||||
|
||||
if (!params[this._PARAM_QUERY]) {
|
||||
SearchPage._$wrpResults.empty().append(this._getWrpResult_message("Enter a search to view results"));
|
||||
return;
|
||||
}
|
||||
|
||||
Omnisearch.pGetResults(decodeURIComponent(location.search.slice(1).replace(/\+/g, " ")))
|
||||
Omnisearch.pGetResults(params[this._PARAM_QUERY])
|
||||
.then(results => {
|
||||
SearchPage._$wrpResults.empty();
|
||||
|
||||
@@ -160,6 +181,12 @@ class SearchPage {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._PARAM_LUCKY in params) {
|
||||
const [result] = results;
|
||||
window.location = `${Renderer.get().baseUrl}${Omnisearch.getResultHref(result.doc)}`;
|
||||
return;
|
||||
}
|
||||
|
||||
SearchPage._rowMetas = results.map(result => {
|
||||
const r = result.doc;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user