diff --git a/assets/javascripts/app/db.js b/assets/javascripts/app/db.js index e9d43327..a2a4f753 100644 --- a/assets/javascripts/app/db.js +++ b/assets/javascripts/app/db.js @@ -19,10 +19,6 @@ } constructor() { - this.onOpenSuccess = this.onOpenSuccess.bind(this); - this.onOpenError = this.onOpenError.bind(this); - this.checkForCorruptedDocs = this.checkForCorruptedDocs.bind(this); - this.deleteCorruptedDocs = this.deleteCorruptedDocs.bind(this); this.versionMultipler = $.isIE() ? 1e5 : 1e9; this.useIndexedDB = this.useIndexedDB(); this.callbacks = []; @@ -45,9 +41,9 @@ NAME, VERSION * this.versionMultipler + this.userVersion(), ); - req.onsuccess = this.onOpenSuccess; - req.onerror = this.onOpenError; - req.onupgradeneeded = this.onUpgradeNeeded; + req.onsuccess = (event) => this.onOpenSuccess(event); + req.onerror = (event) => this.onOpenError(event); + req.onupgradeneeded = (event) => this.onUpgradeNeeded(event); } catch (error) { this.fail("exception", error); } @@ -378,8 +374,7 @@ load(entry, onSuccess, onError) { if (this.shouldLoadWithIDB(entry)) { - onError = this.loadWithXHR.bind(this, entry, onSuccess, onError); - return this.loadWithIDB(entry, onSuccess, onError); + return this.loadWithIDB(entry, onSuccess, () => this.loadWithXHR(entry, onSuccess, onError)); } else { return this.loadWithXHR(entry, onSuccess, onError); } @@ -440,7 +435,7 @@ mode: "readonly", }); txn.oncomplete = () => { - setTimeout(this.checkForCorruptedDocs, 50); + setTimeout(() => this.checkForCorruptedDocs(), 50); }; const req = txn.objectStore("docs").openCursor(); @@ -486,7 +481,7 @@ } if (docs.length === 0) { - setTimeout(this.deleteCorruptedDocs, 0); + setTimeout(() => this.deleteCorruptedDocs(), 0); return; } @@ -497,7 +492,7 @@ }); txn.oncomplete = () => { if (this.corruptedDocs.length > 0) { - setTimeout(this.deleteCorruptedDocs, 0); + setTimeout(() => this.deleteCorruptedDocs(), 0); } }; diff --git a/assets/javascripts/app/searcher.js b/assets/javascripts/app/searcher.js index 15926abe..bb26eeba 100644 --- a/assets/javascripts/app/searcher.js +++ b/assets/javascripts/app/searcher.js @@ -215,12 +215,7 @@ function scoreFuzzyMatch() { } constructor(options) { - this.match = this.match.bind(this); - this.matchChunks = this.matchChunks.bind(this); - if (options == null) { - options = {}; - } - this.options = $.extend({}, DEFAULTS, options); + this.options = $.extend({}, DEFAULTS, options || {}); } find(data, attr, q) { @@ -307,10 +302,10 @@ function scoreFuzzyMatch() { this.matchChunk(); if (this.cursor === this.dataLength || this.scoredEnough()) { - this.delay(this.match); + this.delay(() => this.match()); this.sendResults(); } else { - this.delay(this.matchChunks); + this.delay(() => this.matchChunks()); } } @@ -410,11 +405,6 @@ function scoreFuzzyMatch() { })(); app.SynchronousSearcher = class SynchronousSearcher extends app.Searcher { - constructor(...args) { - this.match = this.match.bind(this); - super(...args); - } - match() { if (this.matcher) { if (!this.allResults) { diff --git a/assets/javascripts/app/serviceworker.js b/assets/javascripts/app/serviceworker.js index f9e5f6ca..b1bd4f49 100644 --- a/assets/javascripts/app/serviceworker.js +++ b/assets/javascripts/app/serviceworker.js @@ -16,7 +16,6 @@ app.ServiceWorker = class ServiceWorker { } constructor() { - this.onUpdateFound = this.onUpdateFound.bind(this); this.onStateChange = this.onStateChange.bind(this); this.registration = null; this.notifyUpdate = true; @@ -51,12 +50,12 @@ app.ServiceWorker = class ServiceWorker { updateRegistration(registration) { this.registration = registration; - $.on(this.registration, "updatefound", this.onUpdateFound); + $.on(this.registration, "updatefound", () => this.onUpdateFound()); } onUpdateFound() { if (this.installingRegistration) { - $.off(this.installingRegistration, "statechange", this.onStateChange()); + $.off(this.installingRegistration, "statechange", this.onStateChange); } this.installingRegistration = this.registration.installing; $.on(this.installingRegistration, "statechange", this.onStateChange); diff --git a/assets/javascripts/app/update_checker.js b/assets/javascripts/app/update_checker.js index 5d967539..03d726ed 100644 --- a/assets/javascripts/app/update_checker.js +++ b/assets/javascripts/app/update_checker.js @@ -7,16 +7,14 @@ */ app.UpdateChecker = class UpdateChecker { constructor() { - this.checkDocs = this.checkDocs.bind(this); - this.onFocus = this.onFocus.bind(this); this.lastCheck = Date.now(); - $.on(window, "focus", this.onFocus); + $.on(window, "focus", () => this.onFocus()); if (app.serviceWorker != null) { - app.serviceWorker.on("updateready", this.onUpdateReady); + app.serviceWorker.on("updateready", () => this.onUpdateReady()); } - setTimeout(this.checkDocs, 0); + setTimeout(() => this.checkDocs(), 0); } check() { diff --git a/assets/javascripts/debug.js b/assets/javascripts/debug.js index e1ea25f0..a3214347 100644 --- a/assets/javascripts/debug.js +++ b/assets/javascripts/debug.js @@ -110,7 +110,7 @@ this.viewTree = function (view, level, visited) { `%c ${Array(level + 1).join(" ")}${ view.constructor.name }: ${!!view.activated}`, - "color:" + ((view.activated && "green") || "red") + "color:" + ((view.activated && "green") || "red"), ); for (var key of Object.keys(view || {})) { diff --git a/assets/javascripts/lib/events.js b/assets/javascripts/lib/events.js index 75c2b9b0..58c37291 100644 --- a/assets/javascripts/lib/events.js +++ b/assets/javascripts/lib/events.js @@ -48,14 +48,12 @@ class Events { } trigger(event, ...args) { - let callbacks; this.eventInProgress = { name: event, args }; - if ( - (callbacks = this._callbacks != null ? this._callbacks[event] : undefined) - ) { - for (var callback of Array.from(callbacks.slice(0))) { + const callbacks = this._callbacks?.[event]; + if (callbacks) { + for (let callback of Array.from(callbacks.slice(0))) { if (typeof callback === "function") { - callback(...Array.from(args || [])); + callback(...args); } } } diff --git a/assets/javascripts/views/content/content.js b/assets/javascripts/views/content/content.js index 9d600f47..aa368c83 100644 --- a/assets/javascripts/views/content/content.js +++ b/assets/javascripts/views/content/content.js @@ -13,24 +13,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.Content = class Content extends app.View { - constructor(...args) { - this.scrollToTop = this.scrollToTop.bind(this); - this.scrollToBottom = this.scrollToBottom.bind(this); - this.scrollStepUp = this.scrollStepUp.bind(this); - this.scrollStepDown = this.scrollStepDown.bind(this); - this.scrollPageUp = this.scrollPageUp.bind(this); - this.scrollPageDown = this.scrollPageDown.bind(this); - this.onReady = this.onReady.bind(this); - this.onBootError = this.onBootError.bind(this); - this.onEntryLoading = this.onEntryLoading.bind(this); - this.onEntryLoaded = this.onEntryLoaded.bind(this); - this.beforeRoute = this.beforeRoute.bind(this); - this.afterRoute = this.afterRoute.bind(this); - this.onClick = this.onClick.bind(this); - this.onAltF = this.onAltF.bind(this); - super(...args); - } - static initClass() { this.el = "._content"; this.loadingClass = "_content-loading"; @@ -68,10 +50,12 @@ app.views.Content = class Content extends app.View { this.entryPage = new app.views.EntryPage(); this.entryPage - .on("loading", this.onEntryLoading) - .on("loaded", this.onEntryLoaded); + .on("loading", () => this.onEntryLoading()) + .on("loaded", () => this.onEntryLoaded()); - app.on("ready", this.onReady).on("bootError", this.onBootError); + app + .on("ready", () => this.onReady()) + .on("bootError", () => this.onBootError()); } show(view) { diff --git a/assets/javascripts/views/content/entry_page.js b/assets/javascripts/views/content/entry_page.js index 7dd0feae..aa0e69c1 100644 --- a/assets/javascripts/views/content/entry_page.js +++ b/assets/javascripts/views/content/entry_page.js @@ -13,16 +13,6 @@ (function () { let LINKS = undefined; app.views.EntryPage = class EntryPage extends app.View { - constructor(...args) { - this.beforeRoute = this.beforeRoute.bind(this); - this.onSuccess = this.onSuccess.bind(this); - this.onError = this.onError.bind(this); - this.onClick = this.onClick.bind(this); - this.onAltC = this.onAltC.bind(this); - this.onAltO = this.onAltO.bind(this); - super(...args); - } - static initClass() { this.className = "_page"; this.errorClass = "_page-error"; @@ -182,7 +172,10 @@ load() { this.loading(); - this.xhr = this.entry.loadFile(this.onSuccess, this.onError); + this.xhr = this.entry.loadFile( + (response) => this.onSuccess(response), + () => this.onError(), + ); } abort() { diff --git a/assets/javascripts/views/content/offline_page.js b/assets/javascripts/views/content/offline_page.js index de33d595..fb554db0 100644 --- a/assets/javascripts/views/content/offline_page.js +++ b/assets/javascripts/views/content/offline_page.js @@ -9,11 +9,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.OfflinePage = class OfflinePage extends app.View { - constructor(...args) { - this.onClick = this.onClick.bind(this); - super(...args); - } - static initClass() { this.className = "_static"; diff --git a/assets/javascripts/views/content/root_page.js b/assets/javascripts/views/content/root_page.js index 93f5b940..b5d76597 100644 --- a/assets/javascripts/views/content/root_page.js +++ b/assets/javascripts/views/content/root_page.js @@ -8,11 +8,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.RootPage = class RootPage extends app.View { - constructor(...args) { - this.onClick = this.onClick.bind(this); - super(...args); - } - static initClass() { this.events = { click: "onClick" }; } diff --git a/assets/javascripts/views/content/settings_page.js b/assets/javascripts/views/content/settings_page.js index f363d996..653e6135 100644 --- a/assets/javascripts/views/content/settings_page.js +++ b/assets/javascripts/views/content/settings_page.js @@ -10,12 +10,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.SettingsPage = class SettingsPage extends app.View { - constructor(...args) { - this.onChange = this.onChange.bind(this); - this.onClick = this.onClick.bind(this); - super(...args); - } - static initClass() { this.className = "_static"; diff --git a/assets/javascripts/views/layout/document.js b/assets/javascripts/views/layout/document.js index a7d7ea0b..fe7985f8 100644 --- a/assets/javascripts/views/layout/document.js +++ b/assets/javascripts/views/layout/document.js @@ -9,12 +9,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.Document = class Document extends app.View { - constructor(...args) { - this.afterRoute = this.afterRoute.bind(this); - this.onVisibilityChange = this.onVisibilityChange.bind(this); - super(...args); - } - static initClass() { this.el = document; diff --git a/assets/javascripts/views/layout/menu.js b/assets/javascripts/views/layout/menu.js index 5e627f82..2a0524c7 100644 --- a/assets/javascripts/views/layout/menu.js +++ b/assets/javascripts/views/layout/menu.js @@ -7,11 +7,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.Menu = class Menu extends app.View { - constructor(...args) { - this.onGlobalClick = this.onGlobalClick.bind(this); - super(...args); - } - static initClass() { this.el = "._menu"; this.activeClass = "active"; @@ -20,7 +15,7 @@ app.views.Menu = class Menu extends app.View { } init() { - $.on(document.body, "click", this.onGlobalClick); + $.on(document.body, "click", (event) => this.onGlobalClick(event)); } onClick(event) { diff --git a/assets/javascripts/views/layout/mobile.js b/assets/javascripts/views/layout/mobile.js index 9c82d497..75b9280c 100644 --- a/assets/javascripts/views/layout/mobile.js +++ b/assets/javascripts/views/layout/mobile.js @@ -54,44 +54,36 @@ app.views.Mobile = class Mobile extends app.View { } constructor() { - this.showSidebar = this.showSidebar.bind(this); - this.hideSidebar = this.hideSidebar.bind(this); - this.onClickBack = this.onClickBack.bind(this); - this.onClickForward = this.onClickForward.bind(this); - this.onClickToggleSidebar = this.onClickToggleSidebar.bind(this); - this.onClickDocPickerTab = this.onClickDocPickerTab.bind(this); - this.onClickSettingsTab = this.onClickSettingsTab.bind(this); - this.onTapSearch = this.onTapSearch.bind(this); - this.onEscape = this.onEscape.bind(this); - this.afterRoute = this.afterRoute.bind(this); - this.el = document.documentElement; super(...arguments); + this.el = document.documentElement; } init() { - $.on($("._search"), "touchend", this.onTapSearch); + $.on($("._search"), "touchend", () => this.onTapSearch()); this.toggleSidebar = $("button[data-toggle-sidebar]"); this.toggleSidebar.removeAttribute("hidden"); - $.on(this.toggleSidebar, "click", this.onClickToggleSidebar); + $.on(this.toggleSidebar, "click", () => this.onClickToggleSidebar()); this.back = $("button[data-back]"); this.back.removeAttribute("hidden"); - $.on(this.back, "click", this.onClickBack); + $.on(this.back, "click", () => this.onClickBack()); this.forward = $("button[data-forward]"); this.forward.removeAttribute("hidden"); - $.on(this.forward, "click", this.onClickForward); + $.on(this.forward, "click", () => this.onClickForward()); this.docPickerTab = $('button[data-tab="doc-picker"]'); this.docPickerTab.removeAttribute("hidden"); - $.on(this.docPickerTab, "click", this.onClickDocPickerTab); + $.on(this.docPickerTab, "click", (event) => + this.onClickDocPickerTab(event), + ); this.settingsTab = $('button[data-tab="settings"]'); this.settingsTab.removeAttribute("hidden"); - $.on(this.settingsTab, "click", this.onClickSettingsTab); + $.on(this.settingsTab, "click", (event) => this.onClickSettingsTab(event)); - app.document.sidebar.search.on("searching", this.showSidebar); + app.document.sidebar.search.on("searching", () => this.showSidebar()); this.activate(); } diff --git a/assets/javascripts/views/layout/path.js b/assets/javascripts/views/layout/path.js index 2cd82dd4..2c0614c8 100644 --- a/assets/javascripts/views/layout/path.js +++ b/assets/javascripts/views/layout/path.js @@ -8,12 +8,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.Path = class Path extends app.View { - constructor(...args) { - this.onClick = this.onClick.bind(this); - this.afterRoute = this.afterRoute.bind(this); - super(...args); - } - static initClass() { this.className = "_path"; this.attributes = { role: "complementary" }; diff --git a/assets/javascripts/views/layout/resizer.js b/assets/javascripts/views/layout/resizer.js index da3e92db..7bf9907e 100644 --- a/assets/javascripts/views/layout/resizer.js +++ b/assets/javascripts/views/layout/resizer.js @@ -11,13 +11,6 @@ let MIN = undefined; let MAX = undefined; app.views.Resizer = class Resizer extends app.View { - constructor(...args) { - this.onDragStart = this.onDragStart.bind(this); - this.onDrag = this.onDrag.bind(this); - this.onDragEnd = this.onDragEnd.bind(this); - super(...args); - } - static initClass() { this.className = "_resizer"; diff --git a/assets/javascripts/views/layout/settings.js b/assets/javascripts/views/layout/settings.js index 26d6eaf9..fefe3f0d 100644 --- a/assets/javascripts/views/layout/settings.js +++ b/assets/javascripts/views/layout/settings.js @@ -13,15 +13,6 @@ (function () { let SIDEBAR_HIDDEN_LAYOUT = undefined; app.views.Settings = class Settings extends app.View { - constructor(...args) { - this.onChange = this.onChange.bind(this); - this.onEnter = this.onEnter.bind(this); - this.onSubmit = this.onSubmit.bind(this); - this.onImport = this.onImport.bind(this); - this.onClick = this.onClick.bind(this); - super(...args); - } - static initClass() { SIDEBAR_HIDDEN_LAYOUT = "_sidebar-hidden"; diff --git a/assets/javascripts/views/list/list_focus.js b/assets/javascripts/views/list/list_focus.js index f04ff75b..486e64ea 100644 --- a/assets/javascripts/views/list/list_focus.js +++ b/assets/javascripts/views/list/list_focus.js @@ -25,15 +25,8 @@ app.views.ListFocus = class ListFocus extends app.View { } constructor(el) { - this.blur = this.blur.bind(this); - this.onDown = this.onDown.bind(this); - this.onUp = this.onUp.bind(this); - this.onLeft = this.onLeft.bind(this); - this.onEnter = this.onEnter.bind(this); - this.onSuperEnter = this.onSuperEnter.bind(this); - this.onClick = this.onClick.bind(this); - this.el = el; super(...arguments); + this.el = el; this.focusOnNextFrame = $.framify(this.focus, this); } diff --git a/assets/javascripts/views/list/list_fold.js b/assets/javascripts/views/list/list_fold.js index 89d23c21..5ced1b2d 100644 --- a/assets/javascripts/views/list/list_fold.js +++ b/assets/javascripts/views/list/list_fold.js @@ -23,11 +23,8 @@ app.views.ListFold = class ListFold extends app.View { } constructor(el) { - this.onLeft = this.onLeft.bind(this); - this.onRight = this.onRight.bind(this); - this.onClick = this.onClick.bind(this); - this.el = el; super(...arguments); + this.el = el; } open(el) { diff --git a/assets/javascripts/views/list/list_select.js b/assets/javascripts/views/list/list_select.js index 17d21485..b991e443 100644 --- a/assets/javascripts/views/list/list_select.js +++ b/assets/javascripts/views/list/list_select.js @@ -16,9 +16,8 @@ app.views.ListSelect = class ListSelect extends app.View { } constructor(el) { - this.onClick = this.onClick.bind(this); - this.el = el; super(...arguments); + this.el = el; } deactivate() { diff --git a/assets/javascripts/views/misc/notif.js b/assets/javascripts/views/misc/notif.js index 16622e07..011600a7 100644 --- a/assets/javascripts/views/misc/notif.js +++ b/assets/javascripts/views/misc/notif.js @@ -13,20 +13,15 @@ app.views.Notif = class Notif extends app.View { this.activeClass = "_in"; this.attributes = { role: "alert" }; - this.defautOptions = { autoHide: 15000 }; + this.defaultOptions = { autoHide: 15000 }; this.events = { click: "onClick" }; } constructor(type, options) { - this.onClick = this.onClick.bind(this); - this.type = type; - if (options == null) { - options = {}; - } - this.options = options; - this.options = $.extend({}, this.constructor.defautOptions, this.options); super(...arguments); + this.type = type; + this.options = $.extend({}, this.constructor.defaultOptions, options || {}); } init() { diff --git a/assets/javascripts/views/pages/base.js b/assets/javascripts/views/pages/base.js index bfd93531..21b6d481 100644 --- a/assets/javascripts/views/pages/base.js +++ b/assets/javascripts/views/pages/base.js @@ -10,10 +10,9 @@ */ app.views.BasePage = class BasePage extends app.View { constructor(el, entry) { - this.paintCode = this.paintCode.bind(this); + super(...arguments); this.el = el; this.entry = entry; - super(...arguments); } deactivate() { @@ -40,7 +39,9 @@ app.views.BasePage = class BasePage extends app.View { this.delay(this.afterRender); } if (this.highlightNodes.length > 0) { - $.requestAnimationFrame(() => $.requestAnimationFrame(this.paintCode)); + $.requestAnimationFrame(() => + $.requestAnimationFrame(() => this.paintCode()), + ); } } @@ -80,7 +81,7 @@ app.views.BasePage = class BasePage extends app.View { } if (this.highlightNodes.length > 0) { - $.requestAnimationFrame(this.paintCode); + $.requestAnimationFrame(() => this.paintCode()); } this.previousTiming = timing; } diff --git a/assets/javascripts/views/pages/hidden.js b/assets/javascripts/views/pages/hidden.js index 6708c450..552b7ee3 100644 --- a/assets/javascripts/views/pages/hidden.js +++ b/assets/javascripts/views/pages/hidden.js @@ -12,10 +12,9 @@ app.views.HiddenPage = class HiddenPage extends app.View { } constructor(el, entry) { - this.onClick = this.onClick.bind(this); + super(...arguments); this.el = el; this.entry = entry; - super(...arguments); } init() { diff --git a/assets/javascripts/views/pages/jquery.js b/assets/javascripts/views/pages/jquery.js index 94ba6035..29925eb0 100644 --- a/assets/javascripts/views/pages/jquery.js +++ b/assets/javascripts/views/pages/jquery.js @@ -11,11 +11,6 @@ //= require views/pages/base app.views.JqueryPage = class JqueryPage extends app.views.BasePage { - constructor(...args) { - this.onIframeLoaded = this.onIframeLoaded.bind(this); - super(...args); - } - static initClass() { this.demoClassName = "_jquery-demo"; } @@ -24,6 +19,7 @@ app.views.JqueryPage = class JqueryPage extends app.views.BasePage { // Prevent jQuery Mobile's demo iframes from scrolling the page for (var iframe of Array.from(this.findAllByTag("iframe"))) { iframe.style.display = "none"; + this.onIframeLoaded = this.onIframeLoaded.bind(this); $.on(iframe, "load", this.onIframeLoaded); } diff --git a/assets/javascripts/views/pages/sqlite.js b/assets/javascripts/views/pages/sqlite.js index b0da0f0e..5050bb20 100644 --- a/assets/javascripts/views/pages/sqlite.js +++ b/assets/javascripts/views/pages/sqlite.js @@ -9,11 +9,6 @@ //= require views/pages/base app.views.SqlitePage = class SqlitePage extends app.views.BasePage { - constructor(...args) { - this.onClick = this.onClick.bind(this); - super(...args); - } - static initClass() { this.events = { click: "onClick" }; } diff --git a/assets/javascripts/views/search/search.js b/assets/javascripts/views/search/search.js index 049988dd..08ddaf5a 100644 --- a/assets/javascripts/views/search/search.js +++ b/assets/javascripts/views/search/search.js @@ -13,24 +13,6 @@ let SEARCH_PARAM = undefined; let HASH_RGX = undefined; app.views.Search = class Search extends app.View { - constructor(...args) { - this.focus = this.focus.bind(this); - this.autoFocus = this.autoFocus.bind(this); - this.onWindowFocus = this.onWindowFocus.bind(this); - this.onReady = this.onReady.bind(this); - this.onInput = this.onInput.bind(this); - this.searchUrl = this.searchUrl.bind(this); - this.google = this.google.bind(this); - this.stackoverflow = this.stackoverflow.bind(this); - this.duckduckgo = this.duckduckgo.bind(this); - this.onResults = this.onResults.bind(this); - this.onEnd = this.onEnd.bind(this); - this.onClick = this.onClick.bind(this); - this.onScopeChange = this.onScopeChange.bind(this); - this.afterRoute = this.afterRoute.bind(this); - super(...args); - } - static initClass() { SEARCH_PARAM = app.config.search_param; @@ -64,13 +46,15 @@ this.addSubview((this.scope = new app.views.SearchScope(this.el))); this.searcher = new app.Searcher(); - this.searcher.on("results", this.onResults).on("end", this.onEnd); + this.searcher + .on("results", (results) => this.onResults(results)) + .on("end", () => this.onEnd()); - this.scope.on("change", this.onScopeChange); + this.scope.on("change", () => this.onScopeChange()); - app.on("ready", this.onReady); - $.on(window, "hashchange", this.searchUrl); - $.on(window, "focus", this.onWindowFocus); + app.on("ready", () => this.onReady()); + $.on(window, "hashchange", () => this.searchUrl()); + $.on(window, "focus", (event) => this.onWindowFocus(event)); } focus() { @@ -247,7 +231,7 @@ if (context.hash) { this.delay(this.searchUrl); } - $.requestAnimationFrame(this.autoFocus); + $.requestAnimationFrame(() => this.autoFocus()); } extractHashValue() { diff --git a/assets/javascripts/views/search/search_scope.js b/assets/javascripts/views/search/search_scope.js index e3f3c521..906178e6 100644 --- a/assets/javascripts/views/search/search_scope.js +++ b/assets/javascripts/views/search/search_scope.js @@ -33,15 +33,8 @@ } constructor(el) { - this.onResults = this.onResults.bind(this); - this.reset = this.reset.bind(this); - this.doScopeSearch = this.doScopeSearch.bind(this); - this.onClick = this.onClick.bind(this); - this.onKeydown = this.onKeydown.bind(this); - this.onTextInput = this.onTextInput.bind(this); - this.afterRoute = this.afterRoute.bind(this); - this.el = el; super(...arguments); + this.el = el; } init() { @@ -51,7 +44,7 @@ fuzzy_min_length: 2, max_results: 1, }); - this.searcher.on("results", this.onResults); + this.searcher.on("results", (results) => this.onResults(results)); } getScope() { diff --git a/assets/javascripts/views/sidebar/doc_list.js b/assets/javascripts/views/sidebar/doc_list.js index 9bd99499..771828ae 100644 --- a/assets/javascripts/views/sidebar/doc_list.js +++ b/assets/javascripts/views/sidebar/doc_list.js @@ -9,16 +9,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.DocList = class DocList extends app.View { - constructor(...args) { - this.render = this.render.bind(this); - this.onOpen = this.onOpen.bind(this); - this.onClose = this.onClose.bind(this); - this.onClick = this.onClick.bind(this); - this.onEnabled = this.onEnabled.bind(this); - this.afterRoute = this.afterRoute.bind(this); - super(...args); - } - static initClass() { this.className = "_list"; this.attributes = { role: "navigation" }; @@ -44,7 +34,7 @@ app.views.DocList = class DocList extends app.View { this.addSubview((this.listFold = new app.views.ListFold(this.el))); this.addSubview((this.listSelect = new app.views.ListSelect(this.el))); - app.on("ready", this.render); + app.on("ready", () => this.render()); } activate() { @@ -248,6 +238,7 @@ app.views.DocList = class DocList extends app.View { $.stopEvent(event); const doc = app.disabledDocs.findBy("slug", slug); if (doc) { + this.onEnabled = this.onEnabled.bind(this); app.enableDoc(doc, this.onEnabled, this.onEnabled); } } diff --git a/assets/javascripts/views/sidebar/doc_picker.js b/assets/javascripts/views/sidebar/doc_picker.js index 764194c4..33f6bcb6 100644 --- a/assets/javascripts/views/sidebar/doc_picker.js +++ b/assets/javascripts/views/sidebar/doc_picker.js @@ -11,13 +11,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.DocPicker = class DocPicker extends app.View { - constructor(...args) { - this.onMouseDown = this.onMouseDown.bind(this); - this.onMouseUp = this.onMouseUp.bind(this); - this.onDOMFocus = this.onDOMFocus.bind(this); - super(...args); - } - static initClass() { this.className = "_list _list-picker"; @@ -34,6 +27,7 @@ app.views.DocPicker = class DocPicker extends app.View { activate() { if (super.activate(...arguments)) { this.render(); + this.onDOMFocus = this.onDOMFocus.bind(this); $.on(this.el, "focus", this.onDOMFocus, true); } } diff --git a/assets/javascripts/views/sidebar/results.js b/assets/javascripts/views/sidebar/results.js index be312186..9c541037 100644 --- a/assets/javascripts/views/sidebar/results.js +++ b/assets/javascripts/views/sidebar/results.js @@ -18,14 +18,9 @@ app.views.Results = class Results extends app.View { } constructor(sidebar, search) { - this.onResults = this.onResults.bind(this); - this.onNoResults = this.onNoResults.bind(this); - this.onClear = this.onClear.bind(this); - this.afterRoute = this.afterRoute.bind(this); - this.onClick = this.onClick.bind(this); + super(...arguments); this.sidebar = sidebar; this.search = search; - super(...arguments); } deactivate() { @@ -39,9 +34,9 @@ app.views.Results = class Results extends app.View { this.addSubview((this.listSelect = new app.views.ListSelect(this.el))); this.search - .on("results", this.onResults) - .on("noresults", this.onNoResults) - .on("clear", this.onClear); + .on("results", (entries, flags) => this.onResults(entries, flags)) + .on("noresults", () => this.onNoResults()) + .on("clear", () => this.onClear()); } onResults(entries, flags) { diff --git a/assets/javascripts/views/sidebar/sidebar.js b/assets/javascripts/views/sidebar/sidebar.js index cd9bcf60..5201fdd1 100644 --- a/assets/javascripts/views/sidebar/sidebar.js +++ b/assets/javascripts/views/sidebar/sidebar.js @@ -10,23 +10,6 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md */ app.views.Sidebar = class Sidebar extends app.View { - constructor(...args) { - this.resetHoverOnMouseMove = this.resetHoverOnMouseMove.bind(this); - this.resetHover = this.resetHover.bind(this); - this.showResults = this.showResults.bind(this); - this.onReady = this.onReady.bind(this); - this.onScopeChange = this.onScopeChange.bind(this); - this.onSearching = this.onSearching.bind(this); - this.onSearchClear = this.onSearchClear.bind(this); - this.onFocus = this.onFocus.bind(this); - this.onSelect = this.onSelect.bind(this); - this.onClick = this.onClick.bind(this); - this.onAltR = this.onAltR.bind(this); - this.onEscape = this.onEscape.bind(this); - this.afterRoute = this.afterRoute.bind(this); - super(...args); - } - static initClass() { this.el = "._sidebar"; @@ -51,14 +34,16 @@ app.views.Sidebar = class Sidebar extends app.View { this.addSubview((this.search = new app.views.Search())); this.search - .on("searching", this.onSearching) - .on("clear", this.onSearchClear) - .scope.on("change", this.onScopeChange); + .on("searching", () => this.onSearching()) + .on("clear", () => this.onSearchClear()) + .scope.on("change", (newDoc, previousDoc) => + this.onScopeChange((newDoc, previousDoc)), + ); this.results = new app.views.Results(this, this.search); this.docList = new app.views.DocList(); - app.on("ready", this.onReady); + app.on("ready", () => this.onReady()); $.on(document.documentElement, "mouseleave", () => this.hide()); $.on(document.documentElement, "mouseenter", () => @@ -85,13 +70,14 @@ app.views.Sidebar = class Sidebar extends app.View { if (options.forceNoHover !== false && !this.hasClass("no-hover")) { this.addClass("no-hover"); + this.resetHoverOnMouseMove = this.resetHoverOnMouseMove.bind(this); $.on(window, "mousemove", this.resetHoverOnMouseMove); } } resetHoverOnMouseMove() { $.off(window, "mousemove", this.resetHoverOnMouseMove); - return $.requestAnimationFrame(this.resetHover); + return $.requestAnimationFrame(() => this.resetHover()); } resetHover() { diff --git a/assets/javascripts/views/sidebar/sidebar_hover.js b/assets/javascripts/views/sidebar/sidebar_hover.js index fb1cffd3..48e3a6a5 100644 --- a/assets/javascripts/views/sidebar/sidebar_hover.js +++ b/assets/javascripts/views/sidebar/sidebar_hover.js @@ -26,19 +26,11 @@ app.views.SidebarHover = class SidebarHover extends app.View { } constructor(el) { - this.position = this.position.bind(this); - this.onFocus = this.onFocus.bind(this); - this.onBlur = this.onBlur.bind(this); - this.onMouseover = this.onMouseover.bind(this); - this.onMouseout = this.onMouseout.bind(this); - this.onScroll = this.onScroll.bind(this); - this.onClick = this.onClick.bind(this); - this.onRoute = this.onRoute.bind(this); + super(...arguments); this.el = el; if (!isPointerEventsSupported()) { delete this.constructor.events.mouseover; } - super(...arguments); } show(el) { diff --git a/assets/javascripts/views/sidebar/type_list.js b/assets/javascripts/views/sidebar/type_list.js index 0670983e..f6c4c2c1 100644 --- a/assets/javascripts/views/sidebar/type_list.js +++ b/assets/javascripts/views/sidebar/type_list.js @@ -21,10 +21,8 @@ app.views.TypeList = class TypeList extends app.View { } constructor(doc) { - this.onOpen = this.onOpen.bind(this); - this.onClose = this.onClose.bind(this); - this.doc = doc; super(...arguments); + this.doc = doc; } init() { diff --git a/assets/javascripts/views/view.js b/assets/javascripts/views/view.js index 6f295240..11ad4777 100644 --- a/assets/javascripts/views/view.js +++ b/assets/javascripts/views/view.js @@ -174,6 +174,7 @@ app.View = class View { if (this.constructor.events) { for (name in this.constructor.events) { method = this.constructor.events[name]; + this[method] = this[method].bind(this); this.onDOM(name, this[method]); } } @@ -181,6 +182,7 @@ app.View = class View { if (this.constructor.routes) { for (name in this.constructor.routes) { method = this.constructor.routes[name]; + this[method] = this[method].bind(this); app.router.on(name, this[method]); } } @@ -188,6 +190,7 @@ app.View = class View { if (this.constructor.shortcuts) { for (name in this.constructor.shortcuts) { method = this.constructor.shortcuts[name]; + this[method] = this[method].bind(this); app.shortcuts.on(name, this[method]); } }