(function(global,factory){typeof exports==='object'&&typeof module!=='undefined'?module.exports=factory():typeof define==='function'&&define.amd?define(factory):(global.Sweetalert2=factory())}(this,(function(){'use strict';var defaultParams={title:'',titleText:'',text:'',html:'',type:null,customClass:'',target:'body',animation:!0,allowOutsideClick:!1,allowEscapeKey:!1,allowEnterKey:!0,showConfirmButton:!0,showCancelButton:!1,preConfirm:null,confirmButtonText:'OK',confirmButtonColor:'#3085d6',confirmButtonClass:null,cancelButtonText:'Cancel',cancelButtonColor:'#aaa',cancelButtonClass:null,buttonsStyling:!0,reverseButtons:!1,focusCancel:!1,showCloseButton:!1,showLoaderOnConfirm:!1,imageUrl:null,imageWidth:null,imageHeight:null,imageClass:null,timer:null,width:500,padding:20,background:'#fff',input:null,inputPlaceholder:'',inputValue:'',inputOptions:{},inputAutoTrim:!0,inputClass:null,inputAttributes:{},inputValidator:null,progressSteps:[],currentProgressStep:null,progressStepsDistance:'40px',onOpen:null,onClose:null};var swalPrefix='swal2-';var prefix=function prefix(items){var result={};for(var i in items){result[items[i]]=swalPrefix+items[i]} return result};var swalClasses=prefix(['container','shown','iosfix','modal','overlay','fade','show','hide','noanimation','close','title','content','buttonswrapper','confirm','cancel','icon','image','input','file','range','select','radio','checkbox','textarea','inputerror','validationerror','progresssteps','activeprogressstep','progresscircle','progressline','loading','styled']);var iconTypes=prefix(['success','warning','info','question','error']);var colorLuminance=function colorLuminance(hex,lum){hex=String(hex).replace(/[^0-9a-f]/gi,'');if(hex.length<6){hex=hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2]} lum=lum||0;var rgb='#';for(var i=0;i<3;i++){var c=parseInt(hex.substr(i*2,2),16);c=Math.round(Math.min(Math.max(0,c+c*lum),255)).toString(16);rgb+=('00'+c).substr(c.length)} return rgb};var uniqueArray=function uniqueArray(arr){var result=[];for(var i in arr){if(result.indexOf(arr[i])===-1){result.push(arr[i])}} return result};var states={previousWindowKeyDown:null,previousActiveElement:null,previousBodyPadding:null};var init=function init(params){if(typeof document==='undefined'){console.error('SweetAlert2 requires document to initialize');return} var container=document.createElement('div');container.className=swalClasses.container;container.innerHTML=sweetHTML;var targetElement=document.querySelector(params.target);if(!targetElement){console.warn('SweetAlert2: Can\'t find the target "'+params.target+'"');targetElement=document.body} targetElement.appendChild(container);var modal=getModal();var input=getChildByClass(modal,swalClasses.input);var file=getChildByClass(modal,swalClasses.file);var range=modal.querySelector('.'+swalClasses.range+' input');var rangeOutput=modal.querySelector('.'+swalClasses.range+' output');var select=getChildByClass(modal,swalClasses.select);var checkbox=modal.querySelector('.'+swalClasses.checkbox+' input');var textarea=getChildByClass(modal,swalClasses.textarea);input.oninput=function(){sweetAlert.resetValidationError()};input.onkeydown=function(event){setTimeout(function(){if(event.keyCode===13&¶ms.allowEnterKey){event.stopPropagation();sweetAlert.clickConfirm()}},0)};file.onchange=function(){sweetAlert.resetValidationError()};range.oninput=function(){sweetAlert.resetValidationError();rangeOutput.value=range.value};range.onchange=function(){sweetAlert.resetValidationError();range.previousSibling.value=range.value};select.onchange=function(){sweetAlert.resetValidationError()};checkbox.onchange=function(){sweetAlert.resetValidationError()};textarea.oninput=function(){sweetAlert.resetValidationError()};return modal};var sweetHTML=('\n \n').replace(/(^|\n)\s*/g,'');var getContainer=function getContainer(){return document.body.querySelector('.'+swalClasses.container)};var getModal=function getModal(){return getContainer()?getContainer().querySelector('.'+swalClasses.modal):null};var getIcons=function getIcons(){var modal=getModal();return modal.querySelectorAll('.'+swalClasses.icon)};var elementByClass=function elementByClass(className){return getContainer()?getContainer().querySelector('.'+className):null};var getTitle=function getTitle(){return elementByClass(swalClasses.title)};var getContent=function getContent(){return elementByClass(swalClasses.content)};var getImage=function getImage(){return elementByClass(swalClasses.image)};var getButtonsWrapper=function getButtonsWrapper(){return elementByClass(swalClasses.buttonswrapper)};var getProgressSteps=function getProgressSteps(){return elementByClass(swalClasses.progresssteps)};var getValidationError=function getValidationError(){return elementByClass(swalClasses.validationerror)};var getConfirmButton=function getConfirmButton(){return elementByClass(swalClasses.confirm)};var getCancelButton=function getCancelButton(){return elementByClass(swalClasses.cancel)};var getCloseButton=function getCloseButton(){return elementByClass(swalClasses.close)};var getFocusableElements=function getFocusableElements(focusCancel){var buttons=[getConfirmButton(),getCancelButton()];if(focusCancel){buttons.reverse()} var focusableElements=buttons.concat(Array.prototype.slice.call(getModal().querySelectorAll('button, input:not([type=hidden]), textarea, select, a, *[tabindex]:not([tabindex="-1"])')));return uniqueArray(focusableElements)};var hasClass=function hasClass(elem,className){if(elem.classList){return elem.classList.contains(className)} return!1};var focusInput=function focusInput(input){input.focus();if(input.type!=='file'){var val=input.value;input.value='';input.value=val}};var addClass=function addClass(elem,className){if(!elem||!className){return} var classes=className.split(/\s+/).filter(Boolean);classes.forEach(function(className){elem.classList.add(className)})};var removeClass=function removeClass(elem,className){if(!elem||!className){return} var classes=className.split(/\s+/).filter(Boolean);classes.forEach(function(className){elem.classList.remove(className)})};var getChildByClass=function getChildByClass(elem,className){for(var i=0;i')} if(params.text||params.html){if(_typeof(params.html)==='object'){content.innerHTML='';if(0 in params.html){for(var _i=0;_i in params.html;_i++){content.appendChild(params.html[_i].cloneNode(!0))}}else{content.appendChild(params.html.cloneNode(!0))}}else if(params.html){content.innerHTML=params.html}else if(params.text){content.textContent=params.text} show(content)}else{hide(content)} if(params.showCloseButton){show(closeButton)}else{hide(closeButton)} modal.className=swalClasses.modal;if(params.customClass){addClass(modal,params.customClass)} var progressStepsContainer=getProgressSteps();var currentProgressStep=parseInt(params.currentProgressStep===null?sweetAlert.getQueueStep():params.currentProgressStep,10);if(params.progressSteps.length){show(progressStepsContainer);empty(progressStepsContainer);if(currentProgressStep>=params.progressSteps.length){console.warn('SweetAlert2: Invalid currentProgressStep parameter, it should be less than progressSteps.length '+'(currentProgressStep like JS arrays starts from 0)')} params.progressSteps.forEach(function(step,index){var circle=document.createElement('li');addClass(circle,swalClasses.progresscircle);circle.innerHTML=step;if(index===currentProgressStep){addClass(circle,swalClasses.activeprogressstep)} progressStepsContainer.appendChild(circle);if(index!==params.progressSteps.length-1){var line=document.createElement('li');addClass(line,swalClasses.progressline);line.style.width=params.progressStepsDistance;progressStepsContainer.appendChild(line)}})}else{hide(progressStepsContainer)} var icons=getIcons();for(var _i2=0;_i2window.innerHeight){states.previousBodyPadding=document.body.style.paddingRight;document.body.style.paddingRight=measureScrollbar()+'px'}};var undoScrollbar=function undoScrollbar(){if(states.previousBodyPadding!==null){document.body.style.paddingRight=states.previousBodyPadding;states.previousBodyPadding=null}};var iOSfix=function iOSfix(){var iOS=/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;if(iOS&&!hasClass(document.body,swalClasses.iosfix)){var offset=document.body.scrollTop;document.body.style.top=offset*-1+'px';addClass(document.body,swalClasses.iosfix)}};var undoIOSfix=function undoIOSfix(){if(hasClass(document.body,swalClasses.iosfix)){var offset=parseInt(document.body.style.top,10);removeClass(document.body,swalClasses.iosfix);document.body.style.top='';document.body.scrollTop=offset*-1}};var sweetAlert=function sweetAlert(){for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]} if(args[0]===undefined){console.error('SweetAlert2 expects at least 1 attribute!');return!1} var params=_extends({},modalParams);switch(_typeof(args[0])){case 'string':params.title=args[0];params.html=args[1];params.type=args[2];break;case 'object':_extends(params,args[0]);params.extraParams=args[0].extraParams;if(params.input==='email'&¶ms.inputValidator===null){params.inputValidator=function(email){return new Promise(function(resolve,reject){var emailRegex=/^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;if(emailRegex.test(email)){resolve()}else{reject('Invalid email address')}})}} if(params.input==='url'&¶ms.inputValidator===null){params.inputValidator=function(url){return new Promise(function(resolve,reject){var urlRegex=/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/;if(urlRegex.test(url)){resolve()}else{reject('Invalid URL')}})}} break;default:console.error('SweetAlert2: Unexpected type of argument! Expected "string" or "object", got '+_typeof(args[0]));return!1} setParameters(params);var container=getContainer();var modal=getModal();return new Promise(function(resolve,reject){if(params.timer){modal.timeout=setTimeout(function(){sweetAlert.closeModal(params.onClose);reject('timer')},params.timer)} var getInput=function getInput(inputType){inputType=inputType||params.input;if(!inputType){return null} switch(inputType){case 'select':case 'textarea':case 'file':return getChildByClass(modal,swalClasses[inputType]);case 'checkbox':return modal.querySelector('.'+swalClasses.checkbox+' input');case 'radio':return modal.querySelector('.'+swalClasses.radio+' input:checked')||modal.querySelector('.'+swalClasses.radio+' input:first-child');case 'range':return modal.querySelector('.'+swalClasses.range+' input');default:return getChildByClass(modal,swalClasses.input)}};var getInputValue=function getInputValue(){var input=getInput();if(!input){return null} switch(params.input){case 'checkbox':return input.checked?1:0;case 'radio':return input.checked?input.value:null;case 'file':return input.files.length?input.files[0]:null;default:return params.inputAutoTrim?input.value.trim():input.value}};if(params.input){setTimeout(function(){var input=getInput();if(input){focusInput(input)}},0)} var confirm=function confirm(value){if(params.showLoaderOnConfirm){sweetAlert.showLoading()} if(params.preConfirm){params.preConfirm(value,params.extraParams).then(function(preConfirmValue){sweetAlert.closeModal(params.onClose);resolve(preConfirmValue||value)},function(error){sweetAlert.hideLoading();if(error){sweetAlert.showValidationError(error)}})}else{sweetAlert.closeModal(params.onClose);resolve(value)}};var onButtonEvent=function onButtonEvent(event){var e=event||window.event;var target=e.target||e.srcElement;var confirmButton=getConfirmButton();var cancelButton=getCancelButton();var targetedConfirm=confirmButton&&(confirmButton===target||confirmButton.contains(target));var targetedCancel=cancelButton&&(cancelButton===target||cancelButton.contains(target));switch(e.type){case 'mouseover':case 'mouseup':if(params.buttonsStyling){if(targetedConfirm){confirmButton.style.backgroundColor=colorLuminance(params.confirmButtonColor,-0.1)}else if(targetedCancel){cancelButton.style.backgroundColor=colorLuminance(params.cancelButtonColor,-0.1)}} break;case 'mouseout':if(params.buttonsStyling){if(targetedConfirm){confirmButton.style.backgroundColor=params.confirmButtonColor}else if(targetedCancel){cancelButton.style.backgroundColor=params.cancelButtonColor}} break;case 'mousedown':if(params.buttonsStyling){if(targetedConfirm){confirmButton.style.backgroundColor=colorLuminance(params.confirmButtonColor,-0.2)}else if(targetedCancel){cancelButton.style.backgroundColor=colorLuminance(params.cancelButtonColor,-0.2)}} break;case 'click':if(targetedConfirm&&sweetAlert.isVisible()){sweetAlert.disableButtons();if(params.input){var inputValue=getInputValue();if(params.inputValidator){sweetAlert.disableInput();params.inputValidator(inputValue,params.extraParams).then(function(){sweetAlert.enableButtons();sweetAlert.enableInput();confirm(inputValue)},function(error){sweetAlert.enableButtons();sweetAlert.enableInput();if(error){sweetAlert.showValidationError(error)}})}else{confirm(inputValue)}}else{confirm(!0)}}else if(targetedCancel&&sweetAlert.isVisible()){sweetAlert.disableButtons();sweetAlert.closeModal(params.onClose);reject('cancel')} break;default:}};var buttons=modal.querySelectorAll('button');for(var i=0;i