From e8f702666f285a3e69866ed1f8d29fa6eaaaeabb Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 13 Oct 2021 15:19:28 +0300 Subject: JS: minor refactoring (#35183) * add missing comments * shorten block comments * reorder constants * reorder public/private methods * sort exports alphabetically in util/index.js * fix a couple of typos --- js/src/scrollspy.js | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) (limited to 'js/src/scrollspy.js') diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index bdc22653b..27bc0cd87 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -17,9 +17,7 @@ import SelectorEngine from './dom/selector-engine' import BaseComponent from './base-component' /** - * ------------------------------------------------------------------------ * Constants - * ------------------------------------------------------------------------ */ const NAME = 'scrollspy' @@ -27,18 +25,6 @@ const DATA_KEY = 'bs.scrollspy' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' -const Default = { - offset: 10, - method: 'auto', - target: '' -} - -const DefaultType = { - offset: 'number', - method: 'string', - target: '(string|element)' -} - const EVENT_ACTIVATE = `activate${EVENT_KEY}` const EVENT_SCROLL = `scroll${EVENT_KEY}` const EVENT_LOAD_DATA_API = `load${EVENT_KEY}${DATA_API_KEY}` @@ -58,10 +44,20 @@ const SELECTOR_DROPDOWN_TOGGLE = '.dropdown-toggle' const METHOD_OFFSET = 'offset' const METHOD_POSITION = 'position' +const Default = { + offset: 10, + method: 'auto', + target: '' +} + +const DefaultType = { + offset: 'number', + method: 'string', + target: '(string|element)' +} + /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ + * Class definition */ class ScrollSpy extends BaseComponent { @@ -81,7 +77,6 @@ class ScrollSpy extends BaseComponent { } // Getters - static get Default() { return Default } @@ -91,7 +86,6 @@ class ScrollSpy extends BaseComponent { } // Public - refresh() { const autoMethod = this._scrollElement === this._scrollElement.window ? METHOD_OFFSET : @@ -141,7 +135,6 @@ class ScrollSpy extends BaseComponent { } // Private - _getConfig(config) { config = { ...Default, @@ -257,7 +250,6 @@ class ScrollSpy extends BaseComponent { } // Static - static jQueryInterface(config) { return this.each(function () { const data = ScrollSpy.getOrCreateInstance(this, config) @@ -276,9 +268,7 @@ class ScrollSpy extends BaseComponent { } /** - * ------------------------------------------------------------------------ - * Data Api implementation - * ------------------------------------------------------------------------ + * Data API implementation */ EventHandler.on(window, EVENT_LOAD_DATA_API, () => { @@ -288,10 +278,7 @@ EventHandler.on(window, EVENT_LOAD_DATA_API, () => { }) /** - * ------------------------------------------------------------------------ * jQuery - * ------------------------------------------------------------------------ - * add .ScrollSpy to jQuery only if jQuery is present */ defineJQueryPlugin(ScrollSpy) -- cgit v1.2.3