Files
szurubooru/client/js/views/pools_header_view.js
Eva 12a7f4f78a client/search: autocomplete tag alias that the user searched for
Instead of always using the first alias.
"Tag input" fields (edit page, bulk tagging, etc.) will display the
matched name in suggestions, and use the first alias upon selection.
2025-04-04 11:31:43 +02:00

61 lines
1.7 KiB
JavaScript

"use strict";
const events = require("../events.js");
const misc = require("../util/misc.js");
const search = require("../util/search.js");
const views = require("../util/views.js");
const PoolAutoCompleteControl = require("../controls/pool_auto_complete_control.js");
const template = views.getTemplate("pools-header");
class PoolsHeaderView extends events.EventTarget {
constructor(ctx) {
super();
this._hostNode = ctx.hostNode;
views.replaceContent(this._hostNode, template(ctx));
if (this._queryInputNode) {
this._autoCompleteControl = new PoolAutoCompleteControl(
this._queryInputNode,
{
confirm: (pool) =>
this._autoCompleteControl.replaceSelectedText(
misc.escapeSearchTerm(pool.matchingNames[0]),
true
),
}
);
}
search.searchInputNodeFocusHelper(this._queryInputNode);
this._formNode.addEventListener("submit", (e) => this._evtSubmit(e));
}
get _formNode() {
return this._hostNode.querySelector("form");
}
get _queryInputNode() {
return this._hostNode.querySelector("[name=search-text]");
}
_evtSubmit(e) {
e.preventDefault();
this._queryInputNode.blur();
this.dispatchEvent(
new CustomEvent("navigate", {
detail: {
parameters: {
query: this._queryInputNode.value,
page: 1,
},
},
})
);
}
}
module.exports = PoolsHeaderView;