( function() { /** globals frmGlobal */ let __; if ( 'undefined' === typeof wp || wp.i18n === undefined || 'function' !== typeof wp.i18n.__ ) { __ = text => text; } else { __ = wp.i18n.__; } const modal = { maybeCreateModal: ( id, { title, content, footer, width, dialogClass } = {} ) => { let modal = document.getElementById( id ); if ( ! modal ) { modal = createEmptyModal( id ); const titleElement = div( { className: 'frm-modal-title' } ); if ( 'string' === typeof title ) { titleElement.textContent = title; } const a = tag( 'a', { child: svg( { href: '#frm_close_icon' } ), className: 'dismiss' } ); const postbox = modal.querySelector( '.postbox' ); postbox.append( div( { className: 'frm_modal_top', children: [ titleElement, div( { child: a } ) ] } ) ); postbox.append( div( { className: 'frm_modal_content' } ) ); if ( footer ) { postbox.append( div( { className: 'frm_modal_footer' } ) ); } } else if ( 'string' === typeof title ) { const titleElement = modal.querySelector( '.frm-modal-title' ); titleElement.textContent = title; } if ( ! content && ! footer ) { makeModalIntoADialogAndOpen( modal, { width, dialogClass } ); return modal; } const postbox = modal.querySelector( '.postbox' ); const modalHelper = getModalHelper( modal, postbox ); if ( content ) { modalHelper( content, 'frm_modal_content' ); } if ( footer ) { modalHelper( footer, 'frm_modal_footer' ); } makeModalIntoADialogAndOpen( modal, { width, dialogClass } ); return modal; }, footerButton: args => { const output = a( args ); output.setAttribute( 'role', 'button' ); output.setAttribute( 'tabindex', 0 ); if ( args.buttonType ) { output.classList.add( 'button' ); if ( ! args.noDismiss && [ 'red', 'primary' ].includes( args.buttonType ) ) { // Primary and red buttons close modals by default on click. // To disable this default behaviour you can use the noDismiss: 1 arg. output.classList.add( 'dismiss' ); } switch ( args.buttonType ) { case 'red': output.classList.add( 'frm-button-red', 'frm-button-primary' ); break; case 'primary': output.classList.add( 'button-primary', 'frm-button-primary' ); break; case 'secondary': output.classList.add( 'button-secondary', 'frm-button-secondary' ); output.style.marginRight = '10px'; break; case 'cancel': output.classList.add( 'button-secondary', 'frm-modal-cancel' ); break; } } return output; } }; const ajax = { async doJsonFetch( action ) { let targetUrl = `${ ajaxurl }?action=frm_${ action }`; if ( ! targetUrl.includes( 'nonce=' ) ) { targetUrl += `&nonce=${ frmGlobal.nonce }`; } const response = await fetch( targetUrl ); const json = await response.json(); if ( ! json.success ) { return Promise.reject( json.data || 'JSON result is not successful' ); } return Promise.resolve( json.data ); }, async doJsonPost( action, formData, { signal } = {} ) { formData.append( 'nonce', frmGlobal.nonce ); const init = { method: 'POST', body: formData }; if ( signal ) { init.signal = signal; } const response = await fetch( `${ ajaxurl }?action=frm_${ action }`, init ); const json = await response.json(); if ( ! json.success ) { return Promise.reject( json.data || 'JSON result is not successful' ); } return Promise.resolve( json.data !== undefined ? json.data : json ); } }; const multiselect = { init() { const $select = jQuery( this ); const id = $select.is( '[id]' ) ? $select.attr( 'id' ).replace( '[]', '' ) : false; let labelledBy = id ? jQuery( `#for_${ id }` ) : false; labelledBy = id && labelledBy.length ? `aria-labelledby="${ labelledBy.attr( 'id' ) }"` : ''; $select.multiselect( { templates: { popupContainer: '', option: '', button: `` }, buttonContainer: '