( function() { /** globals frmGlobal */ let __; if ( 'undefined' === typeof wp || 'undefined' === typeof wp.i18n || 'function' !== typeof wp.i18n.__ ) { __ = text => text; } else { __ = wp.i18n.__; } const modal = { maybeCreateModal: ( id, { title, content, footer, width } = {}) => { 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.appendChild( div({ className: 'frm_modal_top', children: [ titleElement, div({ child: a }) ] }) ); postbox.appendChild( div({ className: 'frm_modal_content' }) ); if ( footer ) { postbox.appendChild( 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 }); 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 ); 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 && -1 !== [ 'red', 'primary' ].indexOf( 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 = { doJsonFetch: async function( action ) { let targetUrl = ajaxurl + '?action=frm_' + action; if ( -1 === targetUrl.indexOf( '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 ); }, doJsonPost: async function( 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( 'undefined' !== typeof json.data ? json.data : json ); } }; const multiselect = { init: function() { 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' ) + '"' : ''; // Set empty title attributes so that none of the dropdown options include title attributes. $select.find( 'option' ).attr( 'title', ' ' ); $select.multiselect({ templates: { popupContainer: '
', option: '', button: '' }, buttonContainer: '