All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.src.utils.setParameters.js Maven / Gradle / Ivy

Go to download

A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes, supported fork of sweetalert

The newest version!
import defaultInputValidators from './defaultInputValidators.js'
import * as dom from './dom/index.js'
import { warn } from './utils.js'

/**
 * @param {SweetAlertOptions} params
 */
function setDefaultInputValidators(params) {
  // Use default `inputValidator` for supported input types if not provided
  if (params.inputValidator) {
    return
  }
  if (params.input === 'email') {
    params.inputValidator = defaultInputValidators['email']
  }
  if (params.input === 'url') {
    params.inputValidator = defaultInputValidators['url']
  }
}

/**
 * @param {SweetAlertOptions} params
 */
function validateCustomTargetElement(params) {
  // Determine if the custom target element is valid
  if (
    !params.target ||
    (typeof params.target === 'string' && !document.querySelector(params.target)) ||
    (typeof params.target !== 'string' && !params.target.appendChild)
  ) {
    warn('Target parameter is not valid, defaulting to "body"')
    params.target = 'body'
  }
}

/**
 * Set type, text and actions on popup
 *
 * @param {SweetAlertOptions} params
 */
export default function setParameters(params) {
  setDefaultInputValidators(params)

  // showLoaderOnConfirm && preConfirm
  if (params.showLoaderOnConfirm && !params.preConfirm) {
    warn(
      'showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' +
        'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' +
        'https://sweetalert2.github.io/#ajax-request'
    )
  }

  validateCustomTargetElement(params)

  // Replace newlines with 
in title if (typeof params.title === 'string') { params.title = params.title.split('\n').join('
') } dom.init(params) }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy