/
var
/
www
/
html
/
lgpd
/
theme
/
boost
/
amd
/
src
/
Upload File
HOME
"use strict"; define(["exports", "jquery", "./util"], function (exports, _jquery, _util) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _jquery2 = _interopRequireDefault(_jquery); var _util2 = _interopRequireDefault(_util); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } /** * ------------------------------------------------------------------------ * Constants * ------------------------------------------------------------------------ */ var NAME = 'carousel'; var VERSION = '4.3.1'; var DATA_KEY = 'bs.carousel'; var EVENT_KEY = ".".concat(DATA_KEY); var DATA_API_KEY = '.data-api'; var JQUERY_NO_CONFLICT = _jquery2.default.fn[NAME]; var ARROW_LEFT_KEYCODE = 37; // KeyboardEvent.which value for left arrow key var ARROW_RIGHT_KEYCODE = 39; // KeyboardEvent.which value for right arrow key var TOUCHEVENT_COMPAT_WAIT = 500; // Time for mouse compat events to fire after touch var SWIPE_THRESHOLD = 40; var Default = { interval: 5000, keyboard: true, slide: false, pause: 'hover', wrap: true, touch: true }; var DefaultType = { interval: '(number|boolean)', keyboard: 'boolean', slide: '(boolean|string)', pause: '(string|boolean)', wrap: 'boolean', touch: 'boolean' }; var Direction = { NEXT: 'next', PREV: 'prev', LEFT: 'left', RIGHT: 'right' }; var Event = { SLIDE: "slide".concat(EVENT_KEY), SLID: "slid".concat(EVENT_KEY), KEYDOWN: "keydown".concat(EVENT_KEY), MOUSEENTER: "mouseenter".concat(EVENT_KEY), MOUSELEAVE: "mouseleave".concat(EVENT_KEY), TOUCHSTART: "touchstart".concat(EVENT_KEY), TOUCHMOVE: "touchmove".concat(EVENT_KEY), TOUCHEND: "touchend".concat(EVENT_KEY), POINTERDOWN: "pointerdown".concat(EVENT_KEY), POINTERUP: "pointerup".concat(EVENT_KEY), DRAG_START: "dragstart".concat(EVENT_KEY), LOAD_DATA_API: "load".concat(EVENT_KEY).concat(DATA_API_KEY), CLICK_DATA_API: "click".concat(EVENT_KEY).concat(DATA_API_KEY) }; var ClassName = { CAROUSEL: 'carousel', ACTIVE: 'active', SLIDE: 'slide', RIGHT: 'carousel-item-right', LEFT: 'carousel-item-left', NEXT: 'carousel-item-next', PREV: 'carousel-item-prev', ITEM: 'carousel-item', POINTER_EVENT: 'pointer-event' }; var Selector = { ACTIVE: '.active', ACTIVE_ITEM: '.active.carousel-item', ITEM: '.carousel-item', ITEM_IMG: '.carousel-item img', NEXT_PREV: '.carousel-item-next, .carousel-item-prev', INDICATORS: '.carousel-indicators', DATA_SLIDE: '[data-slide], [data-slide-to]', DATA_RIDE: '[data-ride="carousel"]' }; var PointerType = { TOUCH: 'touch', PEN: 'pen' /** * ------------------------------------------------------------------------ * Class Definition * ------------------------------------------------------------------------ */ }; var Carousel = function () { function Carousel(element, config) { _classCallCheck(this, Carousel); this._items = null; this._interval = null; this._activeElement = null; this._isPaused = false; this._isSliding = false; this.touchTimeout = null; this.touchStartX = 0; this.touchDeltaX = 0; this._config = this._getConfig(config); this._element = element; this._indicatorsElement = this._element.querySelector(Selector.INDICATORS); this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0; this._pointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent); this._addEventListeners(); } // Getters _createClass(Carousel, [{ key: "next", value: function next() { if (!this._isSliding) { this._slide(Direction.NEXT); } } }, { 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 && (0, _jquery2.default)(this._element).is(':visible') && (0, _jquery2.default)(this._element).css('visibility') !== 'hidden') { this.next(); } } }, { key: "prev", value: function prev() { if (!this._isSliding) { this._slide(Direction.PREV); } } }, { key: "pause", value: function pause(event) { if (!event) { this._isPaused = true; } if (this._element.querySelector(Selector.NEXT_PREV)) { _util2.default.triggerTransitionEnd(this._element); this.cycle(true); } clearInterval(this._interval); this._interval = null; } }, { key: "cycle", value: function cycle(event) { if (!event) { this._isPaused = false; } if (this._interval) { clearInterval(this._interval); this._interval = null; } 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; this._activeElement = this._element.querySelector(Selector.ACTIVE_ITEM); var activeIndex = this._getItemIndex(this._activeElement); if (index > this._items.length - 1 || index < 0) { return; } if (this._isSliding) { (0, _jquery2.default)(this._element).one(Event.SLID, function () { return _this.to(index); }); return; } if (activeIndex === index) { this.pause(); this.cycle(); return; } var direction = index > activeIndex ? Direction.NEXT : Direction.PREV; this._slide(direction, this._items[index]); } }, { key: "dispose", value: function dispose() { (0, _jquery2.default)(this._element).off(EVENT_KEY); _jquery2.default.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; } }, { key: "_getConfig", value: function _getConfig(config) { config = _objectSpread({}, Default, config); _util2.default.typeCheckConfig(NAME, config, DefaultType); return config; } }, { key: "_handleSwipe", value: function _handleSwipe() { var absDeltax = Math.abs(this.touchDeltaX); if (absDeltax <= SWIPE_THRESHOLD) { return; } var direction = absDeltax / this.touchDeltaX; // swipe left if (direction > 0) { this.prev(); } // swipe right if (direction < 0) { this.next(); } } }, { key: "_addEventListeners", value: function _addEventListeners() { var _this2 = this; if (this._config.keyboard) { (0, _jquery2.default)(this._element).on(Event.KEYDOWN, function (event) { return _this2._keydown(event); }); } if (this._config.pause === 'hover') { (0, _jquery2.default)(this._element).on(Event.MOUSEENTER, function (event) { return _this2.pause(event); }).on(Event.MOUSELEAVE, function (event) { return _this2.cycle(event); }); } if (this._config.touch) { this._addTouchEventListeners(); } } }, { key: "_addTouchEventListeners", value: function _addTouchEventListeners() { var _this3 = this; if (!this._touchSupported) { return; } var start = function start(event) { if (_this3._pointerEvent && PointerType[event.originalEvent.pointerType.toUpperCase()]) { _this3.touchStartX = event.originalEvent.clientX; } else if (!_this3._pointerEvent) { _this3.touchStartX = event.originalEvent.touches[0].clientX; } }; var move = function move(event) { // ensure swiping with one touch and not pinching if (event.originalEvent.touches && event.originalEvent.touches.length > 1) { _this3.touchDeltaX = 0; } else { _this3.touchDeltaX = event.originalEvent.touches[0].clientX - _this3.touchStartX; } }; var end = function end(event) { if (_this3._pointerEvent && PointerType[event.originalEvent.pointerType.toUpperCase()]) { _this3.touchDeltaX = event.originalEvent.clientX - _this3.touchStartX; } _this3._handleSwipe(); if (_this3._config.pause === 'hover') { // 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 _this3.pause(); if (_this3.touchTimeout) { clearTimeout(_this3.touchTimeout); } _this3.touchTimeout = setTimeout(function (event) { return _this3.cycle(event); }, TOUCHEVENT_COMPAT_WAIT + _this3._config.interval); } }; (0, _jquery2.default)(this._element.querySelectorAll(Selector.ITEM_IMG)).on(Event.DRAG_START, function (e) { return e.preventDefault(); }); if (this._pointerEvent) { (0, _jquery2.default)(this._element).on(Event.POINTERDOWN, function (event) { return start(event); }); (0, _jquery2.default)(this._element).on(Event.POINTERUP, function (event) { return end(event); }); this._element.classList.add(ClassName.POINTER_EVENT); } else { (0, _jquery2.default)(this._element).on(Event.TOUCHSTART, function (event) { return start(event); }); (0, _jquery2.default)(this._element).on(Event.TOUCHMOVE, function (event) { return move(event); }); (0, _jquery2.default)(this._element).on(Event.TOUCHEND, function (event) { return end(event); }); } } }, { 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: } } }, { key: "_getItemIndex", value: function _getItemIndex(element) { this._items = element && element.parentNode ? [].slice.call(element.parentNode.querySelectorAll(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]; } }, { key: "_triggerSlideEvent", value: function _triggerSlideEvent(relatedTarget, eventDirectionName) { var targetIndex = this._getItemIndex(relatedTarget); var fromIndex = this._getItemIndex(this._element.querySelector(Selector.ACTIVE_ITEM)); var slideEvent = _jquery2.default.Event(Event.SLIDE, { relatedTarget: relatedTarget, direction: eventDirectionName, from: fromIndex, to: targetIndex }); (0, _jquery2.default)(this._element).trigger(slideEvent); return slideEvent; } }, { key: "_setActiveIndicatorElement", value: function _setActiveIndicatorElement(element) { if (this._indicatorsElement) { var indicators = [].slice.call(this._indicatorsElement.querySelectorAll(Selector.ACTIVE)); (0, _jquery2.default)(indicators).removeClass(ClassName.ACTIVE); var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)]; if (nextIndicator) { (0, _jquery2.default)(nextIndicator).addClass(ClassName.ACTIVE); } } } }, { key: "_slide", value: function _slide(direction, element) { var _this4 = this; var activeElement = this._element.querySelector(Selector.ACTIVE_ITEM); 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; var orderClassName; var eventDirectionName; 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 && (0, _jquery2.default)(nextElement).hasClass(ClassName.ACTIVE)) { this._isSliding = false; return; } var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName); if (slideEvent.isDefaultPrevented()) { return; } if (!activeElement || !nextElement) { // Some weirdness is happening, so we bail return; } this._isSliding = true; if (isCycling) { this.pause(); } this._setActiveIndicatorElement(nextElement); var slidEvent = _jquery2.default.Event(Event.SLID, { relatedTarget: nextElement, direction: eventDirectionName, from: activeElementIndex, to: nextElementIndex }); if ((0, _jquery2.default)(this._element).hasClass(ClassName.SLIDE)) { (0, _jquery2.default)(nextElement).addClass(orderClassName); _util2.default.reflow(nextElement); (0, _jquery2.default)(activeElement).addClass(directionalClassName); (0, _jquery2.default)(nextElement).addClass(directionalClassName); var nextElementInterval = parseInt(nextElement.getAttribute('data-interval'), 10); if (nextElementInterval) { this._config.defaultInterval = this._config.defaultInterval || this._config.interval; this._config.interval = nextElementInterval; } else { this._config.interval = this._config.defaultInterval || this._config.interval; } var transitionDuration = _util2.default.getTransitionDurationFromElement(activeElement); (0, _jquery2.default)(activeElement).one(_util2.default.TRANSITION_END, function () { (0, _jquery2.default)(nextElement).removeClass("".concat(directionalClassName, " ").concat(orderClassName)).addClass(ClassName.ACTIVE); (0, _jquery2.default)(activeElement).removeClass("".concat(ClassName.ACTIVE, " ").concat(orderClassName, " ").concat(directionalClassName)); _this4._isSliding = false; setTimeout(function () { return (0, _jquery2.default)(_this4._element).trigger(slidEvent); }, 0); }).emulateTransitionEnd(transitionDuration); } else { (0, _jquery2.default)(activeElement).removeClass(ClassName.ACTIVE); (0, _jquery2.default)(nextElement).addClass(ClassName.ACTIVE); this._isSliding = false; (0, _jquery2.default)(this._element).trigger(slidEvent); } if (isCycling) { this.cycle(); } } }], [{ key: "_jQueryInterface", value: function _jQueryInterface(config) { return this.each(function () { var data = (0, _jquery2.default)(this).data(DATA_KEY); var _config = _objectSpread({}, Default, (0, _jquery2.default)(this).data()); if (_typeof(config) === 'object') { _config = _objectSpread({}, _config, config); } var action = typeof config === 'string' ? config : _config.slide; if (!data) { data = new Carousel(this, _config); (0, _jquery2.default)(this).data(DATA_KEY, data); } if (typeof config === 'number') { data.to(config); } else if (typeof action === 'string') { if (typeof data[action] === 'undefined') { throw new TypeError("No method named \"".concat(action, "\"")); } data[action](); } else if (_config.interval && _config.ride) { data.pause(); data.cycle(); } }); } }, { key: "_dataApiClickHandler", value: function _dataApiClickHandler(event) { var selector = _util2.default.getSelectorFromElement(this); if (!selector) { return; } var target = (0, _jquery2.default)(selector)[0]; if (!target || !(0, _jquery2.default)(target).hasClass(ClassName.CAROUSEL)) { return; } var config = _objectSpread({}, (0, _jquery2.default)(target).data(), (0, _jquery2.default)(this).data()); var slideIndex = this.getAttribute('data-slide-to'); if (slideIndex) { config.interval = false; } Carousel._jQueryInterface.call((0, _jquery2.default)(target), config); if (slideIndex) { (0, _jquery2.default)(target).data(DATA_KEY).to(slideIndex); } event.preventDefault(); } }, { key: "VERSION", get: function get() { return VERSION; } }, { key: "Default", get: function get() { return Default; } }]); return Carousel; }(); /** * ------------------------------------------------------------------------ * Data Api implementation * ------------------------------------------------------------------------ */ (0, _jquery2.default)(document).on(Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler); (0, _jquery2.default)(window).on(Event.LOAD_DATA_API, function () { var carousels = [].slice.call(document.querySelectorAll(Selector.DATA_RIDE)); for (var i = 0, len = carousels.length; i < len; i++) { var $carousel = (0, _jquery2.default)(carousels[i]); Carousel._jQueryInterface.call($carousel, $carousel.data()); } }); /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ */ _jquery2.default.fn[NAME] = Carousel._jQueryInterface; _jquery2.default.fn[NAME].Constructor = Carousel; _jquery2.default.fn[NAME].noConflict = function () { _jquery2.default.fn[NAME] = JQUERY_NO_CONFLICT; return Carousel._jQueryInterface; }; exports.default = Carousel; });