123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790 |
- /*!
- * sweetalert2 v8.12.1
- * Released under the MIT License.
- */
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
- typeof define === 'function' && define.amd ? define(factory) :
- (global.Sweetalert2 = factory());
- }(this, (function () { 'use strict';
- function _typeof(obj) {
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
- _typeof = function (obj) {
- return typeof obj;
- };
- } else {
- _typeof = function (obj) {
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
- };
- }
- return _typeof(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;
- }
- function _extends() {
- _extends = Object.assign || function (target) {
- for (var i = 1; i < arguments.length; i++) {
- var source = arguments[i];
- for (var key in source) {
- if (Object.prototype.hasOwnProperty.call(source, key)) {
- target[key] = source[key];
- }
- }
- }
- return target;
- };
- return _extends.apply(this, arguments);
- }
- function _inherits(subClass, superClass) {
- if (typeof superClass !== "function" && superClass !== null) {
- throw new TypeError("Super expression must either be null or a function");
- }
- subClass.prototype = Object.create(superClass && superClass.prototype, {
- constructor: {
- value: subClass,
- writable: true,
- configurable: true
- }
- });
- if (superClass) _setPrototypeOf(subClass, superClass);
- }
- function _getPrototypeOf(o) {
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
- return o.__proto__ || Object.getPrototypeOf(o);
- };
- return _getPrototypeOf(o);
- }
- function _setPrototypeOf(o, p) {
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
- o.__proto__ = p;
- return o;
- };
- return _setPrototypeOf(o, p);
- }
- function isNativeReflectConstruct() {
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
- if (Reflect.construct.sham) return false;
- if (typeof Proxy === "function") return true;
- try {
- Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
- return true;
- } catch (e) {
- return false;
- }
- }
- function _construct(Parent, args, Class) {
- if (isNativeReflectConstruct()) {
- _construct = Reflect.construct;
- } else {
- _construct = function _construct(Parent, args, Class) {
- var a = [null];
- a.push.apply(a, args);
- var Constructor = Function.bind.apply(Parent, a);
- var instance = new Constructor();
- if (Class) _setPrototypeOf(instance, Class.prototype);
- return instance;
- };
- }
- return _construct.apply(null, arguments);
- }
- function _assertThisInitialized(self) {
- if (self === void 0) {
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- }
- return self;
- }
- function _possibleConstructorReturn(self, call) {
- if (call && (typeof call === "object" || typeof call === "function")) {
- return call;
- }
- return _assertThisInitialized(self);
- }
- function _superPropBase(object, property) {
- while (!Object.prototype.hasOwnProperty.call(object, property)) {
- object = _getPrototypeOf(object);
- if (object === null) break;
- }
- return object;
- }
- function _get(target, property, receiver) {
- if (typeof Reflect !== "undefined" && Reflect.get) {
- _get = Reflect.get;
- } else {
- _get = function _get(target, property, receiver) {
- var base = _superPropBase(target, property);
- if (!base) return;
- var desc = Object.getOwnPropertyDescriptor(base, property);
- if (desc.get) {
- return desc.get.call(receiver);
- }
- return desc.value;
- };
- }
- return _get(target, property, receiver || target);
- }
- var consolePrefix = 'SweetAlert2:';
- /**
- * Filter the unique values into a new array
- * @param arr
- */
- var uniqueArray = function uniqueArray(arr) {
- var result = [];
- for (var i = 0; i < arr.length; i++) {
- if (result.indexOf(arr[i]) === -1) {
- result.push(arr[i]);
- }
- }
- return result;
- };
- /**
- * Returns the array ob object values (Object.values isn't supported in IE11)
- * @param obj
- */
- var objectValues = function objectValues(obj) {
- return Object.keys(obj).map(function (key) {
- return obj[key];
- });
- };
- /**
- * Convert NodeList to Array
- * @param nodeList
- */
- var toArray = function toArray(nodeList) {
- return Array.prototype.slice.call(nodeList);
- };
- /**
- * Standardise console warnings
- * @param message
- */
- var warn = function warn(message) {
- console.warn("".concat(consolePrefix, " ").concat(message));
- };
- /**
- * Standardise console errors
- * @param message
- */
- var error = function error(message) {
- console.error("".concat(consolePrefix, " ").concat(message));
- };
- /**
- * Private global state for `warnOnce`
- * @type {Array}
- * @private
- */
- var previousWarnOnceMessages = [];
- /**
- * Show a console warning, but only if it hasn't already been shown
- * @param message
- */
- var warnOnce = function warnOnce(message) {
- if (!(previousWarnOnceMessages.indexOf(message) !== -1)) {
- previousWarnOnceMessages.push(message);
- warn(message);
- }
- };
- /**
- * Show a one-time console warning about deprecated params/methods
- */
- var warnAboutDepreation = function warnAboutDepreation(deprecatedParam, useInstead) {
- warnOnce("\"".concat(deprecatedParam, "\" is deprecated and will be removed in the next major release. Please use \"").concat(useInstead, "\" instead."));
- };
- /**
- * If `arg` is a function, call it (with no arguments or context) and return the result.
- * Otherwise, just pass the value through
- * @param arg
- */
- var callIfFunction = function callIfFunction(arg) {
- return typeof arg === 'function' ? arg() : arg;
- };
- var isPromise = function isPromise(arg) {
- return arg && Promise.resolve(arg) === arg;
- };
- var DismissReason = Object.freeze({
- cancel: 'cancel',
- backdrop: 'backdrop',
- close: 'close',
- esc: 'esc',
- timer: 'timer'
- });
- var argsToParams = function argsToParams(args) {
- var params = {};
- switch (_typeof(args[0])) {
- case 'object':
- _extends(params, args[0]);
- break;
- default:
- ['title', 'html', 'type'].forEach(function (name, index) {
- switch (_typeof(args[index])) {
- case 'string':
- params[name] = args[index];
- break;
- case 'undefined':
- break;
- default:
- error("Unexpected type of ".concat(name, "! Expected \"string\", got ").concat(_typeof(args[index])));
- }
- });
- }
- return params;
- };
- var swalPrefix = 'swal2-';
- var prefix = function prefix(items) {
- var result = {};
- for (var i in items) {
- result[items[i]] = swalPrefix + items[i];
- }
- return result;
- };
- var swalClasses = prefix(['container', 'shown', 'height-auto', 'iosfix', 'popup', 'modal', 'no-backdrop', 'toast', 'toast-shown', 'toast-column', 'fade', 'show', 'hide', 'noanimation', 'close', 'title', 'header', 'content', 'actions', 'confirm', 'cancel', 'footer', 'icon', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'label', 'textarea', 'inputerror', 'validation-message', 'progress-steps', 'active-progress-step', 'progress-step', 'progress-step-line', 'loading', 'styled', 'top', 'top-start', 'top-end', 'top-left', 'top-right', 'center', 'center-start', 'center-end', 'center-left', 'center-right', 'bottom', 'bottom-start', 'bottom-end', 'bottom-left', 'bottom-right', 'grow-row', 'grow-column', 'grow-fullscreen', 'rtl']);
- var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
- var states = {
- previousBodyPadding: null
- };
- var hasClass = function hasClass(elem, className) {
- return elem.classList.contains(className);
- };
- var applyCustomClass = function applyCustomClass(elem, customClass, className) {
- // Clean up previous custom classes
- toArray(elem.classList).forEach(function (className) {
- if (!(objectValues(swalClasses).indexOf(className) !== -1) && !(objectValues(iconTypes).indexOf(className) !== -1)) {
- elem.classList.remove(className);
- }
- });
- if (customClass && customClass[className]) {
- addClass(elem, customClass[className]);
- }
- };
- function getInput(content, inputType) {
- if (!inputType) {
- return null;
- }
- switch (inputType) {
- case 'select':
- case 'textarea':
- case 'file':
- return getChildByClass(content, swalClasses[inputType]);
- case 'checkbox':
- return content.querySelector(".".concat(swalClasses.checkbox, " input"));
- case 'radio':
- return content.querySelector(".".concat(swalClasses.radio, " input:checked")) || content.querySelector(".".concat(swalClasses.radio, " input:first-child"));
- case 'range':
- return content.querySelector(".".concat(swalClasses.range, " input"));
- default:
- return getChildByClass(content, swalClasses.input);
- }
- }
- var focusInput = function focusInput(input) {
- input.focus(); // place cursor at end of text in text input
- if (input.type !== 'file') {
- // http://stackoverflow.com/a/2345915
- var val = input.value;
- input.value = '';
- input.value = val;
- }
- };
- var toggleClass = function toggleClass(target, classList, condition) {
- if (!target || !classList) {
- return;
- }
- if (typeof classList === 'string') {
- classList = classList.split(/\s+/).filter(Boolean);
- }
- classList.forEach(function (className) {
- if (target.forEach) {
- target.forEach(function (elem) {
- condition ? elem.classList.add(className) : elem.classList.remove(className);
- });
- } else {
- condition ? target.classList.add(className) : target.classList.remove(className);
- }
- });
- };
- var addClass = function addClass(target, classList) {
- toggleClass(target, classList, true);
- };
- var removeClass = function removeClass(target, classList) {
- toggleClass(target, classList, false);
- };
- var getChildByClass = function getChildByClass(elem, className) {
- for (var i = 0; i < elem.childNodes.length; i++) {
- if (hasClass(elem.childNodes[i], className)) {
- return elem.childNodes[i];
- }
- }
- };
- var applyNumericalStyle = function applyNumericalStyle(elem, property, value) {
- if (value || parseInt(value) === 0) {
- elem.style[property] = typeof value === 'number' ? value + 'px' : value;
- } else {
- elem.style.removeProperty(property);
- }
- };
- var show = function show(elem) {
- var display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex';
- elem.style.opacity = '';
- elem.style.display = display;
- };
- var hide = function hide(elem) {
- elem.style.opacity = '';
- elem.style.display = 'none';
- };
- var toggle = function toggle(elem, condition, display) {
- condition ? show(elem, display) : hide(elem);
- }; // borrowed from jquery $(elem).is(':visible') implementation
- var isVisible = function isVisible(elem) {
- return !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
- };
- var isScrollable = function isScrollable(elem) {
- return !!(elem.scrollHeight > elem.clientHeight);
- }; // borrowed from https://stackoverflow.com/a/46352119
- var hasCssAnimation = function hasCssAnimation(elem) {
- var style = window.getComputedStyle(elem);
- var animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0');
- var transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0');
- return animDuration > 0 || transDuration > 0;
- };
- var contains = function contains(haystack, needle) {
- if (typeof haystack.contains === 'function') {
- return haystack.contains(needle);
- }
- };
- var getContainer = function getContainer() {
- return document.body.querySelector('.' + swalClasses.container);
- };
- var elementBySelector = function elementBySelector(selectorString) {
- var container = getContainer();
- return container ? container.querySelector(selectorString) : null;
- };
- var elementByClass = function elementByClass(className) {
- return elementBySelector('.' + className);
- };
- var getPopup = function getPopup() {
- return elementByClass(swalClasses.popup);
- };
- var getIcons = function getIcons() {
- var popup = getPopup();
- return toArray(popup.querySelectorAll('.' + swalClasses.icon));
- };
- var getIcon = function getIcon() {
- var visibleIcon = getIcons().filter(function (icon) {
- return isVisible(icon);
- });
- return visibleIcon.length ? visibleIcon[0] : null;
- };
- var getTitle = function getTitle() {
- return elementByClass(swalClasses.title);
- };
- var getContent = function getContent() {
- return elementByClass(swalClasses.content);
- };
- var getImage = function getImage() {
- return elementByClass(swalClasses.image);
- };
- var getProgressSteps = function getProgressSteps() {
- return elementByClass(swalClasses['progress-steps']);
- };
- var getValidationMessage = function getValidationMessage() {
- return elementByClass(swalClasses['validation-message']);
- };
- var getConfirmButton = function getConfirmButton() {
- return elementBySelector('.' + swalClasses.actions + ' .' + swalClasses.confirm);
- };
- var getCancelButton = function getCancelButton() {
- return elementBySelector('.' + swalClasses.actions + ' .' + swalClasses.cancel);
- };
- var getActions = function getActions() {
- return elementByClass(swalClasses.actions);
- };
- var getHeader = function getHeader() {
- return elementByClass(swalClasses.header);
- };
- var getFooter = function getFooter() {
- return elementByClass(swalClasses.footer);
- };
- var getCloseButton = function getCloseButton() {
- return elementByClass(swalClasses.close);
- };
- var getFocusableElements = function getFocusableElements() {
- var focusableElementsWithTabindex = toArray(getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')) // sort according to tabindex
- .sort(function (a, b) {
- a = parseInt(a.getAttribute('tabindex'));
- b = parseInt(b.getAttribute('tabindex'));
- if (a > b) {
- return 1;
- } else if (a < b) {
- return -1;
- }
- return 0;
- }); // https://github.com/jkup/focusable/blob/master/index.js
- var otherFocusableElements = toArray(getPopup().querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable], audio[controls], video[controls]')).filter(function (el) {
- return el.getAttribute('tabindex') !== '-1';
- });
- return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(function (el) {
- return isVisible(el);
- });
- };
- var isModal = function isModal() {
- return !isToast() && !document.body.classList.contains(swalClasses['no-backdrop']);
- };
- var isToast = function isToast() {
- return document.body.classList.contains(swalClasses['toast-shown']);
- };
- var isLoading = function isLoading() {
- return getPopup().hasAttribute('data-loading');
- };
- // Detect Node env
- var isNodeEnv = function isNodeEnv() {
- return typeof window === 'undefined' || typeof document === 'undefined';
- };
- var sweetHTML = "\n <div aria-labelledby=\"".concat(swalClasses.title, "\" aria-describedby=\"").concat(swalClasses.content, "\" class=\"").concat(swalClasses.popup, "\" tabindex=\"-1\">\n <div class=\"").concat(swalClasses.header, "\">\n <ul class=\"").concat(swalClasses['progress-steps'], "\"></ul>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.error, "\">\n <span class=\"swal2-x-mark\"><span class=\"swal2-x-mark-line-left\"></span><span class=\"swal2-x-mark-line-right\"></span></span>\n </div>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.question, "\"></div>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.warning, "\"></div>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.info, "\"></div>\n <div class=\"").concat(swalClasses.icon, " ").concat(iconTypes.success, "\">\n <div class=\"swal2-success-circular-line-left\"></div>\n <span class=\"swal2-success-line-tip\"></span> <span class=\"swal2-success-line-long\"></span>\n <div class=\"swal2-success-ring\"></div> <div class=\"swal2-success-fix\"></div>\n <div class=\"swal2-success-circular-line-right\"></div>\n </div>\n <img class=\"").concat(swalClasses.image, "\" />\n <h2 class=\"").concat(swalClasses.title, "\" id=\"").concat(swalClasses.title, "\"></h2>\n <button type=\"button\" class=\"").concat(swalClasses.close, "\">×</button>\n </div>\n <div class=\"").concat(swalClasses.content, "\">\n <div id=\"").concat(swalClasses.content, "\"></div>\n <input class=\"").concat(swalClasses.input, "\" />\n <input type=\"file\" class=\"").concat(swalClasses.file, "\" />\n <div class=\"").concat(swalClasses.range, "\">\n <input type=\"range\" />\n <output></output>\n </div>\n <select class=\"").concat(swalClasses.select, "\"></select>\n <div class=\"").concat(swalClasses.radio, "\"></div>\n <label for=\"").concat(swalClasses.checkbox, "\" class=\"").concat(swalClasses.checkbox, "\">\n <input type=\"checkbox\" />\n <span class=\"").concat(swalClasses.label, "\"></span>\n </label>\n <textarea class=\"").concat(swalClasses.textarea, "\"></textarea>\n <div class=\"").concat(swalClasses['validation-message'], "\" id=\"").concat(swalClasses['validation-message'], "\"></div>\n </div>\n <div class=\"").concat(swalClasses.actions, "\">\n <button type=\"button\" class=\"").concat(swalClasses.confirm, "\">OK</button>\n <button type=\"button\" class=\"").concat(swalClasses.cancel, "\">Cancel</button>\n </div>\n <div class=\"").concat(swalClasses.footer, "\">\n </div>\n </div>\n").replace(/(^|\n)\s*/g, '');
- var resetOldContainer = function resetOldContainer() {
- var oldContainer = getContainer();
- if (!oldContainer) {
- return;
- }
- oldContainer.parentNode.removeChild(oldContainer);
- removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]);
- };
- var oldInputVal; // IE11 workaround, see #1109 for details
- var resetValidationMessage = function resetValidationMessage(e) {
- if (Swal.isVisible() && oldInputVal !== e.target.value) {
- Swal.resetValidationMessage();
- }
- oldInputVal = e.target.value;
- };
- var addInputChangeListeners = function addInputChangeListeners() {
- var content = getContent();
- var input = getChildByClass(content, swalClasses.input);
- var file = getChildByClass(content, swalClasses.file);
- var range = content.querySelector(".".concat(swalClasses.range, " input"));
- var rangeOutput = content.querySelector(".".concat(swalClasses.range, " output"));
- var select = getChildByClass(content, swalClasses.select);
- var checkbox = content.querySelector(".".concat(swalClasses.checkbox, " input"));
- var textarea = getChildByClass(content, swalClasses.textarea);
- input.oninput = resetValidationMessage;
- file.onchange = resetValidationMessage;
- select.onchange = resetValidationMessage;
- checkbox.onchange = resetValidationMessage;
- textarea.oninput = resetValidationMessage;
- range.oninput = function (e) {
- resetValidationMessage(e);
- rangeOutput.value = range.value;
- };
- range.onchange = function (e) {
- resetValidationMessage(e);
- range.nextSibling.value = range.value;
- };
- };
- var getTarget = function getTarget(target) {
- return typeof target === 'string' ? document.querySelector(target) : target;
- };
- var setupAccessibility = function setupAccessibility(params) {
- var popup = getPopup();
- popup.setAttribute('role', params.toast ? 'alert' : 'dialog');
- popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive');
- if (!params.toast) {
- popup.setAttribute('aria-modal', 'true');
- }
- };
- var setupRTL = function setupRTL(targetElement) {
- if (window.getComputedStyle(targetElement).direction === 'rtl') {
- addClass(getContainer(), swalClasses.rtl);
- }
- };
- /*
- * Add modal + backdrop to DOM
- */
- var init = function init(params) {
- // Clean up the old popup container if it exists
- resetOldContainer();
- /* istanbul ignore if */
- if (isNodeEnv()) {
- error('SweetAlert2 requires document to initialize');
- return;
- }
- var container = document.createElement('div');
- container.className = swalClasses.container;
- container.innerHTML = sweetHTML;
- var targetElement = getTarget(params.target);
- targetElement.appendChild(container);
- setupAccessibility(params);
- setupRTL(targetElement);
- addInputChangeListeners();
- };
- var parseHtmlToContainer = function parseHtmlToContainer(param, target) {
- // DOM element
- if (param instanceof HTMLElement) {
- target.appendChild(param); // JQuery element(s)
- } else if (_typeof(param) === 'object') {
- handleJqueryElem(target, param); // Plain string
- } else if (param) {
- target.innerHTML = param;
- }
- };
- var handleJqueryElem = function handleJqueryElem(target, elem) {
- target.innerHTML = '';
- if (0 in elem) {
- for (var i = 0; i in elem; i++) {
- target.appendChild(elem[i].cloneNode(true));
- }
- } else {
- target.appendChild(elem.cloneNode(true));
- }
- };
- var animationEndEvent = function () {
- // Prevent run in Node env
- /* istanbul ignore if */
- if (isNodeEnv()) {
- return false;
- }
- var testEl = document.createElement('div');
- var transEndEventNames = {
- 'WebkitAnimation': 'webkitAnimationEnd',
- 'OAnimation': 'oAnimationEnd oanimationend',
- 'animation': 'animationend'
- };
- for (var i in transEndEventNames) {
- if (transEndEventNames.hasOwnProperty(i) && typeof testEl.style[i] !== 'undefined') {
- return transEndEventNames[i];
- }
- }
- return false;
- }();
- // Measure width of scrollbar
- // https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286
- var measureScrollbar = function measureScrollbar() {
- var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints;
- if (supportsTouch) {
- return 0;
- }
- var scrollDiv = document.createElement('div');
- scrollDiv.style.width = '50px';
- scrollDiv.style.height = '50px';
- scrollDiv.style.overflow = 'scroll';
- document.body.appendChild(scrollDiv);
- var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
- document.body.removeChild(scrollDiv);
- return scrollbarWidth;
- };
- function handleButtonsStyling(confirmButton, cancelButton, params) {
- addClass([confirmButton, cancelButton], swalClasses.styled); // Buttons background colors
- if (params.confirmButtonColor) {
- confirmButton.style.backgroundColor = params.confirmButtonColor;
- }
- if (params.cancelButtonColor) {
- cancelButton.style.backgroundColor = params.cancelButtonColor;
- } // Loading state
- var confirmButtonBackgroundColor = window.getComputedStyle(confirmButton).getPropertyValue('background-color');
- confirmButton.style.borderLeftColor = confirmButtonBackgroundColor;
- confirmButton.style.borderRightColor = confirmButtonBackgroundColor;
- }
- function renderButton(button, buttonType, params) {
- toggle(button, params['showC' + buttonType.substring(1) + 'Button'], 'inline-block');
- button.innerHTML = params[buttonType + 'ButtonText']; // Set caption text
- button.setAttribute('aria-label', params[buttonType + 'ButtonAriaLabel']); // ARIA label
- // Add buttons custom classes
- button.className = swalClasses[buttonType];
- applyCustomClass(button, params.customClass, buttonType + 'Button');
- addClass(button, params[buttonType + 'ButtonClass']);
- }
- var renderActions = function renderActions(instance, params) {
- var actions = getActions();
- var confirmButton = getConfirmButton();
- var cancelButton = getCancelButton(); // Actions (buttons) wrapper
- if (!params.showConfirmButton && !params.showCancelButton) {
- hide(actions);
- } else {
- show(actions);
- } // Custom class
- applyCustomClass(actions, params.customClass, 'actions'); // Render confirm button
- renderButton(confirmButton, 'confirm', params); // render Cancel Button
- renderButton(cancelButton, 'cancel', params);
- if (params.buttonsStyling) {
- handleButtonsStyling(confirmButton, cancelButton, params);
- } else {
- removeClass([confirmButton, cancelButton], swalClasses.styled);
- confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = '';
- cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = '';
- }
- };
- function handleBackdropParam(container, backdrop) {
- if (typeof backdrop === 'string') {
- container.style.background = backdrop;
- } else if (!backdrop) {
- addClass([document.documentElement, document.body], swalClasses['no-backdrop']);
- }
- }
- function handlePositionParam(container, position) {
- if (position in swalClasses) {
- addClass(container, swalClasses[position]);
- } else {
- warn('The "position" parameter is not valid, defaulting to "center"');
- addClass(container, swalClasses.center);
- }
- }
- function handleGrowParam(container, grow) {
- if (grow && typeof grow === 'string') {
- var growClass = 'grow-' + grow;
- if (growClass in swalClasses) {
- addClass(container, swalClasses[growClass]);
- }
- }
- }
- var renderContainer = function renderContainer(instance, params) {
- var container = getContainer();
- if (!container) {
- return;
- }
- handleBackdropParam(container, params.backdrop);
- if (!params.backdrop && params.allowOutsideClick) {
- warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
- }
- handlePositionParam(container, params.position);
- handleGrowParam(container, params.grow); // Custom class
- applyCustomClass(container, params.customClass, 'container');
- if (params.customContainerClass) {
- // @deprecated
- addClass(container, params.customContainerClass);
- }
- };
- /**
- * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has.
- * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
- * This is the approach that Babel will probably take to implement private methods/fields
- * https://github.com/tc39/proposal-private-methods
- * https://github.com/babel/babel/pull/7555
- * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
- * then we can use that language feature.
- */
- var privateProps = {
- promise: new WeakMap(),
- innerParams: new WeakMap(),
- domCache: new WeakMap()
- };
- var renderInput = function renderInput(instance, params) {
- var innerParams = privateProps.innerParams.get(instance);
- var rerender = !innerParams || params.input !== innerParams.input;
- var content = getContent();
- var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
- for (var i = 0; i < inputTypes.length; i++) {
- var inputClass = swalClasses[inputTypes[i]];
- var inputContainer = getChildByClass(content, inputClass); // set attributes
- setAttributes(inputTypes[i], params.inputAttributes); // set class
- setClass(inputContainer, inputClass, params);
- rerender && hide(inputContainer);
- }
- if (!params.input) {
- return;
- }
- if (!renderInputType[params.input]) {
- return error("Unexpected type of input! Expected \"text\", \"email\", \"password\", \"number\", \"tel\", \"select\", \"radio\", \"checkbox\", \"textarea\", \"file\" or \"url\", got \"".concat(params.input, "\""));
- }
- if (rerender) {
- var input = renderInputType[params.input](params);
- show(input);
- }
- };
- var removeAttributes = function removeAttributes(input) {
- for (var i = 0; i < input.attributes.length; i++) {
- var attrName = input.attributes[i].name;
- if (!(['type', 'value', 'style'].indexOf(attrName) !== -1)) {
- input.removeAttribute(attrName);
- }
- }
- };
- var setAttributes = function setAttributes(inputType, inputAttributes) {
- var input = getInput(getContent(), inputType);
- if (!input) {
- return;
- }
- removeAttributes(input);
- for (var attr in inputAttributes) {
- // Do not set a placeholder for <input type="range">
- // it'll crash Edge, #1298
- if (inputType === 'range' && attr === 'placeholder') {
- continue;
- }
- input.setAttribute(attr, inputAttributes[attr]);
- }
- };
- var setClass = function setClass(inputContainer, inputClass, params) {
- inputContainer.className = inputClass;
- if (params.inputClass) {
- addClass(inputContainer, params.inputClass);
- }
- if (params.customClass) {
- addClass(inputContainer, params.customClass.input);
- }
- };
- var setInputPlaceholder = function setInputPlaceholder(input, params) {
- if (!input.placeholder || params.inputPlaceholder) {
- input.placeholder = params.inputPlaceholder;
- }
- };
- var renderInputType = {};
- renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = function (params) {
- var input = getChildByClass(getContent(), swalClasses.input);
- if (typeof params.inputValue === 'string' || typeof params.inputValue === 'number') {
- input.value = params.inputValue;
- } else if (!isPromise(params.inputValue)) {
- warn("Unexpected type of inputValue! Expected \"string\", \"number\" or \"Promise\", got \"".concat(_typeof(params.inputValue), "\""));
- }
- setInputPlaceholder(input, params);
- input.type = params.input;
- return input;
- };
- renderInputType.file = function (params) {
- var input = getChildByClass(getContent(), swalClasses.file);
- setInputPlaceholder(input, params);
- input.type = params.input;
- return input;
- };
- renderInputType.range = function (params) {
- var range = getChildByClass(getContent(), swalClasses.range);
- var rangeInput = range.querySelector('input');
- var rangeOutput = range.querySelector('output');
- rangeInput.value = params.inputValue;
- rangeInput.type = params.input;
- rangeOutput.value = params.inputValue;
- return range;
- };
- renderInputType.select = function (params) {
- var select = getChildByClass(getContent(), swalClasses.select);
- select.innerHTML = '';
- if (params.inputPlaceholder) {
- var placeholder = document.createElement('option');
- placeholder.innerHTML = params.inputPlaceholder;
- placeholder.value = '';
- placeholder.disabled = true;
- placeholder.selected = true;
- select.appendChild(placeholder);
- }
- return select;
- };
- renderInputType.radio = function () {
- var radio = getChildByClass(getContent(), swalClasses.radio);
- radio.innerHTML = '';
- return radio;
- };
- renderInputType.checkbox = function (params) {
- var checkbox = getChildByClass(getContent(), swalClasses.checkbox);
- var checkboxInput = getInput(getContent(), 'checkbox');
- checkboxInput.type = 'checkbox';
- checkboxInput.value = 1;
- checkboxInput.id = swalClasses.checkbox;
- checkboxInput.checked = Boolean(params.inputValue);
- var label = checkbox.querySelector('span');
- label.innerHTML = params.inputPlaceholder;
- return checkbox;
- };
- renderInputType.textarea = function (params) {
- var textarea = getChildByClass(getContent(), swalClasses.textarea);
- textarea.value = params.inputValue;
- setInputPlaceholder(textarea, params);
- return textarea;
- };
- var renderContent = function renderContent(instance, params) {
- var content = getContent().querySelector('#' + swalClasses.content); // Content as HTML
- if (params.html) {
- parseHtmlToContainer(params.html, content);
- show(content, 'block'); // Content as plain text
- } else if (params.text) {
- content.textContent = params.text;
- show(content, 'block'); // No content
- } else {
- hide(content);
- }
- renderInput(instance, params); // Custom class
- applyCustomClass(getContent(), params.customClass, 'content');
- };
- var renderFooter = function renderFooter(instance, params) {
- var footer = getFooter();
- toggle(footer, params.footer);
- if (params.footer) {
- parseHtmlToContainer(params.footer, footer);
- } // Custom class
- applyCustomClass(footer, params.customClass, 'footer');
- };
- var renderCloseButton = function renderCloseButton(instance, params) {
- var closeButton = getCloseButton(); // Custom class
- applyCustomClass(closeButton, params.customClass, 'closeButton');
- toggle(closeButton, params.showCloseButton);
- closeButton.setAttribute('aria-label', params.closeButtonAriaLabel);
- };
- var renderIcon = function renderIcon(instance, params) {
- var innerParams = privateProps.innerParams.get(instance); // if the icon with the given type already rendered,
- // apply the custom class without re-rendering the icon
- if (innerParams && params.type === innerParams.type && getIcon()) {
- applyCustomClass(getIcon(), params.customClass, 'icon');
- return;
- }
- hideAllIcons();
- if (!params.type) {
- return;
- }
- adjustSuccessIconBackgoundColor();
- if (Object.keys(iconTypes).indexOf(params.type) !== -1) {
- var icon = elementBySelector(".".concat(swalClasses.icon, ".").concat(iconTypes[params.type]));
- show(icon); // Custom class
- applyCustomClass(icon, params.customClass, 'icon'); // Animate icon
- toggleClass(icon, "swal2-animate-".concat(params.type, "-icon"), params.animation);
- } else {
- error("Unknown type! Expected \"success\", \"error\", \"warning\", \"info\" or \"question\", got \"".concat(params.type, "\""));
- }
- };
- var hideAllIcons = function hideAllIcons() {
- var icons = getIcons();
- for (var i = 0; i < icons.length; i++) {
- hide(icons[i]);
- }
- }; // Adjust success icon background color to match the popup background color
- var adjustSuccessIconBackgoundColor = function adjustSuccessIconBackgoundColor() {
- var popup = getPopup();
- var popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color');
- var successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix');
- for (var i = 0; i < successIconParts.length; i++) {
- successIconParts[i].style.backgroundColor = popupBackgroundColor;
- }
- };
- var renderImage = function renderImage(instance, params) {
- var image = getImage();
- if (!params.imageUrl) {
- return hide(image);
- }
- show(image); // Src, alt
- image.setAttribute('src', params.imageUrl);
- image.setAttribute('alt', params.imageAlt); // Width, height
- applyNumericalStyle(image, 'width', params.imageWidth);
- applyNumericalStyle(image, 'height', params.imageHeight); // Class
- image.className = swalClasses.image;
- applyCustomClass(image, params.customClass, 'image');
- if (params.imageClass) {
- addClass(image, params.imageClass);
- }
- };
- var createStepElement = function createStepElement(step) {
- var stepEl = document.createElement('li');
- addClass(stepEl, swalClasses['progress-step']);
- stepEl.innerHTML = step;
- return stepEl;
- };
- var createLineElement = function createLineElement(params) {
- var lineEl = document.createElement('li');
- addClass(lineEl, swalClasses['progress-step-line']);
- if (params.progressStepsDistance) {
- lineEl.style.width = params.progressStepsDistance;
- }
- return lineEl;
- };
- var renderProgressSteps = function renderProgressSteps(instance, params) {
- var progressStepsContainer = getProgressSteps();
- if (!params.progressSteps || params.progressSteps.length === 0) {
- return hide(progressStepsContainer);
- }
- show(progressStepsContainer);
- progressStepsContainer.innerHTML = '';
- var currentProgressStep = parseInt(params.currentProgressStep === null ? Swal.getQueueStep() : params.currentProgressStep);
- if (currentProgressStep >= params.progressSteps.length) {
- warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
- }
- params.progressSteps.forEach(function (step, index) {
- var stepEl = createStepElement(step);
- progressStepsContainer.appendChild(stepEl);
- if (index === currentProgressStep) {
- addClass(stepEl, swalClasses['active-progress-step']);
- }
- if (index !== params.progressSteps.length - 1) {
- var lineEl = createLineElement(step);
- progressStepsContainer.appendChild(lineEl);
- }
- });
- };
- var renderTitle = function renderTitle(instance, params) {
- var title = getTitle();
- toggle(title, params.title || params.titleText);
- if (params.title) {
- parseHtmlToContainer(params.title, title);
- }
- if (params.titleText) {
- title.innerText = params.titleText;
- } // Custom class
- applyCustomClass(title, params.customClass, 'title');
- };
- var renderHeader = function renderHeader(instance, params) {
- var header = getHeader(); // Custom class
- applyCustomClass(header, params.customClass, 'header'); // Progress steps
- renderProgressSteps(instance, params); // Icon
- renderIcon(instance, params); // Image
- renderImage(instance, params); // Title
- renderTitle(instance, params); // Close button
- renderCloseButton(instance, params);
- };
- var renderPopup = function renderPopup(instance, params) {
- var popup = getPopup(); // Width
- applyNumericalStyle(popup, 'width', params.width); // Padding
- applyNumericalStyle(popup, 'padding', params.padding); // Background
- if (params.background) {
- popup.style.background = params.background;
- } // Default Class
- popup.className = swalClasses.popup;
- if (params.toast) {
- addClass([document.documentElement, document.body], swalClasses['toast-shown']);
- addClass(popup, swalClasses.toast);
- } else {
- addClass(popup, swalClasses.modal);
- } // Custom class
- applyCustomClass(popup, params.customClass, 'popup');
- if (typeof params.customClass === 'string') {
- addClass(popup, params.customClass);
- } // CSS animation
- toggleClass(popup, swalClasses.noanimation, !params.animation);
- };
- var render = function render(instance, params) {
- renderPopup(instance, params);
- renderContainer(instance, params);
- renderHeader(instance, params);
- renderContent(instance, params);
- renderActions(instance, params);
- renderFooter(instance, params);
- };
- /*
- * Global function to determine if SweetAlert2 popup is shown
- */
- var isVisible$1 = function isVisible$$1() {
- return isVisible(getPopup());
- };
- /*
- * Global function to click 'Confirm' button
- */
- var clickConfirm = function clickConfirm() {
- return getConfirmButton() && getConfirmButton().click();
- };
- /*
- * Global function to click 'Cancel' button
- */
- var clickCancel = function clickCancel() {
- return getCancelButton() && getCancelButton().click();
- };
- function fire() {
- var Swal = this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- return _construct(Swal, args);
- }
- /**
- * Returns an extended version of `Swal` containing `params` as defaults.
- * Useful for reusing Swal configuration.
- *
- * For example:
- *
- * Before:
- * const textPromptOptions = { input: 'text', showCancelButton: true }
- * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
- * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
- *
- * After:
- * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
- * const {value: firstName} = await TextPrompt('What is your first name?')
- * const {value: lastName} = await TextPrompt('What is your last name?')
- *
- * @param mixinParams
- */
- function mixin(mixinParams) {
- var MixinSwal =
- /*#__PURE__*/
- function (_this) {
- _inherits(MixinSwal, _this);
- function MixinSwal() {
- _classCallCheck(this, MixinSwal);
- return _possibleConstructorReturn(this, _getPrototypeOf(MixinSwal).apply(this, arguments));
- }
- _createClass(MixinSwal, [{
- key: "_main",
- value: function _main(params) {
- return _get(_getPrototypeOf(MixinSwal.prototype), "_main", this).call(this, _extends({}, mixinParams, params));
- }
- }]);
- return MixinSwal;
- }(this);
- return MixinSwal;
- }
- // private global state for the queue feature
- var currentSteps = [];
- /*
- * Global function for chaining sweetAlert popups
- */
- var queue = function queue(steps) {
- var Swal = this;
- currentSteps = steps;
- var resetAndResolve = function resetAndResolve(resolve, value) {
- currentSteps = [];
- document.body.removeAttribute('data-swal2-queue-step');
- resolve(value);
- };
- var queueResult = [];
- return new Promise(function (resolve) {
- (function step(i, callback) {
- if (i < currentSteps.length) {
- document.body.setAttribute('data-swal2-queue-step', i);
- Swal.fire(currentSteps[i]).then(function (result) {
- if (typeof result.value !== 'undefined') {
- queueResult.push(result.value);
- step(i + 1, callback);
- } else {
- resetAndResolve(resolve, {
- dismiss: result.dismiss
- });
- }
- });
- } else {
- resetAndResolve(resolve, {
- value: queueResult
- });
- }
- })(0);
- });
- };
- /*
- * Global function for getting the index of current popup in queue
- */
- var getQueueStep = function getQueueStep() {
- return document.body.getAttribute('data-swal2-queue-step');
- };
- /*
- * Global function for inserting a popup to the queue
- */
- var insertQueueStep = function insertQueueStep(step, index) {
- if (index && index < currentSteps.length) {
- return currentSteps.splice(index, 0, step);
- }
- return currentSteps.push(step);
- };
- /*
- * Global function for deleting a popup from the queue
- */
- var deleteQueueStep = function deleteQueueStep(index) {
- if (typeof currentSteps[index] !== 'undefined') {
- currentSteps.splice(index, 1);
- }
- };
- /**
- * Show spinner instead of Confirm button and disable Cancel button
- */
- var showLoading = function showLoading() {
- var popup = getPopup();
- if (!popup) {
- Swal.fire('');
- }
- popup = getPopup();
- var actions = getActions();
- var confirmButton = getConfirmButton();
- var cancelButton = getCancelButton();
- show(actions);
- show(confirmButton);
- addClass([popup, actions], swalClasses.loading);
- confirmButton.disabled = true;
- cancelButton.disabled = true;
- popup.setAttribute('data-loading', true);
- popup.setAttribute('aria-busy', true);
- popup.focus();
- };
- var RESTORE_FOCUS_TIMEOUT = 100;
- var globalState = {};
- var focusPreviousActiveElement = function focusPreviousActiveElement() {
- if (globalState.previousActiveElement && globalState.previousActiveElement.focus) {
- globalState.previousActiveElement.focus();
- globalState.previousActiveElement = null;
- } else if (document.body) {
- document.body.focus();
- }
- }; // Restore previous active (focused) element
- var restoreActiveElement = function restoreActiveElement() {
- return new Promise(function (resolve) {
- var x = window.scrollX;
- var y = window.scrollY;
- globalState.restoreFocusTimeout = setTimeout(function () {
- focusPreviousActiveElement();
- resolve();
- }, RESTORE_FOCUS_TIMEOUT); // issues/900
- if (typeof x !== 'undefined' && typeof y !== 'undefined') {
- // IE doesn't have scrollX/scrollY support
- window.scrollTo(x, y);
- }
- });
- };
- /**
- * If `timer` parameter is set, returns number of milliseconds of timer remained.
- * Otherwise, returns undefined.
- */
- var getTimerLeft = function getTimerLeft() {
- return globalState.timeout && globalState.timeout.getTimerLeft();
- };
- /**
- * Stop timer. Returns number of milliseconds of timer remained.
- * If `timer` parameter isn't set, returns undefined.
- */
- var stopTimer = function stopTimer() {
- return globalState.timeout && globalState.timeout.stop();
- };
- /**
- * Resume timer. Returns number of milliseconds of timer remained.
- * If `timer` parameter isn't set, returns undefined.
- */
- var resumeTimer = function resumeTimer() {
- return globalState.timeout && globalState.timeout.start();
- };
- /**
- * Resume timer. Returns number of milliseconds of timer remained.
- * If `timer` parameter isn't set, returns undefined.
- */
- var toggleTimer = function toggleTimer() {
- var timer = globalState.timeout;
- return timer && (timer.running ? timer.stop() : timer.start());
- };
- /**
- * Increase timer. Returns number of milliseconds of an updated timer.
- * If `timer` parameter isn't set, returns undefined.
- */
- var increaseTimer = function increaseTimer(n) {
- return globalState.timeout && globalState.timeout.increase(n);
- };
- /**
- * Check if timer is running. Returns true if timer is running
- * or false if timer is paused or stopped.
- * If `timer` parameter isn't set, returns undefined
- */
- var isTimerRunning = function isTimerRunning() {
- return globalState.timeout && globalState.timeout.isRunning();
- };
- var defaultParams = {
- title: '',
- titleText: '',
- text: '',
- html: '',
- footer: '',
- type: null,
- toast: false,
- customClass: '',
- customContainerClass: '',
- target: 'body',
- backdrop: true,
- animation: true,
- heightAuto: true,
- allowOutsideClick: true,
- allowEscapeKey: true,
- allowEnterKey: true,
- stopKeydownPropagation: true,
- keydownListenerCapture: false,
- showConfirmButton: true,
- showCancelButton: false,
- preConfirm: null,
- confirmButtonText: 'OK',
- confirmButtonAriaLabel: '',
- confirmButtonColor: null,
- confirmButtonClass: '',
- cancelButtonText: 'Cancel',
- cancelButtonAriaLabel: '',
- cancelButtonColor: null,
- cancelButtonClass: '',
- buttonsStyling: true,
- reverseButtons: false,
- focusConfirm: true,
- focusCancel: false,
- showCloseButton: false,
- closeButtonAriaLabel: 'Close this dialog',
- showLoaderOnConfirm: false,
- imageUrl: null,
- imageWidth: null,
- imageHeight: null,
- imageAlt: '',
- imageClass: '',
- timer: null,
- width: null,
- padding: null,
- background: null,
- input: null,
- inputPlaceholder: '',
- inputValue: '',
- inputOptions: {},
- inputAutoTrim: true,
- inputClass: '',
- inputAttributes: {},
- inputValidator: null,
- validationMessage: null,
- grow: false,
- position: 'center',
- progressSteps: [],
- currentProgressStep: null,
- progressStepsDistance: null,
- onBeforeOpen: null,
- onAfterClose: null,
- onOpen: null,
- onClose: null,
- scrollbarPadding: true
- };
- var updatableParams = ['title', 'titleText', 'text', 'html', 'type', 'customClass', 'showConfirmButton', 'showCancelButton', 'confirmButtonText', 'confirmButtonAriaLabel', 'confirmButtonColor', 'confirmButtonClass', 'cancelButtonText', 'cancelButtonAriaLabel', 'cancelButtonColor', 'cancelButtonClass', 'buttonsStyling', 'reverseButtons', 'imageUrl', 'imageWidth', 'imageHeigth', 'imageAlt', 'imageClass', 'progressSteps', 'currentProgressStep'];
- var deprecatedParams = {
- customContainerClass: 'customClass',
- confirmButtonClass: 'customClass',
- cancelButtonClass: 'customClass',
- imageClass: 'customClass',
- inputClass: 'customClass'
- };
- var toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusCancel', 'heightAuto', 'keydownListenerCapture'];
- /**
- * Is valid parameter
- * @param {String} paramName
- */
- var isValidParameter = function isValidParameter(paramName) {
- return defaultParams.hasOwnProperty(paramName);
- };
- /**
- * Is valid parameter for Swal.update() method
- * @param {String} paramName
- */
- var isUpdatableParameter = function isUpdatableParameter(paramName) {
- return updatableParams.indexOf(paramName) !== -1;
- };
- /**
- * Is deprecated parameter
- * @param {String} paramName
- */
- var isDeprecatedParameter = function isDeprecatedParameter(paramName) {
- return deprecatedParams[paramName];
- };
- var checkIfParamIsValid = function checkIfParamIsValid(param) {
- if (!isValidParameter(param)) {
- warn("Unknown parameter \"".concat(param, "\""));
- }
- };
- var checkIfToastParamIsValid = function checkIfToastParamIsValid(param) {
- if (toastIncompatibleParams.indexOf(param) !== -1) {
- warn("The parameter \"".concat(param, "\" is incompatible with toasts"));
- }
- };
- var checkIfParamIsDeprecated = function checkIfParamIsDeprecated(param) {
- if (isDeprecatedParameter(param)) {
- warnAboutDepreation(param, isDeprecatedParameter(param));
- }
- };
- /**
- * Show relevant warnings for given params
- *
- * @param params
- */
- var showWarningsForParams = function showWarningsForParams(params) {
- for (var param in params) {
- checkIfParamIsValid(param);
- if (params.toast) {
- checkIfToastParamIsValid(param);
- }
- checkIfParamIsDeprecated();
- }
- };
- var staticMethods = Object.freeze({
- isValidParameter: isValidParameter,
- isUpdatableParameter: isUpdatableParameter,
- isDeprecatedParameter: isDeprecatedParameter,
- argsToParams: argsToParams,
- isVisible: isVisible$1,
- clickConfirm: clickConfirm,
- clickCancel: clickCancel,
- getContainer: getContainer,
- getPopup: getPopup,
- getTitle: getTitle,
- getContent: getContent,
- getImage: getImage,
- getIcon: getIcon,
- getIcons: getIcons,
- getCloseButton: getCloseButton,
- getActions: getActions,
- getConfirmButton: getConfirmButton,
- getCancelButton: getCancelButton,
- getHeader: getHeader,
- getFooter: getFooter,
- getFocusableElements: getFocusableElements,
- getValidationMessage: getValidationMessage,
- isLoading: isLoading,
- fire: fire,
- mixin: mixin,
- queue: queue,
- getQueueStep: getQueueStep,
- insertQueueStep: insertQueueStep,
- deleteQueueStep: deleteQueueStep,
- showLoading: showLoading,
- enableLoading: showLoading,
- getTimerLeft: getTimerLeft,
- stopTimer: stopTimer,
- resumeTimer: resumeTimer,
- toggleTimer: toggleTimer,
- increaseTimer: increaseTimer,
- isTimerRunning: isTimerRunning
- });
- /**
- * Enables buttons and hide loader.
- */
- function hideLoading() {
- var innerParams = privateProps.innerParams.get(this);
- var domCache = privateProps.domCache.get(this);
- if (!innerParams.showConfirmButton) {
- hide(domCache.confirmButton);
- if (!innerParams.showCancelButton) {
- hide(domCache.actions);
- }
- }
- removeClass([domCache.popup, domCache.actions], swalClasses.loading);
- domCache.popup.removeAttribute('aria-busy');
- domCache.popup.removeAttribute('data-loading');
- domCache.confirmButton.disabled = false;
- domCache.cancelButton.disabled = false;
- }
- function getInput$1(instance) {
- var innerParams = privateProps.innerParams.get(instance || this);
- var domCache = privateProps.domCache.get(instance || this);
- return getInput(domCache.content, innerParams.input);
- }
- var fixScrollbar = function fixScrollbar() {
- // for queues, do not do this more than once
- if (states.previousBodyPadding !== null) {
- return;
- } // if the body has overflow
- if (document.body.scrollHeight > window.innerHeight) {
- // add padding so the content doesn't shift after removal of scrollbar
- states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'));
- document.body.style.paddingRight = states.previousBodyPadding + measureScrollbar() + 'px';
- }
- };
- var undoScrollbar = function undoScrollbar() {
- if (states.previousBodyPadding !== null) {
- document.body.style.paddingRight = states.previousBodyPadding + 'px';
- states.previousBodyPadding = null;
- }
- };
- /* istanbul ignore next */
- var iOSfix = function iOSfix() {
- var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
- if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
- var offset = document.body.scrollTop;
- document.body.style.top = offset * -1 + 'px';
- addClass(document.body, swalClasses.iosfix);
- lockBodyScroll();
- }
- };
- var lockBodyScroll = function lockBodyScroll() {
- // #1246
- var container = getContainer();
- var preventTouchMove;
- container.ontouchstart = function (e) {
- preventTouchMove = e.target === container || !isScrollable(container) && e.target.tagName !== 'INPUT' // #1603
- ;
- };
- container.ontouchmove = function (e) {
- if (preventTouchMove) {
- e.preventDefault();
- e.stopPropagation();
- }
- };
- };
- /* istanbul ignore next */
- var undoIOSfix = function undoIOSfix() {
- if (hasClass(document.body, swalClasses.iosfix)) {
- var offset = parseInt(document.body.style.top, 10);
- removeClass(document.body, swalClasses.iosfix);
- document.body.style.top = '';
- document.body.scrollTop = offset * -1;
- }
- };
- var isIE11 = function isIE11() {
- return !!window.MSInputMethodContext && !!document.documentMode;
- }; // Fix IE11 centering sweetalert2/issues/933
- /* istanbul ignore next */
- var fixVerticalPositionIE = function fixVerticalPositionIE() {
- var container = getContainer();
- var popup = getPopup();
- container.style.removeProperty('align-items');
- if (popup.offsetTop < 0) {
- container.style.alignItems = 'flex-start';
- }
- };
- /* istanbul ignore next */
- var IEfix = function IEfix() {
- if (typeof window !== 'undefined' && isIE11()) {
- fixVerticalPositionIE();
- window.addEventListener('resize', fixVerticalPositionIE);
- }
- };
- /* istanbul ignore next */
- var undoIEfix = function undoIEfix() {
- if (typeof window !== 'undefined' && isIE11()) {
- window.removeEventListener('resize', fixVerticalPositionIE);
- }
- };
- // Adding aria-hidden="true" to elements outside of the active modal dialog ensures that
- // elements not within the active modal dialog will not be surfaced if a user opens a screen
- // reader’s list of elements (headings, form controls, landmarks, etc.) in the document.
- var setAriaHidden = function setAriaHidden() {
- var bodyChildren = toArray(document.body.children);
- bodyChildren.forEach(function (el) {
- if (el === getContainer() || contains(el, getContainer())) {
- return;
- }
- if (el.hasAttribute('aria-hidden')) {
- el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden'));
- }
- el.setAttribute('aria-hidden', 'true');
- });
- };
- var unsetAriaHidden = function unsetAriaHidden() {
- var bodyChildren = toArray(document.body.children);
- bodyChildren.forEach(function (el) {
- if (el.hasAttribute('data-previous-aria-hidden')) {
- el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden'));
- el.removeAttribute('data-previous-aria-hidden');
- } else {
- el.removeAttribute('aria-hidden');
- }
- });
- };
- /**
- * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has.
- * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
- * This is the approach that Babel will probably take to implement private methods/fields
- * https://github.com/tc39/proposal-private-methods
- * https://github.com/babel/babel/pull/7555
- * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
- * then we can use that language feature.
- */
- var privateMethods = {
- swalPromiseResolve: new WeakMap()
- };
- /*
- * Instance method to close sweetAlert
- */
- function removePopupAndResetState(container, isToast, onAfterClose) {
- if (isToast) {
- triggerOnAfterClose(onAfterClose);
- } else {
- restoreActiveElement().then(function () {
- return triggerOnAfterClose(onAfterClose);
- });
- globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
- capture: globalState.keydownListenerCapture
- });
- globalState.keydownHandlerAdded = false;
- } // Unset globalState props so GC will dispose globalState (#1569)
- delete globalState.keydownHandler;
- delete globalState.keydownTarget;
- if (container.parentNode) {
- container.parentNode.removeChild(container);
- }
- removeBodyClasses();
- if (isModal()) {
- undoScrollbar();
- undoIOSfix();
- undoIEfix();
- unsetAriaHidden();
- }
- }
- function removeBodyClasses() {
- removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['toast-column']]);
- }
- function swalCloseEventFinished(popup, container, isToast, onAfterClose) {
- if (hasClass(popup, swalClasses.hide)) {
- removePopupAndResetState(container, isToast, onAfterClose);
- } // Unset WeakMaps so GC will be able to dispose them (#1569)
- unsetWeakMaps(privateProps);
- unsetWeakMaps(privateMethods);
- }
- function close(resolveValue) {
- var container = getContainer();
- var popup = getPopup();
- if (!popup || hasClass(popup, swalClasses.hide)) {
- return;
- }
- var innerParams = privateProps.innerParams.get(this);
- var swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
- var onClose = innerParams.onClose;
- var onAfterClose = innerParams.onAfterClose;
- removeClass(popup, swalClasses.show);
- addClass(popup, swalClasses.hide); // If animation is supported, animate
- if (animationEndEvent && hasCssAnimation(popup)) {
- popup.addEventListener(animationEndEvent, function (e) {
- if (e.target === popup) {
- swalCloseEventFinished(popup, container, isToast(), onAfterClose);
- }
- });
- } else {
- // Otherwise, remove immediately
- removePopupAndResetState(container, isToast(), onAfterClose);
- }
- if (onClose !== null && typeof onClose === 'function') {
- onClose(popup);
- } // Resolve Swal promise
- swalPromiseResolve(resolveValue || {}); // Unset this.params so GC will dispose it (#1569)
- delete this.params;
- }
- var unsetWeakMaps = function unsetWeakMaps(obj) {
- for (var i in obj) {
- obj[i] = new WeakMap();
- }
- };
- var triggerOnAfterClose = function triggerOnAfterClose(onAfterClose) {
- if (onAfterClose !== null && typeof onAfterClose === 'function') {
- setTimeout(function () {
- onAfterClose();
- });
- }
- };
- function setButtonsDisabled(instance, buttons, disabled) {
- var domCache = privateProps.domCache.get(instance);
- buttons.forEach(function (button) {
- domCache[button].disabled = disabled;
- });
- }
- function setInputDisabled(input, disabled) {
- if (!input) {
- return false;
- }
- if (input.type === 'radio') {
- var radiosContainer = input.parentNode.parentNode;
- var radios = radiosContainer.querySelectorAll('input');
- for (var i = 0; i < radios.length; i++) {
- radios[i].disabled = disabled;
- }
- } else {
- input.disabled = disabled;
- }
- }
- function enableButtons() {
- setButtonsDisabled(this, ['confirmButton', 'cancelButton'], false);
- }
- function disableButtons() {
- setButtonsDisabled(this, ['confirmButton', 'cancelButton'], true);
- } // @deprecated
- function enableConfirmButton() {
- warnAboutDepreation('Swal.disableConfirmButton()', "Swal.getConfirmButton().removeAttribute('disabled')");
- setButtonsDisabled(this, ['confirmButton'], false);
- } // @deprecated
- function disableConfirmButton() {
- warnAboutDepreation('Swal.enableConfirmButton()', "Swal.getConfirmButton().setAttribute('disabled', '')");
- setButtonsDisabled(this, ['confirmButton'], true);
- }
- function enableInput() {
- return setInputDisabled(this.getInput(), false);
- }
- function disableInput() {
- return setInputDisabled(this.getInput(), true);
- }
- function showValidationMessage(error) {
- var domCache = privateProps.domCache.get(this);
- domCache.validationMessage.innerHTML = error;
- var popupComputedStyle = window.getComputedStyle(domCache.popup);
- domCache.validationMessage.style.marginLeft = "-".concat(popupComputedStyle.getPropertyValue('padding-left'));
- domCache.validationMessage.style.marginRight = "-".concat(popupComputedStyle.getPropertyValue('padding-right'));
- show(domCache.validationMessage);
- var input = this.getInput();
- if (input) {
- input.setAttribute('aria-invalid', true);
- input.setAttribute('aria-describedBy', swalClasses['validation-message']);
- focusInput(input);
- addClass(input, swalClasses.inputerror);
- }
- } // Hide block with validation message
- function resetValidationMessage$1() {
- var domCache = privateProps.domCache.get(this);
- if (domCache.validationMessage) {
- hide(domCache.validationMessage);
- }
- var input = this.getInput();
- if (input) {
- input.removeAttribute('aria-invalid');
- input.removeAttribute('aria-describedBy');
- removeClass(input, swalClasses.inputerror);
- }
- }
- function getProgressSteps$1() {
- warnAboutDepreation('Swal.getProgressSteps()', "const swalInstance = Swal.fire({progressSteps: ['1', '2', '3']}); const progressSteps = swalInstance.params.progressSteps");
- var innerParams = privateProps.innerParams.get(this);
- return innerParams.progressSteps;
- }
- function setProgressSteps(progressSteps) {
- warnAboutDepreation('Swal.setProgressSteps()', 'Swal.update()');
- var innerParams = privateProps.innerParams.get(this);
- var updatedParams = _extends({}, innerParams, {
- progressSteps: progressSteps
- });
- renderProgressSteps(this, updatedParams);
- privateProps.innerParams.set(this, updatedParams);
- }
- function showProgressSteps() {
- var domCache = privateProps.domCache.get(this);
- show(domCache.progressSteps);
- }
- function hideProgressSteps() {
- var domCache = privateProps.domCache.get(this);
- hide(domCache.progressSteps);
- }
- var Timer =
- /*#__PURE__*/
- function () {
- function Timer(callback, delay) {
- _classCallCheck(this, Timer);
- this.callback = callback;
- this.remaining = delay;
- this.running = false;
- this.start();
- }
- _createClass(Timer, [{
- key: "start",
- value: function start() {
- if (!this.running) {
- this.running = true;
- this.started = new Date();
- this.id = setTimeout(this.callback, this.remaining);
- }
- return this.remaining;
- }
- }, {
- key: "stop",
- value: function stop() {
- if (this.running) {
- this.running = false;
- clearTimeout(this.id);
- this.remaining -= new Date() - this.started;
- }
- return this.remaining;
- }
- }, {
- key: "increase",
- value: function increase(n) {
- var running = this.running;
- if (running) {
- this.stop();
- }
- this.remaining += n;
- if (running) {
- this.start();
- }
- return this.remaining;
- }
- }, {
- key: "getTimerLeft",
- value: function getTimerLeft() {
- if (this.running) {
- this.stop();
- this.start();
- }
- return this.remaining;
- }
- }, {
- key: "isRunning",
- value: function isRunning() {
- return this.running;
- }
- }]);
- return Timer;
- }();
- var defaultInputValidators = {
- email: function email(string, validationMessage) {
- return /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,24}$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage ? validationMessage : 'Invalid email address');
- },
- url: function url(string, validationMessage) {
- // taken from https://stackoverflow.com/a/3809435 with a small change from #1306
- return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage ? validationMessage : 'Invalid URL');
- }
- };
- /**
- * Set type, text and actions on popup
- *
- * @param params
- * @returns {boolean}
- */
- function setParameters(params) {
- // Use default `inputValidator` for supported input types if not provided
- if (!params.inputValidator) {
- Object.keys(defaultInputValidators).forEach(function (key) {
- if (params.input === key) {
- params.inputValidator = defaultInputValidators[key];
- }
- });
- } // showLoaderOnConfirm && preConfirm
- if (params.showLoaderOnConfirm && !params.preConfirm) {
- warn('showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://sweetalert2.github.io/#ajax-request');
- } // params.animation will be actually used in renderPopup.js
- // but in case when params.animation is a function, we need to call that function
- // before popup (re)initialization, so it'll be possible to check Swal.isVisible()
- // inside the params.animation function
- params.animation = callIfFunction(params.animation); // Determine if the custom target element is valid
- if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) {
- warn('Target parameter is not valid, defaulting to "body"');
- params.target = 'body';
- } // Replace newlines with <br> in title
- if (typeof params.title === 'string') {
- params.title = params.title.split('\n').join('<br />');
- }
- var oldPopup = getPopup();
- var targetElement = typeof params.target === 'string' ? document.querySelector(params.target) : params.target;
- if (!oldPopup || // If the model target has changed, refresh the popup
- oldPopup && targetElement && oldPopup.parentNode !== targetElement.parentNode) {
- init(params);
- }
- }
- function swalOpenAnimationFinished(popup, container) {
- popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished);
- container.style.overflowY = 'auto';
- }
- /**
- * Open popup, add necessary classes and styles, fix scrollbar
- *
- * @param {Array} params
- */
- var openPopup = function openPopup(params) {
- var container = getContainer();
- var popup = getPopup();
- if (params.onBeforeOpen !== null && typeof params.onBeforeOpen === 'function') {
- params.onBeforeOpen(popup);
- }
- if (params.animation) {
- addClass(popup, swalClasses.show);
- addClass(container, swalClasses.fade);
- }
- show(popup); // scrolling is 'hidden' until animation is done, after that 'auto'
- if (animationEndEvent && hasCssAnimation(popup)) {
- container.style.overflowY = 'hidden';
- popup.addEventListener(animationEndEvent, swalOpenAnimationFinished.bind(null, popup, container));
- } else {
- container.style.overflowY = 'auto';
- }
- addClass([document.documentElement, document.body, container], swalClasses.shown);
- if (params.heightAuto && params.backdrop && !params.toast) {
- addClass([document.documentElement, document.body], swalClasses['height-auto']);
- }
- if (isModal()) {
- if (params.scrollbarPadding) {
- fixScrollbar();
- }
- iOSfix();
- IEfix();
- setAriaHidden(); // sweetalert2/issues/1247
- setTimeout(function () {
- container.scrollTop = 0;
- });
- }
- if (!isToast() && !globalState.previousActiveElement) {
- globalState.previousActiveElement = document.activeElement;
- }
- if (params.onOpen !== null && typeof params.onOpen === 'function') {
- setTimeout(function () {
- params.onOpen(popup);
- });
- }
- };
- var _this = undefined;
- var handleInputOptions = function handleInputOptions(instance, params) {
- var content = getContent();
- var processInputOptions = function processInputOptions(inputOptions) {
- return populateInputOptions[params.input](content, formatInputOptions(inputOptions), params);
- };
- if (isPromise(params.inputOptions)) {
- showLoading();
- params.inputOptions.then(function (inputOptions) {
- instance.hideLoading();
- processInputOptions(inputOptions);
- });
- } else if (_typeof(params.inputOptions) === 'object') {
- processInputOptions(params.inputOptions);
- } else {
- error("Unexpected type of inputOptions! Expected object, Map or Promise, got ".concat(_typeof(params.inputOptions)));
- }
- };
- var handleInputValue = function handleInputValue(instance, params) {
- var input = instance.getInput();
- hide(input);
- params.inputValue.then(function (inputValue) {
- input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : inputValue + '';
- show(input);
- input.focus();
- instance.hideLoading();
- })["catch"](function (err) {
- error('Error in inputValue promise: ' + err);
- input.value = '';
- show(input);
- input.focus();
- _this.hideLoading();
- });
- };
- var populateInputOptions = {
- select: function select(content, inputOptions, params) {
- var select = getChildByClass(content, swalClasses.select);
- inputOptions.forEach(function (inputOption) {
- var optionValue = inputOption[0];
- var optionLabel = inputOption[1];
- var option = document.createElement('option');
- option.value = optionValue;
- option.innerHTML = optionLabel;
- if (params.inputValue.toString() === optionValue.toString()) {
- option.selected = true;
- }
- select.appendChild(option);
- });
- select.focus();
- },
- radio: function radio(content, inputOptions, params) {
- var radio = getChildByClass(content, swalClasses.radio);
- inputOptions.forEach(function (inputOption) {
- var radioValue = inputOption[0];
- var radioLabel = inputOption[1];
- var radioInput = document.createElement('input');
- var radioLabelElement = document.createElement('label');
- radioInput.type = 'radio';
- radioInput.name = swalClasses.radio;
- radioInput.value = radioValue;
- if (params.inputValue.toString() === radioValue.toString()) {
- radioInput.checked = true;
- }
- var label = document.createElement('span');
- label.innerHTML = radioLabel;
- label.className = swalClasses.label;
- radioLabelElement.appendChild(radioInput);
- radioLabelElement.appendChild(label);
- radio.appendChild(radioLabelElement);
- });
- var radios = radio.querySelectorAll('input');
- if (radios.length) {
- radios[0].focus();
- }
- }
- /**
- * Converts `inputOptions` into an array of `[value, label]`s
- * @param inputOptions
- */
- };
- var formatInputOptions = function formatInputOptions(inputOptions) {
- var result = [];
- if (typeof Map !== 'undefined' && inputOptions instanceof Map) {
- inputOptions.forEach(function (value, key) {
- result.push([key, value]);
- });
- } else {
- Object.keys(inputOptions).forEach(function (key) {
- result.push([key, inputOptions[key]]);
- });
- }
- return result;
- };
- function _main(userParams) {
- var _this = this;
- showWarningsForParams(userParams);
- var innerParams = _extends({}, defaultParams, userParams);
- setParameters(innerParams);
- Object.freeze(innerParams); // clear the previous timer
- if (globalState.timeout) {
- globalState.timeout.stop();
- delete globalState.timeout;
- } // clear the restore focus timeout
- clearTimeout(globalState.restoreFocusTimeout);
- var domCache = {
- popup: getPopup(),
- container: getContainer(),
- content: getContent(),
- actions: getActions(),
- confirmButton: getConfirmButton(),
- cancelButton: getCancelButton(),
- closeButton: getCloseButton(),
- validationMessage: getValidationMessage(),
- progressSteps: getProgressSteps()
- };
- privateProps.domCache.set(this, domCache);
- render(this, innerParams);
- privateProps.innerParams.set(this, innerParams);
- var constructor = this.constructor;
- return new Promise(function (resolve) {
- // functions to handle all closings/dismissals
- var succeedWith = function succeedWith(value) {
- _this.closePopup({
- value: value
- });
- };
- var dismissWith = function dismissWith(dismiss) {
- _this.closePopup({
- dismiss: dismiss
- });
- };
- privateMethods.swalPromiseResolve.set(_this, resolve); // Close on timer
- if (innerParams.timer) {
- globalState.timeout = new Timer(function () {
- dismissWith('timer');
- delete globalState.timeout;
- }, innerParams.timer);
- } // Get the value of the popup input
- var getInputValue = function getInputValue() {
- var input = _this.getInput();
- if (!input) {
- return null;
- }
- switch (innerParams.input) {
- case 'checkbox':
- return input.checked ? 1 : 0;
- case 'radio':
- return input.checked ? input.value : null;
- case 'file':
- return input.files.length ? input.files[0] : null;
- default:
- return innerParams.inputAutoTrim ? input.value.trim() : input.value;
- }
- }; // input autofocus
- if (innerParams.input) {
- setTimeout(function () {
- var input = _this.getInput();
- if (input) {
- focusInput(input);
- }
- }, 0);
- }
- var confirm = function confirm(value) {
- if (innerParams.showLoaderOnConfirm) {
- constructor.showLoading(); // TODO: make showLoading an *instance* method
- }
- if (innerParams.preConfirm) {
- _this.resetValidationMessage();
- var preConfirmPromise = Promise.resolve().then(function () {
- return innerParams.preConfirm(value, innerParams.validationMessage);
- });
- preConfirmPromise.then(function (preConfirmValue) {
- if (isVisible(domCache.validationMessage) || preConfirmValue === false) {
- _this.hideLoading();
- } else {
- succeedWith(typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
- }
- });
- } else {
- succeedWith(value);
- }
- }; // Mouse interactions
- var onButtonEvent = function onButtonEvent(e) {
- var target = e.target;
- var confirmButton = domCache.confirmButton,
- cancelButton = domCache.cancelButton;
- var targetedConfirm = confirmButton && (confirmButton === target || confirmButton.contains(target));
- var targetedCancel = cancelButton && (cancelButton === target || cancelButton.contains(target));
- switch (e.type) {
- case 'click':
- // Clicked 'confirm'
- if (targetedConfirm) {
- _this.disableButtons();
- if (innerParams.input) {
- var inputValue = getInputValue();
- if (innerParams.inputValidator) {
- _this.disableInput();
- var validationPromise = Promise.resolve().then(function () {
- return innerParams.inputValidator(inputValue, innerParams.validationMessage);
- });
- validationPromise.then(function (validationMessage) {
- _this.enableButtons();
- _this.enableInput();
- if (validationMessage) {
- _this.showValidationMessage(validationMessage);
- } else {
- confirm(inputValue);
- }
- });
- } else if (!_this.getInput().checkValidity()) {
- _this.enableButtons();
- _this.showValidationMessage(innerParams.validationMessage);
- } else {
- confirm(inputValue);
- }
- } else {
- confirm(true);
- } // Clicked 'cancel'
- } else if (targetedCancel) {
- _this.disableButtons();
- dismissWith(constructor.DismissReason.cancel);
- }
- break;
- default:
- }
- };
- var buttons = domCache.popup.querySelectorAll('button');
- for (var i = 0; i < buttons.length; i++) {
- buttons[i].onclick = onButtonEvent;
- buttons[i].onmouseover = onButtonEvent;
- buttons[i].onmouseout = onButtonEvent;
- buttons[i].onmousedown = onButtonEvent;
- } // Closing popup by close button
- domCache.closeButton.onclick = function () {
- dismissWith(constructor.DismissReason.close);
- };
- if (innerParams.toast) {
- // Closing popup by internal click
- domCache.popup.onclick = function () {
- if (innerParams.showConfirmButton || innerParams.showCancelButton || innerParams.showCloseButton || innerParams.input) {
- return;
- }
- dismissWith(constructor.DismissReason.close);
- };
- } else {
- var ignoreOutsideClick = false; // Ignore click events that had mousedown on the popup but mouseup on the container
- // This can happen when the user drags a slider
- domCache.popup.onmousedown = function () {
- domCache.container.onmouseup = function (e) {
- domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't
- // have any other direct children aside of the popup
- if (e.target === domCache.container) {
- ignoreOutsideClick = true;
- }
- };
- }; // Ignore click events that had mousedown on the container but mouseup on the popup
- domCache.container.onmousedown = function () {
- domCache.popup.onmouseup = function (e) {
- domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup
- if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
- ignoreOutsideClick = true;
- }
- };
- };
- domCache.container.onclick = function (e) {
- if (ignoreOutsideClick) {
- ignoreOutsideClick = false;
- return;
- }
- if (e.target !== domCache.container) {
- return;
- }
- if (callIfFunction(innerParams.allowOutsideClick)) {
- dismissWith(constructor.DismissReason.backdrop);
- }
- };
- } // Reverse buttons (Confirm on the right side)
- if (innerParams.reverseButtons) {
- domCache.confirmButton.parentNode.insertBefore(domCache.cancelButton, domCache.confirmButton);
- } else {
- domCache.confirmButton.parentNode.insertBefore(domCache.confirmButton, domCache.cancelButton);
- } // Focus handling
- var setFocus = function setFocus(index, increment) {
- var focusableElements = getFocusableElements(innerParams.focusCancel); // search for visible elements and select the next possible match
- for (var _i = 0; _i < focusableElements.length; _i++) {
- index = index + increment; // rollover to first item
- if (index === focusableElements.length) {
- index = 0; // go to last item
- } else if (index === -1) {
- index = focusableElements.length - 1;
- }
- return focusableElements[index].focus();
- } // no visible focusable elements, focus the popup
- domCache.popup.focus();
- };
- var keydownHandler = function keydownHandler(e, innerParams) {
- if (innerParams.stopKeydownPropagation) {
- e.stopPropagation();
- }
- var arrowKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Left', 'Right', 'Up', 'Down' // IE11
- ];
- if (e.key === 'Enter' && !e.isComposing) {
- if (e.target && _this.getInput() && e.target.outerHTML === _this.getInput().outerHTML) {
- if (['textarea', 'file'].indexOf(innerParams.input) !== -1) {
- return; // do not submit
- }
- constructor.clickConfirm();
- e.preventDefault();
- } // TAB
- } else if (e.key === 'Tab') {
- var targetElement = e.target;
- var focusableElements = getFocusableElements(innerParams.focusCancel);
- var btnIndex = -1;
- for (var _i2 = 0; _i2 < focusableElements.length; _i2++) {
- if (targetElement === focusableElements[_i2]) {
- btnIndex = _i2;
- break;
- }
- }
- if (!e.shiftKey) {
- // Cycle to the next button
- setFocus(btnIndex, 1);
- } else {
- // Cycle to the prev button
- setFocus(btnIndex, -1);
- }
- e.stopPropagation();
- e.preventDefault(); // ARROWS - switch focus between buttons
- } else if (arrowKeys.indexOf(e.key) !== -1) {
- // focus Cancel button if Confirm button is currently focused
- if (document.activeElement === domCache.confirmButton && isVisible(domCache.cancelButton)) {
- domCache.cancelButton.focus(); // and vice versa
- } else if (document.activeElement === domCache.cancelButton && isVisible(domCache.confirmButton)) {
- domCache.confirmButton.focus();
- } // ESC
- } else if ((e.key === 'Escape' || e.key === 'Esc') && callIfFunction(innerParams.allowEscapeKey) === true) {
- e.preventDefault();
- dismissWith(constructor.DismissReason.esc);
- }
- };
- if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
- globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
- capture: globalState.keydownListenerCapture
- });
- globalState.keydownHandlerAdded = false;
- }
- if (!innerParams.toast) {
- globalState.keydownHandler = function (e) {
- return keydownHandler(e, innerParams);
- };
- globalState.keydownTarget = innerParams.keydownListenerCapture ? window : domCache.popup;
- globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
- globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
- capture: globalState.keydownListenerCapture
- });
- globalState.keydownHandlerAdded = true;
- }
- _this.enableButtons();
- _this.hideLoading();
- _this.resetValidationMessage();
- if (innerParams.toast && (innerParams.input || innerParams.footer || innerParams.showCloseButton)) {
- addClass(document.body, swalClasses['toast-column']);
- } else {
- removeClass(document.body, swalClasses['toast-column']);
- } // inputOptions, inputValue
- if (innerParams.input === 'select' || innerParams.input === 'radio') {
- handleInputOptions(_this, innerParams);
- } else if (['text', 'email', 'number', 'tel', 'textarea'].indexOf(innerParams.input) !== -1 && isPromise(innerParams.inputValue)) {
- handleInputValue(_this, innerParams);
- }
- openPopup(innerParams);
- if (!innerParams.toast) {
- if (!callIfFunction(innerParams.allowEnterKey)) {
- if (document.activeElement && typeof document.activeElement.blur === 'function') {
- document.activeElement.blur();
- }
- } else if (innerParams.focusCancel && isVisible(domCache.cancelButton)) {
- domCache.cancelButton.focus();
- } else if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) {
- domCache.confirmButton.focus();
- } else {
- setFocus(-1, 1);
- }
- } // fix scroll
- domCache.container.scrollTop = 0;
- });
- }
- /**
- * Updates popup parameters.
- */
- function update(params) {
- var validUpdatableParams = {}; // assign valid params from `params` to `defaults`
- Object.keys(params).forEach(function (param) {
- if (Swal.isUpdatableParameter(param)) {
- validUpdatableParams[param] = params[param];
- } else {
- warn("Invalid parameter to update: \"".concat(param, "\". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js"));
- }
- });
- var innerParams = privateProps.innerParams.get(this);
- var updatedParams = _extends({}, innerParams, validUpdatableParams);
- render(this, updatedParams);
- privateProps.innerParams.set(this, updatedParams);
- Object.defineProperties(this, {
- params: {
- value: _extends({}, this.params, params),
- writable: false,
- enumerable: true
- }
- });
- }
- var instanceMethods = Object.freeze({
- hideLoading: hideLoading,
- disableLoading: hideLoading,
- getInput: getInput$1,
- close: close,
- closePopup: close,
- closeModal: close,
- closeToast: close,
- enableButtons: enableButtons,
- disableButtons: disableButtons,
- enableConfirmButton: enableConfirmButton,
- disableConfirmButton: disableConfirmButton,
- enableInput: enableInput,
- disableInput: disableInput,
- showValidationMessage: showValidationMessage,
- resetValidationMessage: resetValidationMessage$1,
- getProgressSteps: getProgressSteps$1,
- setProgressSteps: setProgressSteps,
- showProgressSteps: showProgressSteps,
- hideProgressSteps: hideProgressSteps,
- _main: _main,
- update: update
- });
- var currentInstance; // SweetAlert constructor
- function SweetAlert() {
- // Prevent run in Node env
- /* istanbul ignore if */
- if (typeof window === 'undefined') {
- return;
- } // Check for the existence of Promise
- /* istanbul ignore if */
- if (typeof Promise === 'undefined') {
- error('This package requires a Promise library, please include a shim to enable it in this browser (See: https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2#1-ie-support)');
- }
- currentInstance = this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- var outerParams = Object.freeze(this.constructor.argsToParams(args));
- Object.defineProperties(this, {
- params: {
- value: outerParams,
- writable: false,
- enumerable: true,
- configurable: true
- }
- });
- var promise = this._main(this.params);
- privateProps.promise.set(this, promise);
- } // `catch` cannot be the name of a module export, so we define our thenable methods here instead
- SweetAlert.prototype.then = function (onFulfilled) {
- var promise = privateProps.promise.get(this);
- return promise.then(onFulfilled);
- };
- SweetAlert.prototype["finally"] = function (onFinally) {
- var promise = privateProps.promise.get(this);
- return promise["finally"](onFinally);
- }; // Assign instance methods from src/instanceMethods/*.js to prototype
- _extends(SweetAlert.prototype, instanceMethods); // Assign static methods from src/staticMethods/*.js to constructor
- _extends(SweetAlert, staticMethods); // Proxy to instance methods to constructor, for now, for backwards compatibility
- Object.keys(instanceMethods).forEach(function (key) {
- SweetAlert[key] = function () {
- if (currentInstance) {
- var _currentInstance;
- return (_currentInstance = currentInstance)[key].apply(_currentInstance, arguments);
- }
- };
- });
- SweetAlert.DismissReason = DismissReason;
- SweetAlert.version = '8.12.1';
- var Swal = SweetAlert;
- Swal["default"] = Swal;
- return Swal;
- })));
- if (typeof this !== 'undefined' && this.Sweetalert2){ this.swal = this.sweetAlert = this.Swal = this.SweetAlert = this.Sweetalert2}
|