sweetalert2.js 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790
  1. /*!
  2. * sweetalert2 v8.12.1
  3. * Released under the MIT License.
  4. */
  5. (function (global, factory) {
  6. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  7. typeof define === 'function' && define.amd ? define(factory) :
  8. (global.Sweetalert2 = factory());
  9. }(this, (function () { 'use strict';
  10. function _typeof(obj) {
  11. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  12. _typeof = function (obj) {
  13. return typeof obj;
  14. };
  15. } else {
  16. _typeof = function (obj) {
  17. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  18. };
  19. }
  20. return _typeof(obj);
  21. }
  22. function _classCallCheck(instance, Constructor) {
  23. if (!(instance instanceof Constructor)) {
  24. throw new TypeError("Cannot call a class as a function");
  25. }
  26. }
  27. function _defineProperties(target, props) {
  28. for (var i = 0; i < props.length; i++) {
  29. var descriptor = props[i];
  30. descriptor.enumerable = descriptor.enumerable || false;
  31. descriptor.configurable = true;
  32. if ("value" in descriptor) descriptor.writable = true;
  33. Object.defineProperty(target, descriptor.key, descriptor);
  34. }
  35. }
  36. function _createClass(Constructor, protoProps, staticProps) {
  37. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  38. if (staticProps) _defineProperties(Constructor, staticProps);
  39. return Constructor;
  40. }
  41. function _extends() {
  42. _extends = Object.assign || function (target) {
  43. for (var i = 1; i < arguments.length; i++) {
  44. var source = arguments[i];
  45. for (var key in source) {
  46. if (Object.prototype.hasOwnProperty.call(source, key)) {
  47. target[key] = source[key];
  48. }
  49. }
  50. }
  51. return target;
  52. };
  53. return _extends.apply(this, arguments);
  54. }
  55. function _inherits(subClass, superClass) {
  56. if (typeof superClass !== "function" && superClass !== null) {
  57. throw new TypeError("Super expression must either be null or a function");
  58. }
  59. subClass.prototype = Object.create(superClass && superClass.prototype, {
  60. constructor: {
  61. value: subClass,
  62. writable: true,
  63. configurable: true
  64. }
  65. });
  66. if (superClass) _setPrototypeOf(subClass, superClass);
  67. }
  68. function _getPrototypeOf(o) {
  69. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  70. return o.__proto__ || Object.getPrototypeOf(o);
  71. };
  72. return _getPrototypeOf(o);
  73. }
  74. function _setPrototypeOf(o, p) {
  75. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  76. o.__proto__ = p;
  77. return o;
  78. };
  79. return _setPrototypeOf(o, p);
  80. }
  81. function isNativeReflectConstruct() {
  82. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  83. if (Reflect.construct.sham) return false;
  84. if (typeof Proxy === "function") return true;
  85. try {
  86. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  87. return true;
  88. } catch (e) {
  89. return false;
  90. }
  91. }
  92. function _construct(Parent, args, Class) {
  93. if (isNativeReflectConstruct()) {
  94. _construct = Reflect.construct;
  95. } else {
  96. _construct = function _construct(Parent, args, Class) {
  97. var a = [null];
  98. a.push.apply(a, args);
  99. var Constructor = Function.bind.apply(Parent, a);
  100. var instance = new Constructor();
  101. if (Class) _setPrototypeOf(instance, Class.prototype);
  102. return instance;
  103. };
  104. }
  105. return _construct.apply(null, arguments);
  106. }
  107. function _assertThisInitialized(self) {
  108. if (self === void 0) {
  109. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  110. }
  111. return self;
  112. }
  113. function _possibleConstructorReturn(self, call) {
  114. if (call && (typeof call === "object" || typeof call === "function")) {
  115. return call;
  116. }
  117. return _assertThisInitialized(self);
  118. }
  119. function _superPropBase(object, property) {
  120. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  121. object = _getPrototypeOf(object);
  122. if (object === null) break;
  123. }
  124. return object;
  125. }
  126. function _get(target, property, receiver) {
  127. if (typeof Reflect !== "undefined" && Reflect.get) {
  128. _get = Reflect.get;
  129. } else {
  130. _get = function _get(target, property, receiver) {
  131. var base = _superPropBase(target, property);
  132. if (!base) return;
  133. var desc = Object.getOwnPropertyDescriptor(base, property);
  134. if (desc.get) {
  135. return desc.get.call(receiver);
  136. }
  137. return desc.value;
  138. };
  139. }
  140. return _get(target, property, receiver || target);
  141. }
  142. var consolePrefix = 'SweetAlert2:';
  143. /**
  144. * Filter the unique values into a new array
  145. * @param arr
  146. */
  147. var uniqueArray = function uniqueArray(arr) {
  148. var result = [];
  149. for (var i = 0; i < arr.length; i++) {
  150. if (result.indexOf(arr[i]) === -1) {
  151. result.push(arr[i]);
  152. }
  153. }
  154. return result;
  155. };
  156. /**
  157. * Returns the array ob object values (Object.values isn't supported in IE11)
  158. * @param obj
  159. */
  160. var objectValues = function objectValues(obj) {
  161. return Object.keys(obj).map(function (key) {
  162. return obj[key];
  163. });
  164. };
  165. /**
  166. * Convert NodeList to Array
  167. * @param nodeList
  168. */
  169. var toArray = function toArray(nodeList) {
  170. return Array.prototype.slice.call(nodeList);
  171. };
  172. /**
  173. * Standardise console warnings
  174. * @param message
  175. */
  176. var warn = function warn(message) {
  177. console.warn("".concat(consolePrefix, " ").concat(message));
  178. };
  179. /**
  180. * Standardise console errors
  181. * @param message
  182. */
  183. var error = function error(message) {
  184. console.error("".concat(consolePrefix, " ").concat(message));
  185. };
  186. /**
  187. * Private global state for `warnOnce`
  188. * @type {Array}
  189. * @private
  190. */
  191. var previousWarnOnceMessages = [];
  192. /**
  193. * Show a console warning, but only if it hasn't already been shown
  194. * @param message
  195. */
  196. var warnOnce = function warnOnce(message) {
  197. if (!(previousWarnOnceMessages.indexOf(message) !== -1)) {
  198. previousWarnOnceMessages.push(message);
  199. warn(message);
  200. }
  201. };
  202. /**
  203. * Show a one-time console warning about deprecated params/methods
  204. */
  205. var warnAboutDepreation = function warnAboutDepreation(deprecatedParam, useInstead) {
  206. warnOnce("\"".concat(deprecatedParam, "\" is deprecated and will be removed in the next major release. Please use \"").concat(useInstead, "\" instead."));
  207. };
  208. /**
  209. * If `arg` is a function, call it (with no arguments or context) and return the result.
  210. * Otherwise, just pass the value through
  211. * @param arg
  212. */
  213. var callIfFunction = function callIfFunction(arg) {
  214. return typeof arg === 'function' ? arg() : arg;
  215. };
  216. var isPromise = function isPromise(arg) {
  217. return arg && Promise.resolve(arg) === arg;
  218. };
  219. var DismissReason = Object.freeze({
  220. cancel: 'cancel',
  221. backdrop: 'backdrop',
  222. close: 'close',
  223. esc: 'esc',
  224. timer: 'timer'
  225. });
  226. var argsToParams = function argsToParams(args) {
  227. var params = {};
  228. switch (_typeof(args[0])) {
  229. case 'object':
  230. _extends(params, args[0]);
  231. break;
  232. default:
  233. ['title', 'html', 'type'].forEach(function (name, index) {
  234. switch (_typeof(args[index])) {
  235. case 'string':
  236. params[name] = args[index];
  237. break;
  238. case 'undefined':
  239. break;
  240. default:
  241. error("Unexpected type of ".concat(name, "! Expected \"string\", got ").concat(_typeof(args[index])));
  242. }
  243. });
  244. }
  245. return params;
  246. };
  247. var swalPrefix = 'swal2-';
  248. var prefix = function prefix(items) {
  249. var result = {};
  250. for (var i in items) {
  251. result[items[i]] = swalPrefix + items[i];
  252. }
  253. return result;
  254. };
  255. 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']);
  256. var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
  257. var states = {
  258. previousBodyPadding: null
  259. };
  260. var hasClass = function hasClass(elem, className) {
  261. return elem.classList.contains(className);
  262. };
  263. var applyCustomClass = function applyCustomClass(elem, customClass, className) {
  264. // Clean up previous custom classes
  265. toArray(elem.classList).forEach(function (className) {
  266. if (!(objectValues(swalClasses).indexOf(className) !== -1) && !(objectValues(iconTypes).indexOf(className) !== -1)) {
  267. elem.classList.remove(className);
  268. }
  269. });
  270. if (customClass && customClass[className]) {
  271. addClass(elem, customClass[className]);
  272. }
  273. };
  274. function getInput(content, inputType) {
  275. if (!inputType) {
  276. return null;
  277. }
  278. switch (inputType) {
  279. case 'select':
  280. case 'textarea':
  281. case 'file':
  282. return getChildByClass(content, swalClasses[inputType]);
  283. case 'checkbox':
  284. return content.querySelector(".".concat(swalClasses.checkbox, " input"));
  285. case 'radio':
  286. return content.querySelector(".".concat(swalClasses.radio, " input:checked")) || content.querySelector(".".concat(swalClasses.radio, " input:first-child"));
  287. case 'range':
  288. return content.querySelector(".".concat(swalClasses.range, " input"));
  289. default:
  290. return getChildByClass(content, swalClasses.input);
  291. }
  292. }
  293. var focusInput = function focusInput(input) {
  294. input.focus(); // place cursor at end of text in text input
  295. if (input.type !== 'file') {
  296. // http://stackoverflow.com/a/2345915
  297. var val = input.value;
  298. input.value = '';
  299. input.value = val;
  300. }
  301. };
  302. var toggleClass = function toggleClass(target, classList, condition) {
  303. if (!target || !classList) {
  304. return;
  305. }
  306. if (typeof classList === 'string') {
  307. classList = classList.split(/\s+/).filter(Boolean);
  308. }
  309. classList.forEach(function (className) {
  310. if (target.forEach) {
  311. target.forEach(function (elem) {
  312. condition ? elem.classList.add(className) : elem.classList.remove(className);
  313. });
  314. } else {
  315. condition ? target.classList.add(className) : target.classList.remove(className);
  316. }
  317. });
  318. };
  319. var addClass = function addClass(target, classList) {
  320. toggleClass(target, classList, true);
  321. };
  322. var removeClass = function removeClass(target, classList) {
  323. toggleClass(target, classList, false);
  324. };
  325. var getChildByClass = function getChildByClass(elem, className) {
  326. for (var i = 0; i < elem.childNodes.length; i++) {
  327. if (hasClass(elem.childNodes[i], className)) {
  328. return elem.childNodes[i];
  329. }
  330. }
  331. };
  332. var applyNumericalStyle = function applyNumericalStyle(elem, property, value) {
  333. if (value || parseInt(value) === 0) {
  334. elem.style[property] = typeof value === 'number' ? value + 'px' : value;
  335. } else {
  336. elem.style.removeProperty(property);
  337. }
  338. };
  339. var show = function show(elem) {
  340. var display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex';
  341. elem.style.opacity = '';
  342. elem.style.display = display;
  343. };
  344. var hide = function hide(elem) {
  345. elem.style.opacity = '';
  346. elem.style.display = 'none';
  347. };
  348. var toggle = function toggle(elem, condition, display) {
  349. condition ? show(elem, display) : hide(elem);
  350. }; // borrowed from jquery $(elem).is(':visible') implementation
  351. var isVisible = function isVisible(elem) {
  352. return !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
  353. };
  354. var isScrollable = function isScrollable(elem) {
  355. return !!(elem.scrollHeight > elem.clientHeight);
  356. }; // borrowed from https://stackoverflow.com/a/46352119
  357. var hasCssAnimation = function hasCssAnimation(elem) {
  358. var style = window.getComputedStyle(elem);
  359. var animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0');
  360. var transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0');
  361. return animDuration > 0 || transDuration > 0;
  362. };
  363. var contains = function contains(haystack, needle) {
  364. if (typeof haystack.contains === 'function') {
  365. return haystack.contains(needle);
  366. }
  367. };
  368. var getContainer = function getContainer() {
  369. return document.body.querySelector('.' + swalClasses.container);
  370. };
  371. var elementBySelector = function elementBySelector(selectorString) {
  372. var container = getContainer();
  373. return container ? container.querySelector(selectorString) : null;
  374. };
  375. var elementByClass = function elementByClass(className) {
  376. return elementBySelector('.' + className);
  377. };
  378. var getPopup = function getPopup() {
  379. return elementByClass(swalClasses.popup);
  380. };
  381. var getIcons = function getIcons() {
  382. var popup = getPopup();
  383. return toArray(popup.querySelectorAll('.' + swalClasses.icon));
  384. };
  385. var getIcon = function getIcon() {
  386. var visibleIcon = getIcons().filter(function (icon) {
  387. return isVisible(icon);
  388. });
  389. return visibleIcon.length ? visibleIcon[0] : null;
  390. };
  391. var getTitle = function getTitle() {
  392. return elementByClass(swalClasses.title);
  393. };
  394. var getContent = function getContent() {
  395. return elementByClass(swalClasses.content);
  396. };
  397. var getImage = function getImage() {
  398. return elementByClass(swalClasses.image);
  399. };
  400. var getProgressSteps = function getProgressSteps() {
  401. return elementByClass(swalClasses['progress-steps']);
  402. };
  403. var getValidationMessage = function getValidationMessage() {
  404. return elementByClass(swalClasses['validation-message']);
  405. };
  406. var getConfirmButton = function getConfirmButton() {
  407. return elementBySelector('.' + swalClasses.actions + ' .' + swalClasses.confirm);
  408. };
  409. var getCancelButton = function getCancelButton() {
  410. return elementBySelector('.' + swalClasses.actions + ' .' + swalClasses.cancel);
  411. };
  412. var getActions = function getActions() {
  413. return elementByClass(swalClasses.actions);
  414. };
  415. var getHeader = function getHeader() {
  416. return elementByClass(swalClasses.header);
  417. };
  418. var getFooter = function getFooter() {
  419. return elementByClass(swalClasses.footer);
  420. };
  421. var getCloseButton = function getCloseButton() {
  422. return elementByClass(swalClasses.close);
  423. };
  424. var getFocusableElements = function getFocusableElements() {
  425. var focusableElementsWithTabindex = toArray(getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')) // sort according to tabindex
  426. .sort(function (a, b) {
  427. a = parseInt(a.getAttribute('tabindex'));
  428. b = parseInt(b.getAttribute('tabindex'));
  429. if (a > b) {
  430. return 1;
  431. } else if (a < b) {
  432. return -1;
  433. }
  434. return 0;
  435. }); // https://github.com/jkup/focusable/blob/master/index.js
  436. 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) {
  437. return el.getAttribute('tabindex') !== '-1';
  438. });
  439. return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(function (el) {
  440. return isVisible(el);
  441. });
  442. };
  443. var isModal = function isModal() {
  444. return !isToast() && !document.body.classList.contains(swalClasses['no-backdrop']);
  445. };
  446. var isToast = function isToast() {
  447. return document.body.classList.contains(swalClasses['toast-shown']);
  448. };
  449. var isLoading = function isLoading() {
  450. return getPopup().hasAttribute('data-loading');
  451. };
  452. // Detect Node env
  453. var isNodeEnv = function isNodeEnv() {
  454. return typeof window === 'undefined' || typeof document === 'undefined';
  455. };
  456. 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, "\">&times;</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, '');
  457. var resetOldContainer = function resetOldContainer() {
  458. var oldContainer = getContainer();
  459. if (!oldContainer) {
  460. return;
  461. }
  462. oldContainer.parentNode.removeChild(oldContainer);
  463. removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]);
  464. };
  465. var oldInputVal; // IE11 workaround, see #1109 for details
  466. var resetValidationMessage = function resetValidationMessage(e) {
  467. if (Swal.isVisible() && oldInputVal !== e.target.value) {
  468. Swal.resetValidationMessage();
  469. }
  470. oldInputVal = e.target.value;
  471. };
  472. var addInputChangeListeners = function addInputChangeListeners() {
  473. var content = getContent();
  474. var input = getChildByClass(content, swalClasses.input);
  475. var file = getChildByClass(content, swalClasses.file);
  476. var range = content.querySelector(".".concat(swalClasses.range, " input"));
  477. var rangeOutput = content.querySelector(".".concat(swalClasses.range, " output"));
  478. var select = getChildByClass(content, swalClasses.select);
  479. var checkbox = content.querySelector(".".concat(swalClasses.checkbox, " input"));
  480. var textarea = getChildByClass(content, swalClasses.textarea);
  481. input.oninput = resetValidationMessage;
  482. file.onchange = resetValidationMessage;
  483. select.onchange = resetValidationMessage;
  484. checkbox.onchange = resetValidationMessage;
  485. textarea.oninput = resetValidationMessage;
  486. range.oninput = function (e) {
  487. resetValidationMessage(e);
  488. rangeOutput.value = range.value;
  489. };
  490. range.onchange = function (e) {
  491. resetValidationMessage(e);
  492. range.nextSibling.value = range.value;
  493. };
  494. };
  495. var getTarget = function getTarget(target) {
  496. return typeof target === 'string' ? document.querySelector(target) : target;
  497. };
  498. var setupAccessibility = function setupAccessibility(params) {
  499. var popup = getPopup();
  500. popup.setAttribute('role', params.toast ? 'alert' : 'dialog');
  501. popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive');
  502. if (!params.toast) {
  503. popup.setAttribute('aria-modal', 'true');
  504. }
  505. };
  506. var setupRTL = function setupRTL(targetElement) {
  507. if (window.getComputedStyle(targetElement).direction === 'rtl') {
  508. addClass(getContainer(), swalClasses.rtl);
  509. }
  510. };
  511. /*
  512. * Add modal + backdrop to DOM
  513. */
  514. var init = function init(params) {
  515. // Clean up the old popup container if it exists
  516. resetOldContainer();
  517. /* istanbul ignore if */
  518. if (isNodeEnv()) {
  519. error('SweetAlert2 requires document to initialize');
  520. return;
  521. }
  522. var container = document.createElement('div');
  523. container.className = swalClasses.container;
  524. container.innerHTML = sweetHTML;
  525. var targetElement = getTarget(params.target);
  526. targetElement.appendChild(container);
  527. setupAccessibility(params);
  528. setupRTL(targetElement);
  529. addInputChangeListeners();
  530. };
  531. var parseHtmlToContainer = function parseHtmlToContainer(param, target) {
  532. // DOM element
  533. if (param instanceof HTMLElement) {
  534. target.appendChild(param); // JQuery element(s)
  535. } else if (_typeof(param) === 'object') {
  536. handleJqueryElem(target, param); // Plain string
  537. } else if (param) {
  538. target.innerHTML = param;
  539. }
  540. };
  541. var handleJqueryElem = function handleJqueryElem(target, elem) {
  542. target.innerHTML = '';
  543. if (0 in elem) {
  544. for (var i = 0; i in elem; i++) {
  545. target.appendChild(elem[i].cloneNode(true));
  546. }
  547. } else {
  548. target.appendChild(elem.cloneNode(true));
  549. }
  550. };
  551. var animationEndEvent = function () {
  552. // Prevent run in Node env
  553. /* istanbul ignore if */
  554. if (isNodeEnv()) {
  555. return false;
  556. }
  557. var testEl = document.createElement('div');
  558. var transEndEventNames = {
  559. 'WebkitAnimation': 'webkitAnimationEnd',
  560. 'OAnimation': 'oAnimationEnd oanimationend',
  561. 'animation': 'animationend'
  562. };
  563. for (var i in transEndEventNames) {
  564. if (transEndEventNames.hasOwnProperty(i) && typeof testEl.style[i] !== 'undefined') {
  565. return transEndEventNames[i];
  566. }
  567. }
  568. return false;
  569. }();
  570. // Measure width of scrollbar
  571. // https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286
  572. var measureScrollbar = function measureScrollbar() {
  573. var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints;
  574. if (supportsTouch) {
  575. return 0;
  576. }
  577. var scrollDiv = document.createElement('div');
  578. scrollDiv.style.width = '50px';
  579. scrollDiv.style.height = '50px';
  580. scrollDiv.style.overflow = 'scroll';
  581. document.body.appendChild(scrollDiv);
  582. var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
  583. document.body.removeChild(scrollDiv);
  584. return scrollbarWidth;
  585. };
  586. function handleButtonsStyling(confirmButton, cancelButton, params) {
  587. addClass([confirmButton, cancelButton], swalClasses.styled); // Buttons background colors
  588. if (params.confirmButtonColor) {
  589. confirmButton.style.backgroundColor = params.confirmButtonColor;
  590. }
  591. if (params.cancelButtonColor) {
  592. cancelButton.style.backgroundColor = params.cancelButtonColor;
  593. } // Loading state
  594. var confirmButtonBackgroundColor = window.getComputedStyle(confirmButton).getPropertyValue('background-color');
  595. confirmButton.style.borderLeftColor = confirmButtonBackgroundColor;
  596. confirmButton.style.borderRightColor = confirmButtonBackgroundColor;
  597. }
  598. function renderButton(button, buttonType, params) {
  599. toggle(button, params['showC' + buttonType.substring(1) + 'Button'], 'inline-block');
  600. button.innerHTML = params[buttonType + 'ButtonText']; // Set caption text
  601. button.setAttribute('aria-label', params[buttonType + 'ButtonAriaLabel']); // ARIA label
  602. // Add buttons custom classes
  603. button.className = swalClasses[buttonType];
  604. applyCustomClass(button, params.customClass, buttonType + 'Button');
  605. addClass(button, params[buttonType + 'ButtonClass']);
  606. }
  607. var renderActions = function renderActions(instance, params) {
  608. var actions = getActions();
  609. var confirmButton = getConfirmButton();
  610. var cancelButton = getCancelButton(); // Actions (buttons) wrapper
  611. if (!params.showConfirmButton && !params.showCancelButton) {
  612. hide(actions);
  613. } else {
  614. show(actions);
  615. } // Custom class
  616. applyCustomClass(actions, params.customClass, 'actions'); // Render confirm button
  617. renderButton(confirmButton, 'confirm', params); // render Cancel Button
  618. renderButton(cancelButton, 'cancel', params);
  619. if (params.buttonsStyling) {
  620. handleButtonsStyling(confirmButton, cancelButton, params);
  621. } else {
  622. removeClass([confirmButton, cancelButton], swalClasses.styled);
  623. confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = '';
  624. cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = '';
  625. }
  626. };
  627. function handleBackdropParam(container, backdrop) {
  628. if (typeof backdrop === 'string') {
  629. container.style.background = backdrop;
  630. } else if (!backdrop) {
  631. addClass([document.documentElement, document.body], swalClasses['no-backdrop']);
  632. }
  633. }
  634. function handlePositionParam(container, position) {
  635. if (position in swalClasses) {
  636. addClass(container, swalClasses[position]);
  637. } else {
  638. warn('The "position" parameter is not valid, defaulting to "center"');
  639. addClass(container, swalClasses.center);
  640. }
  641. }
  642. function handleGrowParam(container, grow) {
  643. if (grow && typeof grow === 'string') {
  644. var growClass = 'grow-' + grow;
  645. if (growClass in swalClasses) {
  646. addClass(container, swalClasses[growClass]);
  647. }
  648. }
  649. }
  650. var renderContainer = function renderContainer(instance, params) {
  651. var container = getContainer();
  652. if (!container) {
  653. return;
  654. }
  655. handleBackdropParam(container, params.backdrop);
  656. if (!params.backdrop && params.allowOutsideClick) {
  657. warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
  658. }
  659. handlePositionParam(container, params.position);
  660. handleGrowParam(container, params.grow); // Custom class
  661. applyCustomClass(container, params.customClass, 'container');
  662. if (params.customContainerClass) {
  663. // @deprecated
  664. addClass(container, params.customContainerClass);
  665. }
  666. };
  667. /**
  668. * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has.
  669. * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
  670. * This is the approach that Babel will probably take to implement private methods/fields
  671. * https://github.com/tc39/proposal-private-methods
  672. * https://github.com/babel/babel/pull/7555
  673. * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
  674. * then we can use that language feature.
  675. */
  676. var privateProps = {
  677. promise: new WeakMap(),
  678. innerParams: new WeakMap(),
  679. domCache: new WeakMap()
  680. };
  681. var renderInput = function renderInput(instance, params) {
  682. var innerParams = privateProps.innerParams.get(instance);
  683. var rerender = !innerParams || params.input !== innerParams.input;
  684. var content = getContent();
  685. var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
  686. for (var i = 0; i < inputTypes.length; i++) {
  687. var inputClass = swalClasses[inputTypes[i]];
  688. var inputContainer = getChildByClass(content, inputClass); // set attributes
  689. setAttributes(inputTypes[i], params.inputAttributes); // set class
  690. setClass(inputContainer, inputClass, params);
  691. rerender && hide(inputContainer);
  692. }
  693. if (!params.input) {
  694. return;
  695. }
  696. if (!renderInputType[params.input]) {
  697. return error("Unexpected type of input! Expected \"text\", \"email\", \"password\", \"number\", \"tel\", \"select\", \"radio\", \"checkbox\", \"textarea\", \"file\" or \"url\", got \"".concat(params.input, "\""));
  698. }
  699. if (rerender) {
  700. var input = renderInputType[params.input](params);
  701. show(input);
  702. }
  703. };
  704. var removeAttributes = function removeAttributes(input) {
  705. for (var i = 0; i < input.attributes.length; i++) {
  706. var attrName = input.attributes[i].name;
  707. if (!(['type', 'value', 'style'].indexOf(attrName) !== -1)) {
  708. input.removeAttribute(attrName);
  709. }
  710. }
  711. };
  712. var setAttributes = function setAttributes(inputType, inputAttributes) {
  713. var input = getInput(getContent(), inputType);
  714. if (!input) {
  715. return;
  716. }
  717. removeAttributes(input);
  718. for (var attr in inputAttributes) {
  719. // Do not set a placeholder for <input type="range">
  720. // it'll crash Edge, #1298
  721. if (inputType === 'range' && attr === 'placeholder') {
  722. continue;
  723. }
  724. input.setAttribute(attr, inputAttributes[attr]);
  725. }
  726. };
  727. var setClass = function setClass(inputContainer, inputClass, params) {
  728. inputContainer.className = inputClass;
  729. if (params.inputClass) {
  730. addClass(inputContainer, params.inputClass);
  731. }
  732. if (params.customClass) {
  733. addClass(inputContainer, params.customClass.input);
  734. }
  735. };
  736. var setInputPlaceholder = function setInputPlaceholder(input, params) {
  737. if (!input.placeholder || params.inputPlaceholder) {
  738. input.placeholder = params.inputPlaceholder;
  739. }
  740. };
  741. var renderInputType = {};
  742. renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = function (params) {
  743. var input = getChildByClass(getContent(), swalClasses.input);
  744. if (typeof params.inputValue === 'string' || typeof params.inputValue === 'number') {
  745. input.value = params.inputValue;
  746. } else if (!isPromise(params.inputValue)) {
  747. warn("Unexpected type of inputValue! Expected \"string\", \"number\" or \"Promise\", got \"".concat(_typeof(params.inputValue), "\""));
  748. }
  749. setInputPlaceholder(input, params);
  750. input.type = params.input;
  751. return input;
  752. };
  753. renderInputType.file = function (params) {
  754. var input = getChildByClass(getContent(), swalClasses.file);
  755. setInputPlaceholder(input, params);
  756. input.type = params.input;
  757. return input;
  758. };
  759. renderInputType.range = function (params) {
  760. var range = getChildByClass(getContent(), swalClasses.range);
  761. var rangeInput = range.querySelector('input');
  762. var rangeOutput = range.querySelector('output');
  763. rangeInput.value = params.inputValue;
  764. rangeInput.type = params.input;
  765. rangeOutput.value = params.inputValue;
  766. return range;
  767. };
  768. renderInputType.select = function (params) {
  769. var select = getChildByClass(getContent(), swalClasses.select);
  770. select.innerHTML = '';
  771. if (params.inputPlaceholder) {
  772. var placeholder = document.createElement('option');
  773. placeholder.innerHTML = params.inputPlaceholder;
  774. placeholder.value = '';
  775. placeholder.disabled = true;
  776. placeholder.selected = true;
  777. select.appendChild(placeholder);
  778. }
  779. return select;
  780. };
  781. renderInputType.radio = function () {
  782. var radio = getChildByClass(getContent(), swalClasses.radio);
  783. radio.innerHTML = '';
  784. return radio;
  785. };
  786. renderInputType.checkbox = function (params) {
  787. var checkbox = getChildByClass(getContent(), swalClasses.checkbox);
  788. var checkboxInput = getInput(getContent(), 'checkbox');
  789. checkboxInput.type = 'checkbox';
  790. checkboxInput.value = 1;
  791. checkboxInput.id = swalClasses.checkbox;
  792. checkboxInput.checked = Boolean(params.inputValue);
  793. var label = checkbox.querySelector('span');
  794. label.innerHTML = params.inputPlaceholder;
  795. return checkbox;
  796. };
  797. renderInputType.textarea = function (params) {
  798. var textarea = getChildByClass(getContent(), swalClasses.textarea);
  799. textarea.value = params.inputValue;
  800. setInputPlaceholder(textarea, params);
  801. return textarea;
  802. };
  803. var renderContent = function renderContent(instance, params) {
  804. var content = getContent().querySelector('#' + swalClasses.content); // Content as HTML
  805. if (params.html) {
  806. parseHtmlToContainer(params.html, content);
  807. show(content, 'block'); // Content as plain text
  808. } else if (params.text) {
  809. content.textContent = params.text;
  810. show(content, 'block'); // No content
  811. } else {
  812. hide(content);
  813. }
  814. renderInput(instance, params); // Custom class
  815. applyCustomClass(getContent(), params.customClass, 'content');
  816. };
  817. var renderFooter = function renderFooter(instance, params) {
  818. var footer = getFooter();
  819. toggle(footer, params.footer);
  820. if (params.footer) {
  821. parseHtmlToContainer(params.footer, footer);
  822. } // Custom class
  823. applyCustomClass(footer, params.customClass, 'footer');
  824. };
  825. var renderCloseButton = function renderCloseButton(instance, params) {
  826. var closeButton = getCloseButton(); // Custom class
  827. applyCustomClass(closeButton, params.customClass, 'closeButton');
  828. toggle(closeButton, params.showCloseButton);
  829. closeButton.setAttribute('aria-label', params.closeButtonAriaLabel);
  830. };
  831. var renderIcon = function renderIcon(instance, params) {
  832. var innerParams = privateProps.innerParams.get(instance); // if the icon with the given type already rendered,
  833. // apply the custom class without re-rendering the icon
  834. if (innerParams && params.type === innerParams.type && getIcon()) {
  835. applyCustomClass(getIcon(), params.customClass, 'icon');
  836. return;
  837. }
  838. hideAllIcons();
  839. if (!params.type) {
  840. return;
  841. }
  842. adjustSuccessIconBackgoundColor();
  843. if (Object.keys(iconTypes).indexOf(params.type) !== -1) {
  844. var icon = elementBySelector(".".concat(swalClasses.icon, ".").concat(iconTypes[params.type]));
  845. show(icon); // Custom class
  846. applyCustomClass(icon, params.customClass, 'icon'); // Animate icon
  847. toggleClass(icon, "swal2-animate-".concat(params.type, "-icon"), params.animation);
  848. } else {
  849. error("Unknown type! Expected \"success\", \"error\", \"warning\", \"info\" or \"question\", got \"".concat(params.type, "\""));
  850. }
  851. };
  852. var hideAllIcons = function hideAllIcons() {
  853. var icons = getIcons();
  854. for (var i = 0; i < icons.length; i++) {
  855. hide(icons[i]);
  856. }
  857. }; // Adjust success icon background color to match the popup background color
  858. var adjustSuccessIconBackgoundColor = function adjustSuccessIconBackgoundColor() {
  859. var popup = getPopup();
  860. var popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color');
  861. var successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix');
  862. for (var i = 0; i < successIconParts.length; i++) {
  863. successIconParts[i].style.backgroundColor = popupBackgroundColor;
  864. }
  865. };
  866. var renderImage = function renderImage(instance, params) {
  867. var image = getImage();
  868. if (!params.imageUrl) {
  869. return hide(image);
  870. }
  871. show(image); // Src, alt
  872. image.setAttribute('src', params.imageUrl);
  873. image.setAttribute('alt', params.imageAlt); // Width, height
  874. applyNumericalStyle(image, 'width', params.imageWidth);
  875. applyNumericalStyle(image, 'height', params.imageHeight); // Class
  876. image.className = swalClasses.image;
  877. applyCustomClass(image, params.customClass, 'image');
  878. if (params.imageClass) {
  879. addClass(image, params.imageClass);
  880. }
  881. };
  882. var createStepElement = function createStepElement(step) {
  883. var stepEl = document.createElement('li');
  884. addClass(stepEl, swalClasses['progress-step']);
  885. stepEl.innerHTML = step;
  886. return stepEl;
  887. };
  888. var createLineElement = function createLineElement(params) {
  889. var lineEl = document.createElement('li');
  890. addClass(lineEl, swalClasses['progress-step-line']);
  891. if (params.progressStepsDistance) {
  892. lineEl.style.width = params.progressStepsDistance;
  893. }
  894. return lineEl;
  895. };
  896. var renderProgressSteps = function renderProgressSteps(instance, params) {
  897. var progressStepsContainer = getProgressSteps();
  898. if (!params.progressSteps || params.progressSteps.length === 0) {
  899. return hide(progressStepsContainer);
  900. }
  901. show(progressStepsContainer);
  902. progressStepsContainer.innerHTML = '';
  903. var currentProgressStep = parseInt(params.currentProgressStep === null ? Swal.getQueueStep() : params.currentProgressStep);
  904. if (currentProgressStep >= params.progressSteps.length) {
  905. warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
  906. }
  907. params.progressSteps.forEach(function (step, index) {
  908. var stepEl = createStepElement(step);
  909. progressStepsContainer.appendChild(stepEl);
  910. if (index === currentProgressStep) {
  911. addClass(stepEl, swalClasses['active-progress-step']);
  912. }
  913. if (index !== params.progressSteps.length - 1) {
  914. var lineEl = createLineElement(step);
  915. progressStepsContainer.appendChild(lineEl);
  916. }
  917. });
  918. };
  919. var renderTitle = function renderTitle(instance, params) {
  920. var title = getTitle();
  921. toggle(title, params.title || params.titleText);
  922. if (params.title) {
  923. parseHtmlToContainer(params.title, title);
  924. }
  925. if (params.titleText) {
  926. title.innerText = params.titleText;
  927. } // Custom class
  928. applyCustomClass(title, params.customClass, 'title');
  929. };
  930. var renderHeader = function renderHeader(instance, params) {
  931. var header = getHeader(); // Custom class
  932. applyCustomClass(header, params.customClass, 'header'); // Progress steps
  933. renderProgressSteps(instance, params); // Icon
  934. renderIcon(instance, params); // Image
  935. renderImage(instance, params); // Title
  936. renderTitle(instance, params); // Close button
  937. renderCloseButton(instance, params);
  938. };
  939. var renderPopup = function renderPopup(instance, params) {
  940. var popup = getPopup(); // Width
  941. applyNumericalStyle(popup, 'width', params.width); // Padding
  942. applyNumericalStyle(popup, 'padding', params.padding); // Background
  943. if (params.background) {
  944. popup.style.background = params.background;
  945. } // Default Class
  946. popup.className = swalClasses.popup;
  947. if (params.toast) {
  948. addClass([document.documentElement, document.body], swalClasses['toast-shown']);
  949. addClass(popup, swalClasses.toast);
  950. } else {
  951. addClass(popup, swalClasses.modal);
  952. } // Custom class
  953. applyCustomClass(popup, params.customClass, 'popup');
  954. if (typeof params.customClass === 'string') {
  955. addClass(popup, params.customClass);
  956. } // CSS animation
  957. toggleClass(popup, swalClasses.noanimation, !params.animation);
  958. };
  959. var render = function render(instance, params) {
  960. renderPopup(instance, params);
  961. renderContainer(instance, params);
  962. renderHeader(instance, params);
  963. renderContent(instance, params);
  964. renderActions(instance, params);
  965. renderFooter(instance, params);
  966. };
  967. /*
  968. * Global function to determine if SweetAlert2 popup is shown
  969. */
  970. var isVisible$1 = function isVisible$$1() {
  971. return isVisible(getPopup());
  972. };
  973. /*
  974. * Global function to click 'Confirm' button
  975. */
  976. var clickConfirm = function clickConfirm() {
  977. return getConfirmButton() && getConfirmButton().click();
  978. };
  979. /*
  980. * Global function to click 'Cancel' button
  981. */
  982. var clickCancel = function clickCancel() {
  983. return getCancelButton() && getCancelButton().click();
  984. };
  985. function fire() {
  986. var Swal = this;
  987. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  988. args[_key] = arguments[_key];
  989. }
  990. return _construct(Swal, args);
  991. }
  992. /**
  993. * Returns an extended version of `Swal` containing `params` as defaults.
  994. * Useful for reusing Swal configuration.
  995. *
  996. * For example:
  997. *
  998. * Before:
  999. * const textPromptOptions = { input: 'text', showCancelButton: true }
  1000. * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
  1001. * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
  1002. *
  1003. * After:
  1004. * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
  1005. * const {value: firstName} = await TextPrompt('What is your first name?')
  1006. * const {value: lastName} = await TextPrompt('What is your last name?')
  1007. *
  1008. * @param mixinParams
  1009. */
  1010. function mixin(mixinParams) {
  1011. var MixinSwal =
  1012. /*#__PURE__*/
  1013. function (_this) {
  1014. _inherits(MixinSwal, _this);
  1015. function MixinSwal() {
  1016. _classCallCheck(this, MixinSwal);
  1017. return _possibleConstructorReturn(this, _getPrototypeOf(MixinSwal).apply(this, arguments));
  1018. }
  1019. _createClass(MixinSwal, [{
  1020. key: "_main",
  1021. value: function _main(params) {
  1022. return _get(_getPrototypeOf(MixinSwal.prototype), "_main", this).call(this, _extends({}, mixinParams, params));
  1023. }
  1024. }]);
  1025. return MixinSwal;
  1026. }(this);
  1027. return MixinSwal;
  1028. }
  1029. // private global state for the queue feature
  1030. var currentSteps = [];
  1031. /*
  1032. * Global function for chaining sweetAlert popups
  1033. */
  1034. var queue = function queue(steps) {
  1035. var Swal = this;
  1036. currentSteps = steps;
  1037. var resetAndResolve = function resetAndResolve(resolve, value) {
  1038. currentSteps = [];
  1039. document.body.removeAttribute('data-swal2-queue-step');
  1040. resolve(value);
  1041. };
  1042. var queueResult = [];
  1043. return new Promise(function (resolve) {
  1044. (function step(i, callback) {
  1045. if (i < currentSteps.length) {
  1046. document.body.setAttribute('data-swal2-queue-step', i);
  1047. Swal.fire(currentSteps[i]).then(function (result) {
  1048. if (typeof result.value !== 'undefined') {
  1049. queueResult.push(result.value);
  1050. step(i + 1, callback);
  1051. } else {
  1052. resetAndResolve(resolve, {
  1053. dismiss: result.dismiss
  1054. });
  1055. }
  1056. });
  1057. } else {
  1058. resetAndResolve(resolve, {
  1059. value: queueResult
  1060. });
  1061. }
  1062. })(0);
  1063. });
  1064. };
  1065. /*
  1066. * Global function for getting the index of current popup in queue
  1067. */
  1068. var getQueueStep = function getQueueStep() {
  1069. return document.body.getAttribute('data-swal2-queue-step');
  1070. };
  1071. /*
  1072. * Global function for inserting a popup to the queue
  1073. */
  1074. var insertQueueStep = function insertQueueStep(step, index) {
  1075. if (index && index < currentSteps.length) {
  1076. return currentSteps.splice(index, 0, step);
  1077. }
  1078. return currentSteps.push(step);
  1079. };
  1080. /*
  1081. * Global function for deleting a popup from the queue
  1082. */
  1083. var deleteQueueStep = function deleteQueueStep(index) {
  1084. if (typeof currentSteps[index] !== 'undefined') {
  1085. currentSteps.splice(index, 1);
  1086. }
  1087. };
  1088. /**
  1089. * Show spinner instead of Confirm button and disable Cancel button
  1090. */
  1091. var showLoading = function showLoading() {
  1092. var popup = getPopup();
  1093. if (!popup) {
  1094. Swal.fire('');
  1095. }
  1096. popup = getPopup();
  1097. var actions = getActions();
  1098. var confirmButton = getConfirmButton();
  1099. var cancelButton = getCancelButton();
  1100. show(actions);
  1101. show(confirmButton);
  1102. addClass([popup, actions], swalClasses.loading);
  1103. confirmButton.disabled = true;
  1104. cancelButton.disabled = true;
  1105. popup.setAttribute('data-loading', true);
  1106. popup.setAttribute('aria-busy', true);
  1107. popup.focus();
  1108. };
  1109. var RESTORE_FOCUS_TIMEOUT = 100;
  1110. var globalState = {};
  1111. var focusPreviousActiveElement = function focusPreviousActiveElement() {
  1112. if (globalState.previousActiveElement && globalState.previousActiveElement.focus) {
  1113. globalState.previousActiveElement.focus();
  1114. globalState.previousActiveElement = null;
  1115. } else if (document.body) {
  1116. document.body.focus();
  1117. }
  1118. }; // Restore previous active (focused) element
  1119. var restoreActiveElement = function restoreActiveElement() {
  1120. return new Promise(function (resolve) {
  1121. var x = window.scrollX;
  1122. var y = window.scrollY;
  1123. globalState.restoreFocusTimeout = setTimeout(function () {
  1124. focusPreviousActiveElement();
  1125. resolve();
  1126. }, RESTORE_FOCUS_TIMEOUT); // issues/900
  1127. if (typeof x !== 'undefined' && typeof y !== 'undefined') {
  1128. // IE doesn't have scrollX/scrollY support
  1129. window.scrollTo(x, y);
  1130. }
  1131. });
  1132. };
  1133. /**
  1134. * If `timer` parameter is set, returns number of milliseconds of timer remained.
  1135. * Otherwise, returns undefined.
  1136. */
  1137. var getTimerLeft = function getTimerLeft() {
  1138. return globalState.timeout && globalState.timeout.getTimerLeft();
  1139. };
  1140. /**
  1141. * Stop timer. Returns number of milliseconds of timer remained.
  1142. * If `timer` parameter isn't set, returns undefined.
  1143. */
  1144. var stopTimer = function stopTimer() {
  1145. return globalState.timeout && globalState.timeout.stop();
  1146. };
  1147. /**
  1148. * Resume timer. Returns number of milliseconds of timer remained.
  1149. * If `timer` parameter isn't set, returns undefined.
  1150. */
  1151. var resumeTimer = function resumeTimer() {
  1152. return globalState.timeout && globalState.timeout.start();
  1153. };
  1154. /**
  1155. * Resume timer. Returns number of milliseconds of timer remained.
  1156. * If `timer` parameter isn't set, returns undefined.
  1157. */
  1158. var toggleTimer = function toggleTimer() {
  1159. var timer = globalState.timeout;
  1160. return timer && (timer.running ? timer.stop() : timer.start());
  1161. };
  1162. /**
  1163. * Increase timer. Returns number of milliseconds of an updated timer.
  1164. * If `timer` parameter isn't set, returns undefined.
  1165. */
  1166. var increaseTimer = function increaseTimer(n) {
  1167. return globalState.timeout && globalState.timeout.increase(n);
  1168. };
  1169. /**
  1170. * Check if timer is running. Returns true if timer is running
  1171. * or false if timer is paused or stopped.
  1172. * If `timer` parameter isn't set, returns undefined
  1173. */
  1174. var isTimerRunning = function isTimerRunning() {
  1175. return globalState.timeout && globalState.timeout.isRunning();
  1176. };
  1177. var defaultParams = {
  1178. title: '',
  1179. titleText: '',
  1180. text: '',
  1181. html: '',
  1182. footer: '',
  1183. type: null,
  1184. toast: false,
  1185. customClass: '',
  1186. customContainerClass: '',
  1187. target: 'body',
  1188. backdrop: true,
  1189. animation: true,
  1190. heightAuto: true,
  1191. allowOutsideClick: true,
  1192. allowEscapeKey: true,
  1193. allowEnterKey: true,
  1194. stopKeydownPropagation: true,
  1195. keydownListenerCapture: false,
  1196. showConfirmButton: true,
  1197. showCancelButton: false,
  1198. preConfirm: null,
  1199. confirmButtonText: 'OK',
  1200. confirmButtonAriaLabel: '',
  1201. confirmButtonColor: null,
  1202. confirmButtonClass: '',
  1203. cancelButtonText: 'Cancel',
  1204. cancelButtonAriaLabel: '',
  1205. cancelButtonColor: null,
  1206. cancelButtonClass: '',
  1207. buttonsStyling: true,
  1208. reverseButtons: false,
  1209. focusConfirm: true,
  1210. focusCancel: false,
  1211. showCloseButton: false,
  1212. closeButtonAriaLabel: 'Close this dialog',
  1213. showLoaderOnConfirm: false,
  1214. imageUrl: null,
  1215. imageWidth: null,
  1216. imageHeight: null,
  1217. imageAlt: '',
  1218. imageClass: '',
  1219. timer: null,
  1220. width: null,
  1221. padding: null,
  1222. background: null,
  1223. input: null,
  1224. inputPlaceholder: '',
  1225. inputValue: '',
  1226. inputOptions: {},
  1227. inputAutoTrim: true,
  1228. inputClass: '',
  1229. inputAttributes: {},
  1230. inputValidator: null,
  1231. validationMessage: null,
  1232. grow: false,
  1233. position: 'center',
  1234. progressSteps: [],
  1235. currentProgressStep: null,
  1236. progressStepsDistance: null,
  1237. onBeforeOpen: null,
  1238. onAfterClose: null,
  1239. onOpen: null,
  1240. onClose: null,
  1241. scrollbarPadding: true
  1242. };
  1243. 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'];
  1244. var deprecatedParams = {
  1245. customContainerClass: 'customClass',
  1246. confirmButtonClass: 'customClass',
  1247. cancelButtonClass: 'customClass',
  1248. imageClass: 'customClass',
  1249. inputClass: 'customClass'
  1250. };
  1251. var toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusCancel', 'heightAuto', 'keydownListenerCapture'];
  1252. /**
  1253. * Is valid parameter
  1254. * @param {String} paramName
  1255. */
  1256. var isValidParameter = function isValidParameter(paramName) {
  1257. return defaultParams.hasOwnProperty(paramName);
  1258. };
  1259. /**
  1260. * Is valid parameter for Swal.update() method
  1261. * @param {String} paramName
  1262. */
  1263. var isUpdatableParameter = function isUpdatableParameter(paramName) {
  1264. return updatableParams.indexOf(paramName) !== -1;
  1265. };
  1266. /**
  1267. * Is deprecated parameter
  1268. * @param {String} paramName
  1269. */
  1270. var isDeprecatedParameter = function isDeprecatedParameter(paramName) {
  1271. return deprecatedParams[paramName];
  1272. };
  1273. var checkIfParamIsValid = function checkIfParamIsValid(param) {
  1274. if (!isValidParameter(param)) {
  1275. warn("Unknown parameter \"".concat(param, "\""));
  1276. }
  1277. };
  1278. var checkIfToastParamIsValid = function checkIfToastParamIsValid(param) {
  1279. if (toastIncompatibleParams.indexOf(param) !== -1) {
  1280. warn("The parameter \"".concat(param, "\" is incompatible with toasts"));
  1281. }
  1282. };
  1283. var checkIfParamIsDeprecated = function checkIfParamIsDeprecated(param) {
  1284. if (isDeprecatedParameter(param)) {
  1285. warnAboutDepreation(param, isDeprecatedParameter(param));
  1286. }
  1287. };
  1288. /**
  1289. * Show relevant warnings for given params
  1290. *
  1291. * @param params
  1292. */
  1293. var showWarningsForParams = function showWarningsForParams(params) {
  1294. for (var param in params) {
  1295. checkIfParamIsValid(param);
  1296. if (params.toast) {
  1297. checkIfToastParamIsValid(param);
  1298. }
  1299. checkIfParamIsDeprecated();
  1300. }
  1301. };
  1302. var staticMethods = Object.freeze({
  1303. isValidParameter: isValidParameter,
  1304. isUpdatableParameter: isUpdatableParameter,
  1305. isDeprecatedParameter: isDeprecatedParameter,
  1306. argsToParams: argsToParams,
  1307. isVisible: isVisible$1,
  1308. clickConfirm: clickConfirm,
  1309. clickCancel: clickCancel,
  1310. getContainer: getContainer,
  1311. getPopup: getPopup,
  1312. getTitle: getTitle,
  1313. getContent: getContent,
  1314. getImage: getImage,
  1315. getIcon: getIcon,
  1316. getIcons: getIcons,
  1317. getCloseButton: getCloseButton,
  1318. getActions: getActions,
  1319. getConfirmButton: getConfirmButton,
  1320. getCancelButton: getCancelButton,
  1321. getHeader: getHeader,
  1322. getFooter: getFooter,
  1323. getFocusableElements: getFocusableElements,
  1324. getValidationMessage: getValidationMessage,
  1325. isLoading: isLoading,
  1326. fire: fire,
  1327. mixin: mixin,
  1328. queue: queue,
  1329. getQueueStep: getQueueStep,
  1330. insertQueueStep: insertQueueStep,
  1331. deleteQueueStep: deleteQueueStep,
  1332. showLoading: showLoading,
  1333. enableLoading: showLoading,
  1334. getTimerLeft: getTimerLeft,
  1335. stopTimer: stopTimer,
  1336. resumeTimer: resumeTimer,
  1337. toggleTimer: toggleTimer,
  1338. increaseTimer: increaseTimer,
  1339. isTimerRunning: isTimerRunning
  1340. });
  1341. /**
  1342. * Enables buttons and hide loader.
  1343. */
  1344. function hideLoading() {
  1345. var innerParams = privateProps.innerParams.get(this);
  1346. var domCache = privateProps.domCache.get(this);
  1347. if (!innerParams.showConfirmButton) {
  1348. hide(domCache.confirmButton);
  1349. if (!innerParams.showCancelButton) {
  1350. hide(domCache.actions);
  1351. }
  1352. }
  1353. removeClass([domCache.popup, domCache.actions], swalClasses.loading);
  1354. domCache.popup.removeAttribute('aria-busy');
  1355. domCache.popup.removeAttribute('data-loading');
  1356. domCache.confirmButton.disabled = false;
  1357. domCache.cancelButton.disabled = false;
  1358. }
  1359. function getInput$1(instance) {
  1360. var innerParams = privateProps.innerParams.get(instance || this);
  1361. var domCache = privateProps.domCache.get(instance || this);
  1362. return getInput(domCache.content, innerParams.input);
  1363. }
  1364. var fixScrollbar = function fixScrollbar() {
  1365. // for queues, do not do this more than once
  1366. if (states.previousBodyPadding !== null) {
  1367. return;
  1368. } // if the body has overflow
  1369. if (document.body.scrollHeight > window.innerHeight) {
  1370. // add padding so the content doesn't shift after removal of scrollbar
  1371. states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'));
  1372. document.body.style.paddingRight = states.previousBodyPadding + measureScrollbar() + 'px';
  1373. }
  1374. };
  1375. var undoScrollbar = function undoScrollbar() {
  1376. if (states.previousBodyPadding !== null) {
  1377. document.body.style.paddingRight = states.previousBodyPadding + 'px';
  1378. states.previousBodyPadding = null;
  1379. }
  1380. };
  1381. /* istanbul ignore next */
  1382. var iOSfix = function iOSfix() {
  1383. var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
  1384. if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
  1385. var offset = document.body.scrollTop;
  1386. document.body.style.top = offset * -1 + 'px';
  1387. addClass(document.body, swalClasses.iosfix);
  1388. lockBodyScroll();
  1389. }
  1390. };
  1391. var lockBodyScroll = function lockBodyScroll() {
  1392. // #1246
  1393. var container = getContainer();
  1394. var preventTouchMove;
  1395. container.ontouchstart = function (e) {
  1396. preventTouchMove = e.target === container || !isScrollable(container) && e.target.tagName !== 'INPUT' // #1603
  1397. ;
  1398. };
  1399. container.ontouchmove = function (e) {
  1400. if (preventTouchMove) {
  1401. e.preventDefault();
  1402. e.stopPropagation();
  1403. }
  1404. };
  1405. };
  1406. /* istanbul ignore next */
  1407. var undoIOSfix = function undoIOSfix() {
  1408. if (hasClass(document.body, swalClasses.iosfix)) {
  1409. var offset = parseInt(document.body.style.top, 10);
  1410. removeClass(document.body, swalClasses.iosfix);
  1411. document.body.style.top = '';
  1412. document.body.scrollTop = offset * -1;
  1413. }
  1414. };
  1415. var isIE11 = function isIE11() {
  1416. return !!window.MSInputMethodContext && !!document.documentMode;
  1417. }; // Fix IE11 centering sweetalert2/issues/933
  1418. /* istanbul ignore next */
  1419. var fixVerticalPositionIE = function fixVerticalPositionIE() {
  1420. var container = getContainer();
  1421. var popup = getPopup();
  1422. container.style.removeProperty('align-items');
  1423. if (popup.offsetTop < 0) {
  1424. container.style.alignItems = 'flex-start';
  1425. }
  1426. };
  1427. /* istanbul ignore next */
  1428. var IEfix = function IEfix() {
  1429. if (typeof window !== 'undefined' && isIE11()) {
  1430. fixVerticalPositionIE();
  1431. window.addEventListener('resize', fixVerticalPositionIE);
  1432. }
  1433. };
  1434. /* istanbul ignore next */
  1435. var undoIEfix = function undoIEfix() {
  1436. if (typeof window !== 'undefined' && isIE11()) {
  1437. window.removeEventListener('resize', fixVerticalPositionIE);
  1438. }
  1439. };
  1440. // Adding aria-hidden="true" to elements outside of the active modal dialog ensures that
  1441. // elements not within the active modal dialog will not be surfaced if a user opens a screen
  1442. // reader’s list of elements (headings, form controls, landmarks, etc.) in the document.
  1443. var setAriaHidden = function setAriaHidden() {
  1444. var bodyChildren = toArray(document.body.children);
  1445. bodyChildren.forEach(function (el) {
  1446. if (el === getContainer() || contains(el, getContainer())) {
  1447. return;
  1448. }
  1449. if (el.hasAttribute('aria-hidden')) {
  1450. el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden'));
  1451. }
  1452. el.setAttribute('aria-hidden', 'true');
  1453. });
  1454. };
  1455. var unsetAriaHidden = function unsetAriaHidden() {
  1456. var bodyChildren = toArray(document.body.children);
  1457. bodyChildren.forEach(function (el) {
  1458. if (el.hasAttribute('data-previous-aria-hidden')) {
  1459. el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden'));
  1460. el.removeAttribute('data-previous-aria-hidden');
  1461. } else {
  1462. el.removeAttribute('aria-hidden');
  1463. }
  1464. });
  1465. };
  1466. /**
  1467. * This module containts `WeakMap`s for each effectively-"private property" that a `Swal` has.
  1468. * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
  1469. * This is the approach that Babel will probably take to implement private methods/fields
  1470. * https://github.com/tc39/proposal-private-methods
  1471. * https://github.com/babel/babel/pull/7555
  1472. * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
  1473. * then we can use that language feature.
  1474. */
  1475. var privateMethods = {
  1476. swalPromiseResolve: new WeakMap()
  1477. };
  1478. /*
  1479. * Instance method to close sweetAlert
  1480. */
  1481. function removePopupAndResetState(container, isToast, onAfterClose) {
  1482. if (isToast) {
  1483. triggerOnAfterClose(onAfterClose);
  1484. } else {
  1485. restoreActiveElement().then(function () {
  1486. return triggerOnAfterClose(onAfterClose);
  1487. });
  1488. globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
  1489. capture: globalState.keydownListenerCapture
  1490. });
  1491. globalState.keydownHandlerAdded = false;
  1492. } // Unset globalState props so GC will dispose globalState (#1569)
  1493. delete globalState.keydownHandler;
  1494. delete globalState.keydownTarget;
  1495. if (container.parentNode) {
  1496. container.parentNode.removeChild(container);
  1497. }
  1498. removeBodyClasses();
  1499. if (isModal()) {
  1500. undoScrollbar();
  1501. undoIOSfix();
  1502. undoIEfix();
  1503. unsetAriaHidden();
  1504. }
  1505. }
  1506. function removeBodyClasses() {
  1507. removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['toast-column']]);
  1508. }
  1509. function swalCloseEventFinished(popup, container, isToast, onAfterClose) {
  1510. if (hasClass(popup, swalClasses.hide)) {
  1511. removePopupAndResetState(container, isToast, onAfterClose);
  1512. } // Unset WeakMaps so GC will be able to dispose them (#1569)
  1513. unsetWeakMaps(privateProps);
  1514. unsetWeakMaps(privateMethods);
  1515. }
  1516. function close(resolveValue) {
  1517. var container = getContainer();
  1518. var popup = getPopup();
  1519. if (!popup || hasClass(popup, swalClasses.hide)) {
  1520. return;
  1521. }
  1522. var innerParams = privateProps.innerParams.get(this);
  1523. var swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
  1524. var onClose = innerParams.onClose;
  1525. var onAfterClose = innerParams.onAfterClose;
  1526. removeClass(popup, swalClasses.show);
  1527. addClass(popup, swalClasses.hide); // If animation is supported, animate
  1528. if (animationEndEvent && hasCssAnimation(popup)) {
  1529. popup.addEventListener(animationEndEvent, function (e) {
  1530. if (e.target === popup) {
  1531. swalCloseEventFinished(popup, container, isToast(), onAfterClose);
  1532. }
  1533. });
  1534. } else {
  1535. // Otherwise, remove immediately
  1536. removePopupAndResetState(container, isToast(), onAfterClose);
  1537. }
  1538. if (onClose !== null && typeof onClose === 'function') {
  1539. onClose(popup);
  1540. } // Resolve Swal promise
  1541. swalPromiseResolve(resolveValue || {}); // Unset this.params so GC will dispose it (#1569)
  1542. delete this.params;
  1543. }
  1544. var unsetWeakMaps = function unsetWeakMaps(obj) {
  1545. for (var i in obj) {
  1546. obj[i] = new WeakMap();
  1547. }
  1548. };
  1549. var triggerOnAfterClose = function triggerOnAfterClose(onAfterClose) {
  1550. if (onAfterClose !== null && typeof onAfterClose === 'function') {
  1551. setTimeout(function () {
  1552. onAfterClose();
  1553. });
  1554. }
  1555. };
  1556. function setButtonsDisabled(instance, buttons, disabled) {
  1557. var domCache = privateProps.domCache.get(instance);
  1558. buttons.forEach(function (button) {
  1559. domCache[button].disabled = disabled;
  1560. });
  1561. }
  1562. function setInputDisabled(input, disabled) {
  1563. if (!input) {
  1564. return false;
  1565. }
  1566. if (input.type === 'radio') {
  1567. var radiosContainer = input.parentNode.parentNode;
  1568. var radios = radiosContainer.querySelectorAll('input');
  1569. for (var i = 0; i < radios.length; i++) {
  1570. radios[i].disabled = disabled;
  1571. }
  1572. } else {
  1573. input.disabled = disabled;
  1574. }
  1575. }
  1576. function enableButtons() {
  1577. setButtonsDisabled(this, ['confirmButton', 'cancelButton'], false);
  1578. }
  1579. function disableButtons() {
  1580. setButtonsDisabled(this, ['confirmButton', 'cancelButton'], true);
  1581. } // @deprecated
  1582. function enableConfirmButton() {
  1583. warnAboutDepreation('Swal.disableConfirmButton()', "Swal.getConfirmButton().removeAttribute('disabled')");
  1584. setButtonsDisabled(this, ['confirmButton'], false);
  1585. } // @deprecated
  1586. function disableConfirmButton() {
  1587. warnAboutDepreation('Swal.enableConfirmButton()', "Swal.getConfirmButton().setAttribute('disabled', '')");
  1588. setButtonsDisabled(this, ['confirmButton'], true);
  1589. }
  1590. function enableInput() {
  1591. return setInputDisabled(this.getInput(), false);
  1592. }
  1593. function disableInput() {
  1594. return setInputDisabled(this.getInput(), true);
  1595. }
  1596. function showValidationMessage(error) {
  1597. var domCache = privateProps.domCache.get(this);
  1598. domCache.validationMessage.innerHTML = error;
  1599. var popupComputedStyle = window.getComputedStyle(domCache.popup);
  1600. domCache.validationMessage.style.marginLeft = "-".concat(popupComputedStyle.getPropertyValue('padding-left'));
  1601. domCache.validationMessage.style.marginRight = "-".concat(popupComputedStyle.getPropertyValue('padding-right'));
  1602. show(domCache.validationMessage);
  1603. var input = this.getInput();
  1604. if (input) {
  1605. input.setAttribute('aria-invalid', true);
  1606. input.setAttribute('aria-describedBy', swalClasses['validation-message']);
  1607. focusInput(input);
  1608. addClass(input, swalClasses.inputerror);
  1609. }
  1610. } // Hide block with validation message
  1611. function resetValidationMessage$1() {
  1612. var domCache = privateProps.domCache.get(this);
  1613. if (domCache.validationMessage) {
  1614. hide(domCache.validationMessage);
  1615. }
  1616. var input = this.getInput();
  1617. if (input) {
  1618. input.removeAttribute('aria-invalid');
  1619. input.removeAttribute('aria-describedBy');
  1620. removeClass(input, swalClasses.inputerror);
  1621. }
  1622. }
  1623. function getProgressSteps$1() {
  1624. warnAboutDepreation('Swal.getProgressSteps()', "const swalInstance = Swal.fire({progressSteps: ['1', '2', '3']}); const progressSteps = swalInstance.params.progressSteps");
  1625. var innerParams = privateProps.innerParams.get(this);
  1626. return innerParams.progressSteps;
  1627. }
  1628. function setProgressSteps(progressSteps) {
  1629. warnAboutDepreation('Swal.setProgressSteps()', 'Swal.update()');
  1630. var innerParams = privateProps.innerParams.get(this);
  1631. var updatedParams = _extends({}, innerParams, {
  1632. progressSteps: progressSteps
  1633. });
  1634. renderProgressSteps(this, updatedParams);
  1635. privateProps.innerParams.set(this, updatedParams);
  1636. }
  1637. function showProgressSteps() {
  1638. var domCache = privateProps.domCache.get(this);
  1639. show(domCache.progressSteps);
  1640. }
  1641. function hideProgressSteps() {
  1642. var domCache = privateProps.domCache.get(this);
  1643. hide(domCache.progressSteps);
  1644. }
  1645. var Timer =
  1646. /*#__PURE__*/
  1647. function () {
  1648. function Timer(callback, delay) {
  1649. _classCallCheck(this, Timer);
  1650. this.callback = callback;
  1651. this.remaining = delay;
  1652. this.running = false;
  1653. this.start();
  1654. }
  1655. _createClass(Timer, [{
  1656. key: "start",
  1657. value: function start() {
  1658. if (!this.running) {
  1659. this.running = true;
  1660. this.started = new Date();
  1661. this.id = setTimeout(this.callback, this.remaining);
  1662. }
  1663. return this.remaining;
  1664. }
  1665. }, {
  1666. key: "stop",
  1667. value: function stop() {
  1668. if (this.running) {
  1669. this.running = false;
  1670. clearTimeout(this.id);
  1671. this.remaining -= new Date() - this.started;
  1672. }
  1673. return this.remaining;
  1674. }
  1675. }, {
  1676. key: "increase",
  1677. value: function increase(n) {
  1678. var running = this.running;
  1679. if (running) {
  1680. this.stop();
  1681. }
  1682. this.remaining += n;
  1683. if (running) {
  1684. this.start();
  1685. }
  1686. return this.remaining;
  1687. }
  1688. }, {
  1689. key: "getTimerLeft",
  1690. value: function getTimerLeft() {
  1691. if (this.running) {
  1692. this.stop();
  1693. this.start();
  1694. }
  1695. return this.remaining;
  1696. }
  1697. }, {
  1698. key: "isRunning",
  1699. value: function isRunning() {
  1700. return this.running;
  1701. }
  1702. }]);
  1703. return Timer;
  1704. }();
  1705. var defaultInputValidators = {
  1706. email: function email(string, validationMessage) {
  1707. 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');
  1708. },
  1709. url: function url(string, validationMessage) {
  1710. // taken from https://stackoverflow.com/a/3809435 with a small change from #1306
  1711. 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');
  1712. }
  1713. };
  1714. /**
  1715. * Set type, text and actions on popup
  1716. *
  1717. * @param params
  1718. * @returns {boolean}
  1719. */
  1720. function setParameters(params) {
  1721. // Use default `inputValidator` for supported input types if not provided
  1722. if (!params.inputValidator) {
  1723. Object.keys(defaultInputValidators).forEach(function (key) {
  1724. if (params.input === key) {
  1725. params.inputValidator = defaultInputValidators[key];
  1726. }
  1727. });
  1728. } // showLoaderOnConfirm && preConfirm
  1729. if (params.showLoaderOnConfirm && !params.preConfirm) {
  1730. 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');
  1731. } // params.animation will be actually used in renderPopup.js
  1732. // but in case when params.animation is a function, we need to call that function
  1733. // before popup (re)initialization, so it'll be possible to check Swal.isVisible()
  1734. // inside the params.animation function
  1735. params.animation = callIfFunction(params.animation); // Determine if the custom target element is valid
  1736. if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) {
  1737. warn('Target parameter is not valid, defaulting to "body"');
  1738. params.target = 'body';
  1739. } // Replace newlines with <br> in title
  1740. if (typeof params.title === 'string') {
  1741. params.title = params.title.split('\n').join('<br />');
  1742. }
  1743. var oldPopup = getPopup();
  1744. var targetElement = typeof params.target === 'string' ? document.querySelector(params.target) : params.target;
  1745. if (!oldPopup || // If the model target has changed, refresh the popup
  1746. oldPopup && targetElement && oldPopup.parentNode !== targetElement.parentNode) {
  1747. init(params);
  1748. }
  1749. }
  1750. function swalOpenAnimationFinished(popup, container) {
  1751. popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished);
  1752. container.style.overflowY = 'auto';
  1753. }
  1754. /**
  1755. * Open popup, add necessary classes and styles, fix scrollbar
  1756. *
  1757. * @param {Array} params
  1758. */
  1759. var openPopup = function openPopup(params) {
  1760. var container = getContainer();
  1761. var popup = getPopup();
  1762. if (params.onBeforeOpen !== null && typeof params.onBeforeOpen === 'function') {
  1763. params.onBeforeOpen(popup);
  1764. }
  1765. if (params.animation) {
  1766. addClass(popup, swalClasses.show);
  1767. addClass(container, swalClasses.fade);
  1768. }
  1769. show(popup); // scrolling is 'hidden' until animation is done, after that 'auto'
  1770. if (animationEndEvent && hasCssAnimation(popup)) {
  1771. container.style.overflowY = 'hidden';
  1772. popup.addEventListener(animationEndEvent, swalOpenAnimationFinished.bind(null, popup, container));
  1773. } else {
  1774. container.style.overflowY = 'auto';
  1775. }
  1776. addClass([document.documentElement, document.body, container], swalClasses.shown);
  1777. if (params.heightAuto && params.backdrop && !params.toast) {
  1778. addClass([document.documentElement, document.body], swalClasses['height-auto']);
  1779. }
  1780. if (isModal()) {
  1781. if (params.scrollbarPadding) {
  1782. fixScrollbar();
  1783. }
  1784. iOSfix();
  1785. IEfix();
  1786. setAriaHidden(); // sweetalert2/issues/1247
  1787. setTimeout(function () {
  1788. container.scrollTop = 0;
  1789. });
  1790. }
  1791. if (!isToast() && !globalState.previousActiveElement) {
  1792. globalState.previousActiveElement = document.activeElement;
  1793. }
  1794. if (params.onOpen !== null && typeof params.onOpen === 'function') {
  1795. setTimeout(function () {
  1796. params.onOpen(popup);
  1797. });
  1798. }
  1799. };
  1800. var _this = undefined;
  1801. var handleInputOptions = function handleInputOptions(instance, params) {
  1802. var content = getContent();
  1803. var processInputOptions = function processInputOptions(inputOptions) {
  1804. return populateInputOptions[params.input](content, formatInputOptions(inputOptions), params);
  1805. };
  1806. if (isPromise(params.inputOptions)) {
  1807. showLoading();
  1808. params.inputOptions.then(function (inputOptions) {
  1809. instance.hideLoading();
  1810. processInputOptions(inputOptions);
  1811. });
  1812. } else if (_typeof(params.inputOptions) === 'object') {
  1813. processInputOptions(params.inputOptions);
  1814. } else {
  1815. error("Unexpected type of inputOptions! Expected object, Map or Promise, got ".concat(_typeof(params.inputOptions)));
  1816. }
  1817. };
  1818. var handleInputValue = function handleInputValue(instance, params) {
  1819. var input = instance.getInput();
  1820. hide(input);
  1821. params.inputValue.then(function (inputValue) {
  1822. input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : inputValue + '';
  1823. show(input);
  1824. input.focus();
  1825. instance.hideLoading();
  1826. })["catch"](function (err) {
  1827. error('Error in inputValue promise: ' + err);
  1828. input.value = '';
  1829. show(input);
  1830. input.focus();
  1831. _this.hideLoading();
  1832. });
  1833. };
  1834. var populateInputOptions = {
  1835. select: function select(content, inputOptions, params) {
  1836. var select = getChildByClass(content, swalClasses.select);
  1837. inputOptions.forEach(function (inputOption) {
  1838. var optionValue = inputOption[0];
  1839. var optionLabel = inputOption[1];
  1840. var option = document.createElement('option');
  1841. option.value = optionValue;
  1842. option.innerHTML = optionLabel;
  1843. if (params.inputValue.toString() === optionValue.toString()) {
  1844. option.selected = true;
  1845. }
  1846. select.appendChild(option);
  1847. });
  1848. select.focus();
  1849. },
  1850. radio: function radio(content, inputOptions, params) {
  1851. var radio = getChildByClass(content, swalClasses.radio);
  1852. inputOptions.forEach(function (inputOption) {
  1853. var radioValue = inputOption[0];
  1854. var radioLabel = inputOption[1];
  1855. var radioInput = document.createElement('input');
  1856. var radioLabelElement = document.createElement('label');
  1857. radioInput.type = 'radio';
  1858. radioInput.name = swalClasses.radio;
  1859. radioInput.value = radioValue;
  1860. if (params.inputValue.toString() === radioValue.toString()) {
  1861. radioInput.checked = true;
  1862. }
  1863. var label = document.createElement('span');
  1864. label.innerHTML = radioLabel;
  1865. label.className = swalClasses.label;
  1866. radioLabelElement.appendChild(radioInput);
  1867. radioLabelElement.appendChild(label);
  1868. radio.appendChild(radioLabelElement);
  1869. });
  1870. var radios = radio.querySelectorAll('input');
  1871. if (radios.length) {
  1872. radios[0].focus();
  1873. }
  1874. }
  1875. /**
  1876. * Converts `inputOptions` into an array of `[value, label]`s
  1877. * @param inputOptions
  1878. */
  1879. };
  1880. var formatInputOptions = function formatInputOptions(inputOptions) {
  1881. var result = [];
  1882. if (typeof Map !== 'undefined' && inputOptions instanceof Map) {
  1883. inputOptions.forEach(function (value, key) {
  1884. result.push([key, value]);
  1885. });
  1886. } else {
  1887. Object.keys(inputOptions).forEach(function (key) {
  1888. result.push([key, inputOptions[key]]);
  1889. });
  1890. }
  1891. return result;
  1892. };
  1893. function _main(userParams) {
  1894. var _this = this;
  1895. showWarningsForParams(userParams);
  1896. var innerParams = _extends({}, defaultParams, userParams);
  1897. setParameters(innerParams);
  1898. Object.freeze(innerParams); // clear the previous timer
  1899. if (globalState.timeout) {
  1900. globalState.timeout.stop();
  1901. delete globalState.timeout;
  1902. } // clear the restore focus timeout
  1903. clearTimeout(globalState.restoreFocusTimeout);
  1904. var domCache = {
  1905. popup: getPopup(),
  1906. container: getContainer(),
  1907. content: getContent(),
  1908. actions: getActions(),
  1909. confirmButton: getConfirmButton(),
  1910. cancelButton: getCancelButton(),
  1911. closeButton: getCloseButton(),
  1912. validationMessage: getValidationMessage(),
  1913. progressSteps: getProgressSteps()
  1914. };
  1915. privateProps.domCache.set(this, domCache);
  1916. render(this, innerParams);
  1917. privateProps.innerParams.set(this, innerParams);
  1918. var constructor = this.constructor;
  1919. return new Promise(function (resolve) {
  1920. // functions to handle all closings/dismissals
  1921. var succeedWith = function succeedWith(value) {
  1922. _this.closePopup({
  1923. value: value
  1924. });
  1925. };
  1926. var dismissWith = function dismissWith(dismiss) {
  1927. _this.closePopup({
  1928. dismiss: dismiss
  1929. });
  1930. };
  1931. privateMethods.swalPromiseResolve.set(_this, resolve); // Close on timer
  1932. if (innerParams.timer) {
  1933. globalState.timeout = new Timer(function () {
  1934. dismissWith('timer');
  1935. delete globalState.timeout;
  1936. }, innerParams.timer);
  1937. } // Get the value of the popup input
  1938. var getInputValue = function getInputValue() {
  1939. var input = _this.getInput();
  1940. if (!input) {
  1941. return null;
  1942. }
  1943. switch (innerParams.input) {
  1944. case 'checkbox':
  1945. return input.checked ? 1 : 0;
  1946. case 'radio':
  1947. return input.checked ? input.value : null;
  1948. case 'file':
  1949. return input.files.length ? input.files[0] : null;
  1950. default:
  1951. return innerParams.inputAutoTrim ? input.value.trim() : input.value;
  1952. }
  1953. }; // input autofocus
  1954. if (innerParams.input) {
  1955. setTimeout(function () {
  1956. var input = _this.getInput();
  1957. if (input) {
  1958. focusInput(input);
  1959. }
  1960. }, 0);
  1961. }
  1962. var confirm = function confirm(value) {
  1963. if (innerParams.showLoaderOnConfirm) {
  1964. constructor.showLoading(); // TODO: make showLoading an *instance* method
  1965. }
  1966. if (innerParams.preConfirm) {
  1967. _this.resetValidationMessage();
  1968. var preConfirmPromise = Promise.resolve().then(function () {
  1969. return innerParams.preConfirm(value, innerParams.validationMessage);
  1970. });
  1971. preConfirmPromise.then(function (preConfirmValue) {
  1972. if (isVisible(domCache.validationMessage) || preConfirmValue === false) {
  1973. _this.hideLoading();
  1974. } else {
  1975. succeedWith(typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
  1976. }
  1977. });
  1978. } else {
  1979. succeedWith(value);
  1980. }
  1981. }; // Mouse interactions
  1982. var onButtonEvent = function onButtonEvent(e) {
  1983. var target = e.target;
  1984. var confirmButton = domCache.confirmButton,
  1985. cancelButton = domCache.cancelButton;
  1986. var targetedConfirm = confirmButton && (confirmButton === target || confirmButton.contains(target));
  1987. var targetedCancel = cancelButton && (cancelButton === target || cancelButton.contains(target));
  1988. switch (e.type) {
  1989. case 'click':
  1990. // Clicked 'confirm'
  1991. if (targetedConfirm) {
  1992. _this.disableButtons();
  1993. if (innerParams.input) {
  1994. var inputValue = getInputValue();
  1995. if (innerParams.inputValidator) {
  1996. _this.disableInput();
  1997. var validationPromise = Promise.resolve().then(function () {
  1998. return innerParams.inputValidator(inputValue, innerParams.validationMessage);
  1999. });
  2000. validationPromise.then(function (validationMessage) {
  2001. _this.enableButtons();
  2002. _this.enableInput();
  2003. if (validationMessage) {
  2004. _this.showValidationMessage(validationMessage);
  2005. } else {
  2006. confirm(inputValue);
  2007. }
  2008. });
  2009. } else if (!_this.getInput().checkValidity()) {
  2010. _this.enableButtons();
  2011. _this.showValidationMessage(innerParams.validationMessage);
  2012. } else {
  2013. confirm(inputValue);
  2014. }
  2015. } else {
  2016. confirm(true);
  2017. } // Clicked 'cancel'
  2018. } else if (targetedCancel) {
  2019. _this.disableButtons();
  2020. dismissWith(constructor.DismissReason.cancel);
  2021. }
  2022. break;
  2023. default:
  2024. }
  2025. };
  2026. var buttons = domCache.popup.querySelectorAll('button');
  2027. for (var i = 0; i < buttons.length; i++) {
  2028. buttons[i].onclick = onButtonEvent;
  2029. buttons[i].onmouseover = onButtonEvent;
  2030. buttons[i].onmouseout = onButtonEvent;
  2031. buttons[i].onmousedown = onButtonEvent;
  2032. } // Closing popup by close button
  2033. domCache.closeButton.onclick = function () {
  2034. dismissWith(constructor.DismissReason.close);
  2035. };
  2036. if (innerParams.toast) {
  2037. // Closing popup by internal click
  2038. domCache.popup.onclick = function () {
  2039. if (innerParams.showConfirmButton || innerParams.showCancelButton || innerParams.showCloseButton || innerParams.input) {
  2040. return;
  2041. }
  2042. dismissWith(constructor.DismissReason.close);
  2043. };
  2044. } else {
  2045. var ignoreOutsideClick = false; // Ignore click events that had mousedown on the popup but mouseup on the container
  2046. // This can happen when the user drags a slider
  2047. domCache.popup.onmousedown = function () {
  2048. domCache.container.onmouseup = function (e) {
  2049. domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't
  2050. // have any other direct children aside of the popup
  2051. if (e.target === domCache.container) {
  2052. ignoreOutsideClick = true;
  2053. }
  2054. };
  2055. }; // Ignore click events that had mousedown on the container but mouseup on the popup
  2056. domCache.container.onmousedown = function () {
  2057. domCache.popup.onmouseup = function (e) {
  2058. domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup
  2059. if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
  2060. ignoreOutsideClick = true;
  2061. }
  2062. };
  2063. };
  2064. domCache.container.onclick = function (e) {
  2065. if (ignoreOutsideClick) {
  2066. ignoreOutsideClick = false;
  2067. return;
  2068. }
  2069. if (e.target !== domCache.container) {
  2070. return;
  2071. }
  2072. if (callIfFunction(innerParams.allowOutsideClick)) {
  2073. dismissWith(constructor.DismissReason.backdrop);
  2074. }
  2075. };
  2076. } // Reverse buttons (Confirm on the right side)
  2077. if (innerParams.reverseButtons) {
  2078. domCache.confirmButton.parentNode.insertBefore(domCache.cancelButton, domCache.confirmButton);
  2079. } else {
  2080. domCache.confirmButton.parentNode.insertBefore(domCache.confirmButton, domCache.cancelButton);
  2081. } // Focus handling
  2082. var setFocus = function setFocus(index, increment) {
  2083. var focusableElements = getFocusableElements(innerParams.focusCancel); // search for visible elements and select the next possible match
  2084. for (var _i = 0; _i < focusableElements.length; _i++) {
  2085. index = index + increment; // rollover to first item
  2086. if (index === focusableElements.length) {
  2087. index = 0; // go to last item
  2088. } else if (index === -1) {
  2089. index = focusableElements.length - 1;
  2090. }
  2091. return focusableElements[index].focus();
  2092. } // no visible focusable elements, focus the popup
  2093. domCache.popup.focus();
  2094. };
  2095. var keydownHandler = function keydownHandler(e, innerParams) {
  2096. if (innerParams.stopKeydownPropagation) {
  2097. e.stopPropagation();
  2098. }
  2099. var arrowKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Left', 'Right', 'Up', 'Down' // IE11
  2100. ];
  2101. if (e.key === 'Enter' && !e.isComposing) {
  2102. if (e.target && _this.getInput() && e.target.outerHTML === _this.getInput().outerHTML) {
  2103. if (['textarea', 'file'].indexOf(innerParams.input) !== -1) {
  2104. return; // do not submit
  2105. }
  2106. constructor.clickConfirm();
  2107. e.preventDefault();
  2108. } // TAB
  2109. } else if (e.key === 'Tab') {
  2110. var targetElement = e.target;
  2111. var focusableElements = getFocusableElements(innerParams.focusCancel);
  2112. var btnIndex = -1;
  2113. for (var _i2 = 0; _i2 < focusableElements.length; _i2++) {
  2114. if (targetElement === focusableElements[_i2]) {
  2115. btnIndex = _i2;
  2116. break;
  2117. }
  2118. }
  2119. if (!e.shiftKey) {
  2120. // Cycle to the next button
  2121. setFocus(btnIndex, 1);
  2122. } else {
  2123. // Cycle to the prev button
  2124. setFocus(btnIndex, -1);
  2125. }
  2126. e.stopPropagation();
  2127. e.preventDefault(); // ARROWS - switch focus between buttons
  2128. } else if (arrowKeys.indexOf(e.key) !== -1) {
  2129. // focus Cancel button if Confirm button is currently focused
  2130. if (document.activeElement === domCache.confirmButton && isVisible(domCache.cancelButton)) {
  2131. domCache.cancelButton.focus(); // and vice versa
  2132. } else if (document.activeElement === domCache.cancelButton && isVisible(domCache.confirmButton)) {
  2133. domCache.confirmButton.focus();
  2134. } // ESC
  2135. } else if ((e.key === 'Escape' || e.key === 'Esc') && callIfFunction(innerParams.allowEscapeKey) === true) {
  2136. e.preventDefault();
  2137. dismissWith(constructor.DismissReason.esc);
  2138. }
  2139. };
  2140. if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
  2141. globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
  2142. capture: globalState.keydownListenerCapture
  2143. });
  2144. globalState.keydownHandlerAdded = false;
  2145. }
  2146. if (!innerParams.toast) {
  2147. globalState.keydownHandler = function (e) {
  2148. return keydownHandler(e, innerParams);
  2149. };
  2150. globalState.keydownTarget = innerParams.keydownListenerCapture ? window : domCache.popup;
  2151. globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
  2152. globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
  2153. capture: globalState.keydownListenerCapture
  2154. });
  2155. globalState.keydownHandlerAdded = true;
  2156. }
  2157. _this.enableButtons();
  2158. _this.hideLoading();
  2159. _this.resetValidationMessage();
  2160. if (innerParams.toast && (innerParams.input || innerParams.footer || innerParams.showCloseButton)) {
  2161. addClass(document.body, swalClasses['toast-column']);
  2162. } else {
  2163. removeClass(document.body, swalClasses['toast-column']);
  2164. } // inputOptions, inputValue
  2165. if (innerParams.input === 'select' || innerParams.input === 'radio') {
  2166. handleInputOptions(_this, innerParams);
  2167. } else if (['text', 'email', 'number', 'tel', 'textarea'].indexOf(innerParams.input) !== -1 && isPromise(innerParams.inputValue)) {
  2168. handleInputValue(_this, innerParams);
  2169. }
  2170. openPopup(innerParams);
  2171. if (!innerParams.toast) {
  2172. if (!callIfFunction(innerParams.allowEnterKey)) {
  2173. if (document.activeElement && typeof document.activeElement.blur === 'function') {
  2174. document.activeElement.blur();
  2175. }
  2176. } else if (innerParams.focusCancel && isVisible(domCache.cancelButton)) {
  2177. domCache.cancelButton.focus();
  2178. } else if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) {
  2179. domCache.confirmButton.focus();
  2180. } else {
  2181. setFocus(-1, 1);
  2182. }
  2183. } // fix scroll
  2184. domCache.container.scrollTop = 0;
  2185. });
  2186. }
  2187. /**
  2188. * Updates popup parameters.
  2189. */
  2190. function update(params) {
  2191. var validUpdatableParams = {}; // assign valid params from `params` to `defaults`
  2192. Object.keys(params).forEach(function (param) {
  2193. if (Swal.isUpdatableParameter(param)) {
  2194. validUpdatableParams[param] = params[param];
  2195. } else {
  2196. warn("Invalid parameter to update: \"".concat(param, "\". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js"));
  2197. }
  2198. });
  2199. var innerParams = privateProps.innerParams.get(this);
  2200. var updatedParams = _extends({}, innerParams, validUpdatableParams);
  2201. render(this, updatedParams);
  2202. privateProps.innerParams.set(this, updatedParams);
  2203. Object.defineProperties(this, {
  2204. params: {
  2205. value: _extends({}, this.params, params),
  2206. writable: false,
  2207. enumerable: true
  2208. }
  2209. });
  2210. }
  2211. var instanceMethods = Object.freeze({
  2212. hideLoading: hideLoading,
  2213. disableLoading: hideLoading,
  2214. getInput: getInput$1,
  2215. close: close,
  2216. closePopup: close,
  2217. closeModal: close,
  2218. closeToast: close,
  2219. enableButtons: enableButtons,
  2220. disableButtons: disableButtons,
  2221. enableConfirmButton: enableConfirmButton,
  2222. disableConfirmButton: disableConfirmButton,
  2223. enableInput: enableInput,
  2224. disableInput: disableInput,
  2225. showValidationMessage: showValidationMessage,
  2226. resetValidationMessage: resetValidationMessage$1,
  2227. getProgressSteps: getProgressSteps$1,
  2228. setProgressSteps: setProgressSteps,
  2229. showProgressSteps: showProgressSteps,
  2230. hideProgressSteps: hideProgressSteps,
  2231. _main: _main,
  2232. update: update
  2233. });
  2234. var currentInstance; // SweetAlert constructor
  2235. function SweetAlert() {
  2236. // Prevent run in Node env
  2237. /* istanbul ignore if */
  2238. if (typeof window === 'undefined') {
  2239. return;
  2240. } // Check for the existence of Promise
  2241. /* istanbul ignore if */
  2242. if (typeof Promise === 'undefined') {
  2243. 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)');
  2244. }
  2245. currentInstance = this;
  2246. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2247. args[_key] = arguments[_key];
  2248. }
  2249. var outerParams = Object.freeze(this.constructor.argsToParams(args));
  2250. Object.defineProperties(this, {
  2251. params: {
  2252. value: outerParams,
  2253. writable: false,
  2254. enumerable: true,
  2255. configurable: true
  2256. }
  2257. });
  2258. var promise = this._main(this.params);
  2259. privateProps.promise.set(this, promise);
  2260. } // `catch` cannot be the name of a module export, so we define our thenable methods here instead
  2261. SweetAlert.prototype.then = function (onFulfilled) {
  2262. var promise = privateProps.promise.get(this);
  2263. return promise.then(onFulfilled);
  2264. };
  2265. SweetAlert.prototype["finally"] = function (onFinally) {
  2266. var promise = privateProps.promise.get(this);
  2267. return promise["finally"](onFinally);
  2268. }; // Assign instance methods from src/instanceMethods/*.js to prototype
  2269. _extends(SweetAlert.prototype, instanceMethods); // Assign static methods from src/staticMethods/*.js to constructor
  2270. _extends(SweetAlert, staticMethods); // Proxy to instance methods to constructor, for now, for backwards compatibility
  2271. Object.keys(instanceMethods).forEach(function (key) {
  2272. SweetAlert[key] = function () {
  2273. if (currentInstance) {
  2274. var _currentInstance;
  2275. return (_currentInstance = currentInstance)[key].apply(_currentInstance, arguments);
  2276. }
  2277. };
  2278. });
  2279. SweetAlert.DismissReason = DismissReason;
  2280. SweetAlert.version = '8.12.1';
  2281. var Swal = SweetAlert;
  2282. Swal["default"] = Swal;
  2283. return Swal;
  2284. })));
  2285. if (typeof this !== 'undefined' && this.Sweetalert2){ this.swal = this.sweetAlert = this.Swal = this.SweetAlert = this.Sweetalert2}