diff options
author | Mario Vavti <mario@mariovavti.com> | 2019-05-10 14:21:36 +0200 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2019-05-10 14:21:36 +0200 |
commit | 9866053f0ce44721c11990c9f9407e7428757c99 (patch) | |
tree | 6e414efa36c3bda00205918cecb9122f951427e3 /vendor/twbs/bootstrap/js/src/button.js | |
parent | 89a2c1a09c896ac3a23df26a1783f5c682188a56 (diff) | |
download | volse-hubzilla-9866053f0ce44721c11990c9f9407e7428757c99.tar.gz volse-hubzilla-9866053f0ce44721c11990c9f9407e7428757c99.tar.bz2 volse-hubzilla-9866053f0ce44721c11990c9f9407e7428757c99.zip |
update bootstrap to version 4.3.1
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/button.js')
-rw-r--r-- | vendor/twbs/bootstrap/js/src/button.js | 266 |
1 files changed, 131 insertions, 135 deletions
diff --git a/vendor/twbs/bootstrap/js/src/button.js b/vendor/twbs/bootstrap/js/src/button.js index cf181d3fc..fcf805502 100644 --- a/vendor/twbs/bootstrap/js/src/button.js +++ b/vendor/twbs/bootstrap/js/src/button.js @@ -1,175 +1,171 @@ -import $ from 'jquery' - /** * -------------------------------------------------------------------------- - * Bootstrap (v4.1.3): button.js + * Bootstrap (v4.3.1): button.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Button = (($) => { - /** - * ------------------------------------------------------------------------ - * Constants - * ------------------------------------------------------------------------ - */ - - const NAME = 'button' - const VERSION = '4.1.3' - const DATA_KEY = 'bs.button' - const EVENT_KEY = `.${DATA_KEY}` - const DATA_API_KEY = '.data-api' - const JQUERY_NO_CONFLICT = $.fn[NAME] - - const ClassName = { - ACTIVE : 'active', - BUTTON : 'btn', - FOCUS : 'focus' - } +import $ from 'jquery' + +/** + * ------------------------------------------------------------------------ + * Constants + * ------------------------------------------------------------------------ + */ + +const NAME = 'button' +const VERSION = '4.3.1' +const DATA_KEY = 'bs.button' +const EVENT_KEY = `.${DATA_KEY}` +const DATA_API_KEY = '.data-api' +const JQUERY_NO_CONFLICT = $.fn[NAME] + +const ClassName = { + ACTIVE : 'active', + BUTTON : 'btn', + FOCUS : 'focus' +} + +const Selector = { + DATA_TOGGLE_CARROT : '[data-toggle^="button"]', + DATA_TOGGLE : '[data-toggle="buttons"]', + INPUT : 'input:not([type="hidden"])', + ACTIVE : '.active', + BUTTON : '.btn' +} + +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}` +} - const Selector = { - DATA_TOGGLE_CARROT : '[data-toggle^="button"]', - DATA_TOGGLE : '[data-toggle="buttons"]', - INPUT : 'input', - ACTIVE : '.active', - BUTTON : '.btn' +/** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ + +class Button { + constructor(element) { + this._element = element } - 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}` + // Getters + + static get VERSION() { + return VERSION } - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ + // Public - class Button { - constructor(element) { - this._element = element - } + toggle() { + let triggerChangeEvent = true + let addAriaPressed = true + const rootElement = $(this._element).closest( + Selector.DATA_TOGGLE + )[0] - // Getters + if (rootElement) { + const input = this._element.querySelector(Selector.INPUT) - static get VERSION() { - return VERSION - } + if (input) { + if (input.type === 'radio') { + if (input.checked && + this._element.classList.contains(ClassName.ACTIVE)) { + triggerChangeEvent = false + } else { + const activeElement = rootElement.querySelector(Selector.ACTIVE) - // Public - - toggle() { - let triggerChangeEvent = true - let addAriaPressed = true - const rootElement = $(this._element).closest( - Selector.DATA_TOGGLE - )[0] - - if (rootElement) { - const input = this._element.querySelector(Selector.INPUT) - - if (input) { - if (input.type === 'radio') { - if (input.checked && - this._element.classList.contains(ClassName.ACTIVE)) { - triggerChangeEvent = false - } else { - const activeElement = rootElement.querySelector(Selector.ACTIVE) - - if (activeElement) { - $(activeElement).removeClass(ClassName.ACTIVE) - } + if (activeElement) { + $(activeElement).removeClass(ClassName.ACTIVE) } } + } - if (triggerChangeEvent) { - if (input.hasAttribute('disabled') || - rootElement.hasAttribute('disabled') || - input.classList.contains('disabled') || - rootElement.classList.contains('disabled')) { - return - } - input.checked = !this._element.classList.contains(ClassName.ACTIVE) - $(input).trigger('change') + if (triggerChangeEvent) { + if (input.hasAttribute('disabled') || + rootElement.hasAttribute('disabled') || + input.classList.contains('disabled') || + rootElement.classList.contains('disabled')) { + return } - - input.focus() - addAriaPressed = false + input.checked = !this._element.classList.contains(ClassName.ACTIVE) + $(input).trigger('change') } - } - if (addAriaPressed) { - this._element.setAttribute('aria-pressed', - !this._element.classList.contains(ClassName.ACTIVE)) + input.focus() + addAriaPressed = false } + } - if (triggerChangeEvent) { - $(this._element).toggleClass(ClassName.ACTIVE) - } + if (addAriaPressed) { + this._element.setAttribute('aria-pressed', + !this._element.classList.contains(ClassName.ACTIVE)) } - dispose() { - $.removeData(this._element, DATA_KEY) - this._element = null + if (triggerChangeEvent) { + $(this._element).toggleClass(ClassName.ACTIVE) } + } - // Static + dispose() { + $.removeData(this._element, DATA_KEY) + this._element = null + } - static _jQueryInterface(config) { - return this.each(function () { - let data = $(this).data(DATA_KEY) + // Static - if (!data) { - data = new Button(this) - $(this).data(DATA_KEY, data) - } + static _jQueryInterface(config) { + return this.each(function () { + let data = $(this).data(DATA_KEY) - if (config === 'toggle') { - data[config]() - } - }) - } + if (!data) { + data = new Button(this) + $(this).data(DATA_KEY, data) + } + + if (config === 'toggle') { + data[config]() + } + }) } +} - /** - * ------------------------------------------------------------------------ - * Data Api implementation - * ------------------------------------------------------------------------ - */ +/** + * ------------------------------------------------------------------------ + * Data Api implementation + * ------------------------------------------------------------------------ + */ - $(document) - .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => { - event.preventDefault() +$(document) + .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => { + event.preventDefault() - let button = event.target + let button = event.target - if (!$(button).hasClass(ClassName.BUTTON)) { - button = $(button).closest(Selector.BUTTON) - } + if (!$(button).hasClass(ClassName.BUTTON)) { + button = $(button).closest(Selector.BUTTON) + } - Button._jQueryInterface.call($(button), 'toggle') - }) - .on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => { - const button = $(event.target).closest(Selector.BUTTON)[0] - $(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type)) - }) + Button._jQueryInterface.call($(button), 'toggle') + }) + .on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => { + const button = $(event.target).closest(Selector.BUTTON)[0] + $(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type)) + }) - /** - * ------------------------------------------------------------------------ - * jQuery - * ------------------------------------------------------------------------ - */ - - $.fn[NAME] = Button._jQueryInterface - $.fn[NAME].Constructor = Button - $.fn[NAME].noConflict = function () { - $.fn[NAME] = JQUERY_NO_CONFLICT - return Button._jQueryInterface - } +/** + * ------------------------------------------------------------------------ + * jQuery + * ------------------------------------------------------------------------ + */ - return Button -})($) +$.fn[NAME] = Button._jQueryInterface +$.fn[NAME].Constructor = Button +$.fn[NAME].noConflict = () => { + $.fn[NAME] = JQUERY_NO_CONFLICT + return Button._jQueryInterface +} export default Button |