LaravelTest
428 строк · 12.7 Кб
1/*!
2* bsStepper v1.7.0 (https://github.com/Johann-S/bs-stepper)
3* Copyright 2018 - 2019 Johann-S <johann.servoire@gmail.com>
4* Licensed under MIT (https://github.com/Johann-S/bs-stepper/blob/master/LICENSE)
5*/
6(function (global, factory) {7typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :8typeof define === 'function' && define.amd ? define(factory) :9(global = global || self, global.Stepper = factory());10}(this, function () { 'use strict';11
12function _extends() {13_extends = Object.assign || function (target) {14for (var i = 1; i < arguments.length; i++) {15var source = arguments[i];16
17for (var key in source) {18if (Object.prototype.hasOwnProperty.call(source, key)) {19target[key] = source[key];20}21}22}23
24return target;25};26
27return _extends.apply(this, arguments);28}29
30var matches = window.Element.prototype.matches;31
32var closest = function closest(element, selector) {33return element.closest(selector);34};35
36var WinEvent = function WinEvent(inType, params) {37return new window.Event(inType, params);38};39
40var createCustomEvent = function createCustomEvent(eventName, params) {41var cEvent = new window.CustomEvent(eventName, params);42return cEvent;43};44/* istanbul ignore next */45
46
47function polyfill() {48if (!window.Element.prototype.matches) {49matches = window.Element.prototype.msMatchesSelector || window.Element.prototype.webkitMatchesSelector;50}51
52if (!window.Element.prototype.closest) {53closest = function closest(element, selector) {54if (!document.documentElement.contains(element)) {55return null;56}57
58do {59if (matches.call(element, selector)) {60return element;61}62
63element = element.parentElement || element.parentNode;64} while (element !== null && element.nodeType === 1);65
66return null;67};68}69
70if (!window.Event || typeof window.Event !== 'function') {71WinEvent = function WinEvent(inType, params) {72params = params || {};73var e = document.createEvent('Event');74e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable));75return e;76};77}78
79if (typeof window.CustomEvent !== 'function') {80var originPreventDefault = window.Event.prototype.preventDefault;81
82createCustomEvent = function createCustomEvent(eventName, params) {83var evt = document.createEvent('CustomEvent');84params = params || {85bubbles: false,86cancelable: false,87detail: null88};89evt.initCustomEvent(eventName, params.bubbles, params.cancelable, params.detail);90
91evt.preventDefault = function () {92if (!this.cancelable) {93return;94}95
96originPreventDefault.call(this);97Object.defineProperty(this, 'defaultPrevented', {98get: function get() {99return true;100}101});102};103
104return evt;105};106}107}108
109polyfill();110
111var MILLISECONDS_MULTIPLIER = 1000;112var ClassName = {113ACTIVE: 'active',114LINEAR: 'linear',115BLOCK: 'dstepper-block',116NONE: 'dstepper-none',117FADE: 'fade',118VERTICAL: 'vertical'119};120var transitionEndEvent = 'transitionend';121var customProperty = 'bsStepper';122
123var show = function show(stepperNode, indexStep, options, done) {124var stepper = stepperNode[customProperty];125
126if (stepper._steps[indexStep].classList.contains(ClassName.ACTIVE) || stepper._stepsContents[indexStep].classList.contains(ClassName.ACTIVE)) {127return;128}129
130var showEvent = createCustomEvent('show.bs-stepper', {131cancelable: true,132detail: {133from: stepper._currentIndex,134to: indexStep,135indexStep: indexStep136}137});138stepperNode.dispatchEvent(showEvent);139
140var activeStep = stepper._steps.filter(function (step) {141return step.classList.contains(ClassName.ACTIVE);142});143
144var activeContent = stepper._stepsContents.filter(function (content) {145return content.classList.contains(ClassName.ACTIVE);146});147
148if (showEvent.defaultPrevented) {149return;150}151
152if (activeStep.length) {153activeStep[0].classList.remove(ClassName.ACTIVE);154}155
156if (activeContent.length) {157activeContent[0].classList.remove(ClassName.ACTIVE);158
159if (!stepperNode.classList.contains(ClassName.VERTICAL) && !stepper.options.animation) {160activeContent[0].classList.remove(ClassName.BLOCK);161}162}163
164showStep(stepperNode, stepper._steps[indexStep], stepper._steps, options);165showContent(stepperNode, stepper._stepsContents[indexStep], stepper._stepsContents, activeContent, done);166};167
168var showStep = function showStep(stepperNode, step, stepList, options) {169stepList.forEach(function (step) {170var trigger = step.querySelector(options.selectors.trigger);171trigger.setAttribute('aria-selected', 'false'); // if stepper is in linear mode, set disabled attribute on the trigger172
173if (stepperNode.classList.contains(ClassName.LINEAR)) {174trigger.setAttribute('disabled', 'disabled');175}176});177step.classList.add(ClassName.ACTIVE);178var currentTrigger = step.querySelector(options.selectors.trigger);179currentTrigger.setAttribute('aria-selected', 'true'); // if stepper is in linear mode, remove disabled attribute on current180
181if (stepperNode.classList.contains(ClassName.LINEAR)) {182currentTrigger.removeAttribute('disabled');183}184};185
186var showContent = function showContent(stepperNode, content, contentList, activeContent, done) {187var stepper = stepperNode[customProperty];188var toIndex = contentList.indexOf(content);189var shownEvent = createCustomEvent('shown.bs-stepper', {190cancelable: true,191detail: {192from: stepper._currentIndex,193to: toIndex,194indexStep: toIndex195}196});197
198function complete() {199content.classList.add(ClassName.BLOCK);200content.removeEventListener(transitionEndEvent, complete);201stepperNode.dispatchEvent(shownEvent);202done();203}204
205if (content.classList.contains(ClassName.FADE)) {206content.classList.remove(ClassName.NONE);207var duration = getTransitionDurationFromElement(content);208content.addEventListener(transitionEndEvent, complete);209
210if (activeContent.length) {211activeContent[0].classList.add(ClassName.NONE);212}213
214content.classList.add(ClassName.ACTIVE);215emulateTransitionEnd(content, duration);216} else {217content.classList.add(ClassName.ACTIVE);218content.classList.add(ClassName.BLOCK);219stepperNode.dispatchEvent(shownEvent);220done();221}222};223
224var getTransitionDurationFromElement = function getTransitionDurationFromElement(element) {225if (!element) {226return 0;227} // Get transition-duration of the element228
229
230var transitionDuration = window.getComputedStyle(element).transitionDuration;231var floatTransitionDuration = parseFloat(transitionDuration); // Return 0 if element or transition duration is not found232
233if (!floatTransitionDuration) {234return 0;235} // If multiple durations are defined, take the first236
237
238transitionDuration = transitionDuration.split(',')[0];239return parseFloat(transitionDuration) * MILLISECONDS_MULTIPLIER;240};241
242var emulateTransitionEnd = function emulateTransitionEnd(element, duration) {243var called = false;244var durationPadding = 5;245var emulatedDuration = duration + durationPadding;246
247function listener() {248called = true;249element.removeEventListener(transitionEndEvent, listener);250}251
252element.addEventListener(transitionEndEvent, listener);253window.setTimeout(function () {254if (!called) {255element.dispatchEvent(WinEvent(transitionEndEvent));256}257
258element.removeEventListener(transitionEndEvent, listener);259}, emulatedDuration);260};261
262var detectAnimation = function detectAnimation(contentList, options) {263if (options.animation) {264contentList.forEach(function (content) {265content.classList.add(ClassName.FADE);266content.classList.add(ClassName.NONE);267});268}269};270
271var buildClickStepLinearListener = function buildClickStepLinearListener() {272return function clickStepLinearListener(event) {273event.preventDefault();274};275};276
277var buildClickStepNonLinearListener = function buildClickStepNonLinearListener(options) {278return function clickStepNonLinearListener(event) {279event.preventDefault();280var step = closest(event.target, options.selectors.steps);281var stepperNode = closest(step, options.selectors.stepper);282var stepper = stepperNode[customProperty];283
284var stepIndex = stepper._steps.indexOf(step);285
286show(stepperNode, stepIndex, options, function () {287stepper._currentIndex = stepIndex;288});289};290};291
292var DEFAULT_OPTIONS = {293linear: true,294animation: false,295selectors: {296steps: '.step',297trigger: '.step-trigger',298stepper: '.bs-stepper'299}300};301
302var Stepper =303/*#__PURE__*/304function () {305function Stepper(element, _options) {306var _this = this;307
308if (_options === void 0) {309_options = {};310}311
312this._element = element;313this._currentIndex = 0;314this._stepsContents = [];315this.options = _extends({}, DEFAULT_OPTIONS, {}, _options);316this.options.selectors = _extends({}, DEFAULT_OPTIONS.selectors, {}, this.options.selectors);317
318if (this.options.linear) {319this._element.classList.add(ClassName.LINEAR);320}321
322this._steps = [].slice.call(this._element.querySelectorAll(this.options.selectors.steps));323
324this._steps.filter(function (step) {325return step.hasAttribute('data-target');326}).forEach(function (step) {327_this._stepsContents.push(_this._element.querySelector(step.getAttribute('data-target')));328});329
330detectAnimation(this._stepsContents, this.options);331
332this._setLinkListeners();333
334Object.defineProperty(this._element, customProperty, {335value: this,336writable: true337});338
339if (this._steps.length) {340show(this._element, this._currentIndex, this.options, function () {});341}342} // Private343
344
345var _proto = Stepper.prototype;346
347_proto._setLinkListeners = function _setLinkListeners() {348var _this2 = this;349
350this._steps.forEach(function (step) {351var trigger = step.querySelector(_this2.options.selectors.trigger);352
353if (_this2.options.linear) {354_this2._clickStepLinearListener = buildClickStepLinearListener(_this2.options);355trigger.addEventListener('click', _this2._clickStepLinearListener);356} else {357_this2._clickStepNonLinearListener = buildClickStepNonLinearListener(_this2.options);358trigger.addEventListener('click', _this2._clickStepNonLinearListener);359}360});361} // Public362;363
364_proto.next = function next() {365var _this3 = this;366
367var nextStep = this._currentIndex + 1 <= this._steps.length - 1 ? this._currentIndex + 1 : this._steps.length - 1;368show(this._element, nextStep, this.options, function () {369_this3._currentIndex = nextStep;370});371};372
373_proto.previous = function previous() {374var _this4 = this;375
376var previousStep = this._currentIndex - 1 >= 0 ? this._currentIndex - 1 : 0;377show(this._element, previousStep, this.options, function () {378_this4._currentIndex = previousStep;379});380};381
382_proto.to = function to(stepNumber) {383var _this5 = this;384
385var tempIndex = stepNumber - 1;386var nextStep = tempIndex >= 0 && tempIndex < this._steps.length ? tempIndex : 0;387show(this._element, nextStep, this.options, function () {388_this5._currentIndex = nextStep;389});390};391
392_proto.reset = function reset() {393var _this6 = this;394
395show(this._element, 0, this.options, function () {396_this6._currentIndex = 0;397});398};399
400_proto.destroy = function destroy() {401var _this7 = this;402
403this._steps.forEach(function (step) {404var trigger = step.querySelector(_this7.options.selectors.trigger);405
406if (_this7.options.linear) {407trigger.removeEventListener('click', _this7._clickStepLinearListener);408} else {409trigger.removeEventListener('click', _this7._clickStepNonLinearListener);410}411});412
413this._element[customProperty] = undefined;414this._element = undefined;415this._currentIndex = undefined;416this._steps = undefined;417this._stepsContents = undefined;418this._clickStepLinearListener = undefined;419this._clickStepNonLinearListener = undefined;420};421
422return Stepper;423}();424
425return Stepper;426
427}));428//# sourceMappingURL=bs-stepper.js.map
429