Sanity-check decaffeinate app.views.Search

pull/1441/head
Simon Legner 1 year ago
parent cf412bd81f
commit bbadf5f228

@ -1,45 +1,30 @@
// TODO: This file was created by bulk-decaffeinate. app.views.Search = class Search extends app.View {
// Sanity-check the conversion and remove this comment. static SEARCH_PARAM = app.config.search_param;
/*
* decaffeinate suggestions: static el = "._search";
* DS102: Remove unnecessary code created because of implicit returns static activeClass = "_search-active";
* DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining
* DS206: Consider reworking classes to avoid initClass static elements = {
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
(function () {
let SEARCH_PARAM = undefined;
let HASH_RGX = undefined;
app.views.Search = class Search extends app.View {
static initClass() {
SEARCH_PARAM = app.config.search_param;
this.el = "._search";
this.activeClass = "_search-active";
this.elements = {
input: "._search-input", input: "._search-input",
resetLink: "._search-clear", resetLink: "._search-clear",
}; };
this.events = { static events = {
input: "onInput", input: "onInput",
click: "onClick", click: "onClick",
submit: "onSubmit", submit: "onSubmit",
}; };
this.shortcuts = { static shortcuts = {
typing: "focus", typing: "focus",
altG: "google", altG: "google",
altS: "stackoverflow", altS: "stackoverflow",
altD: "duckduckgo", altD: "duckduckgo",
}; };
this.routes = { after: "afterRoute" }; static routes = { after: "afterRoute" };
HASH_RGX = new RegExp(`^#${SEARCH_PARAM}=(.*)`); static HASH_RGX = new RegExp(`^#${Search.SEARCH_PARAM}=(.*)`);
}
init() { init() {
this.addSubview((this.scope = new app.views.SearchScope(this.el))); this.addSubview((this.scope = new app.views.SearchScope(this.el)));
@ -70,11 +55,7 @@
if (app.isMobile() || $.isAndroid() || $.isIOS()) { if (app.isMobile() || $.isAndroid() || $.isIOS()) {
return; return;
} }
if ( if (document.activeElement?.tagName === "INPUT") {
(document.activeElement != null
? document.activeElement.tagName
: undefined) === "INPUT"
) {
return; return;
} }
if (app.settings.get("noAutofocus")) { if (app.settings.get("noAutofocus")) {
@ -134,11 +115,7 @@
this.hasResults = null; this.hasResults = null;
this.flags = { urlSearch: url, initialResults: true }; this.flags = { urlSearch: url, initialResults: true };
this.searcher.find( this.searcher.find(this.scope.getScope().entries.all(), "text", this.value);
this.scope.getScope().entries.all(),
"text",
this.value,
);
} }
searchUrl() { searchUrl() {
@ -217,11 +194,7 @@
} }
afterRoute(name, context) { afterRoute(name, context) {
if ( if (app.shortcuts.eventInProgress?.name === "escape") {
(app.shortcuts.eventInProgress != null
? app.shortcuts.eventInProgress.name
: undefined) === "escape"
) {
return; return;
} }
if (!context.init && app.router.isIndex()) { if (!context.init && app.router.isIndex()) {
@ -234,8 +207,8 @@
} }
extractHashValue() { extractHashValue() {
let value; let value = this.getHashValue();
if ((value = this.getHashValue()) != null) { if (value != null) {
app.router.replaceHash(); app.router.replaceHash();
return value; return value;
} }
@ -243,19 +216,7 @@
getHashValue() { getHashValue() {
try { try {
return __guard__( return Search.HASH_RGX.exec($.urlDecode(location.hash))?.[1];
HASH_RGX.exec($.urlDecode(location.hash)),
(x) => x[1],
);
} catch (error) {} } catch (error) {}
} }
}; };
app.views.Search.initClass();
return app.views.Search;
})();
function __guard__(value, transform) {
return typeof value !== "undefined" && value !== null
? transform(value)
: undefined;
}

Loading…
Cancel
Save