diff --git a/assets/javascripts/app/router.js b/assets/javascripts/app/router.js index df254212..c120b9bf 100644 --- a/assets/javascripts/app/router.js +++ b/assets/javascripts/app/router.js @@ -66,8 +66,7 @@ app.Router = class Router extends Events { type(context, next) { const doc = app.docs.findBySlug(context.params.doc); - const type = - doc != null ? doc.types.findBy("slug", context.params.type) : undefined; + const type = doc?.types?.findBy("slug", context.params.type); if (type) { context.doc = doc; diff --git a/assets/javascripts/app/searcher.js b/assets/javascripts/app/searcher.js index 73ef53e2..f2f88cb1 100644 --- a/assets/javascripts/app/searcher.js +++ b/assets/javascripts/app/searcher.js @@ -312,10 +312,7 @@ app.Searcher = class Searcher extends Events { } scoredEnough() { - return ( - (this.scoreMap[100] != null ? this.scoreMap[100].length : undefined) >= - this.options.max_results - ); + return this.scoreMap[100]?.length >= this.options.max_results; } foundEnough() { @@ -388,7 +385,7 @@ app.SynchronousSearcher = class SynchronousSearcher extends app.Searcher { } sendResults(end) { - if (end && (this.allResults != null ? this.allResults.length : undefined)) { + if (end && this.allResults?.length) { return this.triggerResults(this.allResults); } } diff --git a/assets/javascripts/app/settings.js b/assets/javascripts/app/settings.js index 49dea2e0..7337f7b7 100644 --- a/assets/javascripts/app/settings.js +++ b/assets/javascripts/app/settings.js @@ -198,10 +198,7 @@ app.Settings = class Settings { toggleLayout(layout, enable) { const { classList } = document.body; // sidebar is always shown for settings; its state is updated in app.views.Settings - if ( - layout !== "_sidebar-hidden" || - !(app.router != null ? app.router.isSettings : undefined) - ) { + if (layout !== "_sidebar-hidden" || !app.router?.isSettings) { classList.toggle(layout, enable); } classList.toggle("_overlay-scrollbars", $.overlayScrollbarsEnabled()); diff --git a/assets/javascripts/lib/page.js b/assets/javascripts/lib/page.js index f5a2e72a..88f1600d 100644 --- a/assets/javascripts/lib/page.js +++ b/assets/javascripts/lib/page.js @@ -43,7 +43,7 @@ page.stop = function () { page.show = function (path, state) { let res; - if (path === (currentState != null ? currentState.path : undefined)) { + if (path === currentState?.path) { return; } const context = new Context(path, state); diff --git a/assets/javascripts/lib/util.js b/assets/javascripts/lib/util.js index e497b6fd..17740a42 100644 --- a/assets/javascripts/lib/util.js +++ b/assets/javascripts/lib/util.js @@ -453,8 +453,7 @@ $.arrayDelete = function (array, object) { // Returns true if the object is an array or a collection of DOM elements. $.isCollection = (object) => - Array.isArray(object) || - typeof (object != null ? object.item : undefined) === "function"; + Array.isArray(object) || typeof object?.item === "function"; const ESCAPE_HTML_MAP = { "&": "&", diff --git a/assets/javascripts/views/content/entry_page.js b/assets/javascripts/views/content/entry_page.js index aba4c90e..95920878 100644 --- a/assets/javascripts/views/content/entry_page.js +++ b/assets/javascripts/views/content/entry_page.js @@ -144,9 +144,7 @@ app.views.EntryPage = class EntryPage extends app.View { } onRoute(context) { - const isSameFile = - context.entry.filePath() === - (this.entry != null ? this.entry.filePath() : undefined); + const isSameFile = context.entry.filePath() === this.entry?.filePath?.(); this.entry = context.entry; if (!isSameFile) { this.restore() || this.load(); diff --git a/assets/javascripts/views/search/search_scope.js b/assets/javascripts/views/search/search_scope.js index 53a7e71e..f705bd51 100644 --- a/assets/javascripts/views/search/search_scope.js +++ b/assets/javascripts/views/search/search_scope.js @@ -35,7 +35,7 @@ app.views.SearchScope = class SearchScope extends app.View { } name() { - return this.doc != null ? this.doc.name : undefined; + return this.doc?.name; } search(value, searchDisabled) { diff --git a/assets/javascripts/views/sidebar/doc_list.js b/assets/javascripts/views/sidebar/doc_list.js index adda4590..223a5ee9 100644 --- a/assets/javascripts/views/sidebar/doc_list.js +++ b/assets/javascripts/views/sidebar/doc_list.js @@ -83,7 +83,7 @@ app.views.DocList = class DocList extends app.View { var versions = ""; while (true) { versions += this.tmpl("sidebarDoc", doc, { disabled: true }); - if ((docs[0] != null ? docs[0].name : undefined) !== doc.name) { + if (docs[0]?.name !== doc.name) { break; } doc = docs.shift(); @@ -144,7 +144,7 @@ app.views.DocList = class DocList extends app.View { } select(model) { - this.listSelect.selectByHref(model != null ? model.fullPath() : undefined); + this.listSelect.selectByHref(model?.fullPath()); } reveal(model) { diff --git a/assets/javascripts/views/sidebar/doc_picker.js b/assets/javascripts/views/sidebar/doc_picker.js index 52f7d482..9e532ee3 100644 --- a/assets/javascripts/views/sidebar/doc_picker.js +++ b/assets/javascripts/views/sidebar/doc_picker.js @@ -79,7 +79,7 @@ app.views.DocPicker = class DocPicker extends app.View { getSelectedDocs() { return this.findAllByTag("input") - .filter((input) => (input != null ? input.checked : undefined)) + .filter((input) => input?.checked) .map((input) => input.name); }