From 80d0943b95984bfaf4997d2198d467876d294bd8 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 16 Dec 2017 14:00:38 +0200 Subject: [PATCH] Comply to the new rules. --- assets/js/src/application.js | 3 +- assets/js/src/pwa.js | 2 +- build/change-version.js | 32 +- build/generate-sri.js | 2 +- build/postcss.config.js | 4 +- build/rollup.config.js | 11 +- build/saucelabs-unit-test.js | 2 +- build/vnu-jar.js | 2 +- build/workbox.js | 1 + js/src/alert.js | 21 +- js/src/button.js | 29 +- js/src/carousel.js | 48 +- js/src/collapse.js | 45 +- js/src/dropdown.js | 75 ++- js/src/index.js | 4 +- js/src/modal.js | 49 +- js/src/popover.js | 40 +- js/src/scrollspy.js | 76 ++- js/src/tab.js | 40 +- js/src/tooltip.js | 87 ++-- js/src/util.js | 19 +- js/tests/unit/alert.js | 17 +- js/tests/unit/button.js | 53 +-- js/tests/unit/carousel.js | 898 ++++++++++++++++++----------------- js/tests/unit/collapse.js | 153 +++--- js/tests/unit/dropdown.js | 796 ++++++++++++++++--------------- js/tests/unit/modal.js | 19 +- js/tests/unit/popover.js | 18 +- js/tests/unit/scrollspy.js | 572 ++++++++++++---------- js/tests/unit/tab.js | 270 ++++++----- js/tests/unit/tooltip.js | 156 ++++-- js/tests/unit/util.js | 14 +- 32 files changed, 1798 insertions(+), 1760 deletions(-) diff --git a/assets/js/src/application.js b/assets/js/src/application.js index d5ee22ebc3..01c9eef55b 100644 --- a/assets/js/src/application.js +++ b/assets/js/src/application.js @@ -16,7 +16,6 @@ 'use strict' $(function () { - // Tooltip and popover demos $('.tooltip-demo').tooltip({ selector: '[data-toggle="tooltip"]', @@ -60,7 +59,7 @@ $('.btn-clipboard') .tooltip() .on('mouseleave', function () { - // explicitly hide tooltip, since after clicking it remains + // Explicitly hide tooltip, since after clicking it remains // focused (as it's a button), so tooltip would otherwise // remain visible until focus is moved away $(this).tooltip('hide') diff --git a/assets/js/src/pwa.js b/assets/js/src/pwa.js index 3484f05b04..22a0dde6d7 100644 --- a/assets/js/src/pwa.js +++ b/assets/js/src/pwa.js @@ -1,6 +1,6 @@ /* eslint no-console:off */ -(function setupSW() { +(function () { 'use strict' if ('serviceWorker' in navigator) { diff --git a/build/change-version.js b/build/change-version.js index ab4579072b..dc0b0c5dfd 100755 --- a/build/change-version.js +++ b/build/change-version.js @@ -18,8 +18,13 @@ const sh = require('shelljs') sh.config.fatal = true // Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37 -RegExp.quote = (string) => string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&') -RegExp.quoteReplacement = (string) => string.replace(/[$]/g, '$$') +function regExpQuote(string) { + return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&') +} + +function regExpQuoteReplacement(string) { + return string.replace(/[$]/g, '$$') +} const DRY_RUN = false @@ -39,13 +44,9 @@ function walkAsync(directory, excludedDirectories, fileCallback, errback) { process.nextTick(errback, err) return } - if (stats.isSymbolicLink()) { - return - } - else if (stats.isDirectory()) { + if (stats.isDirectory()) { process.nextTick(walkAsync, filepath, excludedDirectories, fileCallback, errback) - } - else if (stats.isFile()) { + } else if (stats.isFile()) { process.nextTick(fileCallback, filepath) } }) @@ -54,18 +55,17 @@ function walkAsync(directory, excludedDirectories, fileCallback, errback) { } function replaceRecursively(directory, excludedDirectories, allowedExtensions, original, replacement) { - original = new RegExp(RegExp.quote(original), 'g') - replacement = RegExp.quoteReplacement(replacement) - const updateFile = !DRY_RUN ? (filepath) => { + original = new RegExp(regExpQuote(original), 'g') + replacement = regExpQuoteReplacement(replacement) + const updateFile = DRY_RUN ? (filepath) => { if (allowedExtensions.has(path.parse(filepath).ext)) { - sh.sed('-i', original, replacement, filepath) + console.log(`FILE: ${filepath}`) + } else { + console.log(`EXCLUDED:${filepath}`) } } : (filepath) => { if (allowedExtensions.has(path.parse(filepath).ext)) { - console.log(`FILE: ${filepath}`) - } - else { - console.log(`EXCLUDED:${filepath}`) + sh.sed('-i', original, replacement, filepath) } } walkAsync(directory, excludedDirectories, updateFile, (err) => { diff --git a/build/generate-sri.js b/build/generate-sri.js index 708e6dfbf8..2ace46e05f 100644 --- a/build/generate-sri.js +++ b/build/generate-sri.js @@ -55,6 +55,6 @@ files.forEach((file) => { console.log(`${file.configPropertyName}: ${integrity}`) - sh.sed('-i', new RegExp(`(\\s${file.configPropertyName}:\\s+"|')(\\S+)("|')`), '$1' + integrity + '$3', configFile) + sh.sed('-i', new RegExp(`(\\s${file.configPropertyName}:\\s+"|')(\\S+)("|')`), `$1${integrity}$3`, configFile) }) }) diff --git a/build/postcss.config.js b/build/postcss.config.js index c7c9a17b05..157291ffd2 100644 --- a/build/postcss.config.js +++ b/build/postcss.config.js @@ -7,6 +7,8 @@ module.exports = (ctx) => ({ sourcesContent: true }, plugins: { - autoprefixer: { cascade: false } + autoprefixer: { + cascade: false + } } }) diff --git a/build/rollup.config.js b/build/rollup.config.js index 0b59aef652..c97e3761c1 100644 --- a/build/rollup.config.js +++ b/build/rollup.config.js @@ -3,16 +3,17 @@ const path = require('path') const babel = require('rollup-plugin-babel') const resolve = require('rollup-plugin-node-resolve') + const pkg = require(path.resolve(__dirname, '../package.json')) const BUNDLE = process.env.BUNDLE === 'true' const year = new Date().getFullYear() let fileDest = 'bootstrap.js' -const external = ['jquery', 'popper.js'] +const external = ['jquery', 'popper.js'] const plugins = [ babel({ - exclude: 'node_modules/**', // only transpile our source code - externalHelpersWhitelist: [ // include only required helpers + exclude: 'node_modules/**', // Only transpile our source code + externalHelpersWhitelist: [ // Include only required helpers 'defineProperties', 'createClass', 'inheritsLoose', @@ -21,13 +22,13 @@ const plugins = [ }) ] const globals = { - jquery: 'jQuery', // ensure we use jQuery which is always available even in noConflict mode + jquery: 'jQuery', // Ensure we use jQuery which is always available even in noConflict mode 'popper.js': 'Popper' } if (BUNDLE) { fileDest = 'bootstrap.bundle.js' - // remove last entry in external array to bundle Popper + // Remove last entry in external array to bundle Popper external.pop() delete globals['popper.js'] plugins.push(resolve()) diff --git a/build/saucelabs-unit-test.js b/build/saucelabs-unit-test.js index 0b4a3b5f0e..3ec68a95b2 100644 --- a/build/saucelabs-unit-test.js +++ b/build/saucelabs-unit-test.js @@ -91,7 +91,7 @@ jsUnitSaucelabs.on('tunnelCreated', () => { if (typeof success !== 'undefined') { const taskIds = success['js tests'] - if (!taskIds || !taskIds.length) { + if (!taskIds || taskIds.length === 0) { throw new Error('Error starting tests through Sauce Labs API') } diff --git a/build/vnu-jar.js b/build/vnu-jar.js index 991d5c1c09..eefcb64ebf 100644 --- a/build/vnu-jar.js +++ b/build/vnu-jar.js @@ -64,5 +64,5 @@ childProcess.exec('java -version', (error, stdout, stderr) => { shell: true, stdio: 'inherit' }) - .on('exit', process.exit) + .on('exit', process.exit) }) diff --git a/build/workbox.js b/build/workbox.js index 17129ec8c3..e51cf6dcbd 100644 --- a/build/workbox.js +++ b/build/workbox.js @@ -4,6 +4,7 @@ const fs = require('fs') const path = require('path') const swBuild = require('workbox-build') const config = require('./workbox.config.json') + const buildPrefix = '_gh_pages/' const workboxSWSrcPath = require.resolve('workbox-sw') diff --git a/js/src/alert.js b/js/src/alert.js index 9f17d5ed0e..147701bfe2 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -1,7 +1,6 @@ import $ from 'jquery' import Util from './util' - /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.3): alert.js @@ -10,8 +9,6 @@ import Util from './util' */ const Alert = (($) => { - - /** * ------------------------------------------------------------------------ * Constants @@ -42,7 +39,6 @@ const Alert = (($) => { SHOW : 'show' } - /** * ------------------------------------------------------------------------ * Class Definition @@ -50,20 +46,17 @@ const Alert = (($) => { */ class Alert { - constructor(element) { this._element = element } - - // getters + // Getters static get VERSION() { return VERSION } - - // public + // Public close(element) { element = element || this._element @@ -83,8 +76,7 @@ const Alert = (($) => { this._element = null } - - // private + // Private _getRootElement(element) { const selector = Util.getSelectorFromElement(element) @@ -129,8 +121,7 @@ const Alert = (($) => { .remove() } - - // static + // Static static _jQueryInterface(config) { return this.each(function () { @@ -157,10 +148,8 @@ const Alert = (($) => { alertInstance.close(this) } } - } - /** * ------------------------------------------------------------------------ * Data Api implementation @@ -173,7 +162,6 @@ const Alert = (($) => { Alert._handleDismiss(new Alert()) ) - /** * ------------------------------------------------------------------------ * jQuery @@ -188,7 +176,6 @@ const Alert = (($) => { } return Alert - })($) export default Alert diff --git a/js/src/button.js b/js/src/button.js index 56688e2462..445e78938b 100644 --- a/js/src/button.js +++ b/js/src/button.js @@ -8,8 +8,6 @@ import $ from 'jquery' */ const Button = (($) => { - - /** * ------------------------------------------------------------------------ * Constants @@ -39,11 +37,10 @@ const Button = (($) => { const Event = { CLICK_DATA_API : `click${EVENT_KEY}${DATA_API_KEY}`, - FOCUS_BLUR_DATA_API : `focus${EVENT_KEY}${DATA_API_KEY} ` - + `blur${EVENT_KEY}${DATA_API_KEY}` + FOCUS_BLUR_DATA_API : `focus${EVENT_KEY}${DATA_API_KEY} ` + + `blur${EVENT_KEY}${DATA_API_KEY}` } - /** * ------------------------------------------------------------------------ * Class Definition @@ -51,25 +48,22 @@ const Button = (($) => { */ class Button { - constructor(element) { this._element = element } - - // getters + // Getters static get VERSION() { return VERSION } - - // public + // Public toggle() { let triggerChangeEvent = true let addAriaPressed = true - const rootElement = $(this._element).closest( + const rootElement = $(this._element).closest( Selector.DATA_TOGGLE )[0] @@ -81,7 +75,6 @@ const Button = (($) => { if (input.checked && $(this._element).hasClass(ClassName.ACTIVE)) { triggerChangeEvent = false - } else { const activeElement = $(rootElement).find(Selector.ACTIVE)[0] @@ -105,7 +98,6 @@ const Button = (($) => { input.focus() addAriaPressed = false } - } if (addAriaPressed) { @@ -123,8 +115,7 @@ const Button = (($) => { this._element = null } - - // static + // Static static _jQueryInterface(config) { return this.each(function () { @@ -140,10 +131,8 @@ const Button = (($) => { } }) } - } - /** * ------------------------------------------------------------------------ * Data Api implementation @@ -167,22 +156,20 @@ const Button = (($) => { $(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type)) }) - /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - $.fn[NAME] = Button._jQueryInterface + $.fn[NAME] = Button._jQueryInterface $.fn[NAME].Constructor = Button - $.fn[NAME].noConflict = function () { + $.fn[NAME].noConflict = function () { $.fn[NAME] = JQUERY_NO_CONFLICT return Button._jQueryInterface } return Button - })($) export default Button diff --git a/js/src/carousel.js b/js/src/carousel.js index 083f2548e4..895d4dd3bf 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -1,7 +1,6 @@ import $ from 'jquery' import Util from './util' - /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.3): carousel.js @@ -10,8 +9,6 @@ import Util from './util' */ const Carousel = (($) => { - - /** * ------------------------------------------------------------------------ * Constants @@ -84,7 +81,6 @@ const Carousel = (($) => { DATA_RIDE : '[data-ride="carousel"]' } - /** * ------------------------------------------------------------------------ * Class Definition @@ -92,7 +88,6 @@ const Carousel = (($) => { */ class Carousel { - constructor(element, config) { this._items = null this._interval = null @@ -110,8 +105,7 @@ const Carousel = (($) => { this._addEventListeners() } - - // getters + // Getters static get VERSION() { return VERSION @@ -121,8 +115,7 @@ const Carousel = (($) => { return Default } - - // public + // Public next() { if (!this._isSliding) { @@ -198,9 +191,9 @@ const Carousel = (($) => { return } - const direction = index > activeIndex ? - Direction.NEXT : - Direction.PREV + const direction = index > activeIndex + ? Direction.NEXT + : Direction.PREV this._slide(direction, this._items[index]) } @@ -219,8 +212,7 @@ const Carousel = (($) => { this._indicatorsElement = null } - - // private + // Private _getConfig(config) { config = { @@ -242,7 +234,7 @@ const Carousel = (($) => { .on(Event.MOUSEENTER, (event) => this.pause(event)) .on(Event.MOUSELEAVE, (event) => this.cycle(event)) if ('ontouchstart' in document.documentElement) { - // if it's a touch-enabled device, mouseenter/leave are fired as + // If it's a touch-enabled device, mouseenter/leave are fired as // part of the mouse compatibility events on first tap - the carousel // would stop cycling until user tapped out of it; // here, we listen for touchend, explicitly pause the carousel @@ -275,7 +267,6 @@ const Carousel = (($) => { this.next() break default: - return } } @@ -299,11 +290,10 @@ const Carousel = (($) => { const delta = direction === Direction.PREV ? -1 : 1 const itemIndex = (activeIndex + delta) % this._items.length - return itemIndex === -1 ? - this._items[this._items.length - 1] : this._items[itemIndex] + return itemIndex === -1 + ? this._items[this._items.length - 1] : this._items[itemIndex] } - _triggerSlideEvent(relatedTarget, eventDirectionName) { const targetIndex = this._getItemIndex(relatedTarget) const fromIndex = this._getItemIndex($(this._element).find(Selector.ACTIVE_ITEM)[0]) @@ -368,7 +358,7 @@ const Carousel = (($) => { } if (!activeElement || !nextElement) { - // some weirdness is happening, so we bail + // Some weirdness is happening, so we bail return } @@ -389,7 +379,6 @@ const Carousel = (($) => { if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.SLIDE)) { - $(nextElement).addClass(orderClassName) Util.reflow(nextElement) @@ -408,10 +397,8 @@ const Carousel = (($) => { this._isSliding = false setTimeout(() => $(this._element).trigger(slidEvent), 0) - }) .emulateTransitionEnd(TRANSITION_DURATION) - } else { $(activeElement).removeClass(ClassName.ACTIVE) $(nextElement).addClass(ClassName.ACTIVE) @@ -425,12 +412,11 @@ const Carousel = (($) => { } } - - // static + // Static static _jQueryInterface(config) { return this.each(function () { - let data = $(this).data(DATA_KEY) + let data = $(this).data(DATA_KEY) let _config = { ...Default, ...$(this).data() @@ -454,7 +440,7 @@ const Carousel = (($) => { data.to(config) } else if (typeof action === 'string') { if (typeof data[action] === 'undefined') { - throw new Error(`No method named "${action}"`) + throw new TypeError(`No method named "${action}"`) } data[action]() } else if (_config.interval) { @@ -495,10 +481,8 @@ const Carousel = (($) => { event.preventDefault() } - } - /** * ------------------------------------------------------------------------ * Data Api implementation @@ -515,22 +499,20 @@ const Carousel = (($) => { }) }) - /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - $.fn[NAME] = Carousel._jQueryInterface + $.fn[NAME] = Carousel._jQueryInterface $.fn[NAME].Constructor = Carousel - $.fn[NAME].noConflict = function () { + $.fn[NAME].noConflict = function () { $.fn[NAME] = JQUERY_NO_CONFLICT return Carousel._jQueryInterface } return Carousel - })($) export default Carousel diff --git a/js/src/collapse.js b/js/src/collapse.js index b0c17112c6..eaaf155e1e 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -1,7 +1,6 @@ import $ from 'jquery' import Util from './util' - /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.3): collapse.js @@ -10,8 +9,6 @@ import Util from './util' */ const Collapse = (($) => { - - /** * ------------------------------------------------------------------------ * Constants @@ -61,7 +58,6 @@ const Collapse = (($) => { DATA_TOGGLE : '[data-toggle="collapse"]' } - /** * ------------------------------------------------------------------------ * Class Definition @@ -69,7 +65,6 @@ const Collapse = (($) => { */ class Collapse { - constructor(element, config) { this._isTransitioning = false this._element = element @@ -99,8 +94,7 @@ const Collapse = (($) => { } } - - // getters + // Getters static get VERSION() { return VERSION @@ -110,8 +104,7 @@ const Collapse = (($) => { return Default } - - // public + // Public toggle() { if ($(this._element).hasClass(ClassName.SHOW)) { @@ -136,7 +129,7 @@ const Collapse = (($) => { .find(Selector.ACTIVES) .filter(`[data-parent="${this._config.parent}"]`) ) - if (!actives.length) { + if (actives.length === 0) { actives = null } } @@ -169,7 +162,7 @@ const Collapse = (($) => { this._element.style[dimension] = 0 - if (this._triggerArray.length) { + if (this._triggerArray.length > 0) { $(this._triggerArray) .removeClass(ClassName.COLLAPSED) .attr('aria-expanded', true) @@ -196,7 +189,7 @@ const Collapse = (($) => { } const capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1) - const scrollSize = `scroll${capitalizedDimension}` + const scrollSize = `scroll${capitalizedDimension}` $(this._element) .one(Util.TRANSITION_END, complete) @@ -217,7 +210,7 @@ const Collapse = (($) => { return } - const dimension = this._getDimension() + const dimension = this._getDimension() this._element.style[dimension] = `${this._element.getBoundingClientRect()[dimension]}px` @@ -228,7 +221,7 @@ const Collapse = (($) => { .removeClass(ClassName.COLLAPSE) .removeClass(ClassName.SHOW) - if (this._triggerArray.length) { + if (this._triggerArray.length > 0) { for (let i = 0; i < this._triggerArray.length; i++) { const trigger = this._triggerArray[i] const selector = Util.getSelectorFromElement(trigger) @@ -236,7 +229,7 @@ const Collapse = (($) => { const $elem = $(selector) if (!$elem.hasClass(ClassName.SHOW)) { $(trigger).addClass(ClassName.COLLAPSED) - .attr('aria-expanded', false) + .attr('aria-expanded', false) } } } @@ -278,15 +271,14 @@ const Collapse = (($) => { this._isTransitioning = null } - - // private + // Private _getConfig(config) { config = { ...Default, ...config } - config.toggle = Boolean(config.toggle) // coerce string values + config.toggle = Boolean(config.toggle) // Coerce string values Util.typeCheckConfig(NAME, config, DefaultType) return config } @@ -301,7 +293,7 @@ const Collapse = (($) => { if (Util.isElement(this._config.parent)) { parent = this._config.parent - // it's a jQuery object + // It's a jQuery object if (typeof this._config.parent.jquery !== 'undefined') { parent = this._config.parent[0] } @@ -326,7 +318,7 @@ const Collapse = (($) => { if (element) { const isOpen = $(element).hasClass(ClassName.SHOW) - if (triggerArray.length) { + if (triggerArray.length > 0) { $(triggerArray) .toggleClass(ClassName.COLLAPSED, !isOpen) .attr('aria-expanded', isOpen) @@ -334,8 +326,7 @@ const Collapse = (($) => { } } - - // static + // Static static _getTargetFromElement(element) { const selector = Util.getSelectorFromElement(element) @@ -363,16 +354,14 @@ const Collapse = (($) => { if (typeof config === 'string') { if (typeof data[config] === 'undefined') { - throw new Error(`No method named "${config}"`) + throw new TypeError(`No method named "${config}"`) } data[config]() } }) } - } - /** * ------------------------------------------------------------------------ * Data Api implementation @@ -395,22 +384,20 @@ const Collapse = (($) => { }) }) - /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - $.fn[NAME] = Collapse._jQueryInterface + $.fn[NAME] = Collapse._jQueryInterface $.fn[NAME].Constructor = Collapse - $.fn[NAME].noConflict = function () { + $.fn[NAME].noConflict = function () { $.fn[NAME] = JQUERY_NO_CONFLICT return Collapse._jQueryInterface } return Collapse - })($) export default Collapse diff --git a/js/src/dropdown.js b/js/src/dropdown.js index a2505c0b54..863f7812e5 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -2,7 +2,6 @@ import $ from 'jquery' import Popper from 'popper.js' import Util from './util' - /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.3): dropdown.js @@ -11,7 +10,6 @@ import Util from './util' */ const Dropdown = (($) => { - /** * ------------------------------------------------------------------------ * Constants @@ -85,7 +83,6 @@ const Dropdown = (($) => { boundary : '(string|element)' } - /** * ------------------------------------------------------------------------ * Class Definition @@ -93,7 +90,6 @@ const Dropdown = (($) => { */ class Dropdown { - constructor(element, config) { this._element = element this._popper = null @@ -104,8 +100,7 @@ const Dropdown = (($) => { this._addEventListeners() } - - // getters + // Getters static get VERSION() { return VERSION @@ -119,7 +114,7 @@ const Dropdown = (($) => { return DefaultType } - // public + // Public toggle() { if (this._element.disabled || $(this._element).hasClass(ClassName.DISABLED)) { @@ -136,7 +131,7 @@ const Dropdown = (($) => { } const relatedTarget = { - relatedTarget : this._element + relatedTarget: this._element } const showEvent = $.Event(Event.SHOW, relatedTarget) @@ -153,10 +148,10 @@ const Dropdown = (($) => { * Popper - https://popper.js.org */ if (typeof Popper === 'undefined') { - throw new Error('Bootstrap dropdown require Popper.js (https://popper.js.org)') + throw new TypeError('Bootstrap dropdown require Popper.js (https://popper.js.org)') } let element = this._element - // for dropup with alignment we use the parent as popper container + // For dropup with alignment we use the parent as popper container if ($(parent).hasClass(ClassName.DROPUP)) { if ($(this._menu).hasClass(ClassName.MENULEFT) || $(this._menu).hasClass(ClassName.MENURIGHT)) { element = parent @@ -171,13 +166,12 @@ const Dropdown = (($) => { this._popper = new Popper(element, this._menu, this._getPopperConfig()) } - - // if this is a touch-enabled device we add extra + // If this is a touch-enabled device we add extra // empty mouseover listeners to the body's immediate children; // only needed because of broken event delegation on iOS // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html if ('ontouchstart' in document.documentElement && - !$(parent).closest(Selector.NAVBAR_NAV).length) { + $(parent).closest(Selector.NAVBAR_NAV).length === 0) { $('body').children().on('mouseover', null, $.noop) } @@ -208,7 +202,7 @@ const Dropdown = (($) => { } } - // private + // Private _addEventListeners() { $(this._element).on(Event.CLICK, (event) => { @@ -244,7 +238,7 @@ const Dropdown = (($) => { _getPlacement() { const $parentDropdown = $(this._element).parent() - let placement = AttachmentMap.BOTTOM + let placement = AttachmentMap.BOTTOM // Handle dropup if ($parentDropdown.hasClass(ClassName.DROPUP)) { @@ -280,14 +274,14 @@ const Dropdown = (($) => { offsetConf.offset = this._config.offset } const popperConfig = { - placement : this._getPlacement(), - modifiers : { - offset : offsetConf, - flip : { - enabled : this._config.flip + placement: this._getPlacement(), + modifiers: { + offset: offsetConf, + flip: { + enabled: this._config.flip }, - preventOverflow : { - boundariesElement : this._config.boundary + preventOverflow: { + boundariesElement: this._config.boundary } } } @@ -295,7 +289,7 @@ const Dropdown = (($) => { return popperConfig } - // static + // Static static _jQueryInterface(config) { return this.each(function () { @@ -309,7 +303,7 @@ const Dropdown = (($) => { if (typeof config === 'string') { if (typeof data[config] === 'undefined') { - throw new Error(`No method named "${config}"`) + throw new TypeError(`No method named "${config}"`) } data[config]() } @@ -324,10 +318,10 @@ const Dropdown = (($) => { const toggles = $.makeArray($(Selector.DATA_TOGGLE)) for (let i = 0; i < toggles.length; i++) { - const parent = Dropdown._getParentFromElement(toggles[i]) - const context = $(toggles[i]).data(DATA_KEY) + const parent = Dropdown._getParentFromElement(toggles[i]) + const context = $(toggles[i]).data(DATA_KEY) const relatedTarget = { - relatedTarget : toggles[i] + relatedTarget: toggles[i] } if (!context) { @@ -340,8 +334,8 @@ const Dropdown = (($) => { } if (event && (event.type === 'click' && - /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) - && $.contains(parent, event.target)) { + /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) && + $.contains(parent, event.target)) { continue } @@ -351,7 +345,7 @@ const Dropdown = (($) => { continue } - // if this is a touch-enabled device we remove the extra + // If this is a touch-enabled device we remove the extra // empty mouseover listeners we added for iOS support if ('ontouchstart' in document.documentElement) { $('body').children().off('mouseover', null, $.noop) @@ -386,8 +380,8 @@ const Dropdown = (($) => { // - If key is other than escape // - If key is not up or down => not a dropdown command // - If trigger inside the menu => not a dropdown command - if (/input|textarea/i.test(event.target.tagName) ? - event.which === SPACE_KEYCODE || event.which !== ESCAPE_KEYCODE && + if (/input|textarea/i.test(event.target.tagName) + ? event.which === SPACE_KEYCODE || event.which !== ESCAPE_KEYCODE && (event.which !== ARROW_DOWN_KEYCODE && event.which !== ARROW_UP_KEYCODE || $(event.target).closest(Selector.MENU).length) : !REGEXP_KEYDOWN.test(event.which)) { return @@ -405,7 +399,6 @@ const Dropdown = (($) => { if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) { - if (event.which === ESCAPE_KEYCODE) { const toggle = $(parent).find(Selector.DATA_TOGGLE)[0] $(toggle).trigger('focus') @@ -417,17 +410,17 @@ const Dropdown = (($) => { const items = $(parent).find(Selector.VISIBLE_ITEMS).get() - if (!items.length) { + if (items.length === 0) { return } let index = items.indexOf(event.target) - if (event.which === ARROW_UP_KEYCODE && index > 0) { // up + if (event.which === ARROW_UP_KEYCODE && index > 0) { // Up index-- } - if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) { // down + if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) { // Down index++ } @@ -437,10 +430,8 @@ const Dropdown = (($) => { items[index].focus() } - } - /** * ------------------------------------------------------------------------ * Data Api implementation @@ -448,7 +439,7 @@ const Dropdown = (($) => { */ $(document) - .on(Event.KEYDOWN_DATA_API, Selector.DATA_TOGGLE, Dropdown._dataApiKeydownHandler) + .on(Event.KEYDOWN_DATA_API, Selector.DATA_TOGGLE, Dropdown._dataApiKeydownHandler) .on(Event.KEYDOWN_DATA_API, Selector.MENU, Dropdown._dataApiKeydownHandler) .on(`${Event.CLICK_DATA_API} ${Event.KEYUP_DATA_API}`, Dropdown._clearMenus) .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) { @@ -460,22 +451,20 @@ const Dropdown = (($) => { e.stopPropagation() }) - /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - $.fn[NAME] = Dropdown._jQueryInterface + $.fn[NAME] = Dropdown._jQueryInterface $.fn[NAME].Constructor = Dropdown - $.fn[NAME].noConflict = function () { + $.fn[NAME].noConflict = function () { $.fn[NAME] = JQUERY_NO_CONFLICT return Dropdown._jQueryInterface } return Dropdown - })($, Popper) export default Dropdown diff --git a/js/src/index.js b/js/src/index.js index 51d09b4e29..db504319c0 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -20,12 +20,12 @@ import Util from './util' (($) => { if (typeof $ === 'undefined') { - throw new Error('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.') + throw new TypeError('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.') } const version = $.fn.jquery.split(' ')[0].split('.') const minMajor = 1 - const ltMajor = 2 + const ltMajor = 2 const minMinor = 9 const minPatch = 1 const maxMajor = 4 diff --git a/js/src/modal.js b/js/src/modal.js index e98277a6dd..ef5994f986 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -1,7 +1,6 @@ import $ from 'jquery' import Util from './util' - /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.3): modal.js @@ -10,8 +9,6 @@ import Util from './util' */ const Modal = (($) => { - - /** * ------------------------------------------------------------------------ * Constants @@ -73,7 +70,6 @@ const Modal = (($) => { NAVBAR_TOGGLER : '.navbar-toggler' } - /** * ------------------------------------------------------------------------ * Class Definition @@ -81,7 +77,6 @@ const Modal = (($) => { */ class Modal { - constructor(element, config) { this._config = this._getConfig(config) this._element = element @@ -94,8 +89,7 @@ const Modal = (($) => { this._scrollbarWidth = 0 } - - // getters + // Getters static get VERSION() { return VERSION @@ -105,8 +99,7 @@ const Modal = (($) => { return Default } - - // public + // Public toggle(relatedTarget) { return this._isShown ? this.hide() : this.show(relatedTarget) @@ -196,7 +189,6 @@ const Modal = (($) => { $(this._dialog).off(Event.MOUSEDOWN_DISMISS) if (transition) { - $(this._element) .one(Util.TRANSITION_END, (event) => this._hideModal(event)) .emulateTransitionEnd(TRANSITION_DURATION) @@ -224,7 +216,7 @@ const Modal = (($) => { this._adjustDialog() } - // private + // Private _getConfig(config) { config = { @@ -241,7 +233,7 @@ const Modal = (($) => { if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) { - // don't move modals dom position + // Don't move modal's DOM position document.body.appendChild(this._element) } @@ -282,11 +274,11 @@ const Modal = (($) => { _enforceFocus() { $(document) - .off(Event.FOCUSIN) // guard against infinite focus loop + .off(Event.FOCUSIN) // Guard against infinite focus loop .on(Event.FOCUSIN, (event) => { if (document !== event.target && this._element !== event.target && - !$(this._element).has(event.target).length) { + $(this._element).has(event.target).length === 0) { this._element.focus() } }) @@ -300,7 +292,6 @@ const Modal = (($) => { this.hide() } }) - } else if (!this._isShown) { $(this._element).off(Event.KEYDOWN_DISMISS) } @@ -334,8 +325,8 @@ const Modal = (($) => { } _showBackdrop(callback) { - const animate = $(this._element).hasClass(ClassName.FADE) ? - ClassName.FADE : '' + const animate = $(this._element).hasClass(ClassName.FADE) + ? ClassName.FADE : '' if (this._isShown && this._config.backdrop) { const doAnimate = Util.supportsTransitionEnd() && animate @@ -382,7 +373,6 @@ const Modal = (($) => { $(this._backdrop) .one(Util.TRANSITION_END, callback) .emulateTransitionEnd(BACKDROP_TRANSITION_DURATION) - } else if (!this._isShown && this._backdrop) { $(this._backdrop).removeClass(ClassName.SHOW) @@ -401,13 +391,11 @@ const Modal = (($) => { } else { callbackRemove() } - } else if (callback) { callback() } } - // ---------------------------------------------------------------------- // the following methods are used to handle overflowing modals // todo (fat): these should probably be refactored out of modal.js @@ -503,12 +491,11 @@ const Modal = (($) => { return scrollbarWidth } - - // static + // Static static _jQueryInterface(config, relatedTarget) { return this.each(function () { - let data = $(this).data(DATA_KEY) + let data = $(this).data(DATA_KEY) const _config = { ...Modal.Default, ...$(this).data(), @@ -522,7 +509,7 @@ const Modal = (($) => { if (typeof config === 'string') { if (typeof data[config] === 'undefined') { - throw new Error(`No method named "${config}"`) + throw new TypeError(`No method named "${config}"`) } data[config](relatedTarget) } else if (_config.show) { @@ -530,10 +517,8 @@ const Modal = (($) => { } }) } - } - /** * ------------------------------------------------------------------------ * Data Api implementation @@ -548,8 +533,8 @@ const Modal = (($) => { target = $(selector)[0] } - const config = $(target).data(DATA_KEY) ? - 'toggle' : { + const config = $(target).data(DATA_KEY) + ? 'toggle' : { ...$(target).data(), ...$(this).data() } @@ -560,7 +545,7 @@ const Modal = (($) => { const $target = $(target).one(Event.SHOW, (showEvent) => { if (showEvent.isDefaultPrevented()) { - // only register focus restorer if modal will actually get shown + // Only register focus restorer if modal will actually get shown return } @@ -574,22 +559,20 @@ const Modal = (($) => { Modal._jQueryInterface.call($(target), config, this) }) - /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - $.fn[NAME] = Modal._jQueryInterface + $.fn[NAME] = Modal._jQueryInterface $.fn[NAME].Constructor = Modal - $.fn[NAME].noConflict = function () { + $.fn[NAME].noConflict = function () { $.fn[NAME] = JQUERY_NO_CONFLICT return Modal._jQueryInterface } return Modal - })($) export default Modal diff --git a/js/src/popover.js b/js/src/popover.js index f557e8bcd2..02d6827329 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -1,7 +1,6 @@ import $ from 'jquery' import Tooltip from './tooltip' - /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.3): popover.js @@ -10,8 +9,6 @@ import Tooltip from './tooltip' */ const Popover = (($) => { - - /** * ------------------------------------------------------------------------ * Constants @@ -31,10 +28,10 @@ const Popover = (($) => { placement : 'right', trigger : 'click', content : '', - template : '' + template : '' } const DefaultType = { @@ -65,7 +62,6 @@ const Popover = (($) => { MOUSELEAVE : `mouseleave${EVENT_KEY}` } - /** * ------------------------------------------------------------------------ * Class Definition @@ -73,9 +69,7 @@ const Popover = (($) => { */ class Popover extends Tooltip { - - - // getters + // Getters static get VERSION() { return VERSION @@ -105,8 +99,7 @@ const Popover = (($) => { return DefaultType } - - // overrides + // Overrides isWithContent() { return this.getTitle() || this._getContent() @@ -124,7 +117,7 @@ const Popover = (($) => { setContent() { const $tip = $(this.getTipElement()) - // we use append for html objects to maintain js events + // We use append for html objects to maintain js events this.setElementContent($tip.find(Selector.TITLE), this.getTitle()) let content = this._getContent() if (typeof content === 'function') { @@ -135,11 +128,11 @@ const Popover = (($) => { $tip.removeClass(`${ClassName.FADE} ${ClassName.SHOW}`) } - // private + // Private _getContent() { - return this.element.getAttribute('data-content') - || this.config.content + return this.element.getAttribute('data-content') || + this.config.content } _cleanTipClass() { @@ -150,12 +143,11 @@ const Popover = (($) => { } } - - // static + // Static static _jQueryInterface(config) { return this.each(function () { - let data = $(this).data(DATA_KEY) + let data = $(this).data(DATA_KEY) const _config = typeof config === 'object' ? config : null if (!data && /destroy|hide/.test(config)) { @@ -169,7 +161,7 @@ const Popover = (($) => { if (typeof config === 'string') { if (typeof data[config] === 'undefined') { - throw new Error(`No method named "${config}"`) + throw new TypeError(`No method named "${config}"`) } data[config]() } @@ -177,22 +169,20 @@ const Popover = (($) => { } } - /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - $.fn[NAME] = Popover._jQueryInterface + $.fn[NAME] = Popover._jQueryInterface $.fn[NAME].Constructor = Popover - $.fn[NAME].noConflict = function () { + $.fn[NAME].noConflict = function () { $.fn[NAME] = JQUERY_NO_CONFLICT return Popover._jQueryInterface } return Popover - })($) export default Popover diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 9a2562a7c1..da2941351b 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -1,7 +1,6 @@ import $ from 'jquery' import Util from './util' - /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.3): scrollspy.js @@ -10,8 +9,6 @@ import Util from './util' */ const ScrollSpy = (($) => { - - /** * ------------------------------------------------------------------------ * Constants @@ -66,7 +63,6 @@ const ScrollSpy = (($) => { POSITION : 'position' } - /** * ------------------------------------------------------------------------ * Class Definition @@ -74,14 +70,13 @@ const ScrollSpy = (($) => { */ class ScrollSpy { - constructor(element, config) { this._element = element this._scrollElement = element.tagName === 'BODY' ? window : element this._config = this._getConfig(config) - this._selector = `${this._config.target} ${Selector.NAV_LINKS},` - + `${this._config.target} ${Selector.LIST_ITEMS},` - + `${this._config.target} ${Selector.DROPDOWN_ITEMS}` + this._selector = `${this._config.target} ${Selector.NAV_LINKS},` + + `${this._config.target} ${Selector.LIST_ITEMS},` + + `${this._config.target} ${Selector.DROPDOWN_ITEMS}` this._offsets = [] this._targets = [] this._activeTarget = null @@ -93,8 +88,7 @@ const ScrollSpy = (($) => { this._process() } - - // getters + // Getters static get VERSION() { return VERSION @@ -104,18 +98,17 @@ const ScrollSpy = (($) => { return Default } - - // public + // Public refresh() { - const autoMethod = this._scrollElement !== this._scrollElement.window ? - OffsetMethod.POSITION : OffsetMethod.OFFSET + const autoMethod = this._scrollElement === this._scrollElement.window + ? OffsetMethod.OFFSET : OffsetMethod.POSITION - const offsetMethod = this._config.method === 'auto' ? - autoMethod : this._config.method + const offsetMethod = this._config.method === 'auto' + ? autoMethod : this._config.method - const offsetBase = offsetMethod === OffsetMethod.POSITION ? - this._getScrollTop() : 0 + const offsetBase = offsetMethod === OffsetMethod.POSITION + ? this._getScrollTop() : 0 this._offsets = [] this._targets = [] @@ -136,7 +129,7 @@ const ScrollSpy = (($) => { if (target) { const targetBCR = target.getBoundingClientRect() if (targetBCR.width || targetBCR.height) { - // todo (fat): remove sketch reliance on jQuery position/offset + // TODO (fat): remove sketch reliance on jQuery position/offset return [ $(target)[offsetMethod]().top + offsetBase, targetSelector @@ -145,8 +138,8 @@ const ScrollSpy = (($) => { } return null }) - .filter((item) => item) - .sort((a, b) => a[0] - b[0]) + .filter((item) => item) + .sort((a, b) => a[0] - b[0]) .forEach((item) => { this._offsets.push(item[0]) this._targets.push(item[1]) @@ -167,8 +160,7 @@ const ScrollSpy = (($) => { this._scrollHeight = null } - - // private + // Private _getConfig(config) { config = { @@ -191,8 +183,8 @@ const ScrollSpy = (($) => { } _getScrollTop() { - return this._scrollElement === window ? - this._scrollElement.pageYOffset : this._scrollElement.scrollTop + return this._scrollElement === window + ? this._scrollElement.pageYOffset : this._scrollElement.scrollTop } _getScrollHeight() { @@ -203,16 +195,16 @@ const ScrollSpy = (($) => { } _getOffsetHeight() { - return this._scrollElement === window ? - window.innerHeight : this._scrollElement.getBoundingClientRect().height + return this._scrollElement === window + ? window.innerHeight : this._scrollElement.getBoundingClientRect().height } _process() { const scrollTop = this._getScrollTop() + this._config.offset const scrollHeight = this._getScrollHeight() - const maxScroll = this._config.offset - + scrollHeight - - this._getOffsetHeight() + const maxScroll = this._config.offset + + scrollHeight - + this._getOffsetHeight() if (this._scrollHeight !== scrollHeight) { this.refresh() @@ -234,9 +226,9 @@ const ScrollSpy = (($) => { } for (let i = this._offsets.length; i--;) { - const isActiveTarget = this._activeTarget !== this._targets[i] - && scrollTop >= this._offsets[i] - && (typeof this._offsets[i + 1] === 'undefined' || + const isActiveTarget = this._activeTarget !== this._targets[i] && + scrollTop >= this._offsets[i] && + (typeof this._offsets[i + 1] === 'undefined' || scrollTop < this._offsets[i + 1]) if (isActiveTarget) { @@ -252,7 +244,7 @@ const ScrollSpy = (($) => { let queries = this._selector.split(',') // eslint-disable-next-line arrow-body-style - queries = queries.map((selector) => { + queries = queries.map((selector) => { return `${selector}[data-target="${target}"],` + `${selector}[href="${target}"]` }) @@ -281,12 +273,11 @@ const ScrollSpy = (($) => { $(this._selector).filter(Selector.ACTIVE).removeClass(ClassName.ACTIVE) } - - // static + // Static static _jQueryInterface(config) { return this.each(function () { - let data = $(this).data(DATA_KEY) + let data = $(this).data(DATA_KEY) const _config = typeof config === 'object' && config if (!data) { @@ -296,17 +287,14 @@ const ScrollSpy = (($) => { if (typeof config === 'string') { if (typeof data[config] === 'undefined') { - throw new Error(`No method named "${config}"`) + throw new TypeError(`No method named "${config}"`) } data[config]() } }) } - - } - /** * ------------------------------------------------------------------------ * Data Api implementation @@ -322,22 +310,20 @@ const ScrollSpy = (($) => { } }) - /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - $.fn[NAME] = ScrollSpy._jQueryInterface + $.fn[NAME] = ScrollSpy._jQueryInterface $.fn[NAME].Constructor = ScrollSpy - $.fn[NAME].noConflict = function () { + $.fn[NAME].noConflict = function () { $.fn[NAME] = JQUERY_NO_CONFLICT return ScrollSpy._jQueryInterface } return ScrollSpy - })($) export default ScrollSpy diff --git a/js/src/tab.js b/js/src/tab.js index e501568e7e..0ae060c468 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -1,7 +1,6 @@ import $ from 'jquery' import Util from './util' - /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.3): tab.js @@ -10,8 +9,6 @@ import Util from './util' */ const Tab = (($) => { - - /** * ------------------------------------------------------------------------ * Constants @@ -52,7 +49,6 @@ const Tab = (($) => { DROPDOWN_ACTIVE_CHILD : '> .dropdown-menu .active' } - /** * ------------------------------------------------------------------------ * Class Definition @@ -60,20 +56,17 @@ const Tab = (($) => { */ class Tab { - constructor(element) { this._element = element } - - // getters + // Getters static get VERSION() { return VERSION } - - // public + // Public show() { if (this._element.parentNode && @@ -86,7 +79,7 @@ const Tab = (($) => { let target let previous const listElement = $(this._element).closest(Selector.NAV_LIST_GROUP)[0] - const selector = Util.getSelectorFromElement(this._element) + const selector = Util.getSelectorFromElement(this._element) if (listElement) { const itemSelector = listElement.nodeName === 'UL' ? Selector.ACTIVE_UL : Selector.ACTIVE @@ -147,8 +140,7 @@ const Tab = (($) => { this._element = null } - - // private + // Private _activate(element, container, callback) { let activeElements @@ -158,10 +150,10 @@ const Tab = (($) => { activeElements = $(container).children(Selector.ACTIVE) } - const active = activeElements[0] - const isTransitioning = callback - && Util.supportsTransitionEnd() - && (active && $(active).hasClass(ClassName.FADE)) + const active = activeElements[0] + const isTransitioning = callback && + Util.supportsTransitionEnd() && + (active && $(active).hasClass(ClassName.FADE)) const complete = () => this._transitionComplete( element, @@ -205,7 +197,6 @@ const Tab = (($) => { if (element.parentNode && $(element.parentNode).hasClass(ClassName.DROPDOWN_MENU)) { - const dropdownElement = $(element).closest(Selector.DROPDOWN)[0] if (dropdownElement) { $(dropdownElement).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE) @@ -219,13 +210,12 @@ const Tab = (($) => { } } - - // static + // Static static _jQueryInterface(config) { return this.each(function () { const $this = $(this) - let data = $this.data(DATA_KEY) + let data = $this.data(DATA_KEY) if (!data) { data = new Tab(this) @@ -234,16 +224,14 @@ const Tab = (($) => { if (typeof config === 'string') { if (typeof data[config] === 'undefined') { - throw new Error(`No method named "${config}"`) + throw new TypeError(`No method named "${config}"`) } data[config]() } }) } - } - /** * ------------------------------------------------------------------------ * Data Api implementation @@ -256,22 +244,20 @@ const Tab = (($) => { Tab._jQueryInterface.call($(this), 'show') }) - /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - $.fn[NAME] = Tab._jQueryInterface + $.fn[NAME] = Tab._jQueryInterface $.fn[NAME].Constructor = Tab - $.fn[NAME].noConflict = function () { + $.fn[NAME].noConflict = function () { $.fn[NAME] = JQUERY_NO_CONFLICT return Tab._jQueryInterface } return Tab - })($) export default Tab diff --git a/js/src/tooltip.js b/js/src/tooltip.js index c26cdc387e..403f7e5b16 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -2,7 +2,6 @@ import $ from 'jquery' import Popper from 'popper.js' import Util from './util' - /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0-beta.3): tooltip.js @@ -11,7 +10,6 @@ import Util from './util' */ const Tooltip = (($) => { - /** * ------------------------------------------------------------------------ * Constants @@ -52,9 +50,9 @@ const Tooltip = (($) => { const Default = { animation : true, - template : '', + template : '', trigger : 'hover focus', title : '', delay : 0, @@ -111,14 +109,13 @@ const Tooltip = (($) => { */ class Tooltip { - constructor(element, config) { /** * Check for Popper dependency * Popper - https://popper.js.org */ if (typeof Popper === 'undefined') { - throw new Error('Bootstrap tooltips require Popper.js (https://popper.js.org)') + throw new TypeError('Bootstrap tooltips require Popper.js (https://popper.js.org)') } // private @@ -128,17 +125,15 @@ const Tooltip = (($) => { this._activeTrigger = {} this._popper = null - // protected + // Protected this.element = element this.config = this._getConfig(config) this.tip = null this._setListeners() - } - - // getters + // Getters static get VERSION() { return VERSION @@ -168,8 +163,7 @@ const Tooltip = (($) => { return DefaultType } - - // public + // Public enable() { this._isEnabled = true @@ -207,9 +201,7 @@ const Tooltip = (($) => { } else { context._leave(null, context) } - } else { - if ($(this.getTipElement()).hasClass(ClassName.SHOW)) { this._leave(null, this) return @@ -275,9 +267,9 @@ const Tooltip = (($) => { $(tip).addClass(ClassName.FADE) } - const placement = typeof this.config.placement === 'function' ? - this.config.placement.call(this, tip, this.element) : - this.config.placement + const placement = typeof this.config.placement === 'function' + ? this.config.placement.call(this, tip, this.element) + : this.config.placement const attachment = this._getAttachment(placement) this.addAttachmentClass(attachment) @@ -313,14 +305,14 @@ const Tooltip = (($) => { this._handlePopperPlacementChange(data) } }, - onUpdate : (data) => { + onUpdate: (data) => { this._handlePopperPlacementChange(data) } }) $(tip).addClass(ClassName.SHOW) - // if this is a touch-enabled device we add extra + // If this is a touch-enabled device we add extra // empty mouseover listeners to the body's immediate children; // only needed because of broken event delegation on iOS // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html @@ -355,7 +347,7 @@ const Tooltip = (($) => { hide(callback) { const tip = this.getTipElement() const hideEvent = $.Event(this.constructor.Event.HIDE) - const complete = () => { + const complete = () => { if (this._hoverState !== HoverState.SHOW && tip.parentNode) { tip.parentNode.removeChild(tip) } @@ -380,7 +372,7 @@ const Tooltip = (($) => { $(tip).removeClass(ClassName.SHOW) - // if this is a touch-enabled device we remove the extra + // If this is a touch-enabled device we remove the extra // empty mouseover listeners we added for iOS support if ('ontouchstart' in document.documentElement) { $('body').children().off('mouseover', null, $.noop) @@ -392,17 +384,14 @@ const Tooltip = (($) => { if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) { - $(tip) .one(Util.TRANSITION_END, complete) .emulateTransitionEnd(TRANSITION_DURATION) - } else { complete() } this._hoverState = '' - } update() { @@ -411,7 +400,7 @@ const Tooltip = (($) => { } } - // protected + // Protected isWithContent() { return Boolean(this.getTitle()) @@ -435,7 +424,7 @@ const Tooltip = (($) => { setElementContent($element, content) { const html = this.config.html if (typeof content === 'object' && (content.nodeType || content.jquery)) { - // content is a DOM node or a jQuery + // Content is a DOM node or a jQuery if (html) { if (!$(content).parent().is($element)) { $element.empty().append(content) @@ -452,16 +441,15 @@ const Tooltip = (($) => { let title = this.element.getAttribute('data-original-title') if (!title) { - title = typeof this.config.title === 'function' ? - this.config.title.call(this.element) : - this.config.title + title = typeof this.config.title === 'function' + ? this.config.title.call(this.element) + : this.config.title } return title } - - // private + // Private _getAttachment(placement) { return AttachmentMap[placement.toUpperCase()] @@ -477,14 +465,13 @@ const Tooltip = (($) => { this.config.selector, (event) => this.toggle(event) ) - } else if (trigger !== Trigger.MANUAL) { - const eventIn = trigger === Trigger.HOVER ? - this.constructor.Event.MOUSEENTER : - this.constructor.Event.FOCUSIN - const eventOut = trigger === Trigger.HOVER ? - this.constructor.Event.MOUSELEAVE : - this.constructor.Event.FOCUSOUT + const eventIn = trigger === Trigger.HOVER + ? this.constructor.Event.MOUSEENTER + : this.constructor.Event.FOCUSIN + const eventOut = trigger === Trigger.HOVER + ? this.constructor.Event.MOUSELEAVE + : this.constructor.Event.FOCUSOUT $(this.element) .on( @@ -508,8 +495,8 @@ const Tooltip = (($) => { if (this.config.selector) { this.config = { ...this.config, - trigger : 'manual', - selector : '' + trigger: 'manual', + selector: '' } } else { this._fixTitle() @@ -627,8 +614,8 @@ const Tooltip = (($) => { if (typeof config.delay === 'number') { config.delay = { - show : config.delay, - hide : config.delay + show: config.delay, + hide: config.delay } } @@ -677,7 +664,7 @@ const Tooltip = (($) => { } _fixTransition() { - const tip = this.getTipElement() + const tip = this.getTipElement() const initConfigAnimation = this.config.animation if (tip.getAttribute('x-placement') !== null) { return @@ -689,11 +676,11 @@ const Tooltip = (($) => { this.config.animation = initConfigAnimation } - // static + // Static static _jQueryInterface(config) { return this.each(function () { - let data = $(this).data(DATA_KEY) + let data = $(this).data(DATA_KEY) const _config = typeof config === 'object' && config if (!data && /dispose|hide/.test(config)) { @@ -707,7 +694,7 @@ const Tooltip = (($) => { if (typeof config === 'string') { if (typeof data[config] === 'undefined') { - throw new Error(`No method named "${config}"`) + throw new TypeError(`No method named "${config}"`) } data[config]() } @@ -715,22 +702,20 @@ const Tooltip = (($) => { } } - /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ - $.fn[NAME] = Tooltip._jQueryInterface + $.fn[NAME] = Tooltip._jQueryInterface $.fn[NAME].Constructor = Tooltip - $.fn[NAME].noConflict = function () { + $.fn[NAME].noConflict = function () { $.fn[NAME] = JQUERY_NO_CONFLICT return Tooltip._jQueryInterface } return Tooltip - })($, Popper) export default Tooltip diff --git a/js/src/util.js b/js/src/util.js index 0ffbb76a3e..373b8adac5 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -8,8 +8,6 @@ import $ from 'jquery' */ const Util = (($) => { - - /** * ------------------------------------------------------------------------ * Private TransitionEnd Helpers @@ -20,7 +18,7 @@ const Util = (($) => { const MAX_UID = 1000000 - // shoutout AngusCroll (https://goo.gl/pxwQGp) + // Shoutout AngusCroll (https://goo.gl/pxwQGp) function toType(obj) { return {}.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() } @@ -75,10 +73,10 @@ const Util = (($) => { } function escapeId(selector) { - // we escape IDs in case of special selectors (selector = '#myId:something') + // We escape IDs in case of special selectors (selector = '#myId:something') // $.escapeSelector does not exist in jQuery < 3 - selector = typeof $.escapeSelector === 'function' ? $.escapeSelector(selector).substr(1) : - selector.replace(/(:|\.|\[|\]|,|=|@)/g, '\\$1') + selector = typeof $.escapeSelector === 'function' ? $.escapeSelector(selector).substr(1) + : selector.replace(/(:|\.|\[|\]|,|=|@)/g, '\\$1') return selector } @@ -107,7 +105,7 @@ const Util = (($) => { selector = element.getAttribute('href') || '' } - // if it's an ID + // If it's an ID if (selector.charAt(0) === '#') { selector = escapeId(selector) } @@ -115,7 +113,7 @@ const Util = (($) => { try { const $selector = $(document).find(selector) return $selector.length > 0 ? selector : null - } catch (error) { + } catch (err) { return null } }, @@ -141,8 +139,8 @@ const Util = (($) => { if (Object.prototype.hasOwnProperty.call(configTypes, property)) { const expectedTypes = configTypes[property] const value = config[property] - const valueType = value && Util.isElement(value) ? - 'element' : toType(value) + const valueType = value && Util.isElement(value) + ? 'element' : toType(value) if (!new RegExp(expectedTypes).test(valueType)) { throw new Error( @@ -158,7 +156,6 @@ const Util = (($) => { setTransitionEndSupport() return Util - })($) export default Util diff --git a/js/tests/unit/alert.js b/js/tests/unit/alert.js index aee2b70d5f..2dcaeb6d00 100644 --- a/js/tests/unit/alert.js +++ b/js/tests/unit/alert.js @@ -34,10 +34,10 @@ $(function () { QUnit.test('should fade element out on clicking .close', function (assert) { assert.expect(1) - var alertHTML = '
' - + '×' - + '

Holy guacamole! Best check yo self, you\'re not looking too good.

' - + '
' + var alertHTML = '
' + + '×' + + '

Holy guacamole! Best check yo self, you\'re not looking too good.

' + + '
' var $alert = $(alertHTML).bootstrapAlert().appendTo($('#qunit-fixture')) @@ -48,10 +48,10 @@ $(function () { QUnit.test('should remove element when clicking .close', function (assert) { assert.expect(2) - var alertHTML = '
' - + '×' - + '

Holy guacamole! Best check yo self, you\'re not looking too good.

' - + '
' + var alertHTML = '
' + + '×' + + '

Holy guacamole! Best check yo self, you\'re not looking too good.

' + + '
' var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom') @@ -75,5 +75,4 @@ $(function () { }) .bootstrapAlert('close') }) - }) diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 54a434d84a..cc2719c3a0 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -87,11 +87,11 @@ $(function () { assert.expect(1) var done = assert.async() - var groupHTML = '
' - + '' - + '
' + var groupHTML = '
' + + '' + + '
' var $group = $(groupHTML).appendTo('#qunit-fixture') $group.find('input').on('change', function (e) { @@ -105,17 +105,17 @@ $(function () { QUnit.test('should check for closest matching toggle', function (assert) { assert.expect(12) - var groupHTML = '
' - + '' - + '' - + '' - + '
' + var groupHTML = '
' + + '' + + '' + + '' + + '
' var $group = $(groupHTML).appendTo('#qunit-fixture') var $btn1 = $group.children().eq(0) @@ -131,7 +131,7 @@ $(function () { assert.ok($btn2.hasClass('active'), 'btn2 has active class') assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked') - $btn2.find('input').trigger('click') // clicking an already checked radio should not un-check it + $btn2.find('input').trigger('click') // Clicking an already checked radio should not un-check it assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class') assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is not checked') assert.ok($btn2.hasClass('active'), 'btn2 has active class') @@ -140,10 +140,10 @@ $(function () { QUnit.test('should not add aria-pressed on labels for radio/checkbox inputs in a data-toggle="buttons" group', function (assert) { assert.expect(2) - var groupHTML = '
' - + '' - + '' - + '
' + var groupHTML = '
' + + '' + + '' + + '
' var $group = $(groupHTML).appendTo('#qunit-fixture') var $btn1 = $group.children().eq(0) @@ -158,11 +158,11 @@ $(function () { QUnit.test('should handle disabled attribute on non-button elements', function (assert) { assert.expect(2) - var groupHTML = '
' - + '' - + '
' + var groupHTML = '
' + + '' + + '
' var $group = $(groupHTML).appendTo('#qunit-fixture') var $btn = $group.children().eq(0) @@ -172,5 +172,4 @@ $(function () { assert.ok($btn.is(':not(.active)'), 'button did not become active') assert.ok(!$input.is(':checked'), 'checkbox did not get checked') }) - }) diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 48752cb917..12bb89e4f4 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -30,8 +30,7 @@ $(function () { $el.bootstrapCarousel() try { $el.bootstrapCarousel('noMethod') - } - catch (err) { + } catch (err) { assert.strictEqual(err.message, 'No method named "noMethod"') } }) @@ -55,8 +54,8 @@ $(function () { try { $('
').bootstrapCarousel(config) - } catch (e) { - message = e.message + } catch (err) { + message = err.message } assert.ok(message === expectedMessage, 'correct error message') @@ -68,14 +67,13 @@ $(function () { try { $('
').bootstrapCarousel(config) - } catch (e) { - message = e.message + } catch (err) { + message = err.message } assert.ok(message === expectedMessage, 'correct error message') }) - QUnit.test('should not fire slid when slide is prevented', function (assert) { assert.expect(1) var done = assert.async() @@ -93,26 +91,26 @@ $(function () { QUnit.test('should reset when slide is prevented', function (assert) { assert.expect(6) - var carouselHTML = '