diff options
author | Mark Otto <markdotto@gmail.com> | 2017-09-06 07:05:12 +0300 |
---|---|---|
committer | Mark Otto <markdotto@gmail.com> | 2017-09-06 07:05:12 +0300 |
commit | df47558ef680adf6e80b5e8402837125c41210c0 (patch) | |
tree | fb9cb52d3ed467f73c16140254b18e9733e640ab /js/dist/dropdown.js | |
parent | fbd1f52f896c599211c24c5c86d04fbbb3e88165 (diff) |
dist
Diffstat (limited to 'js/dist/dropdown.js')
-rw-r--r-- | js/dist/dropdown.js | 447 |
1 files changed, 233 insertions, 214 deletions
diff --git a/js/dist/dropdown.js b/js/dist/dropdown.js index 0b41280743..39096759c6 100644 --- a/js/dist/dropdown.js +++ b/js/dist/dropdown.js @@ -1,3 +1,5 @@ +'use strict'; + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); @@ -11,7 +13,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons * -------------------------------------------------------------------------- */ -var Dropdown = function ($) { +var Dropdown = function () { /** * Check for Popper dependency @@ -108,278 +110,295 @@ var Dropdown = function ($) { // getters - // public + _createClass(Dropdown, [{ + key: 'toggle', - Dropdown.prototype.toggle = function toggle() { - if (this._element.disabled || $(this._element).hasClass(ClassName.DISABLED)) { - return; - } - var parent = Dropdown._getParentFromElement(this._element); - var isActive = $(this._menu).hasClass(ClassName.SHOW); + // public - Dropdown._clearMenus(); + value: function toggle() { + if (this._element.disabled || $(this._element).hasClass(ClassName.DISABLED)) { + return; + } - if (isActive) { - return; - } + var parent = Dropdown._getParentFromElement(this._element); + var isActive = $(this._menu).hasClass(ClassName.SHOW); - var relatedTarget = { - relatedTarget: this._element - }; - var showEvent = $.Event(Event.SHOW, relatedTarget); + Dropdown._clearMenus(); - $(parent).trigger(showEvent); + if (isActive) { + return; + } - if (showEvent.isDefaultPrevented()) { - return; - } + var relatedTarget = { + relatedTarget: this._element + }; + var showEvent = $.Event(Event.SHOW, relatedTarget); - var element = this._element; - // 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; + $(parent).trigger(showEvent); + + if (showEvent.isDefaultPrevented()) { + return; } - } - this._popper = new Popper(element, this._menu, this._getPopperConfig()); - - // 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) { - $('body').children().on('mouseover', null, $.noop); - } - this._element.focus(); - this._element.setAttribute('aria-expanded', true); + var element = this._element; + // 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; + } + } + this._popper = new Popper(element, this._menu, this._getPopperConfig()); + + // 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) { + $('body').children().on('mouseover', null, $.noop); + } - $(this._menu).toggleClass(ClassName.SHOW); - $(parent).toggleClass(ClassName.SHOW).trigger($.Event(Event.SHOWN, relatedTarget)); - }; + this._element.focus(); + this._element.setAttribute('aria-expanded', true); - Dropdown.prototype.dispose = function dispose() { - $.removeData(this._element, DATA_KEY); - $(this._element).off(EVENT_KEY); - this._element = null; - this._menu = null; - if (this._popper !== null) { - this._popper.destroy(); + $(this._menu).toggleClass(ClassName.SHOW); + $(parent).toggleClass(ClassName.SHOW).trigger($.Event(Event.SHOWN, relatedTarget)); } - this._popper = null; - }; - - Dropdown.prototype.update = function update() { - this._inNavbar = this._detectNavbar(); - if (this._popper !== null) { - this._popper.scheduleUpdate(); + }, { + key: 'dispose', + value: function dispose() { + $.removeData(this._element, DATA_KEY); + $(this._element).off(EVENT_KEY); + this._element = null; + this._menu = null; + if (this._popper !== null) { + this._popper.destroy(); + } + this._popper = null; + } + }, { + key: 'update', + value: function update() { + this._inNavbar = this._detectNavbar(); + if (this._popper !== null) { + this._popper.scheduleUpdate(); + } } - }; - - // private - Dropdown.prototype._addEventListeners = function _addEventListeners() { - var _this = this; + // private - $(this._element).on(Event.CLICK, function (event) { - event.preventDefault(); - event.stopPropagation(); - _this.toggle(); - }); - }; - - Dropdown.prototype._getConfig = function _getConfig(config) { - var elementData = $(this._element).data(); - if (elementData.placement !== undefined) { - elementData.placement = AttachmentMap[elementData.placement.toUpperCase()]; + }, { + key: '_addEventListeners', + value: function _addEventListeners() { + var _this = this; + + $(this._element).on(Event.CLICK, function (event) { + event.preventDefault(); + event.stopPropagation(); + _this.toggle(); + }); } + }, { + key: '_getConfig', + value: function _getConfig(config) { + var elementData = $(this._element).data(); + if (typeof elementData.placement !== 'undefined') { + elementData.placement = AttachmentMap[elementData.placement.toUpperCase()]; + } - config = $.extend({}, this.constructor.Default, $(this._element).data(), config); - - Util.typeCheckConfig(NAME, config, this.constructor.DefaultType); + config = $.extend({}, this.constructor.Default, $(this._element).data(), config); - return config; - }; + Util.typeCheckConfig(NAME, config, this.constructor.DefaultType); - Dropdown.prototype._getMenuElement = function _getMenuElement() { - if (!this._menu) { - var parent = Dropdown._getParentFromElement(this._element); - this._menu = $(parent).find(Selector.MENU)[0]; + return config; } - return this._menu; - }; - - Dropdown.prototype._getPlacement = function _getPlacement() { - var $parentDropdown = $(this._element).parent(); - var placement = this._config.placement; - - // Handle dropup - if ($parentDropdown.hasClass(ClassName.DROPUP) || this._config.placement === AttachmentMap.TOP) { - placement = AttachmentMap.TOP; - if ($(this._menu).hasClass(ClassName.MENURIGHT)) { - placement = AttachmentMap.TOPEND; + }, { + key: '_getMenuElement', + value: function _getMenuElement() { + if (!this._menu) { + var parent = Dropdown._getParentFromElement(this._element); + this._menu = $(parent).find(Selector.MENU)[0]; } - } else if ($(this._menu).hasClass(ClassName.MENURIGHT)) { - placement = AttachmentMap.BOTTOMEND; + return this._menu; } - return placement; - }; - - Dropdown.prototype._detectNavbar = function _detectNavbar() { - return $(this._element).closest('.navbar').length > 0; - }; - - Dropdown.prototype._getPopperConfig = function _getPopperConfig() { - var popperConfig = { - placement: this._getPlacement(), - modifiers: { - offset: { - offset: this._config.offset - }, - flip: { - enabled: this._config.flip + }, { + key: '_getPlacement', + value: function _getPlacement() { + var $parentDropdown = $(this._element).parent(); + var placement = this._config.placement; + + // Handle dropup + if ($parentDropdown.hasClass(ClassName.DROPUP) || this._config.placement === AttachmentMap.TOP) { + placement = AttachmentMap.TOP; + if ($(this._menu).hasClass(ClassName.MENURIGHT)) { + placement = AttachmentMap.TOPEND; } + } else if ($(this._menu).hasClass(ClassName.MENURIGHT)) { + placement = AttachmentMap.BOTTOMEND; } + return placement; + } + }, { + key: '_detectNavbar', + value: function _detectNavbar() { + return $(this._element).closest('.navbar').length > 0; + } + }, { + key: '_getPopperConfig', + value: function _getPopperConfig() { + var popperConfig = { + placement: this._getPlacement(), + modifiers: { + offset: { + offset: this._config.offset + }, + flip: { + enabled: this._config.flip + } + } - // Disable Popper.js for Dropdown in Navbar - };if (this._inNavbar) { - popperConfig.modifiers.applyStyle = { - enabled: !this._inNavbar - }; + // Disable Popper.js for Dropdown in Navbar + };if (this._inNavbar) { + popperConfig.modifiers.applyStyle = { + enabled: !this._inNavbar + }; + } + return popperConfig; } - return popperConfig; - }; - // static + // static - Dropdown._jQueryInterface = function _jQueryInterface(config) { - return this.each(function () { - var data = $(this).data(DATA_KEY); - var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' ? config : null; + }], [{ + key: '_jQueryInterface', + value: function _jQueryInterface(config) { + return this.each(function () { + var data = $(this).data(DATA_KEY); + var _config = (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' ? config : null; - if (!data) { - data = new Dropdown(this, _config); - $(this).data(DATA_KEY, data); - } - - if (typeof config === 'string') { - if (data[config] === undefined) { - throw new Error('No method named "' + config + '"'); + if (!data) { + data = new Dropdown(this, _config); + $(this).data(DATA_KEY, data); } - data[config](); - } - }); - }; - Dropdown._clearMenus = function _clearMenus(event) { - if (event && (event.which === RIGHT_MOUSE_BUTTON_WHICH || event.type === 'keyup' && event.which !== TAB_KEYCODE)) { - return; + if (typeof config === 'string') { + if (typeof data[config] === 'undefined') { + throw new Error('No method named "' + config + '"'); + } + data[config](); + } + }); } - - var toggles = $.makeArray($(Selector.DATA_TOGGLE)); - for (var i = 0; i < toggles.length; i++) { - var parent = Dropdown._getParentFromElement(toggles[i]); - var context = $(toggles[i]).data(DATA_KEY); - var relatedTarget = { - relatedTarget: toggles[i] - }; - - if (!context) { - continue; + }, { + key: '_clearMenus', + value: function _clearMenus(event) { + if (event && (event.which === RIGHT_MOUSE_BUTTON_WHICH || event.type === 'keyup' && event.which !== TAB_KEYCODE)) { + return; } - var dropdownMenu = context._menu; - if (!$(parent).hasClass(ClassName.SHOW)) { - continue; - } + var toggles = $.makeArray($(Selector.DATA_TOGGLE)); + for (var i = 0; i < toggles.length; i++) { + var parent = Dropdown._getParentFromElement(toggles[i]); + var context = $(toggles[i]).data(DATA_KEY); + var relatedTarget = { + relatedTarget: toggles[i] + }; - if (event && (event.type === 'click' && /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) && $.contains(parent, event.target)) { - continue; - } + if (!context) { + continue; + } - var hideEvent = $.Event(Event.HIDE, relatedTarget); - $(parent).trigger(hideEvent); - if (hideEvent.isDefaultPrevented()) { - continue; - } + var dropdownMenu = context._menu; + if (!$(parent).hasClass(ClassName.SHOW)) { + continue; + } - // 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); - } + if (event && (event.type === 'click' && /input|textarea/i.test(event.target.tagName) || event.type === 'keyup' && event.which === TAB_KEYCODE) && $.contains(parent, event.target)) { + continue; + } - toggles[i].setAttribute('aria-expanded', 'false'); + var hideEvent = $.Event(Event.HIDE, relatedTarget); + $(parent).trigger(hideEvent); + if (hideEvent.isDefaultPrevented()) { + continue; + } - $(dropdownMenu).removeClass(ClassName.SHOW); - $(parent).removeClass(ClassName.SHOW).trigger($.Event(Event.HIDDEN, relatedTarget)); - } - }; + // 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); + } - Dropdown._getParentFromElement = function _getParentFromElement(element) { - var parent = void 0; - var selector = Util.getSelectorFromElement(element); + toggles[i].setAttribute('aria-expanded', 'false'); - if (selector) { - parent = $(selector)[0]; + $(dropdownMenu).removeClass(ClassName.SHOW); + $(parent).removeClass(ClassName.SHOW).trigger($.Event(Event.HIDDEN, relatedTarget)); + } } + }, { + key: '_getParentFromElement', + value: function _getParentFromElement(element) { + var parent = void 0; + var selector = Util.getSelectorFromElement(element); - return parent || element.parentNode; - }; + if (selector) { + parent = $(selector)[0]; + } - Dropdown._dataApiKeydownHandler = function _dataApiKeydownHandler(event) { - if (!REGEXP_KEYDOWN.test(event.which) || /button/i.test(event.target.tagName) && event.which === SPACE_KEYCODE || /input|textarea/i.test(event.target.tagName)) { - return; + return parent || element.parentNode; } + }, { + key: '_dataApiKeydownHandler', + value: function _dataApiKeydownHandler(event) { + if (!REGEXP_KEYDOWN.test(event.which) || /button/i.test(event.target.tagName) && event.which === SPACE_KEYCODE || /input|textarea/i.test(event.target.tagName)) { + return; + } + + event.preventDefault(); + event.stopPropagation(); - event.preventDefault(); - event.stopPropagation(); + if (this.disabled || $(this).hasClass(ClassName.DISABLED)) { + return; + } - if (this.disabled || $(this).hasClass(ClassName.DISABLED)) { - return; - } + var parent = Dropdown._getParentFromElement(this); + var isActive = $(parent).hasClass(ClassName.SHOW); - var parent = Dropdown._getParentFromElement(this); - var isActive = $(parent).hasClass(ClassName.SHOW); + if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) { - if (!isActive && (event.which !== ESCAPE_KEYCODE || event.which !== SPACE_KEYCODE) || isActive && (event.which === ESCAPE_KEYCODE || event.which === SPACE_KEYCODE)) { + if (event.which === ESCAPE_KEYCODE) { + var toggle = $(parent).find(Selector.DATA_TOGGLE)[0]; + $(toggle).trigger('focus'); + } - if (event.which === ESCAPE_KEYCODE) { - var toggle = $(parent).find(Selector.DATA_TOGGLE)[0]; - $(toggle).trigger('focus'); + $(this).trigger('click'); + return; } - $(this).trigger('click'); - return; - } + var items = $(parent).find(Selector.VISIBLE_ITEMS).get(); - var items = $(parent).find(Selector.VISIBLE_ITEMS).get(); + if (!items.length) { + return; + } - if (!items.length) { - return; - } + var index = items.indexOf(event.target); - var index = items.indexOf(event.target); + if (event.which === ARROW_UP_KEYCODE && index > 0) { + // up + index--; + } - if (event.which === ARROW_UP_KEYCODE && index > 0) { - // up - index--; - } + if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) { + // down + index++; + } - if (event.which === ARROW_DOWN_KEYCODE && index < items.length - 1) { - // down - index++; - } + if (index < 0) { + index = 0; + } - if (index < 0) { - index = 0; + items[index].focus(); } - - items[index].focus(); - }; - - _createClass(Dropdown, null, [{ + }, { key: 'VERSION', get: function get() { return VERSION; @@ -427,5 +446,5 @@ var Dropdown = function ($) { }; return Dropdown; -}(jQuery); /* global Popper */ +}(jQuery, Popper); //# sourceMappingURL=dropdown.js.map
\ No newline at end of file |