let frmDom; ( 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' }) ); 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' ); switch ( args.buttonType ) { case 'primary': output.classList.add( 'button-primary', 'frm-button-primary' ); if ( ! args.noDismiss ) { output.classList.add( 'dismiss' ); } 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 ) { const response = await fetch( ajaxurl + '?action=frm_' + action ); 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 ) { formData.append( 'nonce', frmGlobal.nonce ); const init = { method: 'POST', body: formData }; 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() { let $select, id, labelledBy; $select = jQuery( this ); id = $select.is( '[id]' ) ? $select.attr( 'id' ).replace( '[]', '' ) : false; labelledBy = id ? jQuery( '#for_' + id ) : false; labelledBy = id && labelledBy.length ? 'aria-labelledby="' + labelledBy.attr( 'id' ) + '"' : ''; $select.multiselect({ templates: { popupContainer: '
', option: '', button: '' }, buttonContainer: '