diff --git a/assets/javascripts/views/content/content.js b/assets/javascripts/views/content/content.js index 1d6a401e95..15ea9f55f5 100644 --- a/assets/javascripts/views/content/content.js +++ b/assets/javascripts/views/content/content.js @@ -9,22 +9,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.Content = class Content extends app.View { - constructor(...args) { - super(...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); + constructor() { + super(); } static initClass() { @@ -50,6 +36,21 @@ app.views.Content = class Content extends app.View { } init() { + 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); + this.scrollEl = app.isMobile() ? document.scrollingElement || document.body : this.el; diff --git a/assets/javascripts/views/content/entry_page.js b/assets/javascripts/views/content/entry_page.js index 5a2f9da5f2..3d6c73e415 100644 --- a/assets/javascripts/views/content/entry_page.js +++ b/assets/javascripts/views/content/entry_page.js @@ -10,14 +10,8 @@ (function () { let LINKS = undefined; app.views.EntryPage = class EntryPage extends app.View { - constructor(...args) { - super(...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); + constructor() { + super(); } static initClass() { @@ -40,6 +34,13 @@ } init() { + 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); + this.cacheMap = {}; this.cacheStack = []; } diff --git a/assets/javascripts/views/content/offline_page.js b/assets/javascripts/views/content/offline_page.js index 4426db412c..8a17b96605 100644 --- a/assets/javascripts/views/content/offline_page.js +++ b/assets/javascripts/views/content/offline_page.js @@ -6,9 +6,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.OfflinePage = class OfflinePage extends app.View { - constructor(...args) { - super(...args); - this.onClick = this.onClick.bind(this); + constructor() { + super(); } static initClass() { @@ -20,6 +19,10 @@ app.views.OfflinePage = class OfflinePage extends app.View { }; } + init() { + this.onClick = this.onClick.bind(this); + } + deactivate() { if (super.deactivate(...arguments)) { this.empty(); diff --git a/assets/javascripts/views/content/root_page.js b/assets/javascripts/views/content/root_page.js index 02a4c68bdd..1b1995236b 100644 --- a/assets/javascripts/views/content/root_page.js +++ b/assets/javascripts/views/content/root_page.js @@ -5,8 +5,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.RootPage = class RootPage extends app.View { - constructor(...args) { - super(...args); + constructor() { + super(); this.onClick = this.onClick.bind(this); } diff --git a/assets/javascripts/views/content/settings_page.js b/assets/javascripts/views/content/settings_page.js index e6d3c1335c..0c213c5883 100644 --- a/assets/javascripts/views/content/settings_page.js +++ b/assets/javascripts/views/content/settings_page.js @@ -7,10 +7,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.SettingsPage = class SettingsPage extends app.View { - constructor(...args) { - super(...args); - this.onChange = this.onChange.bind(this); - this.onClick = this.onClick.bind(this); + constructor() { + super(); } static initClass() { @@ -22,6 +20,11 @@ app.views.SettingsPage = class SettingsPage extends app.View { }; } + init() { + this.onChange = this.onChange.bind(this); + this.onClick = this.onClick.bind(this); + } + render() { this.html(this.tmpl("settingsPage", this.currentSettings())); } diff --git a/assets/javascripts/views/layout/document.js b/assets/javascripts/views/layout/document.js index 44df8f6f32..262a84bca6 100644 --- a/assets/javascripts/views/layout/document.js +++ b/assets/javascripts/views/layout/document.js @@ -5,10 +5,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.Document = class Document extends app.View { - constructor(...args) { - super(...args); - this.afterRoute = this.afterRoute.bind(this); - this.onVisibilityChange = this.onVisibilityChange.bind(this); + constructor() { + super(); } static initClass() { @@ -28,6 +26,9 @@ app.views.Document = class Document extends app.View { } init() { + this.afterRoute = this.afterRoute.bind(this); + this.onVisibilityChange = this.onVisibilityChange.bind(this); + this.addSubview( (this.menu = new app.views.Menu()), this.addSubview((this.sidebar = new app.views.Sidebar())) diff --git a/assets/javascripts/views/layout/menu.js b/assets/javascripts/views/layout/menu.js index 801e2e6b93..f4760ea3b7 100644 --- a/assets/javascripts/views/layout/menu.js +++ b/assets/javascripts/views/layout/menu.js @@ -4,9 +4,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.Menu = class Menu extends app.View { - constructor(...args) { - super(...args); - this.onGlobalClick = this.onGlobalClick.bind(this); + constructor() { + super(); } static initClass() { @@ -17,6 +16,8 @@ app.views.Menu = class Menu extends app.View { } init() { + this.onGlobalClick = this.onGlobalClick.bind(this); + $.on(document.body, "click", this.onGlobalClick); } diff --git a/assets/javascripts/views/layout/mobile.js b/assets/javascripts/views/layout/mobile.js index ba60e841d0..df501c5d83 100644 --- a/assets/javascripts/views/layout/mobile.js +++ b/assets/javascripts/views/layout/mobile.js @@ -52,6 +52,9 @@ app.views.Mobile = class Mobile extends app.View { constructor() { super(document.documentElement); + } + + init() { this.showSidebar = this.showSidebar.bind(this); this.hideSidebar = this.hideSidebar.bind(this); this.onClickBack = this.onClickBack.bind(this); @@ -62,10 +65,7 @@ app.views.Mobile = class Mobile extends app.View { this.onTapSearch = this.onTapSearch.bind(this); this.onEscape = this.onEscape.bind(this); this.afterRoute = this.afterRoute.bind(this); - this.el = document.documentElement; - } - init() { $.on($("._search"), "touchend", this.onTapSearch); this.toggleSidebar = $("button[data-toggle-sidebar]"); diff --git a/assets/javascripts/views/layout/path.js b/assets/javascripts/views/layout/path.js index d0bcf4ac95..f8e7b20dd2 100644 --- a/assets/javascripts/views/layout/path.js +++ b/assets/javascripts/views/layout/path.js @@ -5,10 +5,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.Path = class Path extends app.View { - constructor(...args) { - super(...args); - this.onClick = this.onClick.bind(this); - this.afterRoute = this.afterRoute.bind(this); + constructor() { + super(); } static initClass() { @@ -20,6 +18,11 @@ app.views.Path = class Path extends app.View { this.routes = { after: "afterRoute" }; } + init() { + this.onClick = this.onClick.bind(this); + this.afterRoute = this.afterRoute.bind(this); + } + render(...args) { this.html(this.tmpl("path", ...Array.from(args))); this.show(); diff --git a/assets/javascripts/views/layout/resizer.js b/assets/javascripts/views/layout/resizer.js index 3db778c534..c2a79362ea 100644 --- a/assets/javascripts/views/layout/resizer.js +++ b/assets/javascripts/views/layout/resizer.js @@ -8,11 +8,8 @@ let MIN = undefined; let MAX = undefined; app.views.Resizer = class Resizer extends app.View { - constructor(...args) { - super(...args); - this.onDragStart = this.onDragStart.bind(this); - this.onDrag = this.onDrag.bind(this); - this.onDragEnd = this.onDragEnd.bind(this); + constructor() { + super(); } static initClass() { @@ -32,6 +29,10 @@ } init() { + this.onDragStart = this.onDragStart.bind(this); + this.onDrag = this.onDrag.bind(this); + this.onDragEnd = this.onDragEnd.bind(this); + this.el.setAttribute("draggable", "true"); this.appendTo($("._app")); } diff --git a/assets/javascripts/views/layout/settings.js b/assets/javascripts/views/layout/settings.js index 23d4034136..5a040db048 100644 --- a/assets/javascripts/views/layout/settings.js +++ b/assets/javascripts/views/layout/settings.js @@ -10,13 +10,8 @@ (function () { let SIDEBAR_HIDDEN_LAYOUT = undefined; app.views.Settings = class Settings extends app.View { - constructor(...args) { - super(...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); + constructor() { + super(); } static initClass() { @@ -41,6 +36,12 @@ } init() { + 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); + this.addSubview((this.docPicker = new app.views.DocPicker())); } diff --git a/assets/javascripts/views/list/list_focus.js b/assets/javascripts/views/list/list_focus.js index c2aea86a3b..818bdfbf51 100644 --- a/assets/javascripts/views/list/list_focus.js +++ b/assets/javascripts/views/list/list_focus.js @@ -23,6 +23,9 @@ app.views.ListFocus = class ListFocus extends app.View { constructor(el) { super(el); + } + + init() { this.blur = this.blur.bind(this); this.onDown = this.onDown.bind(this); this.onUp = this.onUp.bind(this); @@ -30,7 +33,6 @@ app.views.ListFocus = class ListFocus extends app.View { this.onEnter = this.onEnter.bind(this); this.onSuperEnter = this.onSuperEnter.bind(this); this.onClick = this.onClick.bind(this); - 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 2fc3eaae90..9649f69583 100644 --- a/assets/javascripts/views/list/list_fold.js +++ b/assets/javascripts/views/list/list_fold.js @@ -20,10 +20,12 @@ app.views.ListFold = class ListFold extends app.View { constructor(el) { super(el); + } + + init() { this.onLeft = this.onLeft.bind(this); this.onRight = this.onRight.bind(this); this.onClick = this.onClick.bind(this); - this.el = el; } open(el) { diff --git a/assets/javascripts/views/list/list_select.js b/assets/javascripts/views/list/list_select.js index f37ff65f1a..7594667c0a 100644 --- a/assets/javascripts/views/list/list_select.js +++ b/assets/javascripts/views/list/list_select.js @@ -13,8 +13,10 @@ app.views.ListSelect = class ListSelect extends app.View { constructor(el) { super(el); + } + + init() { this.onClick = this.onClick.bind(this); - this.el = el; } deactivate() { diff --git a/assets/javascripts/views/list/paginated_list.js b/assets/javascripts/views/list/paginated_list.js index ec90de20c9..cb21f71ca1 100644 --- a/assets/javascripts/views/list/paginated_list.js +++ b/assets/javascripts/views/list/paginated_list.js @@ -15,15 +15,14 @@ } constructor(data) { - super(...arguments); - let base; + super(undefined, { data, entries: data }); + } + + init() { this.onClick = this.onClick.bind(this); - this.data = data; - if ( - (base = this.constructor.events || (this.constructor.events = {})) - .click == null - ) { - base.click = "onClick"; + this.constructor.events = this.constructor.events || {}; + if (this.constructor.events.click == null) { + this.constructor.events.click = "onClick"; } } diff --git a/assets/javascripts/views/misc/notice.js b/assets/javascripts/views/misc/notice.js index 7d1258d3a2..a8580927c8 100644 --- a/assets/javascripts/views/misc/notice.js +++ b/assets/javascripts/views/misc/notice.js @@ -11,9 +11,7 @@ app.views.Notice = class Notice extends app.View { } constructor(type, ...rest) { - super(...arguments); - this.type = type; - [...this.args] = Array.from(rest); + super(undefined, { type, args: rest }); } init() { diff --git a/assets/javascripts/views/misc/notif.js b/assets/javascripts/views/misc/notif.js index 3ad7d2246b..50e8f79457 100644 --- a/assets/javascripts/views/misc/notif.js +++ b/assets/javascripts/views/misc/notif.js @@ -16,17 +16,13 @@ app.views.Notif = class Notif extends app.View { } constructor(type, options) { - super(...arguments); - 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(undefined, { type, options: options || {} }); } init() { + this.onClick = this.onClick.bind(this); + this.options = $.extend({}, this.constructor.defautOptions, this.options); + this.show(); } diff --git a/assets/javascripts/views/pages/base.js b/assets/javascripts/views/pages/base.js index 433f2df11a..7efba552cf 100644 --- a/assets/javascripts/views/pages/base.js +++ b/assets/javascripts/views/pages/base.js @@ -7,10 +7,11 @@ */ app.views.BasePage = class BasePage extends app.View { constructor(el, entry) { - super(el); + super(el, { entry }); + } + + init() { this.paintCode = this.paintCode.bind(this); - this.el = el; - this.entry = entry; } deactivate() { diff --git a/assets/javascripts/views/pages/hidden.js b/assets/javascripts/views/pages/hidden.js index cd2ef8d690..a9ba772a39 100644 --- a/assets/javascripts/views/pages/hidden.js +++ b/assets/javascripts/views/pages/hidden.js @@ -9,13 +9,12 @@ app.views.HiddenPage = class HiddenPage extends app.View { } constructor(el, entry) { - super(el); - this.onClick = this.onClick.bind(this); - this.el = el; - this.entry = entry; + super(el, { entry }); } init() { + this.onClick = this.onClick.bind(this); + this.addSubview((this.notice = new app.views.Notice("disabledDoc"))); this.activate(); } diff --git a/assets/javascripts/views/pages/jquery.js b/assets/javascripts/views/pages/jquery.js index 066d32f0df..9074125436 100644 --- a/assets/javascripts/views/pages/jquery.js +++ b/assets/javascripts/views/pages/jquery.js @@ -8,15 +8,18 @@ //= require views/pages/base app.views.JqueryPage = class JqueryPage extends app.views.BasePage { - constructor(...args) { - super(...args); - this.onIframeLoaded = this.onIframeLoaded.bind(this); + constructor() { + super(); } static initClass() { this.demoClassName = "_jquery-demo"; } + init() { + this.onIframeLoaded = this.onIframeLoaded.bind(this); + } + afterRender() { // Prevent jQuery Mobile's demo iframes from scrolling the page for (let iframe of Array.from(this.findAllByTag("iframe"))) { diff --git a/assets/javascripts/views/pages/sqlite.js b/assets/javascripts/views/pages/sqlite.js index 9081ef9cf0..d8da6b04a2 100644 --- a/assets/javascripts/views/pages/sqlite.js +++ b/assets/javascripts/views/pages/sqlite.js @@ -6,15 +6,18 @@ //= require views/pages/base app.views.SqlitePage = class SqlitePage extends app.views.BasePage { - constructor(...args) { - super(...args); - this.onClick = this.onClick.bind(this); + constructor() { + super(); } static initClass() { this.events = { click: "onClick" }; } + init() { + this.onClick = this.onClick.bind(this); + } + onClick(event) { let el, id; if (!(id = event.target.getAttribute("data-toggle"))) { diff --git a/assets/javascripts/views/search/search.js b/assets/javascripts/views/search/search.js index 43b5251d04..229f850d9b 100644 --- a/assets/javascripts/views/search/search.js +++ b/assets/javascripts/views/search/search.js @@ -9,28 +9,13 @@ let SEARCH_PARAM = undefined; let HASH_RGX = undefined; app.views.Search = class Search extends app.View { - constructor(...args) { - super(...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); + constructor() { + super("._search"); } static initClass() { SEARCH_PARAM = app.config.search_param; - this.el = "._search"; this.activeClass = "_search-active"; this.elements = { @@ -57,6 +42,21 @@ } init() { + 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); + this.addSubview((this.scope = new app.views.SearchScope(this.el))); this.searcher = new app.Searcher(); diff --git a/assets/javascripts/views/search/search_scope.js b/assets/javascripts/views/search/search_scope.js index b7137e8ee7..10c18c1fa1 100644 --- a/assets/javascripts/views/search/search_scope.js +++ b/assets/javascripts/views/search/search_scope.js @@ -30,6 +30,9 @@ constructor(el) { super(el); + } + + init() { this.onResults = this.onResults.bind(this); this.reset = this.reset.bind(this); this.doScopeSearch = this.doScopeSearch.bind(this); @@ -37,10 +40,7 @@ this.onKeydown = this.onKeydown.bind(this); this.onTextInput = this.onTextInput.bind(this); this.afterRoute = this.afterRoute.bind(this); - this.el = el; - } - init() { this.placeholder = this.input.getAttribute("placeholder"); this.searcher = new app.SynchronousSearcher({ diff --git a/assets/javascripts/views/sidebar/doc_list.js b/assets/javascripts/views/sidebar/doc_list.js index 8a87238b3e..14dd2103bb 100644 --- a/assets/javascripts/views/sidebar/doc_list.js +++ b/assets/javascripts/views/sidebar/doc_list.js @@ -6,14 +6,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.DocList = class DocList extends app.View { - constructor(...args) { - super(...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); + constructor() { + super(); } static initClass() { @@ -35,6 +29,13 @@ app.views.DocList = class DocList extends app.View { } init() { + 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); + this.lists = {}; this.addSubview((this.listFocus = new app.views.ListFocus(this.el))); diff --git a/assets/javascripts/views/sidebar/doc_picker.js b/assets/javascripts/views/sidebar/doc_picker.js index 211bed9177..8a25df9e9d 100644 --- a/assets/javascripts/views/sidebar/doc_picker.js +++ b/assets/javascripts/views/sidebar/doc_picker.js @@ -7,11 +7,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.DocPicker = class DocPicker extends app.View { - constructor(...args) { - super(...args); - this.onMouseDown = this.onMouseDown.bind(this); - this.onMouseUp = this.onMouseUp.bind(this); - this.onDOMFocus = this.onDOMFocus.bind(this); + constructor() { + super(); } static initClass() { @@ -24,6 +21,10 @@ app.views.DocPicker = class DocPicker extends app.View { } init() { + this.onMouseDown = this.onMouseDown.bind(this); + this.onMouseUp = this.onMouseUp.bind(this); + this.onDOMFocus = this.onDOMFocus.bind(this); + this.addSubview((this.listFold = new app.views.ListFold(this.el))); } diff --git a/assets/javascripts/views/sidebar/entry_list.js b/assets/javascripts/views/sidebar/entry_list.js index 392b77ca5d..1a88f3bc79 100644 --- a/assets/javascripts/views/sidebar/entry_list.js +++ b/assets/javascripts/views/sidebar/entry_list.js @@ -13,8 +13,7 @@ app.views.EntryList = class EntryList extends app.views.PaginatedList { } constructor(entries) { - super(); - this.entries = entries; + super(entries); } init() { diff --git a/assets/javascripts/views/sidebar/results.js b/assets/javascripts/views/sidebar/results.js index f024297cff..a25b3b6266 100644 --- a/assets/javascripts/views/sidebar/results.js +++ b/assets/javascripts/views/sidebar/results.js @@ -14,14 +14,7 @@ app.views.Results = class Results extends app.View { } constructor(sidebar, search) { - super(); - 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); - this.sidebar = sidebar; - this.search = search; + super(undefined, { sidebar, search }); } deactivate() { @@ -31,6 +24,12 @@ app.views.Results = class Results extends app.View { } init() { + 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); + this.addSubview((this.listFocus = new app.views.ListFocus(this.el))); this.addSubview((this.listSelect = new app.views.ListSelect(this.el))); diff --git a/assets/javascripts/views/sidebar/sidebar.js b/assets/javascripts/views/sidebar/sidebar.js index a239e6139a..e215453406 100644 --- a/assets/javascripts/views/sidebar/sidebar.js +++ b/assets/javascripts/views/sidebar/sidebar.js @@ -6,21 +6,8 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ app.views.Sidebar = class Sidebar extends app.View { - constructor(...args) { - super(...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); + constructor() { + super(); } static initClass() { @@ -41,6 +28,20 @@ app.views.Sidebar = class Sidebar extends app.View { } init() { + 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); + if (!app.isMobile()) { this.addSubview((this.hover = new app.views.SidebarHover(this.el))); } diff --git a/assets/javascripts/views/sidebar/sidebar_hover.js b/assets/javascripts/views/sidebar/sidebar_hover.js index a808dfa61d..192bedffe8 100644 --- a/assets/javascripts/views/sidebar/sidebar_hover.js +++ b/assets/javascripts/views/sidebar/sidebar_hover.js @@ -22,7 +22,10 @@ app.views.SidebarHover = class SidebarHover extends app.View { } constructor(el) { - super(...arguments); + super(el); + } + + init() { this.position = this.position.bind(this); this.onFocus = this.onFocus.bind(this); this.onBlur = this.onBlur.bind(this); @@ -31,7 +34,6 @@ app.views.SidebarHover = class SidebarHover extends app.View { this.onScroll = this.onScroll.bind(this); this.onClick = this.onClick.bind(this); this.onRoute = this.onRoute.bind(this); - this.el = el; if (!isPointerEventsSupported()) { delete this.constructor.events.mouseover; } diff --git a/assets/javascripts/views/sidebar/type_list.js b/assets/javascripts/views/sidebar/type_list.js index adf2b84757..b0304137a8 100644 --- a/assets/javascripts/views/sidebar/type_list.js +++ b/assets/javascripts/views/sidebar/type_list.js @@ -17,13 +17,13 @@ app.views.TypeList = class TypeList extends app.View { } constructor(doc) { - super(...arguments); - this.onOpen = this.onOpen.bind(this); - this.onClose = this.onClose.bind(this); - this.doc = doc; + super(undefined, { doc }); } init() { + this.onOpen = this.onOpen.bind(this); + this.onClose = this.onClose.bind(this); + this.lists = {}; this.render(); this.activate(); diff --git a/assets/javascripts/views/view.js b/assets/javascripts/views/view.js index eae30135db..9748e8526a 100644 --- a/assets/javascripts/views/view.js +++ b/assets/javascripts/views/view.js @@ -11,8 +11,12 @@ app.View = class View { $.extend(this.prototype, Events); } - constructor() { - this.setupElement(); + constructor(el, fields = {}) { + this.setupElement(el); + for (let key in fields) { + const value = fields[key]; + this[key] = value; + } if (this.el.className) { this.originalClassName = this.el.className; } @@ -24,13 +28,13 @@ app.View = class View { this.refreshElements(); } - setupElement() { + setupElement(el) { if (this.el == null) { this.el = - typeof this.constructor.el === "string" - ? $(this.constructor.el) - : this.constructor.el - ? this.constructor.el + typeof el === "string" + ? $(el) + : el instanceof Element + ? el : document.createElement(this.constructor.tagName || "div"); }