From eb2e1a606e2c3324e7c511ba07c5ba0195801b00 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Mon, 11 Sep 2017 15:23:33 +0100 Subject: rake update[v4-dev] --- assets/javascripts/bootstrap/alert.js | 168 ++++--- assets/javascripts/bootstrap/button.js | 122 ++--- assets/javascripts/bootstrap/carousel.js | 597 +++++++++++----------- assets/javascripts/bootstrap/collapse.js | 358 +++++++------- assets/javascripts/bootstrap/dropdown.js | 457 ++++++++--------- assets/javascripts/bootstrap/modal.js | 696 ++++++++++++++------------ assets/javascripts/bootstrap/popover.js | 130 ++--- assets/javascripts/bootstrap/scrollspy.js | 313 ++++++------ assets/javascripts/bootstrap/tab.js | 257 +++++----- assets/javascripts/bootstrap/tooltip.js | 798 ++++++++++++++++-------------- assets/javascripts/bootstrap/util.js | 17 +- 11 files changed, 2055 insertions(+), 1858 deletions(-) (limited to 'assets/javascripts/bootstrap') diff --git a/assets/javascripts/bootstrap/alert.js b/assets/javascripts/bootstrap/alert.js index 4dc646c..b3f9db1 100644 --- a/assets/javascripts/bootstrap/alert.js +++ b/assets/javascripts/bootstrap/alert.js @@ -1,3 +1,5 @@ +'use strict'; + 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; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -9,7 +11,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons * -------------------------------------------------------------------------- */ -var Alert = function ($) { +var Alert = function () { /** * ------------------------------------------------------------------------ @@ -39,14 +41,14 @@ var Alert = function ($) { ALERT: 'alert', FADE: 'fade', SHOW: 'show' + }; - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - }; var Alert = function () { function Alert(element) { _classCallCheck(this, Alert); @@ -56,98 +58,110 @@ var Alert = function ($) { // getters - // public + _createClass(Alert, [{ + key: 'close', - Alert.prototype.close = function close(element) { - element = element || this._element; - var rootElement = this._getRootElement(element); - var customEvent = this._triggerCloseEvent(rootElement); + // public - if (customEvent.isDefaultPrevented()) { - return; - } - - this._removeElement(rootElement); - }; - - Alert.prototype.dispose = function dispose() { - $.removeData(this._element, DATA_KEY); - this._element = null; - }; + value: function close(element) { + element = element || this._element; - // private + var rootElement = this._getRootElement(element); + var customEvent = this._triggerCloseEvent(rootElement); - Alert.prototype._getRootElement = function _getRootElement(element) { - var selector = Util.getSelectorFromElement(element); - var parent = false; + if (customEvent.isDefaultPrevented()) { + return; + } - if (selector) { - parent = $(selector)[0]; + this._removeElement(rootElement); } - - if (!parent) { - parent = $(element).closest('.' + ClassName.ALERT)[0]; + }, { + key: 'dispose', + value: function dispose() { + $.removeData(this._element, DATA_KEY); + this._element = null; } - return parent; - }; - - Alert.prototype._triggerCloseEvent = function _triggerCloseEvent(element) { - var closeEvent = $.Event(Event.CLOSE); + // private - $(element).trigger(closeEvent); - return closeEvent; - }; + }, { + key: '_getRootElement', + value: function _getRootElement(element) { + var selector = Util.getSelectorFromElement(element); + var parent = false; - Alert.prototype._removeElement = function _removeElement(element) { - var _this = this; + if (selector) { + parent = $(selector)[0]; + } - $(element).removeClass(ClassName.SHOW); + if (!parent) { + parent = $(element).closest('.' + ClassName.ALERT)[0]; + } - if (!Util.supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) { - this._destroyElement(element); - return; + return parent; } + }, { + key: '_triggerCloseEvent', + value: function _triggerCloseEvent(element) { + var closeEvent = $.Event(Event.CLOSE); - $(element).one(Util.TRANSITION_END, function (event) { - return _this._destroyElement(element, event); - }).emulateTransitionEnd(TRANSITION_DURATION); - }; - - Alert.prototype._destroyElement = function _destroyElement(element) { - $(element).detach().trigger(Event.CLOSED).remove(); - }; - - // static + $(element).trigger(closeEvent); + return closeEvent; + } + }, { + key: '_removeElement', + value: function _removeElement(element) { + var _this = this; - Alert._jQueryInterface = function _jQueryInterface(config) { - return this.each(function () { - var $element = $(this); - var data = $element.data(DATA_KEY); + $(element).removeClass(ClassName.SHOW); - if (!data) { - data = new Alert(this); - $element.data(DATA_KEY, data); + if (!Util.supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) { + this._destroyElement(element); + return; } - if (config === 'close') { - data[config](this); - } - }); - }; + $(element).one(Util.TRANSITION_END, function (event) { + return _this._destroyElement(element, event); + }).emulateTransitionEnd(TRANSITION_DURATION); + } + }, { + key: '_destroyElement', + value: function _destroyElement(element) { + $(element).detach().trigger(Event.CLOSED).remove(); + } - Alert._handleDismiss = function _handleDismiss(alertInstance) { - return function (event) { - if (event) { - event.preventDefault(); - } + // static - alertInstance.close(this); - }; - }; + }], [{ + key: '_jQueryInterface', + value: function _jQueryInterface(config) { + return this.each(function () { + var $element = $(this); + var data = $element.data(DATA_KEY); - _createClass(Alert, null, [{ + if (!data) { + data = new Alert(this); + $element.data(DATA_KEY, data); + } + + if (config === 'close') { + data[config](this); + } + }); + } + }, { + key: '_handleDismiss', + value: function _handleDismiss(alertInstance) { + return function (event) { + if (event) { + event.preventDefault(); + } + + alertInstance.close(this); + }; + } + }, { key: 'VERSION', get: function get() { return VERSION; diff --git a/assets/javascripts/bootstrap/button.js b/assets/javascripts/bootstrap/button.js index def083d..9e6bbe4 100644 --- a/assets/javascripts/bootstrap/button.js +++ b/assets/javascripts/bootstrap/button.js @@ -1,3 +1,5 @@ +'use strict'; + 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; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -9,7 +11,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons * -------------------------------------------------------------------------- */ -var Button = function ($) { +var Button = function () { /** * ------------------------------------------------------------------------ @@ -41,14 +43,14 @@ var Button = function ($) { var 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) + }; - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - }; var Button = function () { function Button(element) { _classCallCheck(this, Button); @@ -58,74 +60,80 @@ var Button = function ($) { // getters - // public + _createClass(Button, [{ + key: 'toggle', + + + // public - Button.prototype.toggle = function toggle() { - var triggerChangeEvent = true; - var addAriaPressed = true; - var rootElement = $(this._element).closest(Selector.DATA_TOGGLE)[0]; + value: function toggle() { + var triggerChangeEvent = true; + var addAriaPressed = true; + var rootElement = $(this._element).closest(Selector.DATA_TOGGLE)[0]; - if (rootElement) { - var input = $(this._element).find(Selector.INPUT)[0]; + if (rootElement) { + var input = $(this._element).find(Selector.INPUT)[0]; - if (input) { - if (input.type === 'radio') { - if (input.checked && $(this._element).hasClass(ClassName.ACTIVE)) { - triggerChangeEvent = false; - } else { - var activeElement = $(rootElement).find(Selector.ACTIVE)[0]; + if (input) { + if (input.type === 'radio') { + if (input.checked && $(this._element).hasClass(ClassName.ACTIVE)) { + triggerChangeEvent = false; + } else { + var activeElement = $(rootElement).find(Selector.ACTIVE)[0]; - 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; + if (triggerChangeEvent) { + if (input.hasAttribute('disabled') || rootElement.hasAttribute('disabled') || input.classList.contains('disabled') || rootElement.classList.contains('disabled')) { + return; + } + input.checked = !$(this._element).hasClass(ClassName.ACTIVE); + $(input).trigger('change'); } - input.checked = !$(this._element).hasClass(ClassName.ACTIVE); - $(input).trigger('change'); + + input.focus(); + addAriaPressed = false; } + } - input.focus(); - addAriaPressed = false; + if (addAriaPressed) { + this._element.setAttribute('aria-pressed', !$(this._element).hasClass(ClassName.ACTIVE)); } - } - if (addAriaPressed) { - this._element.setAttribute('aria-pressed', !$(this._element).hasClass(ClassName.ACTIVE)); + if (triggerChangeEvent) { + $(this._element).toggleClass(ClassName.ACTIVE); + } } - - if (triggerChangeEvent) { - $(this._element).toggleClass(ClassName.ACTIVE); + }, { + key: 'dispose', + value: function dispose() { + $.removeData(this._element, DATA_KEY); + this._element = null; } - }; - - Button.prototype.dispose = function dispose() { - $.removeData(this._element, DATA_KEY); - this._element = null; - }; - // static + // static - Button._jQueryInterface = function _jQueryInterface(config) { - return this.each(function () { - var data = $(this).data(DATA_KEY); + }], [{ + key: '_jQueryInterface', + value: function _jQueryInterface(config) { + return this.each(function () { + var data = $(this).data(DATA_KEY); - if (!data) { - data = new Button(this); - $(this).data(DATA_KEY, data); - } - - if (config === 'toggle') { - data[config](); - } - }); - }; + if (!data) { + data = new Button(this); + $(this).data(DATA_KEY, data); + } - _createClass(Button, null, [{ + if (config === 'toggle') { + data[config](); + } + }); + } + }, { key: 'VERSION', get: function get() { return VERSION; diff --git a/assets/javascripts/bootstrap/carousel.js b/assets/javascripts/bootstrap/carousel.js index c657834..55444d0 100644 --- a/assets/javascripts/bootstrap/carousel.js +++ b/assets/javascripts/bootstrap/carousel.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 Carousel = function ($) { +var Carousel = function () { /** * ------------------------------------------------------------------------ @@ -83,14 +85,14 @@ var Carousel = function ($) { INDICATORS: '.carousel-indicators', DATA_SLIDE: '[data-slide], [data-slide-to]', DATA_RIDE: '[data-ride="carousel"]' + }; - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - }; var Carousel = function () { function Carousel(element, config) { _classCallCheck(this, Carousel); @@ -113,360 +115,381 @@ var Carousel = function ($) { // getters - // public + _createClass(Carousel, [{ + key: 'next', - Carousel.prototype.next = function next() { - if (!this._isSliding) { - this._slide(Direction.NEXT); - } - }; - Carousel.prototype.nextWhenVisible = function nextWhenVisible() { - // Don't call next when the page isn't visible - // or the carousel or its parent isn't visible - if (!document.hidden && $(this._element).is(':visible') && $(this._element).css('visibility') !== 'hidden') { - this.next(); - } - }; + // public - Carousel.prototype.prev = function prev() { - if (!this._isSliding) { - this._slide(Direction.PREV); + value: function next() { + if (!this._isSliding) { + this._slide(Direction.NEXT); + } } - }; - - Carousel.prototype.pause = function pause(event) { - if (!event) { - this._isPaused = true; + }, { + key: 'nextWhenVisible', + value: function nextWhenVisible() { + // Don't call next when the page isn't visible + // or the carousel or its parent isn't visible + if (!document.hidden && $(this._element).is(':visible') && $(this._element).css('visibility') !== 'hidden') { + this.next(); + } } - - if ($(this._element).find(Selector.NEXT_PREV)[0] && Util.supportsTransitionEnd()) { - Util.triggerTransitionEnd(this._element); - this.cycle(true); + }, { + key: 'prev', + value: function prev() { + if (!this._isSliding) { + this._slide(Direction.PREV); + } } + }, { + key: 'pause', + value: function pause(event) { + if (!event) { + this._isPaused = true; + } - clearInterval(this._interval); - this._interval = null; - }; - - Carousel.prototype.cycle = function cycle(event) { - if (!event) { - this._isPaused = false; - } + if ($(this._element).find(Selector.NEXT_PREV)[0] && Util.supportsTransitionEnd()) { + Util.triggerTransitionEnd(this._element); + this.cycle(true); + } - if (this._interval) { clearInterval(this._interval); this._interval = null; } + }, { + key: 'cycle', + value: function cycle(event) { + if (!event) { + this._isPaused = false; + } - if (this._config.interval && !this._isPaused) { - this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval); - } - }; - - Carousel.prototype.to = function to(index) { - var _this = this; - - this._activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]; - - var activeIndex = this._getItemIndex(this._activeElement); - - if (index > this._items.length - 1 || index < 0) { - return; - } + if (this._interval) { + clearInterval(this._interval); + this._interval = null; + } - if (this._isSliding) { - $(this._element).one(Event.SLID, function () { - return _this.to(index); - }); - return; + if (this._config.interval && !this._isPaused) { + this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval); + } } + }, { + key: 'to', + value: function to(index) { + var _this = this; - if (activeIndex === index) { - this.pause(); - this.cycle(); - return; - } + this._activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]; - var direction = index > activeIndex ? Direction.NEXT : Direction.PREV; + var activeIndex = this._getItemIndex(this._activeElement); - this._slide(direction, this._items[index]); - }; + if (index > this._items.length - 1 || index < 0) { + return; + } - Carousel.prototype.dispose = function dispose() { - $(this._element).off(EVENT_KEY); - $.removeData(this._element, DATA_KEY); + if (this._isSliding) { + $(this._element).one(Event.SLID, function () { + return _this.to(index); + }); + return; + } - this._items = null; - this._config = null; - this._element = null; - this._interval = null; - this._isPaused = null; - this._isSliding = null; - this._activeElement = null; - this._indicatorsElement = null; - }; + if (activeIndex === index) { + this.pause(); + this.cycle(); + return; + } - // private + var direction = index > activeIndex ? Direction.NEXT : Direction.PREV; - Carousel.prototype._getConfig = function _getConfig(config) { - config = $.extend({}, Default, config); - Util.typeCheckConfig(NAME, config, DefaultType); - return config; - }; + this._slide(direction, this._items[index]); + } + }, { + key: 'dispose', + value: function dispose() { + $(this._element).off(EVENT_KEY); + $.removeData(this._element, DATA_KEY); + + this._items = null; + this._config = null; + this._element = null; + this._interval = null; + this._isPaused = null; + this._isSliding = null; + this._activeElement = null; + this._indicatorsElement = null; + } - Carousel.prototype._addEventListeners = function _addEventListeners() { - var _this2 = this; + // private - if (this._config.keyboard) { - $(this._element).on(Event.KEYDOWN, function (event) { - return _this2._keydown(event); - }); + }, { + key: '_getConfig', + value: function _getConfig(config) { + config = $.extend({}, Default, config); + Util.typeCheckConfig(NAME, config, DefaultType); + return config; } + }, { + key: '_addEventListeners', + value: function _addEventListeners() { + var _this2 = this; - if (this._config.pause === 'hover') { - $(this._element).on(Event.MOUSEENTER, function (event) { - return _this2.pause(event); - }).on(Event.MOUSELEAVE, function (event) { - return _this2.cycle(event); - }); - if ('ontouchstart' in document.documentElement) { - // 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 - // (as if it's the second time we tap on it, mouseenter compat event - // is NOT fired) and after a timeout (to allow for mouse compatibility - // events to fire) we explicitly restart cycling - $(this._element).on(Event.TOUCHEND, function () { - _this2.pause(); - if (_this2.touchTimeout) { - clearTimeout(_this2.touchTimeout); - } - _this2.touchTimeout = setTimeout(function (event) { - return _this2.cycle(event); - }, TOUCHEVENT_COMPAT_WAIT + _this2._config.interval); + if (this._config.keyboard) { + $(this._element).on(Event.KEYDOWN, function (event) { + return _this2._keydown(event); }); } - } - }; - Carousel.prototype._keydown = function _keydown(event) { - if (/input|textarea/i.test(event.target.tagName)) { - return; + if (this._config.pause === 'hover') { + $(this._element).on(Event.MOUSEENTER, function (event) { + return _this2.pause(event); + }).on(Event.MOUSELEAVE, function (event) { + return _this2.cycle(event); + }); + if ('ontouchstart' in document.documentElement) { + // 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 + // (as if it's the second time we tap on it, mouseenter compat event + // is NOT fired) and after a timeout (to allow for mouse compatibility + // events to fire) we explicitly restart cycling + $(this._element).on(Event.TOUCHEND, function () { + _this2.pause(); + if (_this2.touchTimeout) { + clearTimeout(_this2.touchTimeout); + } + _this2.touchTimeout = setTimeout(function (event) { + return _this2.cycle(event); + }, TOUCHEVENT_COMPAT_WAIT + _this2._config.interval); + }); + } + } } - - switch (event.which) { - case ARROW_LEFT_KEYCODE: - event.preventDefault(); - this.prev(); - break; - case ARROW_RIGHT_KEYCODE: - event.preventDefault(); - this.next(); - break; - default: + }, { + key: '_keydown', + value: function _keydown(event) { + if (/input|textarea/i.test(event.target.tagName)) { return; + } + + switch (event.which) { + case ARROW_LEFT_KEYCODE: + event.preventDefault(); + this.prev(); + break; + case ARROW_RIGHT_KEYCODE: + event.preventDefault(); + this.next(); + break; + default: + return; + } } - }; - - Carousel.prototype._getItemIndex = function _getItemIndex(element) { - this._items = $.makeArray($(element).parent().find(Selector.ITEM)); - return this._items.indexOf(element); - }; - - Carousel.prototype._getItemByDirection = function _getItemByDirection(direction, activeElement) { - var isNextDirection = direction === Direction.NEXT; - var isPrevDirection = direction === Direction.PREV; - var activeIndex = this._getItemIndex(activeElement); - var lastItemIndex = this._items.length - 1; - var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex; - - if (isGoingToWrap && !this._config.wrap) { - return activeElement; + }, { + key: '_getItemIndex', + value: function _getItemIndex(element) { + this._items = $.makeArray($(element).parent().find(Selector.ITEM)); + return this._items.indexOf(element); } + }, { + key: '_getItemByDirection', + value: function _getItemByDirection(direction, activeElement) { + var isNextDirection = direction === Direction.NEXT; + var isPrevDirection = direction === Direction.PREV; + var activeIndex = this._getItemIndex(activeElement); + var lastItemIndex = this._items.length - 1; + var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex; + + if (isGoingToWrap && !this._config.wrap) { + return activeElement; + } - var delta = direction === Direction.PREV ? -1 : 1; - var itemIndex = (activeIndex + delta) % this._items.length; - - return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex]; - }; - - Carousel.prototype._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) { - var targetIndex = this._getItemIndex(relatedTarget); - var fromIndex = this._getItemIndex($(this._element).find(Selector.ACTIVE_ITEM)[0]); - var slideEvent = $.Event(Event.SLIDE, { - relatedTarget: relatedTarget, - direction: eventDirectionName, - from: fromIndex, - to: targetIndex - }); + var delta = direction === Direction.PREV ? -1 : 1; + var itemIndex = (activeIndex + delta) % this._items.length; - $(this._element).trigger(slideEvent); + return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex]; + } + }, { + key: '_triggerSlideEvent', + value: function _triggerSlideEvent(relatedTarget, eventDirectionName) { + var targetIndex = this._getItemIndex(relatedTarget); + var fromIndex = this._getItemIndex($(this._element).find(Selector.ACTIVE_ITEM)[0]); + var slideEvent = $.Event(Event.SLIDE, { + relatedTarget: relatedTarget, + direction: eventDirectionName, + from: fromIndex, + to: targetIndex + }); - return slideEvent; - }; + $(this._element).trigger(slideEvent); - Carousel.prototype._setActiveIndicatorElement = function _setActiveIndicatorElement(element) { - if (this._indicatorsElement) { - $(this._indicatorsElement).find(Selector.ACTIVE).removeClass(ClassName.ACTIVE); + return slideEvent; + } + }, { + key: '_setActiveIndicatorElement', + value: function _setActiveIndicatorElement(element) { + if (this._indicatorsElement) { + $(this._indicatorsElement).find(Selector.ACTIVE).removeClass(ClassName.ACTIVE); - var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)]; + var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)]; - if (nextIndicator) { - $(nextIndicator).addClass(ClassName.ACTIVE); + if (nextIndicator) { + $(nextIndicator).addClass(ClassName.ACTIVE); + } } } - }; - - Carousel.prototype._slide = function _slide(direction, element) { - var _this3 = this; - - var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]; - var activeElementIndex = this._getItemIndex(activeElement); - var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement); - var nextElementIndex = this._getItemIndex(nextElement); - var isCycling = Boolean(this._interval); - - var directionalClassName = void 0; - var orderClassName = void 0; - var eventDirectionName = void 0; - - if (direction === Direction.NEXT) { - directionalClassName = ClassName.LEFT; - orderClassName = ClassName.NEXT; - eventDirectionName = Direction.LEFT; - } else { - directionalClassName = ClassName.RIGHT; - orderClassName = ClassName.PREV; - eventDirectionName = Direction.RIGHT; - } + }, { + key: '_slide', + value: function _slide(direction, element) { + var _this3 = this; + + var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0]; + var activeElementIndex = this._getItemIndex(activeElement); + var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement); + var nextElementIndex = this._getItemIndex(nextElement); + var isCycling = Boolean(this._interval); + + var directionalClassName = void 0; + var orderClassName = void 0; + var eventDirectionName = void 0; + + if (direction === Direction.NEXT) { + directionalClassName = ClassName.LEFT; + orderClassName = ClassName.NEXT; + eventDirectionName = Direction.LEFT; + } else { + directionalClassName = ClassName.RIGHT; + orderClassName = ClassName.PREV; + eventDirectionName = Direction.RIGHT; + } - if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) { - this._isSliding = false; - return; - } + if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) { + this._isSliding = false; + return; + } - var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName); - if (slideEvent.isDefaultPrevented()) { - return; - } + var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName); + if (slideEvent.isDefaultPrevented()) { + return; + } - if (!activeElement || !nextElement) { - // some weirdness is happening, so we bail - return; - } + if (!activeElement || !nextElement) { + // some weirdness is happening, so we bail + return; + } - this._isSliding = true; + this._isSliding = true; - if (isCycling) { - this.pause(); - } + if (isCycling) { + this.pause(); + } - this._setActiveIndicatorElement(nextElement); + this._setActiveIndicatorElement(nextElement); - var slidEvent = $.Event(Event.SLID, { - relatedTarget: nextElement, - direction: eventDirectionName, - from: activeElementIndex, - to: nextElementIndex - }); + var slidEvent = $.Event(Event.SLID, { + relatedTarget: nextElement, + direction: eventDirectionName, + from: activeElementIndex, + to: nextElementIndex + }); - if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.SLIDE)) { + if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.SLIDE)) { - $(nextElement).addClass(orderClassName); + $(nextElement).addClass(orderClassName); - Util.reflow(nextElement); + Util.reflow(nextElement); - $(activeElement).addClass(directionalClassName); - $(nextElement).addClass(directionalClassName); + $(activeElement).addClass(directionalClassName); + $(nextElement).addClass(directionalClassName); - $(activeElement).one(Util.TRANSITION_END, function () { - $(nextElement).removeClass(directionalClassName + ' ' + orderClassName).addClass(ClassName.ACTIVE); + $(activeElement).one(Util.TRANSITION_END, function () { + $(nextElement).removeClass(directionalClassName + ' ' + orderClassName).addClass(ClassName.ACTIVE); - $(activeElement).removeClass(ClassName.ACTIVE + ' ' + orderClassName + ' ' + directionalClassName); + $(activeElement).removeClass(ClassName.ACTIVE + ' ' + orderClassName + ' ' + directionalClassName); - _this3._isSliding = false; + _this3._isSliding = false; - setTimeout(function () { - return $(_this3._element).trigger(slidEvent); - }, 0); - }).emulateTransitionEnd(TRANSITION_DURATION); - } else { - $(activeElement).removeClass(ClassName.ACTIVE); - $(nextElement).addClass(ClassName.ACTIVE); + setTimeout(function () { + return $(_this3._element).trigger(slidEvent); + }, 0); + }).emulateTransitionEnd(TRANSITION_DURATION); + } else { + $(activeElement).removeClass(ClassName.ACTIVE); + $(nextElement).addClass(ClassName.ACTIVE); - this._isSliding = false; - $(this._element).trigger(slidEvent); - } + this._isSliding = false; + $(this._element).trigger(slidEvent); + } - if (isCycling) { - this.cycle(); + if (isCycling) { + this.cycle(); + } } - }; - // static + // static - Carousel._jQueryInterface = function _jQueryInterface(config) { - return this.each(function () { - var data = $(this).data(DATA_KEY); - var _config = $.extend({}, Default, $(this).data()); + }], [{ + key: '_jQueryInterface', + value: function _jQueryInterface(config) { + return this.each(function () { + var data = $(this).data(DATA_KEY); + var _config = $.extend({}, Default, $(this).data()); - if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object') { - $.extend(_config, config); - } - - var action = typeof config === 'string' ? config : _config.slide; + if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object') { + $.extend(_config, config); + } - if (!data) { - data = new Carousel(this, _config); - $(this).data(DATA_KEY, data); - } + var action = typeof config === 'string' ? config : _config.slide; - if (typeof config === 'number') { - data.to(config); - } else if (typeof action === 'string') { - if (data[action] === undefined) { - throw new Error('No method named "' + action + '"'); + if (!data) { + data = new Carousel(this, _config); + $(this).data(DATA_KEY, data); } - data[action](); - } else if (_config.interval) { - data.pause(); - data.cycle(); - } - }); - }; - - Carousel._dataApiClickHandler = function _dataApiClickHandler(event) { - var selector = Util.getSelectorFromElement(this); - if (!selector) { - return; + if (typeof config === 'number') { + data.to(config); + } else if (typeof action === 'string') { + if (typeof data[action] === 'undefined') { + throw new Error('No method named "' + action + '"'); + } + data[action](); + } else if (_config.interval) { + data.pause(); + data.cycle(); + } + }); } + }, { + key: '_dataApiClickHandler', + value: function _dataApiClickHandler(event) { + var selector = Util.getSelectorFromElement(this); - var target = $(selector)[0]; + if (!selector) { + return; + } - if (!target || !$(target).hasClass(ClassName.CAROUSEL)) { - return; - } + var target = $(selector)[0]; - var config = $.extend({}, $(target).data(), $(this).data()); - var slideIndex = this.getAttribute('data-slide-to'); + if (!target || !$(target).hasClass(ClassName.CAROUSEL)) { + return; + } - if (slideIndex) { - config.interval = false; - } + var config = $.extend({}, $(target).data(), $(this).data()); + var slideIndex = this.getAttribute('data-slide-to'); - Carousel._jQueryInterface.call($(target), config); + if (slideIndex) { + config.interval = false; + } - if (slideIndex) { - $(target).data(DATA_KEY).to(slideIndex); - } + Carousel._jQueryInterface.call($(target), config); - event.preventDefault(); - }; + if (slideIndex) { + $(target).data(DATA_KEY).to(slideIndex); + } - _createClass(Carousel, null, [{ + event.preventDefault(); + } + }, { key: 'VERSION', get: function get() { return VERSION; diff --git a/assets/javascripts/bootstrap/collapse.js b/assets/javascripts/bootstrap/collapse.js index 264522a..70941b4 100644 --- a/assets/javascripts/bootstrap/collapse.js +++ b/assets/javascripts/bootstrap/collapse.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 Collapse = function ($) { +var Collapse = function () { /** * ------------------------------------------------------------------------ @@ -60,14 +62,14 @@ var Collapse = function ($) { var Selector = { ACTIVES: '.show, .collapsing', DATA_TOGGLE: '[data-toggle="collapse"]' + }; - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - }; var Collapse = function () { function Collapse(element, config) { _classCallCheck(this, Collapse); @@ -98,222 +100,237 @@ var Collapse = function ($) { // getters - // public - - Collapse.prototype.toggle = function toggle() { - if ($(this._element).hasClass(ClassName.SHOW)) { - this.hide(); - } else { - this.show(); - } - }; - - Collapse.prototype.show = function show() { - var _this = this; + _createClass(Collapse, [{ + key: 'toggle', - if (this._isTransitioning || $(this._element).hasClass(ClassName.SHOW)) { - return; - } - var actives = void 0; - var activesData = void 0; + // public - if (this._parent) { - actives = $.makeArray($(this._parent).children().children(Selector.ACTIVES)); - if (!actives.length) { - actives = null; + value: function toggle() { + if ($(this._element).hasClass(ClassName.SHOW)) { + this.hide(); + } else { + this.show(); } } + }, { + key: 'show', + value: function show() { + var _this = this; - if (actives) { - activesData = $(actives).data(DATA_KEY); - if (activesData && activesData._isTransitioning) { + if (this._isTransitioning || $(this._element).hasClass(ClassName.SHOW)) { return; } - } - var startEvent = $.Event(Event.SHOW); - $(this._element).trigger(startEvent); - if (startEvent.isDefaultPrevented()) { - return; - } + var actives = void 0; + var activesData = void 0; - if (actives) { - Collapse._jQueryInterface.call($(actives), 'hide'); - if (!activesData) { - $(actives).data(DATA_KEY, null); + if (this._parent) { + actives = $.makeArray($(this._parent).children().children(Selector.ACTIVES)); + if (!actives.length) { + actives = null; + } } - } - var dimension = this._getDimension(); + if (actives) { + activesData = $(actives).data(DATA_KEY); + if (activesData && activesData._isTransitioning) { + return; + } + } - $(this._element).removeClass(ClassName.COLLAPSE).addClass(ClassName.COLLAPSING); + var startEvent = $.Event(Event.SHOW); + $(this._element).trigger(startEvent); + if (startEvent.isDefaultPrevented()) { + return; + } - this._element.style[dimension] = 0; + if (actives) { + Collapse._jQueryInterface.call($(actives), 'hide'); + if (!activesData) { + $(actives).data(DATA_KEY, null); + } + } - if (this._triggerArray.length) { - $(this._triggerArray).removeClass(ClassName.COLLAPSED).attr('aria-expanded', true); - } + var dimension = this._getDimension(); - this.setTransitioning(true); + $(this._element).removeClass(ClassName.COLLAPSE).addClass(ClassName.COLLAPSING); - var complete = function complete() { - $(_this._element).removeClass(ClassName.COLLAPSING).addClass(ClassName.COLLAPSE).addClass(ClassName.SHOW); + this._element.style[dimension] = 0; - _this._element.style[dimension] = ''; + if (this._triggerArray.length) { + $(this._triggerArray).removeClass(ClassName.COLLAPSED).attr('aria-expanded', true); + } - _this.setTransitioning(false); + this.setTransitioning(true); - $(_this._element).trigger(Event.SHOWN); - }; + var complete = function complete() { + $(_this._element).removeClass(ClassName.COLLAPSING).addClass(ClassName.COLLAPSE).addClass(ClassName.SHOW); - if (!Util.supportsTransitionEnd()) { - complete(); - return; - } + _this._element.style[dimension] = ''; - var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1); - var scrollSize = 'scroll' + capitalizedDimension; + _this.setTransitioning(false); - $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION); + $(_this._element).trigger(Event.SHOWN); + }; - this._element.style[dimension] = this._element[scrollSize] + 'px'; - }; + if (!Util.supportsTransitionEnd()) { + complete(); + return; + } - Collapse.prototype.hide = function hide() { - var _this2 = this; + var capitalizedDimension = dimension[0].toUpperCase() + dimension.slice(1); + var scrollSize = 'scroll' + capitalizedDimension; - if (this._isTransitioning || !$(this._element).hasClass(ClassName.SHOW)) { - return; - } + $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION); - var startEvent = $.Event(Event.HIDE); - $(this._element).trigger(startEvent); - if (startEvent.isDefaultPrevented()) { - return; + this._element.style[dimension] = this._element[scrollSize] + 'px'; } + }, { + key: 'hide', + value: function hide() { + var _this2 = this; - var dimension = this._getDimension(); - - this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + 'px'; - - Util.reflow(this._element); - - $(this._element).addClass(ClassName.COLLAPSING).removeClass(ClassName.COLLAPSE).removeClass(ClassName.SHOW); - - if (this._triggerArray.length) { - for (var i = 0; i < this._triggerArray.length; i++) { - var trigger = this._triggerArray[i]; - var selector = Util.getSelectorFromElement(trigger); - if (selector !== null) { - var $elem = $(selector); - if (!$elem.hasClass(ClassName.SHOW)) { - $(trigger).addClass(ClassName.COLLAPSED).attr('aria-expanded', false); - } - } + if (this._isTransitioning || !$(this._element).hasClass(ClassName.SHOW)) { + return; } - } - this.setTransitioning(true); + var startEvent = $.Event(Event.HIDE); + $(this._element).trigger(startEvent); + if (startEvent.isDefaultPrevented()) { + return; + } - var complete = function complete() { - _this2.setTransitioning(false); - $(_this2._element).removeClass(ClassName.COLLAPSING).addClass(ClassName.COLLAPSE).trigger(Event.HIDDEN); - }; + var dimension = this._getDimension(); - this._element.style[dimension] = ''; + this._element.style[dimension] = this._element.getBoundingClientRect()[dimension] + 'px'; - if (!Util.supportsTransitionEnd()) { - complete(); - return; - } + Util.reflow(this._element); - $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION); - }; + $(this._element).addClass(ClassName.COLLAPSING).removeClass(ClassName.COLLAPSE).removeClass(ClassName.SHOW); - Collapse.prototype.setTransitioning = function setTransitioning(isTransitioning) { - this._isTransitioning = isTransitioning; - }; + if (this._triggerArray.length) { + for (var i = 0; i < this._triggerArray.length; i++) { + var trigger = this._triggerArray[i]; + var selector = Util.getSelectorFromElement(trigger); + if (selector !== null) { + var $elem = $(selector); + if (!$elem.hasClass(ClassName.SHOW)) { + $(trigger).addClass(ClassName.COLLAPSED).attr('aria-expanded', false); + } + } + } + } - Collapse.prototype.dispose = function dispose() { - $.removeData(this._element, DATA_KEY); + this.setTransitioning(true); - this._config = null; - this._parent = null; - this._element = null; - this._triggerArray = null; - this._isTransitioning = null; - }; + var complete = function complete() { + _this2.setTransitioning(false); + $(_this2._element).removeClass(ClassName.COLLAPSING).addClass(ClassName.COLLAPSE).trigger(Event.HIDDEN); + }; - // private + this._element.style[dimension] = ''; - Collapse.prototype._getConfig = function _getConfig(config) { - config = $.extend({}, Default, config); - config.toggle = Boolean(config.toggle); // coerce string values - Util.typeCheckConfig(NAME, config, DefaultType); - return config; - }; + if (!Util.supportsTransitionEnd()) { + complete(); + return; + } - Collapse.prototype._getDimension = function _getDimension() { - var hasWidth = $(this._element).hasClass(Dimension.WIDTH); - return hasWidth ? Dimension.WIDTH : Dimension.HEIGHT; - }; + $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION); + } + }, { + key: 'setTransitioning', + value: function setTransitioning(isTransitioning) { + this._isTransitioning = isTransitioning; + } + }, { + key: 'dispose', + value: function dispose() { + $.removeData(this._element, DATA_KEY); + + this._config = null; + this._parent = null; + this._element = null; + this._triggerArray = null; + this._isTransitioning = null; + } - Collapse.prototype._getParent = function _getParent() { - var _this3 = this; + // private - var parent = $(this._config.parent)[0]; - var selector = '[data-toggle="collapse"][data-parent="' + this._config.parent + '"]'; + }, { + key: '_getConfig', + value: function _getConfig(config) { + config = $.extend({}, Default, config); + config.toggle = Boolean(config.toggle); // coerce string values + Util.typeCheckConfig(NAME, config, DefaultType); + return config; + } + }, { + key: '_getDimension', + value: function _getDimension() { + var hasWidth = $(this._element).hasClass(Dimension.WIDTH); + return hasWidth ? Dimension.WIDTH : Dimension.HEIGHT; + } + }, { + key: '_getParent', + value: function _getParent() { + var _this3 = this; - $(parent).find(selector).each(function (i, element) { - _this3._addAriaAndCollapsedClass(Collapse._getTargetFromElement(element), [element]); - }); + var parent = $(this._config.parent)[0]; + var selector = '[data-toggle="collapse"][data-parent="' + this._config.parent + '"]'; - return parent; - }; + $(parent).find(selector).each(function (i, element) { + _this3._addAriaAndCollapsedClass(Collapse._getTargetFromElement(element), [element]); + }); - Collapse.prototype._addAriaAndCollapsedClass = function _addAriaAndCollapsedClass(element, triggerArray) { - if (element) { - var isOpen = $(element).hasClass(ClassName.SHOW); + return parent; + } + }, { + key: '_addAriaAndCollapsedClass', + value: function _addAriaAndCollapsedClass(element, triggerArray) { + if (element) { + var isOpen = $(element).hasClass(ClassName.SHOW); - if (triggerArray.length) { - $(triggerArray).toggleClass(ClassName.COLLAPSED, !isOpen).attr('aria-expanded', isOpen); + if (triggerArray.length) { + $(triggerArray).toggleClass(ClassName.COLLAPSED, !isOpen).attr('aria-expanded', isOpen); + } } } - }; - - // static - Collapse._getTargetFromElement = function _getTargetFromElement(element) { - var selector = Util.getSelectorFromElement(element); - return selector ? $(selector)[0] : null; - }; + // static - Collapse._jQueryInterface = function _jQueryInterface(config) { - return this.each(function () { - var $this = $(this); - var data = $this.data(DATA_KEY); - var _config = $.extend({}, Default, $this.data(), (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config); - - if (!data && _config.toggle && /show|hide/.test(config)) { - _config.toggle = false; - } - - if (!data) { - data = new Collapse(this, _config); - $this.data(DATA_KEY, data); - } + }], [{ + key: '_getTargetFromElement', + value: function _getTargetFromElement(element) { + var selector = Util.getSelectorFromElement(element); + return selector ? $(selector)[0] : null; + } + }, { + key: '_jQueryInterface', + value: function _jQueryInterface(config) { + return this.each(function () { + var $this = $(this); + var data = $this.data(DATA_KEY); + var _config = $.extend({}, Default, $this.data(), (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config); + + if (!data && _config.toggle && /show|hide/.test(config)) { + _config.toggle = false; + } - if (typeof config === 'string') { - if (data[config] === undefined) { - throw new Error('No method named "' + config + '"'); + if (!data) { + data = new Collapse(this, _config); + $this.data(DATA_KEY, data); } - data[config](); - } - }); - }; - _createClass(Collapse, null, [{ + if (typeof config === 'string') { + if (typeof data[config] === 'undefined') { + throw new Error('No method named "' + config + '"'); + } + data[config](); + } + }); + } + }, { key: 'VERSION', get: function get() { return VERSION; @@ -335,7 +352,8 @@ var Collapse = function ($) { */ $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) { - if (!/input|textarea/i.test(event.target.tagName)) { + // preventDefault only for elements (which change the URL) not inside the collapsible element + if (event.target.tagName === 'A' && !$.contains(this, event.target)) { event.preventDefault(); } diff --git a/assets/javascripts/bootstrap/dropdown.js b/assets/javascripts/bootstrap/dropdown.js index 1015eca..0c739de 100644 --- a/assets/javascripts/bootstrap/dropdown.js +++ b/assets/javascripts/bootstrap/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 @@ -76,23 +78,21 @@ var Dropdown = function ($) { }; var Default = { - placement: AttachmentMap.BOTTOM, offset: 0, flip: true }; var DefaultType = { - placement: 'string', offset: '(number|string)', flip: 'boolean' + }; - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - }; var Dropdown = function () { function Dropdown(element, config) { _classCallCheck(this, Dropdown); @@ -108,278 +108,291 @@ 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); + + $(parent).trigger(showEvent); - 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; + 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; } - }; - - // private - - Dropdown.prototype._addEventListeners = function _addEventListeners() { - var _this = this; - - $(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: 'update', + value: function update() { + this._inNavbar = this._detectNavbar(); + if (this._popper !== null) { + this._popper.scheduleUpdate(); + } } - config = $.extend({}, this.constructor.Default, $(this._element).data(), config); + // private - Util.typeCheckConfig(NAME, config, this.constructor.DefaultType); + }, { + 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) { + 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 = AttachmentMap.BOTTOM; + + // Handle dropup + if ($parentDropdown.hasClass(ClassName.DROPUP)) { + 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 - }; + 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,4 +440,4 @@ var Dropdown = function ($) { }; return Dropdown; -}(jQuery); /* global Popper */ +}(jQuery, Popper); diff --git a/assets/javascripts/bootstrap/modal.js b/assets/javascripts/bootstrap/modal.js index e9f405e..781f9a3 100644 --- a/assets/javascripts/bootstrap/modal.js +++ b/assets/javascripts/bootstrap/modal.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 Modal = function ($) { +var Modal = function () { /** * ------------------------------------------------------------------------ @@ -70,15 +72,16 @@ var Modal = function ($) { DATA_TOGGLE: '[data-toggle="modal"]', DATA_DISMISS: '[data-dismiss="modal"]', FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top', + STICKY_CONTENT: '.sticky-top', NAVBAR_TOGGLER: '.navbar-toggler' + }; - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - }; var Modal = function () { function Modal(element, config) { _classCallCheck(this, Modal); @@ -96,417 +99,452 @@ var Modal = function ($) { // getters - // public - - Modal.prototype.toggle = function toggle(relatedTarget) { - return this._isShown ? this.hide() : this.show(relatedTarget); - }; - - Modal.prototype.show = function show(relatedTarget) { - var _this = this; + _createClass(Modal, [{ + key: 'toggle', - if (this._isTransitioning) { - return; - } - if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) { - this._isTransitioning = true; - } - - var showEvent = $.Event(Event.SHOW, { - relatedTarget: relatedTarget - }); + // public - $(this._element).trigger(showEvent); - - if (this._isShown || showEvent.isDefaultPrevented()) { - return; + value: function toggle(relatedTarget) { + return this._isShown ? this.hide() : this.show(relatedTarget); } + }, { + key: 'show', + value: function show(relatedTarget) { + var _this = this; - this._isShown = true; - - this._checkScrollbar(); - this._setScrollbar(); - - $(document.body).addClass(ClassName.OPEN); - - this._setEscapeEvent(); - this._setResizeEvent(); + if (this._isTransitioning) { + return; + } - $(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, function (event) { - return _this.hide(event); - }); + if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) { + this._isTransitioning = true; + } - $(this._dialog).on(Event.MOUSEDOWN_DISMISS, function () { - $(_this._element).one(Event.MOUSEUP_DISMISS, function (event) { - if ($(event.target).is(_this._element)) { - _this._ignoreBackdropClick = true; - } + var showEvent = $.Event(Event.SHOW, { + relatedTarget: relatedTarget }); - }); - this._showBackdrop(function () { - return _this._showElement(relatedTarget); - }); - }; + $(this._element).trigger(showEvent); - Modal.prototype.hide = function hide(event) { - var _this2 = this; + if (this._isShown || showEvent.isDefaultPrevented()) { + return; + } - if (event) { - event.preventDefault(); - } + this._isShown = true; - if (this._isTransitioning || !this._isShown) { - return; - } + this._checkScrollbar(); + this._setScrollbar(); - var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE); + this._adjustDialog(); - if (transition) { - this._isTransitioning = true; - } + $(document.body).addClass(ClassName.OPEN); - var hideEvent = $.Event(Event.HIDE); + this._setEscapeEvent(); + this._setResizeEvent(); - $(this._element).trigger(hideEvent); + $(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, function (event) { + return _this.hide(event); + }); - if (!this._isShown || hideEvent.isDefaultPrevented()) { - return; + $(this._dialog).on(Event.MOUSEDOWN_DISMISS, function () { + $(_this._element).one(Event.MOUSEUP_DISMISS, function (event) { + if ($(event.target).is(_this._element)) { + _this._ignoreBackdropClick = true; + } + }); + }); + + this._showBackdrop(function () { + return _this._showElement(relatedTarget); + }); } + }, { + key: 'hide', + value: function hide(event) { + var _this2 = this; - this._isShown = false; + if (event) { + event.preventDefault(); + } - this._setEscapeEvent(); - this._setResizeEvent(); + if (this._isTransitioning || !this._isShown) { + return; + } - $(document).off(Event.FOCUSIN); + var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE); - $(this._element).removeClass(ClassName.SHOW); + if (transition) { + this._isTransitioning = true; + } - $(this._element).off(Event.CLICK_DISMISS); - $(this._dialog).off(Event.MOUSEDOWN_DISMISS); + var hideEvent = $.Event(Event.HIDE); - if (transition) { + $(this._element).trigger(hideEvent); - $(this._element).one(Util.TRANSITION_END, function (event) { - return _this2._hideModal(event); - }).emulateTransitionEnd(TRANSITION_DURATION); - } else { - this._hideModal(); - } - }; + if (!this._isShown || hideEvent.isDefaultPrevented()) { + return; + } - Modal.prototype.dispose = function dispose() { - $.removeData(this._element, DATA_KEY); + this._isShown = false; - $(window, document, this._element, this._backdrop).off(EVENT_KEY); + this._setEscapeEvent(); + this._setResizeEvent(); - this._config = null; - this._element = null; - this._dialog = null; - this._backdrop = null; - this._isShown = null; - this._isBodyOverflowing = null; - this._ignoreBackdropClick = null; - this._scrollbarWidth = null; - }; + $(document).off(Event.FOCUSIN); - Modal.prototype.handleUpdate = function handleUpdate() { - this._adjustDialog(); - }; + $(this._element).removeClass(ClassName.SHOW); - // private + $(this._element).off(Event.CLICK_DISMISS); + $(this._dialog).off(Event.MOUSEDOWN_DISMISS); - Modal.prototype._getConfig = function _getConfig(config) { - config = $.extend({}, Default, config); - Util.typeCheckConfig(NAME, config, DefaultType); - return config; - }; + if (transition) { - Modal.prototype._showElement = function _showElement(relatedTarget) { - var _this3 = this; + $(this._element).one(Util.TRANSITION_END, function (event) { + return _this2._hideModal(event); + }).emulateTransitionEnd(TRANSITION_DURATION); + } else { + this._hideModal(); + } + } + }, { + key: 'dispose', + value: function dispose() { + $.removeData(this._element, DATA_KEY); - var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE); + $(window, document, this._element, this._backdrop).off(EVENT_KEY); - if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) { - // don't move modals dom position - document.body.appendChild(this._element); + this._config = null; + this._element = null; + this._dialog = null; + this._backdrop = null; + this._isShown = null; + this._isBodyOverflowing = null; + this._ignoreBackdropClick = null; + this._scrollbarWidth = null; + } + }, { + key: 'handleUpdate', + value: function handleUpdate() { + this._adjustDialog(); } - this._element.style.display = 'block'; - this._element.removeAttribute('aria-hidden'); - this._element.scrollTop = 0; + // private - if (transition) { - Util.reflow(this._element); + }, { + key: '_getConfig', + value: function _getConfig(config) { + config = $.extend({}, Default, config); + Util.typeCheckConfig(NAME, config, DefaultType); + return config; } + }, { + key: '_showElement', + value: function _showElement(relatedTarget) { + var _this3 = this; - $(this._element).addClass(ClassName.SHOW); + var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE); - if (this._config.focus) { - this._enforceFocus(); - } + if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) { + // don't move modals dom position + document.body.appendChild(this._element); + } - var shownEvent = $.Event(Event.SHOWN, { - relatedTarget: relatedTarget - }); + this._element.style.display = 'block'; + this._element.removeAttribute('aria-hidden'); + this._element.scrollTop = 0; - var transitionComplete = function transitionComplete() { - if (_this3._config.focus) { - _this3._element.focus(); + if (transition) { + Util.reflow(this._element); } - _this3._isTransitioning = false; - $(_this3._element).trigger(shownEvent); - }; - - if (transition) { - $(this._dialog).one(Util.TRANSITION_END, transitionComplete).emulateTransitionEnd(TRANSITION_DURATION); - } else { - transitionComplete(); - } - }; - Modal.prototype._enforceFocus = function _enforceFocus() { - var _this4 = this; + $(this._element).addClass(ClassName.SHOW); - $(document).off(Event.FOCUSIN) // guard against infinite focus loop - .on(Event.FOCUSIN, function (event) { - if (document !== event.target && _this4._element !== event.target && !$(_this4._element).has(event.target).length) { - _this4._element.focus(); + if (this._config.focus) { + this._enforceFocus(); } - }); - }; - Modal.prototype._setEscapeEvent = function _setEscapeEvent() { - var _this5 = this; + var shownEvent = $.Event(Event.SHOWN, { + relatedTarget: relatedTarget + }); - if (this._isShown && this._config.keyboard) { - $(this._element).on(Event.KEYDOWN_DISMISS, function (event) { - if (event.which === ESCAPE_KEYCODE) { - event.preventDefault(); - _this5.hide(); + var transitionComplete = function transitionComplete() { + if (_this3._config.focus) { + _this3._element.focus(); + } + _this3._isTransitioning = false; + $(_this3._element).trigger(shownEvent); + }; + + if (transition) { + $(this._dialog).one(Util.TRANSITION_END, transitionComplete).emulateTransitionEnd(TRANSITION_DURATION); + } else { + transitionComplete(); + } + } + }, { + key: '_enforceFocus', + value: function _enforceFocus() { + var _this4 = this; + + $(document).off(Event.FOCUSIN) // guard against infinite focus loop + .on(Event.FOCUSIN, function (event) { + if (document !== event.target && _this4._element !== event.target && !$(_this4._element).has(event.target).length) { + _this4._element.focus(); } }); - } else if (!this._isShown) { - $(this._element).off(Event.KEYDOWN_DISMISS); } - }; - - Modal.prototype._setResizeEvent = function _setResizeEvent() { - var _this6 = this; - - if (this._isShown) { - $(window).on(Event.RESIZE, function (event) { - return _this6.handleUpdate(event); + }, { + key: '_setEscapeEvent', + value: function _setEscapeEvent() { + var _this5 = this; + + if (this._isShown && this._config.keyboard) { + $(this._element).on(Event.KEYDOWN_DISMISS, function (event) { + if (event.which === ESCAPE_KEYCODE) { + event.preventDefault(); + _this5.hide(); + } + }); + } else if (!this._isShown) { + $(this._element).off(Event.KEYDOWN_DISMISS); + } + } + }, { + key: '_setResizeEvent', + value: function _setResizeEvent() { + var _this6 = this; + + if (this._isShown) { + $(window).on(Event.RESIZE, function (event) { + return _this6.handleUpdate(event); + }); + } else { + $(window).off(Event.RESIZE); + } + } + }, { + key: '_hideModal', + value: function _hideModal() { + var _this7 = this; + + this._element.style.display = 'none'; + this._element.setAttribute('aria-hidden', true); + this._isTransitioning = false; + this._showBackdrop(function () { + $(document.body).removeClass(ClassName.OPEN); + _this7._resetAdjustments(); + _this7._resetScrollbar(); + $(_this7._element).trigger(Event.HIDDEN); }); - } else { - $(window).off(Event.RESIZE); } - }; - - Modal.prototype._hideModal = function _hideModal() { - var _this7 = this; - - this._element.style.display = 'none'; - this._element.setAttribute('aria-hidden', true); - this._isTransitioning = false; - this._showBackdrop(function () { - $(document.body).removeClass(ClassName.OPEN); - _this7._resetAdjustments(); - _this7._resetScrollbar(); - $(_this7._element).trigger(Event.HIDDEN); - }); - }; - - Modal.prototype._removeBackdrop = function _removeBackdrop() { - if (this._backdrop) { - $(this._backdrop).remove(); - this._backdrop = null; + }, { + key: '_removeBackdrop', + value: function _removeBackdrop() { + if (this._backdrop) { + $(this._backdrop).remove(); + this._backdrop = null; + } } - }; + }, { + key: '_showBackdrop', + value: function _showBackdrop(callback) { + var _this8 = this; - Modal.prototype._showBackdrop = function _showBackdrop(callback) { - var _this8 = this; + var animate = $(this._element).hasClass(ClassName.FADE) ? ClassName.FADE : ''; - var animate = $(this._element).hasClass(ClassName.FADE) ? ClassName.FADE : ''; + if (this._isShown && this._config.backdrop) { + var doAnimate = Util.supportsTransitionEnd() && animate; - if (this._isShown && this._config.backdrop) { - var doAnimate = Util.supportsTransitionEnd() && animate; + this._backdrop = document.createElement('div'); + this._backdrop.className = ClassName.BACKDROP; - this._backdrop = document.createElement('div'); - this._backdrop.className = ClassName.BACKDROP; + if (animate) { + $(this._backdrop).addClass(animate); + } - if (animate) { - $(this._backdrop).addClass(animate); - } + $(this._backdrop).appendTo(document.body); + + $(this._element).on(Event.CLICK_DISMISS, function (event) { + if (_this8._ignoreBackdropClick) { + _this8._ignoreBackdropClick = false; + return; + } + if (event.target !== event.currentTarget) { + return; + } + if (_this8._config.backdrop === 'static') { + _this8._element.focus(); + } else { + _this8.hide(); + } + }); + + if (doAnimate) { + Util.reflow(this._backdrop); + } - $(this._backdrop).appendTo(document.body); + $(this._backdrop).addClass(ClassName.SHOW); - $(this._element).on(Event.CLICK_DISMISS, function (event) { - if (_this8._ignoreBackdropClick) { - _this8._ignoreBackdropClick = false; + if (!callback) { return; } - if (event.target !== event.currentTarget) { + + if (!doAnimate) { + callback(); return; } - if (_this8._config.backdrop === 'static') { - _this8._element.focus(); - } else { - _this8.hide(); - } - }); - if (doAnimate) { - Util.reflow(this._backdrop); - } - - $(this._backdrop).addClass(ClassName.SHOW); + $(this._backdrop).one(Util.TRANSITION_END, callback).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION); + } else if (!this._isShown && this._backdrop) { + $(this._backdrop).removeClass(ClassName.SHOW); - if (!callback) { - return; - } + var callbackRemove = function callbackRemove() { + _this8._removeBackdrop(); + if (callback) { + callback(); + } + }; - if (!doAnimate) { + if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) { + $(this._backdrop).one(Util.TRANSITION_END, callbackRemove).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION); + } else { + callbackRemove(); + } + } else if (callback) { callback(); - return; } + } - $(this._backdrop).one(Util.TRANSITION_END, callback).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION); - } else if (!this._isShown && this._backdrop) { - $(this._backdrop).removeClass(ClassName.SHOW); + // ---------------------------------------------------------------------- + // the following methods are used to handle overflowing modals + // todo (fat): these should probably be refactored out of modal.js + // ---------------------------------------------------------------------- - var callbackRemove = function callbackRemove() { - _this8._removeBackdrop(); - if (callback) { - callback(); - } - }; + }, { + key: '_adjustDialog', + value: function _adjustDialog() { + var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight; - if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) { - $(this._backdrop).one(Util.TRANSITION_END, callbackRemove).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION); - } else { - callbackRemove(); + if (!this._isBodyOverflowing && isModalOverflowing) { + this._element.style.paddingLeft = this._scrollbarWidth + 'px'; } - } else if (callback) { - callback(); - } - }; - - // ---------------------------------------------------------------------- - // the following methods are used to handle overflowing modals - // todo (fat): these should probably be refactored out of modal.js - // ---------------------------------------------------------------------- - Modal.prototype._adjustDialog = function _adjustDialog() { - var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight; - - if (!this._isBodyOverflowing && isModalOverflowing) { - this._element.style.paddingLeft = this._scrollbarWidth + 'px'; + if (this._isBodyOverflowing && !isModalOverflowing) { + this._element.style.paddingRight = this._scrollbarWidth + 'px'; + } } - - if (this._isBodyOverflowing && !isModalOverflowing) { - this._element.style.paddingRight = this._scrollbarWidth + 'px'; + }, { + key: '_resetAdjustments', + value: function _resetAdjustments() { + this._element.style.paddingLeft = ''; + this._element.style.paddingRight = ''; } - }; - - Modal.prototype._resetAdjustments = function _resetAdjustments() { - this._element.style.paddingLeft = ''; - this._element.style.paddingRight = ''; - }; - - Modal.prototype._checkScrollbar = function _checkScrollbar() { - this._isBodyOverflowing = document.body.clientWidth < window.innerWidth; - this._scrollbarWidth = this._getScrollbarWidth(); - }; - - Modal.prototype._setScrollbar = function _setScrollbar() { - var _this9 = this; - - if (this._isBodyOverflowing) { - // Note: DOMNode.style.paddingRight returns the actual value or '' if not set - // while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set - - // Adjust fixed content padding + }, { + key: '_checkScrollbar', + value: function _checkScrollbar() { + var rect = document.body.getBoundingClientRect(); + this._isBodyOverflowing = rect.left + rect.right < window.innerWidth; + this._scrollbarWidth = this._getScrollbarWidth(); + } + }, { + key: '_setScrollbar', + value: function _setScrollbar() { + var _this9 = this; + + if (this._isBodyOverflowing) { + // Note: DOMNode.style.paddingRight returns the actual value or '' if not set + // while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set + + // Adjust fixed content padding + $(Selector.FIXED_CONTENT).each(function (index, element) { + var actualPadding = $(element)[0].style.paddingRight; + var calculatedPadding = $(element).css('padding-right'); + $(element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this9._scrollbarWidth + 'px'); + }); + + // Adjust sticky content margin + $(Selector.STICKY_CONTENT).each(function (index, element) { + var actualMargin = $(element)[0].style.marginRight; + var calculatedMargin = $(element).css('margin-right'); + $(element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) - _this9._scrollbarWidth + 'px'); + }); + + // Adjust navbar-toggler margin + $(Selector.NAVBAR_TOGGLER).each(function (index, element) { + var actualMargin = $(element)[0].style.marginRight; + var calculatedMargin = $(element).css('margin-right'); + $(element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) + _this9._scrollbarWidth + 'px'); + }); + + // Adjust body padding + var actualPadding = document.body.style.paddingRight; + var calculatedPadding = $('body').css('padding-right'); + $('body').data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + this._scrollbarWidth + 'px'); + } + } + }, { + key: '_resetScrollbar', + value: function _resetScrollbar() { + // Restore fixed content padding $(Selector.FIXED_CONTENT).each(function (index, element) { - var actualPadding = $(element)[0].style.paddingRight; - var calculatedPadding = $(element).css('padding-right'); - $(element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this9._scrollbarWidth + 'px'); + var padding = $(element).data('padding-right'); + if (typeof padding !== 'undefined') { + $(element).css('padding-right', padding).removeData('padding-right'); + } }); - // Adjust navbar-toggler margin - $(Selector.NAVBAR_TOGGLER).each(function (index, element) { - var actualMargin = $(element)[0].style.marginRight; - var calculatedMargin = $(element).css('margin-right'); - $(element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) + _this9._scrollbarWidth + 'px'); + // Restore sticky content and navbar-toggler margin + $(Selector.STICKY_CONTENT + ', ' + Selector.NAVBAR_TOGGLER).each(function (index, element) { + var margin = $(element).data('margin-right'); + if (typeof margin !== 'undefined') { + $(element).css('margin-right', margin).removeData('margin-right'); + } }); - // Adjust body padding - var actualPadding = document.body.style.paddingRight; - var calculatedPadding = $('body').css('padding-right'); - $('body').data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + this._scrollbarWidth + 'px'); - } - }; - - Modal.prototype._resetScrollbar = function _resetScrollbar() { - // Restore fixed content padding - $(Selector.FIXED_CONTENT).each(function (index, element) { - var padding = $(element).data('padding-right'); + // Restore body padding + var padding = $('body').data('padding-right'); if (typeof padding !== 'undefined') { - $(element).css('padding-right', padding).removeData('padding-right'); + $('body').css('padding-right', padding).removeData('padding-right'); } - }); + } + }, { + key: '_getScrollbarWidth', + value: function _getScrollbarWidth() { + // thx d.walsh + var scrollDiv = document.createElement('div'); + scrollDiv.className = ClassName.SCROLLBAR_MEASURER; + document.body.appendChild(scrollDiv); + var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth; + document.body.removeChild(scrollDiv); + return scrollbarWidth; + } - // Restore navbar-toggler margin - $(Selector.NAVBAR_TOGGLER).each(function (index, element) { - var margin = $(element).data('margin-right'); - if (typeof margin !== 'undefined') { - $(element).css('margin-right', margin).removeData('margin-right'); - } - }); + // static - // Restore body padding - var padding = $('body').data('padding-right'); - if (typeof padding !== 'undefined') { - $('body').css('padding-right', padding).removeData('padding-right'); - } - }; - - Modal.prototype._getScrollbarWidth = function _getScrollbarWidth() { - // thx d.walsh - var scrollDiv = document.createElement('div'); - scrollDiv.className = ClassName.SCROLLBAR_MEASURER; - document.body.appendChild(scrollDiv); - var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth; - document.body.removeChild(scrollDiv); - return scrollbarWidth; - }; - - // static - - Modal._jQueryInterface = function _jQueryInterface(config, relatedTarget) { - return this.each(function () { - var data = $(this).data(DATA_KEY); - var _config = $.extend({}, Modal.Default, $(this).data(), (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config); - - if (!data) { - data = new Modal(this, _config); - $(this).data(DATA_KEY, data); - } + }], [{ + key: '_jQueryInterface', + value: function _jQueryInterface(config, relatedTarget) { + return this.each(function () { + var data = $(this).data(DATA_KEY); + var _config = $.extend({}, Modal.Default, $(this).data(), (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config); - if (typeof config === 'string') { - if (data[config] === undefined) { - throw new Error('No method named "' + config + '"'); + if (!data) { + data = new Modal(this, _config); + $(this).data(DATA_KEY, data); } - data[config](relatedTarget); - } else if (_config.show) { - data.show(relatedTarget); - } - }); - }; - _createClass(Modal, null, [{ + if (typeof config === 'string') { + if (typeof data[config] === 'undefined') { + throw new Error('No method named "' + config + '"'); + } + data[config](relatedTarget); + } else if (_config.show) { + data.show(relatedTarget); + } + }); + } + }, { key: 'VERSION', get: function get() { return VERSION; diff --git a/assets/javascripts/bootstrap/popover.js b/assets/javascripts/bootstrap/popover.js index 2ae9b24..74891c1 100644 --- a/assets/javascripts/bootstrap/popover.js +++ b/assets/javascripts/bootstrap/popover.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; }; }(); @@ -15,7 +17,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" * -------------------------------------------------------------------------- */ -var Popover = function ($) { +var Popover = function () { /** * ------------------------------------------------------------------------ @@ -63,87 +65,99 @@ var Popover = function ($) { FOCUSOUT: 'focusout' + EVENT_KEY, MOUSEENTER: 'mouseenter' + EVENT_KEY, MOUSELEAVE: 'mouseleave' + EVENT_KEY + }; - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - }; var Popover = function (_Tooltip) { _inherits(Popover, _Tooltip); function Popover() { _classCallCheck(this, Popover); - return _possibleConstructorReturn(this, _Tooltip.apply(this, arguments)); + return _possibleConstructorReturn(this, (Popover.__proto__ || Object.getPrototypeOf(Popover)).apply(this, arguments)); } - // overrides + _createClass(Popover, [{ + key: 'isWithContent', - Popover.prototype.isWithContent = function isWithContent() { - return this.getTitle() || this._getContent(); - }; - Popover.prototype.addAttachmentClass = function addAttachmentClass(attachment) { - $(this.getTipElement()).addClass(CLASS_PREFIX + '-' + attachment); - }; + // overrides - Popover.prototype.getTipElement = function getTipElement() { - return this.tip = this.tip || $(this.config.template)[0]; - }; - - Popover.prototype.setContent = function setContent() { - var $tip = $(this.getTipElement()); - - // we use append for html objects to maintain js events - this.setElementContent($tip.find(Selector.TITLE), this.getTitle()); - this.setElementContent($tip.find(Selector.CONTENT), this._getContent()); + value: function isWithContent() { + return this.getTitle() || this._getContent(); + } + }, { + key: 'addAttachmentClass', + value: function addAttachmentClass(attachment) { + $(this.getTipElement()).addClass(CLASS_PREFIX + '-' + attachment); + } + }, { + key: 'getTipElement', + value: function getTipElement() { + this.tip = this.tip || $(this.config.template)[0]; + return this.tip; + } + }, { + key: 'setContent', + value: function setContent() { + var $tip = $(this.getTipElement()); - $tip.removeClass(ClassName.FADE + ' ' + ClassName.SHOW); - }; + // we use append for html objects to maintain js events + this.setElementContent($tip.find(Selector.TITLE), this.getTitle()); + this.setElementContent($tip.find(Selector.CONTENT), this._getContent()); - // private + $tip.removeClass(ClassName.FADE + ' ' + ClassName.SHOW); + } - Popover.prototype._getContent = function _getContent() { - return this.element.getAttribute('data-content') || (typeof this.config.content === 'function' ? this.config.content.call(this.element) : this.config.content); - }; + // private - Popover.prototype._cleanTipClass = function _cleanTipClass() { - var $tip = $(this.getTipElement()); - var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX); - if (tabClass !== null && tabClass.length > 0) { - $tip.removeClass(tabClass.join('')); + }, { + key: '_getContent', + value: function _getContent() { + return this.element.getAttribute('data-content') || (typeof this.config.content === 'function' ? this.config.content.call(this.element) : this.config.content); + } + }, { + key: '_cleanTipClass', + value: function _cleanTipClass() { + var $tip = $(this.getTipElement()); + var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX); + if (tabClass !== null && tabClass.length > 0) { + $tip.removeClass(tabClass.join('')); + } } - }; - - // static - Popover._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; + // static - if (!data && /destroy|hide/.test(config)) { - return; - } + }], [{ + 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 Popover(this, _config); - $(this).data(DATA_KEY, data); - } + if (!data && /destroy|hide/.test(config)) { + return; + } - if (typeof config === 'string') { - if (data[config] === undefined) { - throw new Error('No method named "' + config + '"'); + if (!data) { + data = new Popover(this, _config); + $(this).data(DATA_KEY, data); } - data[config](); - } - }); - }; - _createClass(Popover, null, [{ + if (typeof config === 'string') { + if (typeof data[config] === 'undefined') { + throw new Error('No method named "' + config + '"'); + } + data[config](); + } + }); + } + }, { key: 'VERSION', diff --git a/assets/javascripts/bootstrap/scrollspy.js b/assets/javascripts/bootstrap/scrollspy.js index 7eaaeb3..18bdfce 100644 --- a/assets/javascripts/bootstrap/scrollspy.js +++ b/assets/javascripts/bootstrap/scrollspy.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 ScrollSpy = function ($) { +var ScrollSpy = function () { /** * ------------------------------------------------------------------------ @@ -64,14 +66,14 @@ var ScrollSpy = function ($) { var OffsetMethod = { OFFSET: 'offset', POSITION: 'position' + }; - /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ - */ + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - }; var ScrollSpy = function () { function ScrollSpy(element, config) { var _this = this; @@ -97,182 +99,197 @@ var ScrollSpy = function ($) { // getters - // public + _createClass(ScrollSpy, [{ + key: 'refresh', - ScrollSpy.prototype.refresh = function refresh() { - var _this2 = this; - var autoMethod = this._scrollElement !== this._scrollElement.window ? OffsetMethod.POSITION : OffsetMethod.OFFSET; + // public - var offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method; + value: function refresh() { + var _this2 = this; - var offsetBase = offsetMethod === OffsetMethod.POSITION ? this._getScrollTop() : 0; + var autoMethod = this._scrollElement !== this._scrollElement.window ? OffsetMethod.POSITION : OffsetMethod.OFFSET; - this._offsets = []; - this._targets = []; - - this._scrollHeight = this._getScrollHeight(); + var offsetMethod = this._config.method === 'auto' ? autoMethod : this._config.method; - var targets = $.makeArray($(this._selector)); + var offsetBase = offsetMethod === OffsetMethod.POSITION ? this._getScrollTop() : 0; - targets.map(function (element) { - var target = void 0; - var targetSelector = Util.getSelectorFromElement(element); + this._offsets = []; + this._targets = []; - if (targetSelector) { - target = $(targetSelector)[0]; - } + this._scrollHeight = this._getScrollHeight(); - if (target) { - var targetBCR = target.getBoundingClientRect(); - if (targetBCR.width || targetBCR.height) { - // todo (fat): remove sketch reliance on jQuery position/offset - return [$(target)[offsetMethod]().top + offsetBase, targetSelector]; - } - } - return null; - }).filter(function (item) { - return item; - }).sort(function (a, b) { - return a[0] - b[0]; - }).forEach(function (item) { - _this2._offsets.push(item[0]); - _this2._targets.push(item[1]); - }); - }; - - ScrollSpy.prototype.dispose = function dispose() { - $.removeData(this._element, DATA_KEY); - $(this._scrollElement).off(EVENT_KEY); - - this._element = null; - this._scrollElement = null; - this._config = null; - this._selector = null; - this._offsets = null; - this._targets = null; - this._activeTarget = null; - this._scrollHeight = null; - }; + var targets = $.makeArray($(this._selector)); - // private + targets.map(function (element) { + var target = void 0; + var targetSelector = Util.getSelectorFromElement(element); - ScrollSpy.prototype._getConfig = function _getConfig(config) { - config = $.extend({}, Default, config); + if (targetSelector) { + target = $(targetSelector)[0]; + } - if (typeof config.target !== 'string') { - var id = $(config.target).attr('id'); - if (!id) { - id = Util.getUID(NAME); - $(config.target).attr('id', id); - } - config.target = '#' + id; + if (target) { + var targetBCR = target.getBoundingClientRect(); + if (targetBCR.width || targetBCR.height) { + // todo (fat): remove sketch reliance on jQuery position/offset + return [$(target)[offsetMethod]().top + offsetBase, targetSelector]; + } + } + return null; + }).filter(function (item) { + return item; + }).sort(function (a, b) { + return a[0] - b[0]; + }).forEach(function (item) { + _this2._offsets.push(item[0]); + _this2._targets.push(item[1]); + }); + } + }, { + key: 'dispose', + value: function dispose() { + $.removeData(this._element, DATA_KEY); + $(this._scrollElement).off(EVENT_KEY); + + this._element = null; + this._scrollElement = null; + this._config = null; + this._selector = null; + this._offsets = null; + this._targets = null; + this._activeTarget = null; + this._scrollHeight = null; } - Util.typeCheckConfig(NAME, config, DefaultType); - - return config; - }; - - ScrollSpy.prototype._getScrollTop = function _getScrollTop() { - return this._scrollElement === window ? this._scrollElement.pageYOffset : this._scrollElement.scrollTop; - }; - - ScrollSpy.prototype._getScrollHeight = function _getScrollHeight() { - return this._scrollElement.scrollHeight || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); - }; + // private - ScrollSpy.prototype._getOffsetHeight = function _getOffsetHeight() { - return this._scrollElement === window ? window.innerHeight : this._scrollElement.getBoundingClientRect().height; - }; + }, { + key: '_getConfig', + value: function _getConfig(config) { + config = $.extend({}, Default, config); + + if (typeof config.target !== 'string') { + var id = $(config.target).attr('id'); + if (!id) { + id = Util.getUID(NAME); + $(config.target).attr('id', id); + } + config.target = '#' + id; + } - ScrollSpy.prototype._process = function _process() { - var scrollTop = this._getScrollTop() + this._config.offset; - var scrollHeight = this._getScrollHeight(); - var maxScroll = this._config.offset + scrollHeight - this._getOffsetHeight(); + Util.typeCheckConfig(NAME, config, DefaultType); - if (this._scrollHeight !== scrollHeight) { - this.refresh(); + return config; } - - if (scrollTop >= maxScroll) { - var target = this._targets[this._targets.length - 1]; - - if (this._activeTarget !== target) { - this._activate(target); - } - return; + }, { + key: '_getScrollTop', + value: function _getScrollTop() { + return this._scrollElement === window ? this._scrollElement.pageYOffset : this._scrollElement.scrollTop; } - - if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) { - this._activeTarget = null; - this._clear(); - return; + }, { + key: '_getScrollHeight', + value: function _getScrollHeight() { + return this._scrollElement.scrollHeight || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight); + } + }, { + key: '_getOffsetHeight', + value: function _getOffsetHeight() { + return this._scrollElement === window ? window.innerHeight : this._scrollElement.getBoundingClientRect().height; } + }, { + key: '_process', + value: function _process() { + var scrollTop = this._getScrollTop() + this._config.offset; + var scrollHeight = this._getScrollHeight(); + var maxScroll = this._config.offset + scrollHeight - this._getOffsetHeight(); + + if (this._scrollHeight !== scrollHeight) { + this.refresh(); + } - for (var i = this._offsets.length; i--;) { - var isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] && (this._offsets[i + 1] === undefined || scrollTop < this._offsets[i + 1]); + if (scrollTop >= maxScroll) { + var target = this._targets[this._targets.length - 1]; - if (isActiveTarget) { - this._activate(this._targets[i]); + if (this._activeTarget !== target) { + this._activate(target); + } + return; } - } - }; - - ScrollSpy.prototype._activate = function _activate(target) { - this._activeTarget = target; - this._clear(); + if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) { + this._activeTarget = null; + this._clear(); + return; + } - var queries = this._selector.split(','); - queries = queries.map(function (selector) { - return selector + '[data-target="' + target + '"],' + (selector + '[href="' + target + '"]'); - }); + for (var i = this._offsets.length; i--;) { + var isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] && (typeof this._offsets[i + 1] === 'undefined' || scrollTop < this._offsets[i + 1]); - var $link = $(queries.join(',')); - - if ($link.hasClass(ClassName.DROPDOWN_ITEM)) { - $link.closest(Selector.DROPDOWN).find(Selector.DROPDOWN_TOGGLE).addClass(ClassName.ACTIVE); - $link.addClass(ClassName.ACTIVE); - } else { - // Set triggered link as active - $link.addClass(ClassName.ACTIVE); - // Set triggered links parents as active - // With both