PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / stripe / js / frmtrans_admin.js

frmtrans_admin.js in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More trunk, at stripe/js/frmtrans_admin.js

140 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function() {
2 function toggleSub() {
3 const val = this.value;
4 const show = val === 'recurring';
5 slideOpts( this, show, '.frm_trans_sub_opts' );
6 toggleOpts( this, ! show, '.frm_gateway_no_recur' );
7 }
8
9 function slideOpts( opt, show, c ) {
10 const opts = jQuery( opt ).closest( '.frm_form_action_settings' ).find( c );
11 if ( show ) {
12 opts.slideDown( 'fast' );
13 } else {
14 opts.slideUp( 'fast' );
15 }
16 }
17
18 function toggleOpts( opt, show, c ) {
19 const opts = jQuery( opt ).closest( '.frm_form_action_settings' ).find( c );
20 if ( show ) {
21 opts.css( 'display', '' );
22 opts.removeClass( 'frm_hidden' );
23 } else {
24 opts.css( 'display', 'none' );
25 opts.addClass( 'frm_hidden' );
26 }
27 }
28
29 function toggleGateway() {
30 const gateway = this.value;
31 const { checked } = this;
32
33 toggleOpts( this, checked, `.show_${ gateway }` );
34
35 const gateways = [ 'stripe', 'square', 'paypal' ];
36 const toggleOff = gateways.filter( g => g !== gateway );
37
38 const settings = jQuery( this ).closest( '.frm_form_action_settings' );
39 const showClass = `show_${ settings.find( '.frm_gateway_opt input:checked' ).attr( 'value' ) }`;
40
41 toggleOff.forEach(
42 function( gateway ) {
43 const gatewaySettings = settings.get( 0 ).querySelectorAll( `.show_${ gateway }` );
44 gatewaySettings.forEach(
45 setting => {
46 if ( ! setting.classList.contains( showClass ) ) {
47 setting.style.display = 'none';
48 }
49 }
50 );
51 }
52 );
53
54 wp.hooks.doAction( 'frm_trans_toggled_gateway', { gateway, checked, settings } );
55
56 document.querySelectorAll( '.frm-billing-section-heading' ).forEach( function( el ) {
57 el.textContent = gateway === 'paypal' ? el.dataset.billingLabel : el.dataset.customerLabel;
58 } );
59 }
60
61 function frmTransLiteAdminJS() {
62 return {
63 init() {
64 const actions = document.getElementById( 'frm_notification_settings' );
65 if ( actions ) {
66 jQuery( actions ).on( 'change', '.frm_trans_type', toggleSub );
67
68 document.addEventListener(
69 'change',
70 function( event ) {
71 if ( ! event.target || ! event.target.checked || 'radio' !== event.target.type ) {
72 return;
73 }
74
75 if ( event.target.closest( '.frm-long-icon-buttons' ) && event.target.closest( '.frm_form_action_settings' ) ) {
76 toggleGateway.call( event.target );
77 }
78 }
79 );
80 }
81
82 document.querySelectorAll( '.frm_trans_ajax_link' ).forEach(
83 link => link.addEventListener(
84 'click',
85 function( event ) {
86 runAjaxLink.bind( link )( event );
87 }
88 )
89 );
90 }
91 };
92 }
93
94 function runAjaxLink( e ) {
95 e.preventDefault();
96
97 const $link = jQuery( this );
98 const handleConfirmedClick = e => {
99 e.preventDefault();
100
101 const href = $link.attr( 'href' );
102 const loadingImage = document.createElement( 'span' );
103 loadingImage.className = 'frm-loading-img';
104
105 $link.replaceWith( loadingImage );
106 jQuery.ajax( {
107 type: 'GET',
108 url: href,
109 data: {
110 nonce: frm_trans_vars.nonce
111 },
112 success( html ) {
113 jQuery( loadingImage ).replaceWith( html );
114 }
115 } );
116 };
117
118 if ( ! e.currentTarget.dataset.frmverify ) {
119 handleConfirmedClick( e );
120 return;
121 }
122
123 jQuery( '#frm-confirmed-click' ).one( 'click', handleConfirmedClick );
124
125 // Prevent handleConfirmedClick from triggering when the current modal is closed so that it won't be run by other elements.
126 const unbindHandleConfirmedClick = e => {
127 if ( e.target.matches( '.ui-widget-overlay, .dismiss' ) ) {
128 // eslint-disable-next-line no-jquery/no-bind
129 jQuery( '#frm-confirmed-click' ).unbind( 'click', handleConfirmedClick );
130 document.removeEventListener( 'click', unbindHandleConfirmedClick );
131 }
132 };
133
134 document.addEventListener( 'click', unbindHandleConfirmedClick );
135 return false;
136 }
137
138 jQuery( document ).ready( frmTransLiteAdminJS().init );
139 }() );
140