| 1 |
( function() { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
const selectors = 'tr[data-slug="formidable"] .deactivate a, tr[data-slug="formidable-pro"] .deactivate a, tr[data-slug="formidable-forms-pro"] .deactivate a'; |
| 5 |
|
| 6 |
let deactivationModal, deactivationUrl; |
| 7 |
|
| 8 |
const Modal = { |
| 9 |
init: function( id, width ) { |
| 10 |
const $info = jQuery( id ); |
| 11 |
const self = this; |
| 12 |
|
| 13 |
if ( ! $info.length ) { |
| 14 |
return false; |
| 15 |
} |
| 16 |
|
| 17 |
if ( typeof width === 'undefined' ) { |
| 18 |
width = '550px'; |
| 19 |
} |
| 20 |
|
| 21 |
const dialogArgs = { |
| 22 |
dialogClass: 'frm-dialog', |
| 23 |
modal: true, |
| 24 |
autoOpen: false, |
| 25 |
closeOnEscape: true, |
| 26 |
width: width, |
| 27 |
resizable: false, |
| 28 |
draggable: false, |
| 29 |
open: function() { |
| 30 |
jQuery( '.ui-dialog-titlebar' ).addClass( 'frm_hidden' ).removeClass( 'ui-helper-clearfix' ); |
| 31 |
jQuery( '#wpwrap' ).addClass( 'frm_overlay' ); |
| 32 |
jQuery( '.frm-dialog' ).removeClass( 'ui-widget ui-widget-content ui-corner-all' ); |
| 33 |
$info.removeClass( 'ui-dialog-content ui-widget-content' ); |
| 34 |
self.bindClickForDialogClose( $info ); |
| 35 |
}, |
| 36 |
close: function() { |
| 37 |
jQuery( '#wpwrap' ).removeClass( 'frm_overlay' ); |
| 38 |
jQuery( '.spinner' ).css( 'visibility', 'hidden' ); |
| 39 |
|
| 40 |
this.removeAttribute( 'data-option-type' ); |
| 41 |
const optionType = document.getElementById( 'bulk-option-type' ); |
| 42 |
if ( optionType ) { |
| 43 |
optionType.value = ''; |
| 44 |
} |
| 45 |
} |
| 46 |
}; |
| 47 |
|
| 48 |
$info.dialog( dialogArgs ); |
| 49 |
|
| 50 |
return $info; |
| 51 |
}, |
| 52 |
|
| 53 |
bindClickForDialogClose: function( $modal ) { |
| 54 |
const closeModal = function() { |
| 55 |
$modal.dialog( 'close' ); |
| 56 |
}; |
| 57 |
jQuery( '.ui-widget-overlay' ).on( 'click', closeModal ); |
| 58 |
$modal.on( 'click', 'a.dismiss', closeModal ); |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
const addSkipBtn = formEl => { |
| 63 |
const btn = frmDom.a( { |
| 64 |
text: FrmDeactivationFeedbackI18n.skip_text, |
| 65 |
href: deactivationUrl, |
| 66 |
className: 'frm-skip-link' |
| 67 |
}); |
| 68 |
|
| 69 |
formEl.querySelector( '.frm_submit' ).prepend( btn ); |
| 70 |
}; |
| 71 |
|
| 72 |
const onClickDeactivate = event => { |
| 73 |
event.preventDefault(); |
| 74 |
|
| 75 |
if ( ! deactivationModal ) { |
| 76 |
deactivationModal = Modal.init( |
| 77 |
'#frm-deactivation-modal', |
| 78 |
'440px' |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
deactivationUrl = event.target.href + '&frm_feedback_submitted=1'; |
| 83 |
|
| 84 |
const pluginSlug = event.target.closest( 'tr' ).dataset.slug; |
| 85 |
|
| 86 |
const url = 'https://feedback.strategy11.com/wp-json/frm/v2/forms/deactivation-feedback?plugin_slug=' + pluginSlug + '&site=' + window.location.host + '&return=html&exclude_script=jquery&exclude_style=formidable-css'; |
| 87 |
|
| 88 |
const response = fetch( url, { |
| 89 |
method: 'GET' |
| 90 |
}); |
| 91 |
|
| 92 |
response |
| 93 |
.then( response => response.json() ) |
| 94 |
.then( response => { |
| 95 |
const wrapper = document.getElementById( 'frm-deactivation-form-wrapper' ); |
| 96 |
const form = response.renderedHtml.replace( /<link\b[^>]*(formidableforms.css|action=frmpro_css)[^>]*>/gi, '' ); |
| 97 |
|
| 98 |
jQuery( wrapper ).html( form ); |
| 99 |
wrapper.setAttribute( 'data-slug', pluginSlug ); |
| 100 |
addSkipBtn( wrapper ); |
| 101 |
deactivationModal.dialog( 'open' ); |
| 102 |
}) |
| 103 |
.catch( error => { |
| 104 |
console.error( error ); |
| 105 |
}); |
| 106 |
}; |
| 107 |
|
| 108 |
frmDom.util.documentOn( 'click', selectors, onClickDeactivate ); |
| 109 |
|
| 110 |
document.addEventListener( 'frmFormCompleteBeforeReplace', function( event ) { |
| 111 |
document.getElementById( 'frm-deactivation-modal-icon' ).remove(); |
| 112 |
window.location.href = deactivationUrl; |
| 113 |
}); |
| 114 |
}() ); |
| 115 |
|