/home/mip/mip/public/img/credit/datatables/dev.tar
gulpfile-wrap-template.js000066400000000554151520616460011505 0ustar00;(function(window, document, undefined) {
  "use strict";
  
  <%= contents %>
  
  /*
   * Use SweetAlert with RequireJS
   */
  
  if (typeof define === 'function' && define.amd) {
    define(function () {
      return sweetAlert;
    });
  } else if (typeof module !== 'undefined' && module.exports) {
    module.exports = sweetAlert;
  }

})(window, document);ie9.css000066400000001175151520616460005760 0ustar00/* Internet Explorer 9 has some special quirks that are fixed here */
/* The icons are not animated. */
/* This file is automatically merged into sweet-alert.min.js through Gulp */

/* Error icon */
.sweet-alert .sa-icon.sa-error .sa-line.sa-left {
  -ms-transform: rotate(45deg)\9;
}
.sweet-alert .sa-icon.sa-error .sa-line.sa-right {
  -ms-transform: rotate(-45deg)\9;
}


/* Success icon */
.sweet-alert .sa-icon.sa-success {
  border-color: transparent\9;
}
.sweet-alert .sa-icon.sa-success .sa-line.sa-tip {
  -ms-transform: rotate(45deg)\9;
}
.sweet-alert .sa-icon.sa-success .sa-line.sa-long {
  -ms-transform: rotate(-45deg)\9;
}sweetalert.scss000066400000034640151520616460007637 0ustar00// SweetAlert
// 2014-2015 (c) - Tristan Edwards
// github.com/t4t5/sweetalert


body.stop-scrolling {
  height: 100%;
  overflow: hidden;
}

.sweet-overlay {
  background-color: rgb(0, 0, 0); /* IE8 */
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=40)"; /* IE8 */
  background-color: rgba(black, 0.4);

  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;

  display: none;
  z-index: 10000;
}

.sweet-alert {
  $width: 478px;
  $padding: 17px;

  background-color: white;
  font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  width: $width;
  padding: $padding;
  border-radius: 5px;
  text-align: center;

  position: fixed;
  left: 50%;
  top: 50%;
  margin-left: -($width/2 + $padding);
  margin-top: -200px;

  overflow: hidden;
  display: none;
  z-index: 99999;

  @media all and (max-width: 540px) {
    width: auto;
    margin-left: 0;
    margin-right: 0;

    left: 15px;
    right: 15px;
  }

  h2 {
    color: #575757;
    font-size: 30px;
    text-align: center;
    font-weight: 600;
    text-transform: none;
    position: relative;
    margin: 25px 0;
    padding: 0;
    line-height: 40px;
    display: block;
  }

  p {
    color: #797979;
    font-size: 16px;
    text-align: center;
    font-weight: 300;
    position: relative;
    text-align: inherit;
    float: none;
    margin: 0;
    padding: 0;
    line-height: normal;
  }

  fieldset {
    border: none;
    position: relative;
  }

  .sa-error-container {
    background-color: #f1f1f1;
    margin-left: -17px;
    margin-right: -17px;
    overflow: hidden;
    padding: 0 10px;
    max-height: 0;
    webkit-transition: padding 0.15s, max-height 0.15s;
    transition: padding 0.15s, max-height 0.15s;
    &.show {
      padding: 10px 0;
      max-height: 100px;
      webkit-transition: padding 0.2s, max-height 0.2s;
      transition: padding 0.25s, max-height 0.25s;
    }

    .icon {
      display: inline-block;
      width: 24px;
      height: 24px;
      border-radius: 50%;
      background-color: rgb(234, 125, 125);
      color: white;
      line-height: 24px;
      text-align: center;
      margin-right: 3px;
    }
    p {
      display: inline-block;
    }
  }

  .sa-input-error {
    position: absolute;
    top: 29px;
    right: 26px;
    width: 20px;
    height: 20px;
    opacity: 0;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
    -webkit-transform-origin: 50% 50%;
    transform-origin: 50% 50%;
    -webkit-transition: all 0.1s;
    transition: all 0.1s;
    &::before, &::after {
      content: "";
      width: 20px;
      height: 6px;
      background-color: #f06e57;
      border-radius: 3px;
      position: absolute;
      top: 50%;
      margin-top: -4px;
      left: 50%;
      margin-left: -9px;
    }
    &::before {
      -webkit-transform: rotate(-45deg);
      transform: rotate(-45deg);
    }
    &::after {
      -webkit-transform: rotate(45deg);
      transform: rotate(45deg);
    }
    &.show {
      opacity: 1;
      -webkit-transform: scale(1);
      transform: scale(1);
    }
  }

  input {
    width: 100%;
    box-sizing: border-box;
    border-radius: 3px;
    border: 1px solid rgb(215, 215, 215);
    height: 43px;
    margin-top: 10px;
    margin-bottom: 17px;
    font-size: 18px;
    box-shadow: inset 0px 1px 1px rgba(black, 0.06);
    padding: 0 12px;
    display: none;
    -webkit-transition: all 0.3s;
    transition: all 0.3s;
    &:focus {
      outline: none;
      box-shadow: 0px 0px 3px rgb(196, 230, 245);
      border: 1px solid rgb(180, 219, 237);
      &::-moz-placeholder {
        transition: opacity 0.3s 0.03s ease;
        opacity: 0.5;
      }
      &:-ms-input-placeholder {
        transition: opacity 0.3s 0.03s ease;
        opacity: 0.5;
      }
      &::-webkit-input-placeholder {
        transition: opacity 0.3s 0.03s ease;
        opacity: 0.5;
      }
    }
    &::-moz-placeholder {
      color: lighten(#575757, 40);
    }
    &:-ms-input-placeholder {
      color: lighten(#575757, 40);
    }
    &::-webkit-input-placeholder {
      color: lighten(#575757, 40);
    }
  }
  &.show-input input {
    display: block;
  }

  .sa-confirm-button-container {
    display: inline-block;
    position: relative;
  }

  .la-ball-fall {
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -27px;
    margin-top: 4px;
    opacity: 0;
    visibility: hidden;
  }

  button {
    $btnBlue: #8CD4F5;
    $btnGray: #C1C1C1;

    background-color: $btnBlue;
    color: white;
    border: none;
    box-shadow: none;
    font-size: 17px;
    font-weight: 500;
    -webkit-border-radius: 4px;
    border-radius: 5px;
    padding: 10px 32px;
    margin: 26px 5px 0 5px;
    cursor: pointer;
    &:focus {
      outline: none;
      box-shadow: 0 0 2px rgba(128, 179, 235, 0.5), inset 0 0 0 1px rgba(0, 0, 0, 0.05);
    }
    &:hover {
      background-color: darken($btnBlue, 3%);
    }
    &:active {
      background-color: darken($btnBlue, 10%);
    }
    &.cancel {
      background-color: $btnGray;
      &:hover {
        background-color: darken($btnGray, 3%);
      }
      &:active {
        background-color: darken($btnGray, 10%);
      }
      // Cancel button should keep the same style
      &:focus {
        box-shadow: rgba(197, 205, 211, 0.8) 0px 0px 2px, rgba(0, 0, 0, 0.0470588) 0px 0px 0px 1px inset !important;
      }
    }

    &[disabled] {
      opacity: .6;
      cursor: default;
    }

    &.confirm[disabled] {
      color: transparent;
      ~ .la-ball-fall {
        opacity: 1;
        visibility: visible;
        transition-delay: 0s;
      }
    }

    // Removes selection outline in Firefox
    &::-moz-focus-inner {
      border: 0;
    }
  }

  // Only show focus-style when there is multiple choice of actions
  &[data-has-cancel-button=false] button {
    box-shadow: none !important;
  }

  &[data-has-confirm-button=false][data-has-cancel-button=false] {
    padding-bottom: 40px;
  }

  .sa-icon {
    $red:     #F27474;
    $orange:  #F8BB86;
    $blue:    #C9DAE1;
    $green:   #A5DC86;

    width: 80px;
    height: 80px;
    border: 4px solid gray;
    -webkit-border-radius: 40px;
    border-radius: 40px;
    border-radius: 50%;
    margin: 20px auto;
    padding: 0;
    position: relative;
    box-sizing: content-box;

    &.sa-error {
      border-color: $red;

      .sa-x-mark {
        position: relative;
        display: block;
      }

      .sa-line {
        position: absolute;
        height: 5px;
        width: 47px;
        background-color: $red;
        display: block;
        top: 37px;
        border-radius: 2px;

        &.sa-left {
          -webkit-transform: rotate(45deg);
          transform: rotate(45deg);
          left: 17px;
        }
        &.sa-right {
          -webkit-transform: rotate(-45deg);
          transform: rotate(-45deg);
          right: 16px;
        }
      }
    }
    &.sa-warning {
      border-color: $orange;

      .sa-body { // Exclamation mark body
        position: absolute;
        width: 5px;
        height: 47px;
        left: 50%;
        top: 10px;
        -webkit-border-radius: 2px;
        border-radius: 2px;
        margin-left: -2px;
        background-color: $orange;
      }
      .sa-dot { // Exclamation mark dot
        position: absolute;
        width: 7px;
        height: 7px;
        -webkit-border-radius: 50%;
        border-radius: 50%;
        margin-left: -3px;
        left: 50%;
        bottom: 10px;
        background-color: $orange;
      }
    }
    &.sa-info {
      border-color: $blue;

      &::before { // i-letter body
        content: "";
        position: absolute;
        width: 5px;
        height: 29px;
        left: 50%;
        bottom: 17px;
        border-radius: 2px;
        margin-left: -2px;
        background-color: $blue;
      }
      &::after { // i-letter dot
        content: "";
        position: absolute;
        width: 7px;
        height: 7px;
        border-radius: 50%;
        margin-left: -3px;
        top: 19px;
        background-color: $blue;
      }
    }
    &.sa-success {
      border-color: $green;

      &::before, &::after { // Emulate moving circular line
        content: '';
        -webkit-border-radius: 40px;
        border-radius: 40px;
        border-radius: 50%;
        position: absolute;
        width: 60px;
        height: 120px;
        background: white;
        -webkit-transform: rotate(45deg);
        transform: rotate(45deg);
      }
      &::before {
        -webkit-border-radius: 120px 0 0 120px;
        border-radius: 120px 0 0 120px;
        top: -7px;
        left: -33px;

         -webkit-transform: rotate(-45deg);
        transform: rotate(-45deg);
        -webkit-transform-origin: 60px 60px;
        transform-origin: 60px 60px;
      }
      &::after {
        -webkit-border-radius: 0 120px 120px 0;
        border-radius: 0 120px 120px 0;
        top: -11px;
        left: 30px;

        -webkit-transform: rotate(-45deg);
        transform: rotate(-45deg);
        -webkit-transform-origin: 0px 60px;
        transform-origin: 0px 60px;
      }

      .sa-placeholder { // Ring
        width: 80px;
        height: 80px;
        border: 4px solid rgba($green, 0.2);
        -webkit-border-radius: 40px;
        border-radius: 40px;
        border-radius: 50%;
        box-sizing: content-box;

        position: absolute;
        left: -4px;
        top: -4px;
        z-index: 2;
      }

      .sa-fix { // Hide corners left from animation
        width: 5px;
        height: 90px;
        background-color: white;

        position: absolute;
        left: 28px;
        top: 8px;
        z-index: 1;

        -webkit-transform: rotate(-45deg);
        transform: rotate(-45deg);
      }

      .sa-line {
        height: 5px;
        background-color: $green;
        display: block;
        border-radius: 2px;

        position: absolute;
        z-index: 2;

        &.sa-tip {
          width: 25px;

          left: 14px;
          top: 46px;

          -webkit-transform: rotate(45deg);
          transform: rotate(45deg);
        }
        &.sa-long {
          width: 47px;

          right: 8px;
          top: 38px;

          -webkit-transform: rotate(-45deg);
          transform: rotate(-45deg);
        }
      }
    }
    &.sa-custom {
      background-size: contain;
      border-radius: 0;
      border: none;
      background-position: center center;
      background-repeat: no-repeat;
    }
  }

}

/*
 * Animations
 */

@mixin keyframes($animation-name) {
  @-webkit-keyframes #{$animation-name} {
    @content;
  }
  @keyframes #{$animation-name} {
    @content;
  }
}
@mixin animation($str) {
  -webkit-animation: #{$str};
  animation: #{$str};
}


// Modal animation

@include keyframes(showSweetAlert) {
  0%    { transform: scale(0.7);  -webkit-transform: scale(0.7);  }
  45%   { transform: scale(1.05); -webkit-transform: scale(1.05); }
  80%   { transform: scale(0.95); -webkit-transform: scale(0.95);   }
  100%  { transform: scale(1);    -webkit-transform: scale(1);    }
}
@include keyframes(hideSweetAlert) {
  0%    { transform: scale(1);    -webkit-transform: scale(1);    }
  100%  { transform: scale(0.5);  -webkit-transform: scale(0.5);  }
}

@include keyframes(slideFromTop) {
  0%    { top: 0%;  }
  100%  { top: 50%; }
}
@include keyframes(slideToTop) {
  0%    { top: 50%; }
  100%  { top: 0%;  }
}

@include keyframes(slideFromBottom) {
  0%    { top: 70%; }
  100%  { top: 50%;  }
}
@include keyframes(slideToBottom) {
  0%    { top: 50%;  }
  100%  { top: 70%; }
}

.showSweetAlert {
  &[data-animation=pop] {
    @include animation('showSweetAlert 0.3s');
  }
  &[data-animation=none] {
    @include animation('none');
  }
  &[data-animation=slide-from-top] {
    @include animation('slideFromTop 0.3s');
  }
  &[data-animation=slide-from-bottom] {
    @include animation('slideFromBottom 0.3s');
  }
}

.hideSweetAlert {
  &[data-animation=pop] {
    @include animation('hideSweetAlert 0.2s');
  }
  &[data-animation=none] {
    @include animation('none');
  }
  &[data-animation=slide-from-top] {
    @include animation('slideToTop 0.4s');
  }
  &[data-animation=slide-from-bottom] {
    @include animation('slideToBottom 0.3s');
  }
}



// Success icon animation

@include keyframes(animateSuccessTip) {
  0%    { width: 0;     left: 1px;    top: 19px; }
  54%   { width: 0;     left: 1px;    top: 19px; }
  70%   { width: 50px;  left: -8px;   top: 37px; }
  84%   { width: 17px;  left: 21px;   top: 48px; }
  100%  { width: 25px;  left: 14px;   top: 45px; }
}
@include keyframes(animateSuccessLong) {
  0%    { width: 0;     right: 46px;  top: 54px; }
  65%   { width: 0;     right: 46px;  top: 54px; }
  84%   { width: 55px;  right: 0px;   top: 35px; }
  100%  { width: 47px;  right: 8px;   top: 38px; }
}
@include keyframes(rotatePlaceholder) {
  0%    { transform: rotate(-45deg);  -webkit-transform: rotate(-45deg);  }
  5%    { transform: rotate(-45deg);  -webkit-transform: rotate(-45deg);    }
  12%   { transform: rotate(-405deg); -webkit-transform: rotate(-405deg); }
  100%  { transform: rotate(-405deg); -webkit-transform: rotate(-405deg); }
}

.animateSuccessTip {
  @include animation('animateSuccessTip 0.75s');
}
.animateSuccessLong {
  @include animation('animateSuccessLong 0.75s');
}
.sa-icon.sa-success.animate::after {
  @include animation('rotatePlaceholder 4.25s ease-in');
}


// Error icon animation

@include keyframes(animateErrorIcon) {
  0%    { transform: rotateX(100deg); -webkit-transform: rotateX(100deg); opacity: 0; }
  100%  { transform: rotateX(0deg);   -webkit-transform: rotateX(0deg);   opacity: 1; }
}
.animateErrorIcon {
  @include animation('animateErrorIcon 0.5s');
}
@include keyframes(animateXMark) {
  0%    { transform: scale(0.4);  -webkit-transform: scale(0.4);  margin-top: 26px; opacity: 0; }
  50%   { transform: scale(0.4);  -webkit-transform: scale(0.4);  margin-top: 26px; opacity: 0; }
  80%   { transform: scale(1.15); -webkit-transform: scale(1.15); margin-top: -6px;             }
  100%  { transform: scale(1);    -webkit-transform: scale(1);    margin-top: 0;    opacity: 1; }
}
.animateXMark {
  @include animation('animateXMark 0.5s');
}

@include keyframes(pulseWarning) {
  0%    { border-color: #F8D486; }
  100%  { border-color: #F8BB86; }
}
.pulseWarning {
  @include animation('pulseWarning 0.75s infinite alternate');
}

@include keyframes(pulseWarningIns) {
  0%    { background-color: #F8D486; }
  100%  { background-color: #F8BB86; }
}
.pulseWarningIns {
  @include animation('pulseWarningIns 0.75s infinite alternate');
}

@include keyframes(rotate-loading) {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}
modules/handle-swal-dom.js000066400000006405151520616460011543 0ustar00import { hexToRgb } from './utils';
import { removeClass, getTopMargin, fadeIn, show, addClass } from './handle-dom';
import defaultParams from './default-params';

var modalClass   = '.sweet-alert';
var overlayClass = '.sweet-overlay';

/*
 * Add modal + overlay to DOM
 */
import injectedHTML from './injected-html';

var sweetAlertInitialize = function() {
  var sweetWrap = document.createElement('div');
  sweetWrap.innerHTML = injectedHTML;

  // Append elements to body
  while (sweetWrap.firstChild) {
    document.body.appendChild(sweetWrap.firstChild);
  }
};

/*
 * Get DOM element of modal
 */
var getModal = function() {
  var $modal = document.querySelector(modalClass);

  if (!$modal) {
    sweetAlertInitialize();
    $modal = getModal();
  }

  return $modal;
};

/*
 * Get DOM element of input (in modal)
 */
var getInput = function() {
  var $modal = getModal();
  if ($modal) {
    return $modal.querySelector('input');
  }
};

/*
 * Get DOM element of overlay
 */
var getOverlay = function() {
  return document.querySelector(overlayClass);
};

/*
 * Add box-shadow style to button (depending on its chosen bg-color)
 */
var setFocusStyle = function($button, bgColor) {
  var rgbColor = hexToRgb(bgColor);
  $button.style.boxShadow = '0 0 2px rgba(' + rgbColor + ', 0.8), inset 0 0 0 1px rgba(0, 0, 0, 0.05)';
};

/*
 * Animation when opening modal
 */
var openModal = function(callback) {
  var $modal = getModal();
  fadeIn(getOverlay(), 10);
  show($modal);
  addClass($modal, 'showSweetAlert');
  removeClass($modal, 'hideSweetAlert');

  window.previousActiveElement = document.activeElement;
  var $okButton = $modal.querySelector('button.confirm');
  $okButton.focus();

  setTimeout(function () {
    addClass($modal, 'visible');
  }, 500);

  var timer = $modal.getAttribute('data-timer');

  if (timer !== 'null' && timer !== '') {
    var timerCallback = callback;
    $modal.timeout = setTimeout(function() {
      var doneFunctionExists = ((timerCallback || null) && $modal.getAttribute('data-has-done-function') === 'true');
      if (doneFunctionExists) { 
        timerCallback(null);
      }
      else {
        sweetAlert.close();
      }
    }, timer);
  }
};

/*
 * Reset the styling of the input
 * (for example if errors have been shown)
 */
var resetInput = function() {
  var $modal = getModal();
  var $input = getInput();

  removeClass($modal, 'show-input');
  $input.value = defaultParams.inputValue;
  $input.setAttribute('type', defaultParams.inputType);
  $input.setAttribute('placeholder', defaultParams.inputPlaceholder);

  resetInputError();
};


var resetInputError = function(event) {
  // If press enter => ignore
  if (event && event.keyCode === 13) {
    return false;
  }

  var $modal = getModal();

  var $errorIcon = $modal.querySelector('.sa-input-error');
  removeClass($errorIcon, 'show');

  var $errorContainer = $modal.querySelector('.sa-error-container');
  removeClass($errorContainer, 'show');
};


/*
 * Set "margin-top"-property on modal based on its computed height
 */
var fixVerticalPosition = function() {
  var $modal = getModal();
  $modal.style.marginTop = getTopMargin(getModal());
};


export { 
  sweetAlertInitialize,
  getModal,
  getOverlay,
  getInput,
  setFocusStyle,
  openModal,
  resetInput,
  resetInputError,
  fixVerticalPosition
};
modules/handle-key.js000066400000003751151520616460010611 0ustar00import { stopEventPropagation, fireClick } from './handle-dom';
import { setFocusStyle } from './handle-swal-dom';


var handleKeyDown = function(event, params, modal) {
  var e = event || window.event;
  var keyCode = e.keyCode || e.which;

  var $okButton     = modal.querySelector('button.confirm');
  var $cancelButton = modal.querySelector('button.cancel');
  var $modalButtons = modal.querySelectorAll('button[tabindex]');


  if ([9, 13, 32, 27].indexOf(keyCode) === -1) {
    // Don't do work on keys we don't care about.
    return;
  }

  var $targetElement = e.target || e.srcElement;

  var btnIndex = -1; // Find the button - note, this is a nodelist, not an array.
  for (var i = 0; i < $modalButtons.length; i++) {
    if ($targetElement === $modalButtons[i]) {
      btnIndex = i;
      break;
    }
  }

  if (keyCode === 9) {
    // TAB
    if (btnIndex === -1) {
      // No button focused. Jump to the confirm button.
      $targetElement = $okButton;
    } else {
      // Cycle to the next button
      if (btnIndex === $modalButtons.length - 1) {
        $targetElement = $modalButtons[0];
      } else {
        $targetElement = $modalButtons[btnIndex + 1];
      }
    }

    stopEventPropagation(e);
    $targetElement.focus();

    if (params.confirmButtonColor) {
      setFocusStyle($targetElement, params.confirmButtonColor);
    }
  } else {
    if (keyCode === 13) {
      if ($targetElement.tagName === 'INPUT') {
        $targetElement = $okButton;
        $okButton.focus();
      }

      if (btnIndex === -1) {
        // ENTER/SPACE clicked outside of a button.
        $targetElement = $okButton;
      } else {
        // Do nothing - let the browser handle it.
        $targetElement = undefined;
      }
    } else if (keyCode === 27 && params.allowEscapeKey === true) {
      $targetElement = $cancelButton;
      fireClick($targetElement, e);
    } else {
      // Fallback - let the browser handle it.
      $targetElement = undefined;
    }
  }
};

export default handleKeyDown;
modules/handle-dom.js000066400000007736151520616460010607 0ustar00var hasClass = function(elem, className) {
  return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' ');
};

var addClass = function(elem, className) {
  if (!hasClass(elem, className)) {
    elem.className += ' ' + className;
  }
};

var removeClass = function(elem, className) {
  var newClass = ' ' + elem.className.replace(/[\t\r\n]/g, ' ') + ' ';
  if (hasClass(elem, className)) {
    while (newClass.indexOf(' ' + className + ' ') >= 0) {
      newClass = newClass.replace(' ' + className + ' ', ' ');
    }
    elem.className = newClass.replace(/^\s+|\s+$/g, '');
  }
};

var escapeHtml = function(str) {
  var div = document.createElement('div');
  div.appendChild(document.createTextNode(str));
  return div.innerHTML;
};

var _show = function(elem) {
  elem.style.opacity = '';
  elem.style.display = 'block';
};

var show = function(elems) {
  if (elems && !elems.length) {
    return _show(elems);
  }
  for (var i = 0; i < elems.length; ++i) {
    _show(elems[i]);
  }
};

var _hide = function(elem) {
  elem.style.opacity = '';
  elem.style.display = 'none';
};

var hide = function(elems) {
  if (elems && !elems.length) {
    return _hide(elems);
  }
  for (var i = 0; i < elems.length; ++i) {
    _hide(elems[i]);
  }
};

var isDescendant = function(parent, child) {
  var node = child.parentNode;
  while (node !== null) {
    if (node === parent) {
      return true;
    }
    node = node.parentNode;
  }
  return false;
};

var getTopMargin = function(elem) {
  elem.style.left = '-9999px';
  elem.style.display = 'block';

  var height = elem.clientHeight,
      padding;
  if (typeof getComputedStyle !== "undefined") { // IE 8
    padding = parseInt(getComputedStyle(elem).getPropertyValue('padding-top'), 10);
  } else {
    padding = parseInt(elem.currentStyle.padding);
  }

  elem.style.left = '';
  elem.style.display = 'none';
  return ('-' + parseInt((height + padding) / 2) + 'px');
};

var fadeIn = function(elem, interval) {
  if (+elem.style.opacity < 1) {
    interval = interval || 16;
    elem.style.opacity = 0;
    elem.style.display = 'block';
    var last = +new Date();
    var tick = function() {
      elem.style.opacity = +elem.style.opacity + (new Date() - last) / 100;
      last = +new Date();

      if (+elem.style.opacity < 1) {
        setTimeout(tick, interval);
      }
    };
    tick();
  }
  elem.style.display = 'block'; //fallback IE8
};

var fadeOut = function(elem, interval) {
  interval = interval || 16;
  elem.style.opacity = 1;
  var last = +new Date();
  var tick = function() {
    elem.style.opacity = +elem.style.opacity - (new Date() - last) / 100;
    last = +new Date();

    if (+elem.style.opacity > 0) {
      setTimeout(tick, interval);
    } else {
      elem.style.display = 'none';
    }
  };
  tick();
};

var fireClick = function(node) {
  // Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/
  // Then fixed for today's Chrome browser.
  if (typeof MouseEvent === 'function') {
    // Up-to-date approach
    var mevt = new MouseEvent('click', {
      view: window,
      bubbles: false,
      cancelable: true
    });
    node.dispatchEvent(mevt);
  } else if ( document.createEvent ) {
    // Fallback
    var evt = document.createEvent('MouseEvents');
    evt.initEvent('click', false, false);
    node.dispatchEvent(evt);
  } else if (document.createEventObject) {
    node.fireEvent('onclick') ;
  } else if (typeof node.onclick === 'function' ) {
    node.onclick();
  }
};

var stopEventPropagation = function(e) {
  // In particular, make sure the space bar doesn't scroll the main window.
  if (typeof e.stopPropagation === 'function') {
    e.stopPropagation();
    e.preventDefault();
  } else if (window.event && window.event.hasOwnProperty('cancelBubble')) {
    window.event.cancelBubble = true;
  }
};

export { 
  hasClass, addClass, removeClass, 
  escapeHtml, 
  _show, show, _hide, hide, 
  isDescendant, 
  getTopMargin,
  fadeIn, fadeOut,
  fireClick,
  stopEventPropagation
};
modules/default-params.js000066400000001027151520616460011467 0ustar00var defaultParams = {
  title: '',
  text: '',
  type: null,
  allowOutsideClick: false,
  showConfirmButton: true,
  showCancelButton: false,
  closeOnConfirm: true,
  closeOnCancel: true,
  confirmButtonText: 'OK',
  confirmButtonColor: '#8CD4F5',
  cancelButtonText: 'Cancel',
  imageUrl: null,
  imageSize: null,
  timer: null,
  customClass: '',
  html: false,
  animation: true,
  allowEscapeKey: true,
  inputType: 'text',
  inputPlaceholder: '',
  inputValue: '',
  showLoaderOnConfirm: false
};

export default defaultParams;
modules/injected-html.js000066400000003123151520616460011310 0ustar00var injectedHTML = 

  // Dark overlay
  `<div class="sweet-overlay" tabIndex="-1"></div>` +

  // Modal
  `<div class="sweet-alert">` +

    // Error icon
    `<div class="sa-icon sa-error">
      <span class="sa-x-mark">
        <span class="sa-line sa-left"></span>
        <span class="sa-line sa-right"></span>
      </span>
    </div>` +

    // Warning icon
    `<div class="sa-icon sa-warning">
      <span class="sa-body"></span>
      <span class="sa-dot"></span>
    </div>` +

    // Info icon
    `<div class="sa-icon sa-info"></div>` +

    // Success icon
    `<div class="sa-icon sa-success">
      <span class="sa-line sa-tip"></span>
      <span class="sa-line sa-long"></span>

      <div class="sa-placeholder"></div>
      <div class="sa-fix"></div>
    </div>` +

    `<div class="sa-icon sa-custom"></div>` +

    // Title, text and input
    `<h2>Title</h2>
    <p>Text</p>
    <fieldset>
      <input type="text" tabIndex="3" />
      <div class="sa-input-error"></div>
    </fieldset>` +

    // Input errors
    `<div class="sa-error-container">
      <div class="icon">!</div>
      <p>Not valid!</p>
    </div>` +

    // Cancel and confirm buttons
    `<div class="sa-button-container">
      <button class="cancel" tabIndex="2">Cancel</button>
      <div class="sa-confirm-button-container">
        <button class="confirm" tabIndex="1">OK</button>` + 

        // Loading animation
        `<div class="la-ball-fall">
          <div></div>
          <div></div>
          <div></div>
        </div>
      </div>
    </div>` +

  // End of modal
  `</div>`;

export default injectedHTML;
modules/handle-click.js000066400000007015151520616460011103 0ustar00import { colorLuminance } from './utils';
import { getModal } from './handle-swal-dom';
import { hasClass, isDescendant } from './handle-dom';


/*
 * User clicked on "Confirm"/"OK" or "Cancel"
 */
var handleButton = function(event, params, modal) {
  var e = event || window.event;
  var target = e.target || e.srcElement;

  var targetedConfirm = target.className.indexOf('confirm') !== -1;
  var targetedOverlay = target.className.indexOf('sweet-overlay') !== -1;
  var modalIsVisible  = hasClass(modal, 'visible');
  var doneFunctionExists = (params.doneFunction && modal.getAttribute('data-has-done-function') === 'true');

  // Since the user can change the background-color of the confirm button programmatically,
  // we must calculate what the color should be on hover/active
  var normalColor, hoverColor, activeColor;
  if (targetedConfirm && params.confirmButtonColor) {
    normalColor  = params.confirmButtonColor;
    hoverColor   = colorLuminance(normalColor, -0.04);
    activeColor  = colorLuminance(normalColor, -0.14);
  }

  function shouldSetConfirmButtonColor(color) {
    if (targetedConfirm && params.confirmButtonColor) {
      target.style.backgroundColor = color;
    }
  }

  switch (e.type) {
    case 'mouseover':
      shouldSetConfirmButtonColor(hoverColor);
      break;

    case 'mouseout':
      shouldSetConfirmButtonColor(normalColor);
      break;

    case 'mousedown':
      shouldSetConfirmButtonColor(activeColor);
      break;

    case 'mouseup':
      shouldSetConfirmButtonColor(hoverColor);
      break;

    case 'focus':
      let $confirmButton = modal.querySelector('button.confirm');
      let $cancelButton  = modal.querySelector('button.cancel');

      if (targetedConfirm) {
        $cancelButton.style.boxShadow = 'none';
      } else {
        $confirmButton.style.boxShadow = 'none';
      }
      break;

    case 'click':
      let clickedOnModal = (modal === target);
      let clickedOnModalChild = isDescendant(modal, target);

      // Ignore click outside if allowOutsideClick is false
      if (!clickedOnModal && !clickedOnModalChild && modalIsVisible && !params.allowOutsideClick) {
        break;
      }

      if (targetedConfirm && doneFunctionExists && modalIsVisible) {
        handleConfirm(modal, params);
      } else if (doneFunctionExists && modalIsVisible || targetedOverlay) {
        handleCancel(modal, params);
      } else if (isDescendant(modal, target) && target.tagName === 'BUTTON') {
        sweetAlert.close();
      }
      break;
  }
};

/*
 *  User clicked on "Confirm"/"OK"
 */
var handleConfirm = function(modal, params) {
  var callbackValue = true;

  if (hasClass(modal, 'show-input')) {
    callbackValue = modal.querySelector('input').value;

    if (!callbackValue) {
      callbackValue = '';
    }
  }

  params.doneFunction(callbackValue);

  if (params.closeOnConfirm) {
    sweetAlert.close();
  }
  // Disable cancel and confirm button if the parameter is true
  if (params.showLoaderOnConfirm) {
    sweetAlert.disableButtons();
  }
};

/*
 *  User clicked on "Cancel"
 */
var handleCancel = function(modal, params) {
  // Check if callback function expects a parameter (to track cancel actions)
  var functionAsStr = String(params.doneFunction).replace(/\s/g, '');
  var functionHandlesCancel = functionAsStr.substring(0, 9) === 'function(' && functionAsStr.substring(9, 10) !== ')';

  if (functionHandlesCancel) {
    params.doneFunction(false);
  }

  if (params.closeOnCancel) {
    sweetAlert.close();
  }
};


export default {
  handleButton,
  handleConfirm,
  handleCancel
};
modules/utils.js000066400000002766151520616460007735 0ustar00/*
 * Allow user to pass their own params
 */
var extend = function(a, b) {
  for (var key in b) {
    if (b.hasOwnProperty(key)) {
      a[key] = b[key];
    }
  }
  return a;
};

/*
 * Convert HEX codes to RGB values (#000000 -> rgb(0,0,0))
 */
var hexToRgb = function(hex) {
  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  return result ? parseInt(result[1], 16) + ', ' + parseInt(result[2], 16) + ', ' + parseInt(result[3], 16) : null;
};

/*
 * Check if the user is using Internet Explorer 8 (for fallbacks)
 */
var isIE8 = function() {
  return (window.attachEvent && !window.addEventListener);
};

/*
 * IE compatible logging for developers
 */
var logStr = function(string) {
  if (window.console) {
    // IE...
    window.console.log('SweetAlert: ' + string);
  }
};

/*
 * Set hover, active and focus-states for buttons 
 * (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color)
 */
var colorLuminance = function(hex, lum) {
  // Validate hex string
  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;

  // Convert to decimal and change luminosity
  var rgb = '#';
  var c;
  var i;

  for (i = 0; i < 3; i++) {
    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;
};


export {
  extend,
  hexToRgb,
  isIE8,
  logStr,
  colorLuminance
};
modules/set-params.js000066400000013066151520616460010644 0ustar00var alertTypes = ['error', 'warning', 'info', 'success', 'input', 'prompt'];

import {
  isIE8
} from './utils';

import {
  getModal,
  getInput,
  setFocusStyle
} from './handle-swal-dom';

import {
  hasClass, addClass, removeClass,
  escapeHtml,
  _show, show, _hide, hide
} from './handle-dom';


/*
 * Set type, text and actions on modal
 */
var setParameters = function(params) {
  var modal = getModal();

  var $title = modal.querySelector('h2');
  var $text = modal.querySelector('p');
  var $cancelBtn = modal.querySelector('button.cancel');
  var $confirmBtn = modal.querySelector('button.confirm');

  /*
   * Title
   */
  $title.innerHTML = params.html ? params.title : escapeHtml(params.title).split('\n').join('<br>');

  /*
   * Text
   */
  $text.innerHTML = params.html ? params.text : escapeHtml(params.text || '').split('\n').join('<br>');
  if (params.text) show($text);

  /*
   * Custom class
   */
  if (params.customClass) {
    addClass(modal, params.customClass);
    modal.setAttribute('data-custom-class', params.customClass);
  } else {
    // Find previously set classes and remove them
    let customClass = modal.getAttribute('data-custom-class');
    removeClass(modal, customClass);
    modal.setAttribute('data-custom-class', '');
  }

  /*
   * Icon
   */
  hide(modal.querySelectorAll('.sa-icon'));

  if (params.type && !isIE8()) {

    let validType = false;

    for (let i = 0; i < alertTypes.length; i++) {
      if (params.type === alertTypes[i]) {
        validType = true;
        break;
      }
    }

    if (!validType) {
      logStr('Unknown alert type: ' + params.type);
      return false;
    }

    let typesWithIcons = ['success', 'error', 'warning', 'info'];
    let $icon;

    if (typesWithIcons.indexOf(params.type) !== -1) {
      $icon = modal.querySelector('.sa-icon.' + 'sa-' + params.type);
      show($icon);
    }

    let $input = getInput();

    // Animate icon
    switch (params.type) {

      case 'success':
        addClass($icon, 'animate');
        addClass($icon.querySelector('.sa-tip'), 'animateSuccessTip');
        addClass($icon.querySelector('.sa-long'), 'animateSuccessLong');
        break;

      case 'error':
        addClass($icon, 'animateErrorIcon');
        addClass($icon.querySelector('.sa-x-mark'), 'animateXMark');
        break;

      case 'warning':
        addClass($icon, 'pulseWarning');
        addClass($icon.querySelector('.sa-body'), 'pulseWarningIns');
        addClass($icon.querySelector('.sa-dot'), 'pulseWarningIns');
        break;

      case 'input':
      case 'prompt':
        $input.setAttribute('type', params.inputType);
        $input.value = params.inputValue;
        $input.setAttribute('placeholder', params.inputPlaceholder);
        addClass(modal, 'show-input');
        setTimeout(function () {
          $input.focus();
          $input.addEventListener('keyup', swal.resetInputError);
        }, 400);
        break;
    }
  }

  /*
   * Custom image
   */
  if (params.imageUrl) {
    let $customIcon = modal.querySelector('.sa-icon.sa-custom');

    $customIcon.style.backgroundImage = 'url(' + params.imageUrl + ')';
    show($customIcon);

    let _imgWidth = 80;
    let _imgHeight = 80;

    if (params.imageSize) {
      let dimensions = params.imageSize.toString().split('x');
      let imgWidth = dimensions[0];
      let imgHeight = dimensions[1];

      if (!imgWidth || !imgHeight) {
        logStr('Parameter imageSize expects value with format WIDTHxHEIGHT, got ' + params.imageSize);
      } else {
        _imgWidth = imgWidth;
        _imgHeight = imgHeight;
      }
    }

    $customIcon.setAttribute('style', $customIcon.getAttribute('style') + 'width:' + _imgWidth + 'px; height:' + _imgHeight + 'px');
  }

  /*
   * Show cancel button?
   */
  modal.setAttribute('data-has-cancel-button', params.showCancelButton);
  if (params.showCancelButton) {
    $cancelBtn.style.display = 'inline-block';
  } else {
    hide($cancelBtn);
  }

  /*
   * Show confirm button?
   */
  modal.setAttribute('data-has-confirm-button', params.showConfirmButton);
  if (params.showConfirmButton) {
    $confirmBtn.style.display = 'inline-block';
  } else {
    hide($confirmBtn);
  }

  /*
   * Custom text on cancel/confirm buttons
   */
  if (params.cancelButtonText) {
    $cancelBtn.innerHTML = escapeHtml(params.cancelButtonText);
  }
  if (params.confirmButtonText) {
    $confirmBtn.innerHTML = escapeHtml(params.confirmButtonText);
  }

  /*
   * Custom color on confirm button
   */
  if (params.confirmButtonColor) {
    // Set confirm button to selected background color
    $confirmBtn.style.backgroundColor = params.confirmButtonColor;

    // Set the confirm button color to the loading ring
    $confirmBtn.style.borderLeftColor = params.confirmLoadingButtonColor;
    $confirmBtn.style.borderRightColor = params.confirmLoadingButtonColor;

    // Set box-shadow to default focused button
    setFocusStyle($confirmBtn, params.confirmButtonColor);
  }

  /*
   * Allow outside click
   */
  modal.setAttribute('data-allow-outside-click', params.allowOutsideClick);

  /*
   * Callback function
   */
  var hasDoneFunction = params.doneFunction ? true : false;
  modal.setAttribute('data-has-done-function', hasDoneFunction);

  /*
   * Animation
   */
  if (!params.animation) {
    modal.setAttribute('data-animation', 'none');
  } else if (typeof params.animation === 'string') {
    modal.setAttribute('data-animation', params.animation); // Custom animation
  } else {
    modal.setAttribute('data-animation', 'pop');
  }

  /*
   * Timer
   */
  modal.setAttribute('data-timer', params.timer);
};

export default setParameters;
loader-animation.css000066400000010126151520616460010511 0ustar00/*!
 * Load Awesome v1.1.0 (http://github.danielcardoso.net/load-awesome/)
 * Copyright 2015 Daniel Cardoso <@DanielCardoso>
 * Licensed under MIT
 */
.la-ball-fall,
.la-ball-fall > div {
position: relative;
-webkit-box-sizing: border-box;
   -moz-box-sizing: border-box;
        box-sizing: border-box;
}
.la-ball-fall {
  display: block;
  font-size: 0;
  color: #fff;
}
.la-ball-fall.la-dark {
  color: #333;
}
.la-ball-fall > div {
  display: inline-block;
  float: none;
  background-color: currentColor;
  border: 0 solid currentColor;
}
.la-ball-fall {
  width: 54px;
  height: 18px;
}
.la-ball-fall > div {
  width: 10px;
  height: 10px;
  margin: 4px;
  border-radius: 100%;
  opacity: 0;
  -webkit-animation: ball-fall 1s ease-in-out infinite;
     -moz-animation: ball-fall 1s ease-in-out infinite;
       -o-animation: ball-fall 1s ease-in-out infinite;
          animation: ball-fall 1s ease-in-out infinite;
}
.la-ball-fall > div:nth-child(1) {
  -webkit-animation-delay: -200ms;
     -moz-animation-delay: -200ms;
       -o-animation-delay: -200ms;
          animation-delay: -200ms;
}
.la-ball-fall > div:nth-child(2) {
  -webkit-animation-delay: -100ms;
     -moz-animation-delay: -100ms;
       -o-animation-delay: -100ms;
          animation-delay: -100ms;
}
.la-ball-fall > div:nth-child(3) {
  -webkit-animation-delay: 0ms;
     -moz-animation-delay: 0ms;
       -o-animation-delay: 0ms;
          animation-delay: 0ms;
}
.la-ball-fall.la-sm {
  width: 26px;
  height: 8px;
}
.la-ball-fall.la-sm > div {
  width: 4px;
  height: 4px;
  margin: 2px;
}
.la-ball-fall.la-2x {
  width: 108px;
  height: 36px;
}
.la-ball-fall.la-2x > div {
  width: 20px;
  height: 20px;
  margin: 8px;
}
.la-ball-fall.la-3x {
  width: 162px;
  height: 54px;
}
.la-ball-fall.la-3x > div {
  width: 30px;
  height: 30px;
  margin: 12px;
}
/*
 * Animation
 */
@-webkit-keyframes ball-fall {
  0% {
    opacity: 0;
    -webkit-transform: translateY(-145%);
            transform: translateY(-145%);
  }
  10% {
      opacity: .5;
  }
  20% {
    opacity: 1;
    -webkit-transform: translateY(0);
            transform: translateY(0);
  }
  80% {
    opacity: 1;
    -webkit-transform: translateY(0);
            transform: translateY(0);
  }
  90% {
      opacity: .5;
  }
  100% {
    opacity: 0;
    -webkit-transform: translateY(145%);
            transform: translateY(145%);
  }
}
@-moz-keyframes ball-fall {
  0% {
    opacity: 0;
    -moz-transform: translateY(-145%);
         transform: translateY(-145%);
  }
  10% {
    opacity: .5;
  }
  20% {
    opacity: 1;
    -moz-transform: translateY(0);
         transform: translateY(0);
  }
  80% {
    opacity: 1;
    -moz-transform: translateY(0);
         transform: translateY(0);
  }
  90% {
    opacity: .5;
  }
  100% {
    opacity: 0;
    -moz-transform: translateY(145%);
         transform: translateY(145%);
  }
}
@-o-keyframes ball-fall {
  0% {
    opacity: 0;
    -o-transform: translateY(-145%);
       transform: translateY(-145%);
  }
  10% {
    opacity: .5;
  }
  20% {
    opacity: 1;
    -o-transform: translateY(0);
       transform: translateY(0);
  }
  80% {
    opacity: 1;
    -o-transform: translateY(0);
       transform: translateY(0);
  }
  90% {
    opacity: .5;
  }
  100% {
    opacity: 0;
    -o-transform: translateY(145%);
       transform: translateY(145%);
  }
}
@keyframes ball-fall {
  0% {
    opacity: 0;
    -webkit-transform: translateY(-145%);
       -moz-transform: translateY(-145%);
         -o-transform: translateY(-145%);
            transform: translateY(-145%);
  }
  10% {
    opacity: .5;
  }
  20% {
    opacity: 1;
    -webkit-transform: translateY(0);
       -moz-transform: translateY(0);
         -o-transform: translateY(0);
            transform: translateY(0);
  }
  80% {
    opacity: 1;
    -webkit-transform: translateY(0);
       -moz-transform: translateY(0);
         -o-transform: translateY(0);
            transform: translateY(0);
  }
  90% {
    opacity: .5;
  }
  100% {
    opacity: 0;
    -webkit-transform: translateY(145%);
       -moz-transform: translateY(145%);
         -o-transform: translateY(145%);
            transform: translateY(145%);
  }
}
sweetalert.es6.js000066400000020171151520616460007766 0ustar00// SweetAlert
// 2014-2015 (c) - Tristan Edwards
// github.com/t4t5/sweetalert

/*
 * jQuery-like functions for manipulating the DOM
 */
import {
  hasClass, addClass, removeClass,
  escapeHtml,
  _show, show, _hide, hide,
  isDescendant,
  getTopMargin,
  fadeIn, fadeOut,
  fireClick,
  stopEventPropagation
} from './modules/handle-dom';

/*
 * Handy utilities
 */
import {
  extend,
  hexToRgb,
  isIE8,
  logStr,
  colorLuminance
} from './modules/utils';

/*
 *  Handle sweetAlert's DOM elements
 */
import {
  sweetAlertInitialize,
  getModal,
  getOverlay,
  getInput,
  setFocusStyle,
  openModal,
  resetInput,
  fixVerticalPosition
} from './modules/handle-swal-dom';


// Handle button events and keyboard events
import { handleButton, handleConfirm, handleCancel } from './modules/handle-click';
import handleKeyDown from './modules/handle-key';


// Default values
import defaultParams from './modules/default-params';
import setParameters from './modules/set-params';

/*
 * Remember state in cases where opening and handling a modal will fiddle with it.
 * (We also use window.previousActiveElement as a global variable)
 */
var previousWindowKeyDown;
var lastFocusedButton;


/*
 * Global sweetAlert function
 * (this is what the user calls)
 */
var sweetAlert, swal;

export default sweetAlert = swal = function() {
  var customizations = arguments[0];

  addClass(document.body, 'stop-scrolling');
  resetInput();

  /*
   * Use argument if defined or default value from params object otherwise.
   * Supports the case where a default value is boolean true and should be
   * overridden by a corresponding explicit argument which is boolean false.
   */
  function argumentOrDefault(key) {
    var args = customizations;
    return (args[key] === undefined) ?  defaultParams[key] : args[key];
  }

  if (customizations === undefined) {
    logStr('SweetAlert expects at least 1 attribute!');
    return false;
  }

  var params = extend({}, defaultParams);

  switch (typeof customizations) {

    // Ex: swal("Hello", "Just testing", "info");
    case 'string':
      params.title = customizations;
      params.text  = arguments[1] || '';
      params.type  = arguments[2] || '';
      break;

    // Ex: swal({ title:"Hello", text: "Just testing", type: "info" });
    case 'object':
      if (customizations.title === undefined) {
        logStr('Missing "title" argument!');
        return false;
      }

      params.title = customizations.title;

      for (let customName in defaultParams) {
        params[customName] = argumentOrDefault(customName);
      }

      // Show "Confirm" instead of "OK" if cancel button is visible
      params.confirmButtonText = params.showCancelButton ? 'Confirm' : defaultParams.confirmButtonText;
      params.confirmButtonText = argumentOrDefault('confirmButtonText');

      // Callback function when clicking on "OK"/"Cancel"
      params.doneFunction = arguments[1] || null;

      break;

    default:
      logStr('Unexpected type of argument! Expected "string" or "object", got ' + typeof customizations);
      return false;

  }

  setParameters(params);
  fixVerticalPosition();
  openModal(arguments[1]);

  // Modal interactions
  var modal = getModal();


  /*
   * Make sure all modal buttons respond to all events
   */
  var $buttons = modal.querySelectorAll('button');
  var buttonEvents = ['onclick', 'onmouseover', 'onmouseout', 'onmousedown', 'onmouseup', 'onfocus'];
  var onButtonEvent = (e) => handleButton(e, params, modal);

  for (let btnIndex = 0; btnIndex < $buttons.length; btnIndex++) {
    for (let evtIndex = 0; evtIndex < buttonEvents.length; evtIndex++) {
      let btnEvt = buttonEvents[evtIndex];
      $buttons[btnIndex][btnEvt] = onButtonEvent;
    }
  }

  // Clicking outside the modal dismisses it (if allowed by user)
  getOverlay().onclick = onButtonEvent;

  previousWindowKeyDown = window.onkeydown;

  var onKeyEvent = (e) => handleKeyDown(e, params, modal);
  window.onkeydown = onKeyEvent;

  window.onfocus = function () {
    // When the user has focused away and focused back from the whole window.
    setTimeout(function () {
      // Put in a timeout to jump out of the event sequence.
      // Calling focus() in the event sequence confuses things.
      if (lastFocusedButton !== undefined) {
        lastFocusedButton.focus();
        lastFocusedButton = undefined;
      }
    }, 0);
  };
  
  // Show alert with enabled buttons always
  swal.enableButtons();
};



/*
 * Set default params for each popup
 * @param {Object} userParams
 */
sweetAlert.setDefaults = swal.setDefaults = function(userParams) {
  if (!userParams) {
    throw new Error('userParams is required');
  }
  if (typeof userParams !== 'object') {
    throw new Error('userParams has to be a object');
  }

  extend(defaultParams, userParams);
};


/*
 * Animation when closing modal
 */
sweetAlert.close = swal.close = function() {
  var modal = getModal();

  fadeOut(getOverlay(), 5);
  fadeOut(modal, 5);
  removeClass(modal, 'showSweetAlert');
  addClass(modal, 'hideSweetAlert');
  removeClass(modal, 'visible');

  /*
   * Reset icon animations
   */
  var $successIcon = modal.querySelector('.sa-icon.sa-success');
  removeClass($successIcon, 'animate');
  removeClass($successIcon.querySelector('.sa-tip'), 'animateSuccessTip');
  removeClass($successIcon.querySelector('.sa-long'), 'animateSuccessLong');

  var $errorIcon = modal.querySelector('.sa-icon.sa-error');
  removeClass($errorIcon, 'animateErrorIcon');
  removeClass($errorIcon.querySelector('.sa-x-mark'), 'animateXMark');

  var $warningIcon = modal.querySelector('.sa-icon.sa-warning');
  removeClass($warningIcon, 'pulseWarning');
  removeClass($warningIcon.querySelector('.sa-body'), 'pulseWarningIns');
  removeClass($warningIcon.querySelector('.sa-dot'), 'pulseWarningIns');

  // Reset custom class (delay so that UI changes aren't visible)
  setTimeout(function() {
    var customClass = modal.getAttribute('data-custom-class');
    removeClass(modal, customClass);
  }, 300);

  // Make page scrollable again
  removeClass(document.body, 'stop-scrolling');

  // Reset the page to its previous state
  window.onkeydown = previousWindowKeyDown;
  if (window.previousActiveElement) {
    window.previousActiveElement.focus();
  }
  lastFocusedButton = undefined;
  clearTimeout(modal.timeout);

  return true;
};


/*
 * Validation of the input field is done by user
 * If something is wrong => call showInputError with errorMessage
 */
sweetAlert.showInputError = swal.showInputError = function(errorMessage) {
  var modal = getModal();

  var $errorIcon = modal.querySelector('.sa-input-error');
  addClass($errorIcon, 'show');

  var $errorContainer = modal.querySelector('.sa-error-container');
  addClass($errorContainer, 'show');

  $errorContainer.querySelector('p').innerHTML = errorMessage;

  setTimeout(function() {
    sweetAlert.enableButtons();
  }, 1);

  modal.querySelector('input').focus();
};


/*
 * Reset input error DOM elements
 */
sweetAlert.resetInputError = swal.resetInputError = function(event) {
  // If press enter => ignore
  if (event && event.keyCode === 13) {
    return false;
  }

  var $modal = getModal();

  var $errorIcon = $modal.querySelector('.sa-input-error');
  removeClass($errorIcon, 'show');

  var $errorContainer = $modal.querySelector('.sa-error-container');
  removeClass($errorContainer, 'show');
};

/*
 * Disable confirm and cancel buttons
 */
sweetAlert.disableButtons = swal.disableButtons = function(event) {
  var modal = getModal();
  var $confirmButton = modal.querySelector('button.confirm');
  var $cancelButton = modal.querySelector('button.cancel');
  $confirmButton.disabled = true;
  $cancelButton.disabled = true;
};

/*
 * Enable confirm and cancel buttons
 */
sweetAlert.enableButtons = swal.enableButtons = function(event) {
  var modal = getModal();
  var $confirmButton = modal.querySelector('button.confirm');
  var $cancelButton = modal.querySelector('button.cancel');
  $confirmButton.disabled = false;
  $cancelButton.disabled = false;
};

if (typeof window !== 'undefined') {
  // The 'handle-click' module requires
  // that 'sweetAlert' was set as global.
  window.sweetAlert = window.swal = sweetAlert;
} else {
  logStr('SweetAlert is a frontend module!');
}