sweetalert2.bundle.js 103 KB

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