Commit realizado el 12:13:52 08-04-2024
This commit is contained in:
File diff suppressed because one or more lines are too long
1
wp-content/plugins/wpforms-lite/assets/js/integrations/divi/formselector.es5.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/divi/formselector.es5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,176 @@
|
||||
/* global wpforms_divi_builder */
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
|
||||
/**
|
||||
* WPFormsSelector component.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
class WPFormsSelector extends Component {
|
||||
|
||||
/**
|
||||
* Module slug.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
static slug = 'wpforms_selector';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {string} props List of properties.
|
||||
*/
|
||||
constructor( props ) {
|
||||
|
||||
super( props );
|
||||
|
||||
this.state = {
|
||||
error: null,
|
||||
isLoading: true,
|
||||
form: null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set types for properties.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @returns {object} Properties type.
|
||||
*/
|
||||
static get propTypes() {
|
||||
|
||||
return {
|
||||
form_id: PropTypes.number, // eslint-disable-line camelcase
|
||||
show_title: PropTypes.string, // eslint-disable-line camelcase
|
||||
show_desc: PropTypes.string, // eslint-disable-line camelcase
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if form settings was updated.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {object} prevProps List of previous properties.
|
||||
*/
|
||||
componentDidUpdate( prevProps ) {
|
||||
|
||||
if ( prevProps.form_id !== this.props.form_id || prevProps.show_title !== this.props.show_title || prevProps.show_desc !== this.props.show_desc ) {
|
||||
this.componentDidMount();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax request for form HTML.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*/
|
||||
componentDidMount() {
|
||||
|
||||
var formData = new FormData();
|
||||
|
||||
formData.append( 'nonce', wpforms_divi_builder.nonce );
|
||||
formData.append( 'action', 'wpforms_divi_preview' );
|
||||
formData.append( 'form_id', this.props.form_id );
|
||||
formData.append( 'show_title', this.props.show_title );
|
||||
formData.append( 'show_desc', this.props.show_desc );
|
||||
|
||||
fetch(
|
||||
wpforms_divi_builder.ajax_url,
|
||||
{
|
||||
method: 'POST',
|
||||
cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Cache-Control': 'no-cache',
|
||||
},
|
||||
body: new URLSearchParams( formData ),
|
||||
},
|
||||
)
|
||||
.then( res => res.json() )
|
||||
.then(
|
||||
( result ) => {
|
||||
|
||||
this.setState( {
|
||||
isLoading: false,
|
||||
form: result.data,
|
||||
} );
|
||||
},
|
||||
( error ) => {
|
||||
|
||||
this.setState( {
|
||||
isLoading: false,
|
||||
error,
|
||||
} );
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render module view.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @returns {JSX.Element} View for module.
|
||||
*/
|
||||
render() {
|
||||
|
||||
var { error, isLoaded, form } = this.state,
|
||||
wrapperClasses = isLoaded ? 'wpforms-divi-form-preview loading' : 'wpforms-divi-form-preview';
|
||||
|
||||
if ( error || ! form ) {
|
||||
|
||||
return (
|
||||
<div className="wpforms-divi-form-placeholder">
|
||||
<img src={wpforms_divi_builder.placeholder}/>
|
||||
<h3>{wpforms_divi_builder.placeholder_title}</h3>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={wrapperClasses}>
|
||||
{<div dangerouslySetInnerHTML={{ __html: form }}/>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
jQuery( window )
|
||||
|
||||
// Register custom modules.
|
||||
.on( 'et_builder_api_ready', ( event, API ) => {
|
||||
API.registerModules( [ WPFormsSelector ] );
|
||||
} )
|
||||
|
||||
// Re-initialize WPForms frontend.
|
||||
.on( 'wpformsDiviModuleDisplay', ( event ) => {
|
||||
window.wpforms.init();
|
||||
} );
|
||||
|
||||
// Make all the modern dropdowns disabled.
|
||||
jQuery( document )
|
||||
.on( 'wpformsReady', ( event ) => {
|
||||
|
||||
var $ = jQuery;
|
||||
|
||||
$( '.choicesjs-select' ).each( function() {
|
||||
|
||||
var $instance = $( this ).data( 'choicesjs' );
|
||||
|
||||
if ( ! $instance || typeof $instance.disable !== 'function' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$instance.disable();
|
||||
} );
|
||||
} );
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/divi/formselector.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/divi/formselector.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,477 @@
|
||||
/* global elementor, elementorCommon, wpformsElementorVars, elementorFrontend, Choices */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* WPForms integration with Elementor (modern widget).
|
||||
*
|
||||
* @since 1.8.3
|
||||
*/
|
||||
var WPFormsElementorModern = window.WPFormsElementorModern || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
// Widget events.
|
||||
$( window )
|
||||
.on( 'elementor/frontend/init', function( event, id, instance ) {
|
||||
|
||||
elementor.channels.editor.on( 'elementorWPFormsResetStyleSettings', app.confirmResetStyleSettings );
|
||||
elementor.channels.editor.on( 'section:activated', app.checkForLeadForms );
|
||||
elementor.hooks.addAction( 'panel/open_editor/widget/wpforms', app.widgetPanelOpen );
|
||||
elementorFrontend.hooks.addAction( 'frontend/element_ready/wpforms.default', app.widgetReady );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* On section change event handler.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {string} sectionName The current section name.
|
||||
* @param {object} editor Editor instance.
|
||||
*
|
||||
*/
|
||||
checkForLeadForms( sectionName, editor ) {
|
||||
|
||||
if ( sectionName !== 'field_styles' || editor.model.attributes.widgetType !== 'wpforms' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
let $panelContent = editor.$childViewContainer[0];
|
||||
let widgetView = editor.options.editedElementView.$el[0];
|
||||
let formId = editor.model.attributes.settings.attributes.form_id;
|
||||
let $form = $( widgetView ).find( `#wpforms-${formId}` );
|
||||
|
||||
if ( $form.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $form.hasClass( 'wpforms-lead-forms-container' ) ) {
|
||||
$( $panelContent ).addClass( 'wpforms-elementor-disabled' );
|
||||
$( $panelContent ).find( '.wpforms-elementor-lead-forms-notice' ).css( 'display', 'block' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize widget controls when widget is activated.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {object} panel Panel object.
|
||||
* @param {object} model Model object.
|
||||
* @param {object} view View object.
|
||||
*/
|
||||
widgetPanelOpen: function( panel, model, view ) {
|
||||
|
||||
const settingsModel = model.get( 'settings' );
|
||||
|
||||
// Apply settings from the textarea.
|
||||
settingsModel.on( 'change:copyPasteJsonValue', ( changedModel ) => {
|
||||
app.pasteSettings( changedModel );
|
||||
} );
|
||||
|
||||
// Change style settings.
|
||||
settingsModel.on( 'change', ( changedModel ) => {
|
||||
app.changeStyleSettings( changedModel, view );
|
||||
|
||||
if ( ! changedModel.changed.copyPasteJsonValue && ! changedModel.changed.form_id ) {
|
||||
app.updateCopyPasteContent( changedModel );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Widget ready events.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {jQuery} $scope The current element wrapped with jQuery.
|
||||
*/
|
||||
widgetReady: function( $scope ) {
|
||||
|
||||
let formId = $scope.find( '.wpforms-form' ).data( 'formid' );
|
||||
|
||||
app.updateAccentColors( $scope, formId );
|
||||
app.loadChoicesJS( $scope, formId );
|
||||
app.initRichTextField( formId );
|
||||
},
|
||||
|
||||
/**
|
||||
* Show the reset style settings confirm popup.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {object} event Event object.
|
||||
*/
|
||||
confirmResetStyleSettings: function( event ) {
|
||||
|
||||
elementorCommon.dialogsManager.createWidget( 'confirm', {
|
||||
message: wpformsElementorVars.strings.reset_settings_confirm_text,
|
||||
headerMessage: wpformsElementorVars.strings.reset_style_settings,
|
||||
strings: {
|
||||
confirm: wpformsElementorVars.strings.continue,
|
||||
cancel: wpformsElementorVars.strings.cancel,
|
||||
},
|
||||
defaultOption: 'cancel',
|
||||
onConfirm: function onConfirm() {
|
||||
app.resetStyleSettings( event );
|
||||
},
|
||||
} ).show();
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset style settings button handler.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {object} event Event object.
|
||||
*/
|
||||
resetStyleSettings: function( event ) {
|
||||
|
||||
let model = event.options.elementSettingsModel;
|
||||
let container = event.options.container;
|
||||
let widgetContainer = container.view.$el[0];
|
||||
let defaults = model.defaults;
|
||||
let styleSettings = app.getStyleAttributesKeys();
|
||||
let globals = model.get( '__globals__' );
|
||||
let defaultValues = {};
|
||||
let $widgetStyles = $( widgetContainer ).find( '#wpforms-css-vars-root' ).next( 'style' );
|
||||
|
||||
// Prepare default style settings values.
|
||||
styleSettings.forEach( function( element ) {
|
||||
defaultValues[ element ] = defaults[element];
|
||||
} );
|
||||
|
||||
// Reset global style settings.
|
||||
if ( globals ) {
|
||||
elementorCommon.api.run( 'document/globals/settings', {
|
||||
container: container,
|
||||
settings: {},
|
||||
options: {
|
||||
external: true,
|
||||
render: false,
|
||||
},
|
||||
} );
|
||||
}
|
||||
|
||||
// Reset widget settings to default.
|
||||
elementorCommon.api.run( 'document/elements/settings', {
|
||||
container,
|
||||
options: {
|
||||
external: true,
|
||||
},
|
||||
settings: defaultValues,
|
||||
} );
|
||||
|
||||
// Reset CSS vars for widget container and form specific <style> tag.
|
||||
widgetContainer.style = '';
|
||||
$widgetStyles.text( '' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Change style setting handler.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {object} changedModel Changed model.
|
||||
* @param {object} view View.
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
changeStyleSettings: function( changedModel, view ) {
|
||||
|
||||
let widgetContainer = view.$el[0];
|
||||
let parsedAtts = changedModel.parseGlobalSettings( changedModel );
|
||||
|
||||
for ( let element in changedModel.changed ) {
|
||||
|
||||
if ( ! app.getStyleAttributesKeys().includes( element ) ) {
|
||||
view.allowRender = element !== 'copyPasteJsonValue';
|
||||
continue;
|
||||
}
|
||||
|
||||
view.allowRender = false;
|
||||
let attrValue = app.getParsedValue( element, parsedAtts );
|
||||
let property = element.replace( /[A-Z]/g, letter => `-${letter.toLowerCase()}` );
|
||||
let borderRadiusItems = [ 'fieldBorderRadius', 'buttonBorderRadius' ];
|
||||
|
||||
if ( borderRadiusItems.includes( element ) ) {
|
||||
attrValue = attrValue + 'px';
|
||||
}
|
||||
|
||||
switch ( property ) {
|
||||
case 'field-size':
|
||||
case 'label-size':
|
||||
case 'button-size':
|
||||
for ( const key in wpformsElementorVars.sizes[ property ][ attrValue ] ) {
|
||||
widgetContainer.style.setProperty(
|
||||
`--wpforms-${property}-${key}`,
|
||||
wpformsElementorVars.sizes[ property ][ attrValue ][ key ],
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
widgetContainer.style.setProperty( `--wpforms-${property}`, attrValue );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy/paste widget settings.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {object} model Settings model.
|
||||
*/
|
||||
updateCopyPasteContent: function( model ) {
|
||||
|
||||
let styleSettings = app.getStyleAttributesKeys();
|
||||
let content = {};
|
||||
let atts = model.parseGlobalSettings( model );
|
||||
|
||||
styleSettings.forEach( function( element ) {
|
||||
content[element] = app.getParsedValue( element, atts );
|
||||
} );
|
||||
|
||||
model.setExternalChange( 'copyPasteJsonValue', JSON.stringify( content ) );
|
||||
},
|
||||
|
||||
/**
|
||||
* Paste settings.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {object} model Settings model.
|
||||
*/
|
||||
pasteSettings: function( model ) {
|
||||
|
||||
let copyPasteJsonValue = model.changed.copyPasteJsonValue;
|
||||
let pasteAttributes = app.parseValidateJson( copyPasteJsonValue );
|
||||
|
||||
if ( ! pasteAttributes ) {
|
||||
|
||||
elementorCommon.dialogsManager.createWidget( 'alert', {
|
||||
message: wpformsElementorVars.strings.copy_paste_error,
|
||||
headerMessage: wpformsElementorVars.strings.heads_up,
|
||||
} ).show();
|
||||
|
||||
this.updateCopyPasteContent( model );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
model.set( pasteAttributes );
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Parse and validate JSON string.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {string} value JSON string.
|
||||
*
|
||||
* @returns {boolean|object} Parsed JSON object OR false on error.
|
||||
*/
|
||||
parseValidateJson: function( value ) {
|
||||
|
||||
if ( typeof value !== 'string' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let atts;
|
||||
|
||||
try {
|
||||
atts = JSON.parse( value );
|
||||
} catch ( error ) {
|
||||
atts = false;
|
||||
}
|
||||
|
||||
return atts;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get list of the style attributes keys.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @returns {Array} Style attributes keys.
|
||||
*/
|
||||
getStyleAttributesKeys: function() {
|
||||
|
||||
return [
|
||||
'fieldSize',
|
||||
'fieldBorderRadius',
|
||||
'fieldBackgroundColor',
|
||||
'fieldBorderColor',
|
||||
'fieldTextColor',
|
||||
'labelSize',
|
||||
'labelColor',
|
||||
'labelSublabelColor',
|
||||
'labelErrorColor',
|
||||
'buttonSize',
|
||||
'buttonBorderRadius',
|
||||
'buttonBackgroundColor',
|
||||
'buttonTextColor',
|
||||
];
|
||||
},
|
||||
|
||||
/**
|
||||
* Get parsed attribute value.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {string} attrName Attribute name.
|
||||
* @param {object} parsedAtts Parsed attributes.
|
||||
*
|
||||
* @returns {string} Attribute value.
|
||||
*/
|
||||
getParsedValue: function( attrName, parsedAtts ) {
|
||||
|
||||
let rawValue = parsedAtts[ attrName ];
|
||||
let value;
|
||||
|
||||
if ( typeof rawValue === 'undefined' ) {
|
||||
value = false;
|
||||
} else if ( typeof rawValue === 'object' && Object.prototype.hasOwnProperty.call( rawValue, 'value' ) ) {
|
||||
value = rawValue.value;
|
||||
} else {
|
||||
value = rawValue;
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize RichText field.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {int} formId Form ID.
|
||||
*/
|
||||
initRichTextField: function( formId ) {
|
||||
|
||||
// Set default tab to `Visual`.
|
||||
$( `#wpforms-${formId} .wp-editor-wrap` ).removeClass( 'html-active' ).addClass( 'tmce-active' );
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Update accent colors of some fields in Elementor widget.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {jQuery} widgetContainer Widget container.
|
||||
* @param {integer} formId Event details object.
|
||||
*/
|
||||
updateAccentColors: function( widgetContainer, formId ) {
|
||||
|
||||
const $form = widgetContainer.find( `#wpforms-${formId}` ),
|
||||
FrontendModern = window.WPForms.FrontendModern;
|
||||
|
||||
FrontendModern.updateGBBlockPageIndicatorColor( $form );
|
||||
FrontendModern.updateGBBlockIconChoicesColor( $form );
|
||||
FrontendModern.updateGBBlockRatingColor( $form );
|
||||
},
|
||||
|
||||
/**
|
||||
* Init Modern style Dropdown fields (<select>).
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {jQuery} widgetContainer Widget container.
|
||||
* @param {integer} formId Form id.
|
||||
*/
|
||||
loadChoicesJS: function( widgetContainer, formId ) {
|
||||
|
||||
if ( typeof window.Choices !== 'function' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $form = widgetContainer.find( `#wpforms-${formId}` );
|
||||
|
||||
$form.find( '.choicesjs-select' ).each( function( idx, el ) {
|
||||
|
||||
const $el = $( el );
|
||||
|
||||
if ( $el.data( 'choice' ) === 'active' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var args = window.wpforms_choicesjs_config || {},
|
||||
searchEnabled = $el.data( 'search-enabled' ),
|
||||
$field = $el.closest( '.wpforms-field' );
|
||||
|
||||
args.searchEnabled = 'undefined' !== typeof searchEnabled ? searchEnabled : true;
|
||||
args.callbackOnInit = function() {
|
||||
|
||||
var self = this,
|
||||
$element = $( self.passedElement.element ),
|
||||
$input = $( self.input.element ),
|
||||
sizeClass = $element.data( 'size-class' );
|
||||
|
||||
// Add CSS-class for size.
|
||||
if ( sizeClass ) {
|
||||
$( self.containerOuter.element ).addClass( sizeClass );
|
||||
}
|
||||
|
||||
/**
|
||||
* If a multiple select has selected choices - hide a placeholder text.
|
||||
* In case if select is empty - we return placeholder text back.
|
||||
*/
|
||||
if ( $element.prop( 'multiple' ) ) {
|
||||
|
||||
// On init event.
|
||||
$input.data( 'placeholder', $input.attr( 'placeholder' ) );
|
||||
|
||||
if ( self.getValue( true ).length ) {
|
||||
$input.removeAttr( 'placeholder' );
|
||||
}
|
||||
}
|
||||
|
||||
this.disable();
|
||||
$field.find( '.is-disabled' ).removeClass( 'is-disabled' );
|
||||
};
|
||||
|
||||
try {
|
||||
const choicesInstance = new Choices( el, args );
|
||||
|
||||
// Save Choices.js instance for future access.
|
||||
$el.data( 'choicesjs', choicesInstance );
|
||||
|
||||
} catch ( e ) {} // eslint-disable-line no-empty
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsElementorModern.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/elementor/editor-modern.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/elementor/editor-modern.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsElementorModern=window.WPFormsElementorModern||function(i,l){var d={init:function(){d.events()},events:function(){l(i).on("elementor/frontend/init",function(e,t,o){elementor.channels.editor.on("elementorWPFormsResetStyleSettings",d.confirmResetStyleSettings),elementor.channels.editor.on("section:activated",d.checkForLeadForms),elementor.hooks.addAction("panel/open_editor/widget/wpforms",d.widgetPanelOpen),elementorFrontend.hooks.addAction("frontend/element_ready/wpforms.default",d.widgetReady)})},checkForLeadForms(e,t){var o;"field_styles"===e&&"wpforms"===t.model.attributes.widgetType&&(e=t.$childViewContainer[0],o=t.options.editedElementView.$el[0],t=t.model.attributes.settings.attributes.form_id,0!==(o=l(o).find("#wpforms-"+t)).length)&&o.hasClass("wpforms-lead-forms-container")&&(l(e).addClass("wpforms-elementor-disabled"),l(e).find(".wpforms-elementor-lead-forms-notice").css("display","block"))},widgetPanelOpen:function(e,t,o){t=t.get("settings");t.on("change:copyPasteJsonValue",e=>{d.pasteSettings(e)}),t.on("change",e=>{d.changeStyleSettings(e,o),e.changed.copyPasteJsonValue||e.changed.form_id||d.updateCopyPasteContent(e)})},widgetReady:function(e){var t=e.find(".wpforms-form").data("formid");d.updateAccentColors(e,t),d.loadChoicesJS(e,t),d.initRichTextField(t)},confirmResetStyleSettings:function(e){elementorCommon.dialogsManager.createWidget("confirm",{message:wpformsElementorVars.strings.reset_settings_confirm_text,headerMessage:wpformsElementorVars.strings.reset_style_settings,strings:{confirm:wpformsElementorVars.strings.continue,cancel:wpformsElementorVars.strings.cancel},defaultOption:"cancel",onConfirm:function(){d.resetStyleSettings(e)}}).show()},resetStyleSettings:function(e){var t=e.options.elementSettingsModel,e=e.options.container,o=e.view.$el[0];let n=t.defaults;var s=d.getStyleAttributesKeys(),t=t.get("__globals__");let r={};var a=l(o).find("#wpforms-css-vars-root").next("style");s.forEach(function(e){r[e]=n[e]}),t&&elementorCommon.api.run("document/globals/settings",{container:e,settings:{},options:{external:!0,render:!1}}),elementorCommon.api.run("document/elements/settings",{container:e,options:{external:!0},settings:r}),o.style="",a.text("")},changeStyleSettings:function(e,t){var o,n=t.$el[0],s=e.parseGlobalSettings(e);for(o in e.changed)if(d.getStyleAttributesKeys().includes(o)){t.allowRender=!1;let e=d.getParsedValue(o,s);var r=o.replace(/[A-Z]/g,e=>"-"+e.toLowerCase());switch(["fieldBorderRadius","buttonBorderRadius"].includes(o)&&(e+="px"),r){case"field-size":case"label-size":case"button-size":for(const a in wpformsElementorVars.sizes[r][e])n.style.setProperty(`--wpforms-${r}-`+a,wpformsElementorVars.sizes[r][e][a]);break;default:n.style.setProperty("--wpforms-"+r,e)}}else t.allowRender="copyPasteJsonValue"!==o},updateCopyPasteContent:function(e){var t=d.getStyleAttributesKeys();let o={},n=e.parseGlobalSettings(e);t.forEach(function(e){o[e]=d.getParsedValue(e,n)}),e.setExternalChange("copyPasteJsonValue",JSON.stringify(o))},pasteSettings:function(e){var t=e.changed.copyPasteJsonValue,t=d.parseValidateJson(t);t?e.set(t):(elementorCommon.dialogsManager.createWidget("alert",{message:wpformsElementorVars.strings.copy_paste_error,headerMessage:wpformsElementorVars.strings.heads_up}).show(),this.updateCopyPasteContent(e))},parseValidateJson:function(e){if("string"!=typeof e)return!1;let t;try{t=JSON.parse(e)}catch(e){t=!1}return t},getStyleAttributesKeys:function(){return["fieldSize","fieldBorderRadius","fieldBackgroundColor","fieldBorderColor","fieldTextColor","labelSize","labelColor","labelSublabelColor","labelErrorColor","buttonSize","buttonBorderRadius","buttonBackgroundColor","buttonTextColor"]},getParsedValue:function(e,t){t=t[e];let o;return o=void 0!==t&&("object"==typeof t&&Object.prototype.hasOwnProperty.call(t,"value")?t.value:t)},initRichTextField:function(e){l(`#wpforms-${e} .wp-editor-wrap`).removeClass("html-active").addClass("tmce-active")},updateAccentColors:function(e,t){e=e.find("#wpforms-"+t),t=i.WPForms.FrontendModern;t.updateGBBlockPageIndicatorColor(e),t.updateGBBlockIconChoicesColor(e),t.updateGBBlockRatingColor(e)},loadChoicesJS:function(e,t){"function"==typeof i.Choices&&e.find("#wpforms-"+t).find(".choicesjs-select").each(function(e,t){var o=l(t);if("active"!==o.data("choice")){var n=i.wpforms_choicesjs_config||{},s=o.data("search-enabled"),r=o.closest(".wpforms-field");n.searchEnabled=void 0===s||s,n.callbackOnInit=function(){var e=l(this.passedElement.element),t=l(this.input.element),o=e.data("size-class");o&&l(this.containerOuter.element).addClass(o),e.prop("multiple")&&(t.data("placeholder",t.attr("placeholder")),this.getValue(!0).length)&&t.removeAttr("placeholder"),this.disable(),r.find(".is-disabled").removeClass("is-disabled")};try{var a=new Choices(t,n);o.data("choicesjs",a)}catch(e){}}})}};return d}((document,window),jQuery);WPFormsElementorModern.init();
|
@@ -0,0 +1,560 @@
|
||||
/* global wpformsElementorVars, elementor, elementorFrontend */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* WPForms integration with Elementor in the editor.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 1.6.2 Moved frontend integration to `wpforms-elementor-frontend.js`
|
||||
*/
|
||||
var WPFormsElementor = window.WPFormsElementor || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Runtime variables.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var vars = {};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
// Widget events.
|
||||
$( window ).on( 'elementor/frontend/init', function( event, id, instance ) {
|
||||
|
||||
// Widget buttons click.
|
||||
elementor.channels.editor.on( 'elementorWPFormsAddFormBtnClick', app.addFormBtnClick );
|
||||
|
||||
// Widget frontend events.
|
||||
elementorFrontend.hooks.addAction( 'frontend/element_ready/wpforms.default', app.widgetPreviewEvents );
|
||||
|
||||
// Initialize widget controls.
|
||||
elementor.hooks.addAction( 'panel/open_editor/widget/wpforms', app.widgetPanelOpen );
|
||||
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Widget events.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {jQuery} $scope The current element wrapped with jQuery.
|
||||
*/
|
||||
widgetPreviewEvents: function( $scope ) {
|
||||
|
||||
$scope
|
||||
.on( 'click', '.wpforms-btn', app.addFormBtnClick )
|
||||
.on( 'click', '.wpforms-admin-no-forms-container a', app.clickLinkInPreview )
|
||||
.on( 'change', '.wpforms-elementor-form-selector select', app.selectFormInPreview )
|
||||
.on( 'click mousedown focus keydown submit', '.wpforms-container *', app.disableEvents )
|
||||
.on( 'click', '.wpforms-comprehensive-link', app.openComprehensiveLink );
|
||||
|
||||
app.updateSameForms( $scope );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update all the same forms on the preview.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {jQuery} $scope The current element wrapped with jQuery.
|
||||
*/
|
||||
updateSameForms: function( $scope ) {
|
||||
|
||||
var elementId = $scope.data( 'id' ),
|
||||
$formContainer = $scope.find( '.wpforms-container' ),
|
||||
formContainerHtml = $formContainer.html(),
|
||||
formContainerId = $formContainer.attr( 'id' );
|
||||
|
||||
$scope
|
||||
.closest( '.elementor-inner' )
|
||||
.find( '.elementor-widget-wpforms:not(.elementor-element-' + elementId + ')' )
|
||||
.each( function() {
|
||||
|
||||
var $anotherFormContainer = $( this ).find( '.wpforms-container' );
|
||||
|
||||
if ( $anotherFormContainer.attr( 'id' ) === formContainerId ) {
|
||||
$anotherFormContainer.html( formContainerHtml );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize widget controls when widget is activated.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} panel Panel object.
|
||||
* @param {object} model Model object.
|
||||
*/
|
||||
widgetPanelOpen: function( panel, model ) {
|
||||
|
||||
vars.widgetId = model.attributes.id;
|
||||
vars.formId = model.attributes.settings.attributes.form_id;
|
||||
|
||||
app.widgetPanelInit( panel );
|
||||
|
||||
app.widgetPanelObserver.init( panel );
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialize widget controls when widget is activated.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} panel Panel object.
|
||||
*/
|
||||
widgetPanelInit: function( panel ) {
|
||||
|
||||
var $formSelectControl = panel.$el.find( '.elementor-control.elementor-control-form_id' ),
|
||||
$formSelect = $formSelectControl.find( 'select' ),
|
||||
$addFormNoticeControl = panel.$el.find( '.elementor-control.elementor-control-add_form_notice' ),
|
||||
$testFormNoticeControl = panel.$el.find( '.elementor-control.elementor-control-test_form_notice' );
|
||||
|
||||
// Update form select options if it is available after adding the form.
|
||||
if ( vars.formSelectOptions ) {
|
||||
$formSelect.html( vars.formSelectOptions );
|
||||
}
|
||||
|
||||
// Update form select value.
|
||||
if ( vars.formId && vars.formId !== '' ) {
|
||||
$formSelect.val( vars.formId );
|
||||
}
|
||||
|
||||
// Hide not needed controls.
|
||||
if ( $formSelect.find( 'option' ).length > 0 ) {
|
||||
$addFormNoticeControl.hide();
|
||||
} else {
|
||||
$formSelectControl.hide();
|
||||
$testFormNoticeControl.hide();
|
||||
}
|
||||
|
||||
// Show needed controls.
|
||||
if ( parseInt( $formSelect.val(), 10 ) > 0 ) {
|
||||
$testFormNoticeControl.show();
|
||||
}
|
||||
|
||||
// Select form.
|
||||
panel.$el.find( '.elementor-control.elementor-control-form_id' ).on( 'change', 'select', function() {
|
||||
|
||||
// Update `vars.formId` to be able to restore selected value after options update.
|
||||
vars.formId = $( this ).val();
|
||||
} );
|
||||
|
||||
// Click on the `Edit the selected form` link.
|
||||
panel.$el.find( '.elementor-control.elementor-control-edit_form' ).on( 'click', 'a', app.editFormLinkClick );
|
||||
},
|
||||
|
||||
/**
|
||||
* The observer needed to re-init controls when the widget panel section and tabs switches.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @member {object}
|
||||
*/
|
||||
widgetPanelObserver: {
|
||||
|
||||
/**
|
||||
* Initialize observer.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {object} panel Panel object.
|
||||
*/
|
||||
init: function( panel ) {
|
||||
|
||||
// Skip if observer for current widget already initialized.
|
||||
if ( vars.observerWidgetId === vars.widgetId ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Disconnect previous widget observer.
|
||||
if ( typeof vars.observer !== 'undefined' && typeof vars.observer.disconnect === 'function' ) {
|
||||
vars.observer.disconnect();
|
||||
}
|
||||
|
||||
var obs = {
|
||||
targetNode : panel.$el.find( '#elementor-panel-content-wrapper' )[0],
|
||||
config : {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
},
|
||||
};
|
||||
|
||||
app.widgetPanelObserver.panel = panel;
|
||||
|
||||
obs.observer = new MutationObserver( app.widgetPanelObserver.callback );
|
||||
obs.observer.observe( obs.targetNode, obs.config );
|
||||
|
||||
vars.observerWidgetId = vars.widgetId;
|
||||
vars.observer = obs.observer;
|
||||
},
|
||||
|
||||
/**
|
||||
* Observer callback.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {Array} mutationsList Mutation list.
|
||||
*/
|
||||
callback: function( mutationsList ) {
|
||||
|
||||
var mutation,
|
||||
quit = false;
|
||||
|
||||
for ( var i in mutationsList ) {
|
||||
mutation = mutationsList[ i ];
|
||||
|
||||
if ( mutation.type === 'childList' && mutation.addedNodes.length > 0 ) {
|
||||
quit = app.widgetPanelObserver.callbackMutationChildList( mutation );
|
||||
}
|
||||
|
||||
if ( mutation.type === 'attributes' ) {
|
||||
quit = app.widgetPanelObserver.callbackMutationAttributes( mutation );
|
||||
}
|
||||
|
||||
if ( quit ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Process 'childList' mutation.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {MutationRecord} mutation Mutation record.
|
||||
*
|
||||
* @returns {boolean} True if detect needed node.
|
||||
*/
|
||||
callbackMutationChildList: function( mutation ) {
|
||||
|
||||
var addedNodes = mutation.addedNodes || [],
|
||||
node;
|
||||
|
||||
for ( var n in addedNodes ) {
|
||||
node = addedNodes[ n ];
|
||||
|
||||
if ( node && node.classList && node.classList.contains( 'elementor-control-section_form' ) ) {
|
||||
app.widgetPanelInit( app.widgetPanelObserver.panel );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Process 'attributes' mutation.
|
||||
*
|
||||
* @since 1.6.3
|
||||
*
|
||||
* @param {MutationRecord} mutation Mutation record.
|
||||
*
|
||||
* @returns {boolean} True if detect needed target.
|
||||
*/
|
||||
callbackMutationAttributes: function( mutation ) {
|
||||
|
||||
if (
|
||||
mutation.target &&
|
||||
mutation.target.classList &&
|
||||
mutation.target.classList.contains( 'elementor-tab-control-content' )
|
||||
) {
|
||||
app.widgetPanelInit( app.widgetPanelObserver.panel );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Edit selected form button click event handler.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} event Event object.
|
||||
*/
|
||||
editFormLinkClick: function( event ) {
|
||||
|
||||
app.findFormSelector( event );
|
||||
app.openBuilderPopup( vars.$select.val() );
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new form button click event handler.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} event Event object.
|
||||
*/
|
||||
addFormBtnClick: function( event ) {
|
||||
|
||||
app.findFormSelector( event );
|
||||
app.openBuilderPopup( 0 );
|
||||
},
|
||||
|
||||
/**
|
||||
* Find and store the form selector control wrapped in jQuery object.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} event Event object.
|
||||
*/
|
||||
findFormSelector: function( event ) {
|
||||
|
||||
let view = elementor.getPanelView().getCurrentPageView();
|
||||
|
||||
// We need to be sure that we are on the widget Content section.
|
||||
if ( view.activeSection && view.activeSection !== 'section_form' ) {
|
||||
$( view.ui.tabs[0] ).trigger( 'click' );
|
||||
}
|
||||
|
||||
vars.$select = event && event.$el ?
|
||||
event.$el.closest( '#elementor-controls' ).find( 'select[data-setting="form_id"]' ) :
|
||||
window.parent.jQuery( '#elementor-controls select[data-setting="form_id"]' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Preview: Form selector event handler.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
selectFormInPreview: function() {
|
||||
|
||||
vars.formId = $( this ).val();
|
||||
|
||||
app.findFormSelector();
|
||||
|
||||
// To be sure, that both form selector selects are in sync.
|
||||
app.refreshFormsList( null, vars.formId );
|
||||
},
|
||||
|
||||
/**
|
||||
* Preview: Click on the link event handler.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} event Event object.
|
||||
*/
|
||||
clickLinkInPreview: function( event ) {
|
||||
|
||||
if ( event.target && event.target.href ) {
|
||||
window.open( event.target.href, '_blank', 'noopener,noreferrer' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable events.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} event Event object.
|
||||
*
|
||||
* @returns {boolean} Always false.
|
||||
*/
|
||||
disableEvents: function( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Open the compreshenvie guide link,
|
||||
* as elementor disables all links in the preview.
|
||||
*
|
||||
* @since 1.8.3
|
||||
*
|
||||
* @param {object} event Event object.
|
||||
*/
|
||||
openComprehensiveLink: function( event ) {
|
||||
|
||||
const url = $( this ).attr( 'href' );
|
||||
|
||||
// Open the url in a new tab with JS bc elementor doesn't allow links in the preview.
|
||||
window.open( url, '_blank' ).focus();
|
||||
},
|
||||
|
||||
/**
|
||||
* Open builder popup.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {number} formId Form id. 0 for create new form.
|
||||
*/
|
||||
openBuilderPopup: function( formId ) {
|
||||
|
||||
formId = parseInt( formId || '0', 10 );
|
||||
|
||||
if ( ! vars.$popup ) {
|
||||
|
||||
// We need to add popup markup to the editor top document.
|
||||
var $elementor = window.parent.jQuery( '#elementor-editor-wrapper' ),
|
||||
popupTpl = wp.template( 'wpforms-builder-elementor-popup' );
|
||||
|
||||
$elementor.after( popupTpl() );
|
||||
vars.$popup = $elementor.siblings( '#wpforms-builder-elementor-popup' );
|
||||
}
|
||||
|
||||
var url = formId > 0 ? wpformsElementorVars.edit_form_url + formId : wpformsElementorVars.add_form_url,
|
||||
$iframe = vars.$popup.find( 'iframe' );
|
||||
|
||||
app.builderCloseButtonEvent();
|
||||
$iframe.attr( 'src', url );
|
||||
vars.$popup.fadeIn();
|
||||
},
|
||||
|
||||
/**
|
||||
* Close button (inside the form builder) click event.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
builderCloseButtonEvent: function() {
|
||||
|
||||
vars.$popup
|
||||
.off( 'wpformsBuilderInPopupClose' )
|
||||
.on( 'wpformsBuilderInPopupClose', function( e, action, formId ) {
|
||||
|
||||
if ( action !== 'saved' || ! formId ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.refreshFormsList( null, formId );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Refresh forms list event handler.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} event Event object.
|
||||
* @param {number} setFormId Set selected form to.
|
||||
*/
|
||||
refreshFormsList: function( event, setFormId ) {
|
||||
|
||||
if ( event ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
app.findFormSelector();
|
||||
|
||||
var data = {
|
||||
action: 'wpforms_admin_get_form_selector_options',
|
||||
nonce : wpformsElementorVars.nonce,
|
||||
};
|
||||
|
||||
vars.$select.prop( 'disabled', true );
|
||||
|
||||
$.post( wpformsElementorVars.ajax_url, data )
|
||||
.done( function( response ) {
|
||||
|
||||
if ( ! response.success ) {
|
||||
app.debug( response );
|
||||
return;
|
||||
}
|
||||
|
||||
vars.formSelectOptions = response.data;
|
||||
vars.$select.html( response.data );
|
||||
|
||||
if ( setFormId ) {
|
||||
vars.formId = setFormId;
|
||||
}
|
||||
|
||||
if ( vars.formId && vars.formId !== '' ) {
|
||||
vars.$select.val( vars.formId ).trigger( 'change' );
|
||||
}
|
||||
} )
|
||||
.fail( function( xhr, textStatus ) {
|
||||
|
||||
app.debug( {
|
||||
xhr: xhr,
|
||||
textStatus: textStatus,
|
||||
} );
|
||||
} )
|
||||
.always( function() {
|
||||
|
||||
if ( ! vars.$select || vars.$select.length < 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
vars.$select.prop( 'disabled', false );
|
||||
|
||||
var $formSelectOptions = vars.$select.find( 'option' ),
|
||||
$formSelectControl = vars.$select.closest( '.elementor-control' );
|
||||
|
||||
if ( $formSelectOptions.length > 0 ) {
|
||||
$formSelectControl.show();
|
||||
$formSelectControl.siblings( '.elementor-control-add_form_notice' ).hide();
|
||||
}
|
||||
if ( parseInt( vars.$select.val(), 10 ) > 0 ) {
|
||||
$formSelectControl.siblings( '.elementor-control-test_form_notice' ).show();
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Debug output helper.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {mixed} msg Debug message.
|
||||
*/
|
||||
debug: function( msg ) {
|
||||
|
||||
if ( app.isDebug() ) {
|
||||
console.log( 'WPForms Debug:', msg );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Is debug mode.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @returns {boolean} True if the debug enabled.
|
||||
*/
|
||||
isDebug: function() {
|
||||
|
||||
return ( ( window.top.location.hash && '#wpformsdebug' === window.top.location.hash ) || wpformsElementorVars.debug );
|
||||
},
|
||||
};
|
||||
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsElementor.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/elementor/editor.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/elementor/editor.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,89 @@
|
||||
/* global wpforms, wpformsElementorVars, wpformsModernFileUpload, wpformsRecaptchaLoad, grecaptcha */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* WPForms integration with Elementor on the frontend.
|
||||
*
|
||||
* @since 1.6.2 Moved from `wpforms-elementor.js`
|
||||
*/
|
||||
var WPFormsElementorFrontend = window.WPFormsElementorFrontend || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
var app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Register JS events.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*/
|
||||
events: function() {
|
||||
|
||||
window.addEventListener( 'elementor/popup/show', function( event ) {
|
||||
|
||||
let $modal = $( '#elementor-popup-modal-' + event.detail.id ),
|
||||
$form = $modal.find( '.wpforms-form' );
|
||||
|
||||
if ( ! $form.length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.initFields( $form );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Init all things for WPForms.
|
||||
*
|
||||
* @since 1.6.2
|
||||
*
|
||||
* @param {object} $form jQuery selector.
|
||||
*/
|
||||
initFields: function( $form ) {
|
||||
|
||||
// Init WPForms things.
|
||||
wpforms.ready();
|
||||
|
||||
// Init `Modern File Upload` field.
|
||||
if ( 'undefined' !== typeof wpformsModernFileUpload ) {
|
||||
wpformsModernFileUpload.init();
|
||||
}
|
||||
|
||||
// Init CAPTCHA.
|
||||
if ( 'undefined' !== typeof wpformsRecaptchaLoad ) {
|
||||
if ( 'recaptcha' === wpformsElementorVars.captcha_provider && 'v3' === wpformsElementorVars.recaptcha_type ) {
|
||||
if ( 'undefined' !== typeof grecaptcha ) {
|
||||
grecaptcha.ready( wpformsRecaptchaLoad );
|
||||
}
|
||||
} else {
|
||||
wpformsRecaptchaLoad();
|
||||
}
|
||||
}
|
||||
|
||||
// Register a custom event.
|
||||
$( document ).trigger( 'wpforms_elementor_form_fields_initialized', [ $form ] );
|
||||
},
|
||||
};
|
||||
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsElementorFrontend.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/elementor/frontend.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/elementor/frontend.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsElementorFrontend=window.WPFormsElementorFrontend||function(o,e,n){var r={init:function(){r.events()},events:function(){e.addEventListener("elementor/popup/show",function(e){e=n("#elementor-popup-modal-"+e.detail.id).find(".wpforms-form");e.length&&r.initFields(e)})},initFields:function(e){wpforms.ready(),"undefined"!=typeof wpformsModernFileUpload&&wpformsModernFileUpload.init(),"undefined"!=typeof wpformsRecaptchaLoad&&("recaptcha"===wpformsElementorVars.captcha_provider&&"v3"===wpformsElementorVars.recaptcha_type?"undefined"!=typeof grecaptcha&&grecaptcha.ready(wpformsRecaptchaLoad):wpformsRecaptchaLoad()),n(o).trigger("wpforms_elementor_form_fields_initialized",[e])}};return r}(document,window,jQuery);WPFormsElementorFrontend.init();
|
@@ -0,0 +1,346 @@
|
||||
/* global wpforms_builder, wpforms_builder_stripe */
|
||||
|
||||
/**
|
||||
* Stripe builder function.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
const WPFormsStripeModernBuilder = window.WPFormsStripeModernBuilder || ( function( document, window, $ ) {
|
||||
/**
|
||||
* Elements holder.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
let el = {};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
const app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
init() {
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialized once the DOM is fully loaded.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
ready() {
|
||||
if ( app.isLegacySettings() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Cache DOM elements.
|
||||
el = {
|
||||
$alert: $( '#wpforms-stripe-credit-card-alert' ),
|
||||
$panelContent: $( '#wpforms-panel-content-section-payment-stripe' ),
|
||||
$feeNotice: $( '.wpforms-stripe-notice-info' ),
|
||||
};
|
||||
|
||||
app.bindUIActions();
|
||||
|
||||
if ( ! wpforms_builder_stripe.is_pro ) {
|
||||
const toggleInput = '.wpforms-panel-content-section-payment-toggle input',
|
||||
planNameInput = '.wpforms-panel-content-section-payment-plan-name input';
|
||||
|
||||
$( toggleInput ).each( app.toggleContent );
|
||||
$( planNameInput ).each( app.checkPlanName );
|
||||
|
||||
$( '#wpforms-panel-payments' )
|
||||
.on( 'click', toggleInput, app.toggleContent )
|
||||
.on( 'click', '.wpforms-panel-content-section-payment-plan-head-buttons-toggle', app.togglePlan )
|
||||
.on( 'click', '.wpforms-panel-content-section-payment-plan-head-buttons-delete', app.deletePlan )
|
||||
.on( 'input', planNameInput, app.renamePlan )
|
||||
.on( 'focusout', planNameInput, app.checkPlanName );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Process various events as a response to UI interactions.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
bindUIActions() {
|
||||
const $builder = $( '#wpforms-builder' );
|
||||
|
||||
$builder.on( 'wpformsFieldDelete', app.disableNotifications )
|
||||
.on( 'wpformsSaved', app.requiredFieldsCheck )
|
||||
.on( 'wpformsFieldAdd', app.fieldAdded )
|
||||
.on( 'wpformsFieldDelete', app.fieldDeleted )
|
||||
.on( 'wpformsPaymentsPlanCreated', app.toggleMultiplePlansWarning )
|
||||
.on( 'wpformsPaymentsPlanDeleted', app.toggleMultiplePlansWarning );
|
||||
},
|
||||
|
||||
/**
|
||||
* On form save notify users about required fields.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
requiredFieldsCheck() {
|
||||
if ( ! $( '#wpforms-panel-field-stripe-enable_recurring' ).is( ':checked' ) || el.$panelContent.hasClass( 'wpforms-hidden' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.$panelContent.find( '.wpforms-panel-content-section-payment-plan' ).each( function() {
|
||||
const $plan = $( this ),
|
||||
planId = $plan.data( 'plan-id' );
|
||||
|
||||
if ( ! $plan.find( `#wpforms-panel-field-stripe-recurring-${ planId }-email` ).val() ) {
|
||||
app.recurringEmailAlert();
|
||||
|
||||
return false;
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Show alert for required recurring email field.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
recurringEmailAlert() {
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.stripe_recurring_email,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable notifications.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {Object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
disableNotifications( e, id, type ) {
|
||||
if ( ! app.isStripeField( type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $notificationWrap = $( '.wpforms-panel-content-section-notifications [id*="-stripe-wrap"]' );
|
||||
|
||||
$notificationWrap.find( 'input[id*="-stripe"]' ).prop( 'checked', false );
|
||||
$notificationWrap.addClass( 'wpforms-hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Determinate is legacy settings is loaded.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @return {boolean} True is legacy settings loaded.
|
||||
*/
|
||||
isLegacySettings() {
|
||||
return $( '#wpforms-panel-field-stripe-enable' ).length;
|
||||
},
|
||||
|
||||
/**
|
||||
* We have to do several actions when the "Stripe" field is added.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {Object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
fieldAdded( e, id, type ) {
|
||||
if ( ! app.isStripeField( type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.settingsToggle( true );
|
||||
el.$feeNotice.toggleClass( 'wpforms-hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* We have to do several actions when the "Stripe" field is deleted.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {Object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
fieldDeleted( e, id, type ) {
|
||||
if ( ! app.isStripeField( type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.settingsToggle( false );
|
||||
el.$feeNotice.toggleClass( 'wpforms-hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Determinate if field type is Stripe credit card.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {string} type Field type.
|
||||
*
|
||||
* @return {boolean} True if Stripe field.
|
||||
*/
|
||||
isStripeField( type ) {
|
||||
return wpforms_builder_stripe.field_slugs.includes( type );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles visibility of multiple plans warning.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
toggleMultiplePlansWarning() {
|
||||
el.$panelContent.find( '.wpforms-stripe-multiple-plans-warning' ).toggleClass( 'wpforms-hidden', el.$panelContent.find( '.wpforms-panel-content-section-payment-plan' ).length === 1 );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles visibility of the Stripe addon settings.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {boolean} display Show or hide settings.
|
||||
*/
|
||||
settingsToggle( display ) {
|
||||
if (
|
||||
! el.$alert.length &&
|
||||
! el.$panelContent.length
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
el.$alert.toggleClass( 'wpforms-hidden', display );
|
||||
el.$panelContent.toggleClass( 'wpforms-hidden', ! display );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle payments content.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
toggleContent() {
|
||||
const $input = $( this );
|
||||
|
||||
if (
|
||||
$( '#wpforms-panel-field-stripe-enable_recurring' ).is( ':checked' ) &&
|
||||
$( '#wpforms-panel-field-stripe-enable_one_time' ).is( ':checked' )
|
||||
) {
|
||||
$input.prop( 'checked', false );
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: $input.attr( 'id' ) === 'wpforms-panel-field-stripe-enable_recurring' ? wpforms_builder_stripe.disabled_recurring : wpforms_builder_stripe.disabled_one_time,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
|
||||
$input.prop( 'checked', false );
|
||||
}
|
||||
|
||||
const $wrapper = $input.closest( '.wpforms-panel-content-section-payment' ),
|
||||
isChecked = $input.prop( 'checked' ) && ! $( '#wpforms-panel-field-settings-disable_entries' ).prop( 'checked' );
|
||||
|
||||
$wrapper.find( '.wpforms-panel-content-section-payment-toggled-body' ).toggle( isChecked );
|
||||
$wrapper.toggleClass( 'wpforms-panel-content-section-payment-open', isChecked );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle a plan content.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
togglePlan() {
|
||||
const $plan = $( this ).closest( '.wpforms-panel-content-section-payment-plan' ),
|
||||
$icon = $plan.find( '.wpforms-panel-content-section-payment-plan-head-buttons-toggle' );
|
||||
|
||||
$icon.toggleClass( 'fa-chevron-circle-up fa-chevron-circle-down' );
|
||||
$plan.find( '.wpforms-panel-content-section-payment-plan-body' ).toggle( $icon.hasClass( 'fa-chevron-circle-down' ) );
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a plan.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
deletePlan() {
|
||||
// Trigger a warning modal when trying to delete single plan without pro addon.
|
||||
$( '.wpforms-panel-content-section-payment-button-add-plan' ).click();
|
||||
},
|
||||
|
||||
/**
|
||||
* Check a plan name on empty value.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
checkPlanName() {
|
||||
const $input = $( this ),
|
||||
$plan = $input.closest( '.wpforms-panel-content-section-payment-plan' ),
|
||||
$planName = $plan.find( '.wpforms-panel-content-section-payment-plan-head-title' );
|
||||
|
||||
if ( $input.val() ) {
|
||||
$planName.html( $input.val() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultValue = wpforms_builder_stripe.plan_placeholder;
|
||||
|
||||
$planName.html( defaultValue );
|
||||
$input.val( defaultValue );
|
||||
},
|
||||
|
||||
/**
|
||||
* Rename a plan.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
renamePlan() {
|
||||
const $input = $( this ),
|
||||
$plan = $input.closest( '.wpforms-panel-content-section-payment-plan' ),
|
||||
$planName = $plan.find( '.wpforms-panel-content-section-payment-plan-head-title' );
|
||||
|
||||
if ( ! $input.val() ) {
|
||||
$planName.html( '' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$planName.html( $input.val() );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsStripeModernBuilder.init();
|
@@ -0,0 +1 @@
|
||||
const WPFormsStripeModernBuilder=window.WPFormsStripeModernBuilder||function(l){let o={};const i={init(){l(i.ready)},ready(){var e,n;i.isLegacySettings()||(o={$alert:l("#wpforms-stripe-credit-card-alert"),$panelContent:l("#wpforms-panel-content-section-payment-stripe"),$feeNotice:l(".wpforms-stripe-notice-info")},i.bindUIActions(),wpforms_builder_stripe.is_pro)||(n=".wpforms-panel-content-section-payment-plan-name input",l(e=".wpforms-panel-content-section-payment-toggle input").each(i.toggleContent),l(n).each(i.checkPlanName),l("#wpforms-panel-payments").on("click",e,i.toggleContent).on("click",".wpforms-panel-content-section-payment-plan-head-buttons-toggle",i.togglePlan).on("click",".wpforms-panel-content-section-payment-plan-head-buttons-delete",i.deletePlan).on("input",n,i.renamePlan).on("focusout",n,i.checkPlanName))},bindUIActions(){l("#wpforms-builder").on("wpformsFieldDelete",i.disableNotifications).on("wpformsSaved",i.requiredFieldsCheck).on("wpformsFieldAdd",i.fieldAdded).on("wpformsFieldDelete",i.fieldDeleted).on("wpformsPaymentsPlanCreated",i.toggleMultiplePlansWarning).on("wpformsPaymentsPlanDeleted",i.toggleMultiplePlansWarning)},requiredFieldsCheck(){l("#wpforms-panel-field-stripe-enable_recurring").is(":checked")&&!o.$panelContent.hasClass("wpforms-hidden")&&o.$panelContent.find(".wpforms-panel-content-section-payment-plan").each(function(){var e=l(this),n=e.data("plan-id");if(!e.find(`#wpforms-panel-field-stripe-recurring-${n}-email`).val())return i.recurringEmailAlert(),!1})},recurringEmailAlert(){l.alert({title:wpforms_builder.heads_up,content:wpforms_builder.stripe_recurring_email,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}})},disableNotifications(e,n,t){i.isStripeField(t)&&((t=l('.wpforms-panel-content-section-notifications [id*="-stripe-wrap"]')).find('input[id*="-stripe"]').prop("checked",!1),t.addClass("wpforms-hidden"))},isLegacySettings(){return l("#wpforms-panel-field-stripe-enable").length},fieldAdded(e,n,t){i.isStripeField(t)&&(i.settingsToggle(!0),o.$feeNotice.toggleClass("wpforms-hidden"))},fieldDeleted(e,n,t){i.isStripeField(t)&&(i.settingsToggle(!1),o.$feeNotice.toggleClass("wpforms-hidden"))},isStripeField(e){return wpforms_builder_stripe.field_slugs.includes(e)},toggleMultiplePlansWarning(){o.$panelContent.find(".wpforms-stripe-multiple-plans-warning").toggleClass("wpforms-hidden",1===o.$panelContent.find(".wpforms-panel-content-section-payment-plan").length)},settingsToggle(e){(o.$alert.length||o.$panelContent.length)&&(o.$alert.toggleClass("wpforms-hidden",e),o.$panelContent.toggleClass("wpforms-hidden",!e))},toggleContent(){var e=l(this),n=(l("#wpforms-panel-field-stripe-enable_recurring").is(":checked")&&l("#wpforms-panel-field-stripe-enable_one_time").is(":checked")&&(e.prop("checked",!1),l.alert({title:wpforms_builder.heads_up,content:"wpforms-panel-field-stripe-enable_recurring"===e.attr("id")?wpforms_builder_stripe.disabled_recurring:wpforms_builder_stripe.disabled_one_time,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}}),e.prop("checked",!1)),e.closest(".wpforms-panel-content-section-payment")),e=e.prop("checked")&&!l("#wpforms-panel-field-settings-disable_entries").prop("checked");n.find(".wpforms-panel-content-section-payment-toggled-body").toggle(e),n.toggleClass("wpforms-panel-content-section-payment-open",e)},togglePlan(){var e=l(this).closest(".wpforms-panel-content-section-payment-plan"),n=e.find(".wpforms-panel-content-section-payment-plan-head-buttons-toggle");n.toggleClass("fa-chevron-circle-up fa-chevron-circle-down"),e.find(".wpforms-panel-content-section-payment-plan-body").toggle(n.hasClass("fa-chevron-circle-down"))},deletePlan(){l(".wpforms-panel-content-section-payment-button-add-plan").click()},checkPlanName(){var e,n=l(this),t=n.closest(".wpforms-panel-content-section-payment-plan").find(".wpforms-panel-content-section-payment-plan-head-title");n.val()?t.html(n.val()):(e=wpforms_builder_stripe.plan_placeholder,t.html(e),n.val(e))},renamePlan(){var e=l(this),n=e.closest(".wpforms-panel-content-section-payment-plan").find(".wpforms-panel-content-section-payment-plan-head-title");e.val()?n.html(e.val()):n.html("")}};return i}((document,window,jQuery));WPFormsStripeModernBuilder.init();
|
@@ -0,0 +1,220 @@
|
||||
/* global wpforms_builder, wpforms_builder_stripe_card_field */
|
||||
|
||||
/**
|
||||
* WPForms Stripe Card Field function.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var WPFormsStripeCardField = window.WPFormsStripeCardField || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
const app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
app.bindUIActions();
|
||||
},
|
||||
|
||||
/**
|
||||
* Process various events as a response to UI interactions.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
bindUIActions: function() {
|
||||
|
||||
$( document ).on( 'wpformsSaved', app.ajaxRequiredCheck );
|
||||
$( document ).on( 'wpformsSaved', app.paymentsEnabledCheck );
|
||||
|
||||
$( document ).on( 'click', '#wpforms-add-fields-' + wpforms_builder_stripe_card_field.field_slug, app.stripeKeysCheck );
|
||||
$( document ).on( 'change', '.wpforms-field-option-stripe-credit-card .wpforms-field-option-row-sublabel_position select', app.sublabelPositionChange );
|
||||
$( document ).on( 'change', '.wpforms-field-option-stripe-credit-card .wpforms-field-option-row-link_email select', app.linkEmailChange );
|
||||
|
||||
$( document ).on( 'wpformsFieldAdd', app.disableAddCardButton );
|
||||
$( document ).on( 'wpformsFieldDelete', app.enableAddCardButton );
|
||||
$( document ).on( 'wpformsFieldDelete', app.maybeResetLinkEmailField );
|
||||
},
|
||||
|
||||
/**
|
||||
* On form save notify users if AJAX submission is required.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
ajaxRequiredCheck: function() {
|
||||
|
||||
if ( ! $( '.wpforms-field.wpforms-field-' + wpforms_builder_stripe_card_field.field_slug ).length ||
|
||||
$( '#wpforms-panel-field-settings-ajax_submit' ).is( ':checked' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.stripe_ajax_required,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* On form save notify users if Stripe payments are not enabled.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
paymentsEnabledCheck: function() {
|
||||
|
||||
if ( ! $( `.wpforms-field.wpforms-field-${ wpforms_builder_stripe_card_field.field_slug }:visible` ).length ||
|
||||
$( '#wpforms-panel-field-stripe-enable' ).is( ':checked' ) ||
|
||||
$( '#wpforms-panel-field-stripe-enable_one_time' ).is( ':checked' ) ||
|
||||
$( '#wpforms-panel-field-stripe-enable_recurring' ).is( ':checked' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.payments_enabled_required,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* On adding Stripe Credit Card field notify users if Stripe keys are missing.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
stripeKeysCheck: function() {
|
||||
|
||||
if ( ! $( this ).hasClass( 'stripe-keys-required' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.stripe_keys_required,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable "Add Card" button in the fields list.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
disableAddCardButton: function( e, id, type ) {
|
||||
|
||||
if ( wpforms_builder_stripe_card_field.field_slug === type ) {
|
||||
$( '#wpforms-add-fields-' + wpforms_builder_stripe_card_field.field_slug )
|
||||
.prop( 'disabled', true );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Enable "Add Card" button in the fields list.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
enableAddCardButton: function( e, id, type ) {
|
||||
|
||||
if ( wpforms_builder_stripe_card_field.field_slug === type ) {
|
||||
$( '#wpforms-add-fields-' + wpforms_builder_stripe_card_field.field_slug )
|
||||
.prop( 'disabled', false );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Switch sublabels preview mode.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
sublabelPositionChange: function() {
|
||||
|
||||
const fieldId = $( this ).parent().data( 'field-id' ),
|
||||
$fieldPreview = $( `#wpforms-field-${fieldId}` ).find( '.wpforms-stripe-payment-element' );
|
||||
|
||||
$fieldPreview.toggleClass( 'above' );
|
||||
$fieldPreview.toggleClass( 'floating' );
|
||||
$fieldPreview.find( 'select' ).val( $fieldPreview.hasClass( 'above' ) ? 'empty' : 'country' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Switch Link Email Field mapping.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
linkEmailChange: function() {
|
||||
|
||||
const fieldId = $( this ).parent().data( 'field-id' );
|
||||
|
||||
$( `#wpforms-field-${fieldId}` ).find( '.wpforms-stripe-link-email' ).toggleClass( 'wpforms-hidden', $( this ).val() !== '' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Maybe reset link email field if mapped email was removed.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
maybeResetLinkEmailField: function( e, id, type ) {
|
||||
|
||||
if ( type !== 'email' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$( '.wpforms-field-option-stripe-credit-card .wpforms-field-option-row-link_email select' ).trigger( 'change' );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsStripeCardField.init();
|
@@ -0,0 +1 @@
|
||||
"use strict";var WPFormsStripeCardField=window.WPFormsStripeCardField||function(e,s){const i={init:function(){i.bindUIActions()},bindUIActions:function(){s(e).on("wpformsSaved",i.ajaxRequiredCheck),s(e).on("wpformsSaved",i.paymentsEnabledCheck),s(e).on("click","#wpforms-add-fields-"+wpforms_builder_stripe_card_field.field_slug,i.stripeKeysCheck),s(e).on("change",".wpforms-field-option-stripe-credit-card .wpforms-field-option-row-sublabel_position select",i.sublabelPositionChange),s(e).on("change",".wpforms-field-option-stripe-credit-card .wpforms-field-option-row-link_email select",i.linkEmailChange),s(e).on("wpformsFieldAdd",i.disableAddCardButton),s(e).on("wpformsFieldDelete",i.enableAddCardButton),s(e).on("wpformsFieldDelete",i.maybeResetLinkEmailField)},ajaxRequiredCheck:function(){s(".wpforms-field.wpforms-field-"+wpforms_builder_stripe_card_field.field_slug).length&&!s("#wpforms-panel-field-settings-ajax_submit").is(":checked")&&s.alert({title:wpforms_builder.heads_up,content:wpforms_builder.stripe_ajax_required,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}})},paymentsEnabledCheck:function(){!s(`.wpforms-field.wpforms-field-${wpforms_builder_stripe_card_field.field_slug}:visible`).length||s("#wpforms-panel-field-stripe-enable").is(":checked")||s("#wpforms-panel-field-stripe-enable_one_time").is(":checked")||s("#wpforms-panel-field-stripe-enable_recurring").is(":checked")||s.alert({title:wpforms_builder.heads_up,content:wpforms_builder.payments_enabled_required,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}})},stripeKeysCheck:function(){s(this).hasClass("stripe-keys-required")&&s.alert({title:wpforms_builder.heads_up,content:wpforms_builder.stripe_keys_required,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}})},disableAddCardButton:function(e,i,r){wpforms_builder_stripe_card_field.field_slug===r&&s("#wpforms-add-fields-"+wpforms_builder_stripe_card_field.field_slug).prop("disabled",!0)},enableAddCardButton:function(e,i,r){wpforms_builder_stripe_card_field.field_slug===r&&s("#wpforms-add-fields-"+wpforms_builder_stripe_card_field.field_slug).prop("disabled",!1)},sublabelPositionChange:function(){var e=s(this).parent().data("field-id"),e=s("#wpforms-field-"+e).find(".wpforms-stripe-payment-element");e.toggleClass("above"),e.toggleClass("floating"),e.find("select").val(e.hasClass("above")?"empty":"country")},linkEmailChange:function(){var e=s(this).parent().data("field-id");s("#wpforms-field-"+e).find(".wpforms-stripe-link-email").toggleClass("wpforms-hidden",""!==s(this).val())},maybeResetLinkEmailField:function(e,i,r){"email"===r&&s(".wpforms-field-option-stripe-credit-card .wpforms-field-option-row-link_email select").trigger("change")}};return i}(document,(window,jQuery));WPFormsStripeCardField.init();
|
@@ -0,0 +1,200 @@
|
||||
/* global wpforms_builder, wpforms_builder_stripe */
|
||||
|
||||
/**
|
||||
* Stripe builder function.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
|
||||
const WPFormsStripe = window.WPFormsStripe || ( function( document, window, $ ) {
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
const app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
init() {
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Initialized once the DOM is fully loaded.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
ready() {
|
||||
if ( ! app.isLegacySettings() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.settingsDisplay();
|
||||
app.settingsConditions();
|
||||
|
||||
app.bindUIActions();
|
||||
},
|
||||
|
||||
/**
|
||||
* Process various events as a response to UI interactions.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
bindUIActions() {
|
||||
$( document )
|
||||
.on( 'wpformsFieldDelete', app.disableNotifications )
|
||||
.on( 'wpformsSaved', app.requiredFieldsCheck )
|
||||
.on( 'wpformsFieldUpdate', app.settingsDisplay )
|
||||
.on( 'wpformsFieldUpdate', app.settingsConditions );
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles visibility of the Stripe settings.
|
||||
*
|
||||
* If a credit card field has been added then reveal the settings,
|
||||
* otherwise hide them.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
settingsDisplay() {
|
||||
const $alert = $( '#wpforms-stripe-credit-card-alert' );
|
||||
const $content = $( '#stripe-provider' );
|
||||
|
||||
// Check if any Credit Card fields were added to the form.
|
||||
const ccFieldsAdded = wpforms_builder_stripe.field_slugs.filter( function( fieldSlug ) {
|
||||
const $el = $( '.wpforms-field-option-' + fieldSlug );
|
||||
|
||||
return $el.length ? $el : null;
|
||||
} );
|
||||
|
||||
if ( ccFieldsAdded.length ) {
|
||||
$alert.hide();
|
||||
$content.find( '#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2' ).show();
|
||||
} else {
|
||||
$alert.show();
|
||||
$content.find( '#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2' ).hide();
|
||||
$content.find( '#wpforms-panel-field-stripe-enable' ).prop( 'checked', false );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggles the visibility of the related settings.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
settingsConditions() {
|
||||
$( '#wpforms-panel-field-stripe-enable' ).conditions( {
|
||||
conditions: {
|
||||
element: '#wpforms-panel-field-stripe-enable',
|
||||
type: 'checked',
|
||||
operator: 'is',
|
||||
},
|
||||
actions: {
|
||||
if: {
|
||||
element: '.wpforms-panel-content-section-stripe-body',
|
||||
action: 'show',
|
||||
},
|
||||
else: {
|
||||
element: '.wpforms-panel-content-section-stripe-body',
|
||||
action: 'hide',
|
||||
},
|
||||
},
|
||||
effect: 'appear',
|
||||
} );
|
||||
|
||||
$( '#wpforms-panel-field-stripe-recurring-enable' ).conditions( {
|
||||
conditions: {
|
||||
element: '#wpforms-panel-field-stripe-recurring-enable',
|
||||
type: 'checked',
|
||||
operator: 'is',
|
||||
},
|
||||
actions: {
|
||||
if: {
|
||||
element: '#wpforms-panel-field-stripe-recurring-period-wrap,#wpforms-panel-field-stripe-recurring-conditional_logic-wrap,#wpforms-conditional-groups-payments-stripe-recurring,#wpforms-panel-field-stripe-recurring-email-wrap,#wpforms-panel-field-stripe-recurring-name-wrap',
|
||||
action: 'show',
|
||||
},
|
||||
else: {
|
||||
element: '#wpforms-panel-field-stripe-recurring-period-wrap,#wpforms-panel-field-stripe-recurring-conditional_logic-wrap,#wpforms-conditional-groups-payments-stripe-recurring,#wpforms-panel-field-stripe-recurring-email-wrap,#wpforms-panel-field-stripe-recurring-name-wrap',
|
||||
action: 'hide',
|
||||
},
|
||||
},
|
||||
effect: 'appear',
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* On form save notify users about required fields.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
requiredFieldsCheck() {
|
||||
if (
|
||||
! $( '#wpforms-panel-field-stripe-enable' ).is( ':checked' ) ||
|
||||
! $( '#wpforms-panel-field-stripe-recurring-enable' ).is( ':checked' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $( '#wpforms-panel-field-stripe-recurring-email' ).val() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: wpforms_builder.heads_up,
|
||||
content: wpforms_builder.stripe_recurring_email,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: wpforms_builder.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Disable notifications.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {Object} e Event object.
|
||||
* @param {number} id Field ID.
|
||||
* @param {string} type Field type.
|
||||
*/
|
||||
disableNotifications( e, id, type ) {
|
||||
if ( ! wpforms_builder_stripe.field_slugs.includes( type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $notificationWrap = $( '.wpforms-panel-content-section-notifications [id*="-stripe-wrap"]' );
|
||||
|
||||
$notificationWrap.find( 'input[id*="-stripe"]' ).prop( 'checked', false );
|
||||
$notificationWrap.addClass( 'wpforms-hidden' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Determinate is legacy settings is loaded.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @return {boolean} True is legacy settings loaded.
|
||||
*/
|
||||
isLegacySettings() {
|
||||
return $( '#wpforms-panel-field-stripe-enable' ).length;
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsStripe.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/admin-builder-stripe.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/admin-builder-stripe.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
const WPFormsStripe=window.WPFormsStripe||function(e,n){const i={init(){n(i.ready)},ready(){i.isLegacySettings()&&(i.settingsDisplay(),i.settingsConditions(),i.bindUIActions())},bindUIActions(){n(e).on("wpformsFieldDelete",i.disableNotifications).on("wpformsSaved",i.requiredFieldsCheck).on("wpformsFieldUpdate",i.settingsDisplay).on("wpformsFieldUpdate",i.settingsConditions)},settingsDisplay(){var e=n("#wpforms-stripe-credit-card-alert"),i=n("#stripe-provider");wpforms_builder_stripe.field_slugs.filter(function(e){e=n(".wpforms-field-option-"+e);return e.length?e:null}).length?(e.hide(),i.find("#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2").show()):(e.show(),i.find("#wpforms-stripe-new-interface-alert, .wpforms-stripe-notice-info, .wpforms-panel-field, .wpforms-conditional-block-panel, h2").hide(),i.find("#wpforms-panel-field-stripe-enable").prop("checked",!1))},settingsConditions(){n("#wpforms-panel-field-stripe-enable").conditions({conditions:{element:"#wpforms-panel-field-stripe-enable",type:"checked",operator:"is"},actions:{if:{element:".wpforms-panel-content-section-stripe-body",action:"show"},else:{element:".wpforms-panel-content-section-stripe-body",action:"hide"}},effect:"appear"}),n("#wpforms-panel-field-stripe-recurring-enable").conditions({conditions:{element:"#wpforms-panel-field-stripe-recurring-enable",type:"checked",operator:"is"},actions:{if:{element:"#wpforms-panel-field-stripe-recurring-period-wrap,#wpforms-panel-field-stripe-recurring-conditional_logic-wrap,#wpforms-conditional-groups-payments-stripe-recurring,#wpforms-panel-field-stripe-recurring-email-wrap,#wpforms-panel-field-stripe-recurring-name-wrap",action:"show"},else:{element:"#wpforms-panel-field-stripe-recurring-period-wrap,#wpforms-panel-field-stripe-recurring-conditional_logic-wrap,#wpforms-conditional-groups-payments-stripe-recurring,#wpforms-panel-field-stripe-recurring-email-wrap,#wpforms-panel-field-stripe-recurring-name-wrap",action:"hide"}},effect:"appear"})},requiredFieldsCheck(){n("#wpforms-panel-field-stripe-enable").is(":checked")&&n("#wpforms-panel-field-stripe-recurring-enable").is(":checked")&&(n("#wpforms-panel-field-stripe-recurring-email").val()||n.alert({title:wpforms_builder.heads_up,content:wpforms_builder.stripe_recurring_email,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:wpforms_builder.ok,btnClass:"btn-confirm",keys:["enter"]}}}))},disableNotifications(e,i,r){wpforms_builder_stripe.field_slugs.includes(r)&&((r=n('.wpforms-panel-content-section-notifications [id*="-stripe-wrap"]')).find('input[id*="-stripe"]').prop("checked",!1),r.addClass("wpforms-hidden"))},isLegacySettings(){return n("#wpforms-panel-field-stripe-enable").length}};return i}(document,(window,jQuery));WPFormsStripe.init();
|
@@ -0,0 +1,170 @@
|
||||
/* global wpforms_admin_settings_stripe, wpforms_admin */
|
||||
|
||||
/**
|
||||
* Stripe integration settings script.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
|
||||
const WPFormsSettingsStripe = window.WPFormsSettingsStripe || ( function( document, window, $ ) {
|
||||
/**
|
||||
* Elements holder.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
const el = {};
|
||||
|
||||
/**
|
||||
* Runtime variables.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
const vars = {
|
||||
alertTitle: wpforms_admin.heads_up,
|
||||
alertContent: wpforms_admin_settings_stripe.mode_update,
|
||||
ok: wpforms_admin.ok,
|
||||
hideClassName: 'wpforms-hide',
|
||||
};
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
const app = {
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
init() {
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
ready() {
|
||||
app.setup();
|
||||
app.bindEvents();
|
||||
},
|
||||
|
||||
/**
|
||||
* Setup. Prepare some variables.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
setup() {
|
||||
// Cache DOM elements.
|
||||
el.$wrapper = $( '.wpforms-admin-content-payments' );
|
||||
el.$liveConnectionBlock = $( '.wpforms-stripe-connection-status-live' );
|
||||
el.$testConnectionBlock = $( '.wpforms-stripe-connection-status-test' );
|
||||
el.$testModeCheckbox = $( '#wpforms-setting-stripe-test-mode' );
|
||||
el.copyButton = $( '#wpforms-setting-row-stripe-webhooks-endpoint-set .wpforms-copy-to-clipboard' );
|
||||
el.webhookEndpointUrl = $( 'input#wpforms-stripe-webhook-endpoint-url' );
|
||||
el.webhookMethod = $( 'input[name="stripe-webhooks-communication"]' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind events.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
bindEvents() {
|
||||
el.$wrapper
|
||||
.on( 'change', '#wpforms-setting-stripe-test-mode', app.triggerModeSwitchAlert );
|
||||
el.copyButton
|
||||
.on( 'click', app.copyWebhooksEndpoint );
|
||||
el.webhookMethod
|
||||
.on( 'change', app.onMethodChange );
|
||||
},
|
||||
|
||||
/**
|
||||
* Conditionally show Stripe mode switch warning.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
triggerModeSwitchAlert() {
|
||||
if ( el.$testModeCheckbox.is( ':checked' ) ) {
|
||||
el.$liveConnectionBlock.addClass( vars.hideClassName );
|
||||
el.$testConnectionBlock.removeClass( vars.hideClassName );
|
||||
} else {
|
||||
el.$testConnectionBlock.addClass( vars.hideClassName );
|
||||
el.$liveConnectionBlock.removeClass( vars.hideClassName );
|
||||
}
|
||||
|
||||
if ( $( '#wpforms-setting-row-stripe-connection-status .wpforms-connected' ).is( ':visible' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.alert( {
|
||||
title: vars.alertTitle,
|
||||
content: vars.alertContent,
|
||||
icon: 'fa fa-exclamation-circle',
|
||||
type: 'orange',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: vars.ok,
|
||||
btnClass: 'btn-confirm',
|
||||
keys: [ 'enter' ],
|
||||
},
|
||||
},
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy webhooks endpoint URL to clipboard.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*
|
||||
* @param {Object} event Event object.
|
||||
*/
|
||||
copyWebhooksEndpoint( event ) {
|
||||
event.preventDefault();
|
||||
|
||||
// Use Clipboard API for modern browsers and HTTPS connections, in other cases use old-fashioned way.
|
||||
if ( navigator.clipboard ) {
|
||||
navigator.clipboard.writeText( el.webhookEndpointUrl.val() ).then(
|
||||
function() {
|
||||
el.copyButton.find( 'span' ).removeClass( 'dashicons-admin-page' ).addClass( 'dashicons-yes-alt' );
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
el.webhookEndpointUrl.attr( 'disabled', false ).focus().select();
|
||||
|
||||
document.execCommand( 'copy' );
|
||||
|
||||
el.copyButton.find( 'span' ).removeClass( 'dashicons-admin-page' ).addClass( 'dashicons-yes-alt' );
|
||||
|
||||
el.webhookEndpointUrl.attr( 'disabled', true );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the endpoint URL.
|
||||
*
|
||||
* @since 1.8.4
|
||||
*/
|
||||
onMethodChange() {
|
||||
const checked = el.webhookMethod.filter( ':checked' ).val(),
|
||||
newUrl = wpforms_admin_settings_stripe.webhook_urls[ checked ];
|
||||
|
||||
el.webhookEndpointUrl.val( newUrl );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsSettingsStripe.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/admin-settings-stripe.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/admin-settings-stripe.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
const WPFormsSettingsStripe=window.WPFormsSettingsStripe||function(t,e){const o={},n={alertTitle:wpforms_admin.heads_up,alertContent:wpforms_admin_settings_stripe.mode_update,ok:wpforms_admin.ok,hideClassName:"wpforms-hide"},s={init(){e(s.ready)},ready(){s.setup(),s.bindEvents()},setup(){o.$wrapper=e(".wpforms-admin-content-payments"),o.$liveConnectionBlock=e(".wpforms-stripe-connection-status-live"),o.$testConnectionBlock=e(".wpforms-stripe-connection-status-test"),o.$testModeCheckbox=e("#wpforms-setting-stripe-test-mode"),o.copyButton=e("#wpforms-setting-row-stripe-webhooks-endpoint-set .wpforms-copy-to-clipboard"),o.webhookEndpointUrl=e("input#wpforms-stripe-webhook-endpoint-url"),o.webhookMethod=e('input[name="stripe-webhooks-communication"]')},bindEvents(){o.$wrapper.on("change","#wpforms-setting-stripe-test-mode",s.triggerModeSwitchAlert),o.copyButton.on("click",s.copyWebhooksEndpoint),o.webhookMethod.on("change",s.onMethodChange)},triggerModeSwitchAlert(){(o.$testModeCheckbox.is(":checked")?(o.$liveConnectionBlock.addClass(n.hideClassName),o.$testConnectionBlock):(o.$testConnectionBlock.addClass(n.hideClassName),o.$liveConnectionBlock)).removeClass(n.hideClassName),e("#wpforms-setting-row-stripe-connection-status .wpforms-connected").is(":visible")||e.alert({title:n.alertTitle,content:n.alertContent,icon:"fa fa-exclamation-circle",type:"orange",buttons:{confirm:{text:n.ok,btnClass:"btn-confirm",keys:["enter"]}}})},copyWebhooksEndpoint(e){e.preventDefault(),navigator.clipboard?navigator.clipboard.writeText(o.webhookEndpointUrl.val()).then(function(){o.copyButton.find("span").removeClass("dashicons-admin-page").addClass("dashicons-yes-alt")}):(o.webhookEndpointUrl.attr("disabled",!1).focus().select(),t.execCommand("copy"),o.copyButton.find("span").removeClass("dashicons-admin-page").addClass("dashicons-yes-alt"),o.webhookEndpointUrl.attr("disabled",!0))},onMethodChange(){var e=o.webhookMethod.filter(":checked").val(),e=wpforms_admin_settings_stripe.webhook_urls[e];o.webhookEndpointUrl.val(e)}};return s}(document,(window,jQuery));WPFormsSettingsStripe.init();
|
@@ -0,0 +1,454 @@
|
||||
/* global Stripe, wpforms, wpforms_settings, wpforms_stripe, WPForms */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* WPForms Stripe Elements function.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
var WPFormsStripeElements = window.WPFormsStripeElements || ( function( document, window, $ ) {
|
||||
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {object}
|
||||
*/
|
||||
const app = {
|
||||
|
||||
stripe: null,
|
||||
|
||||
/**
|
||||
* Number of page locked to switch.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @type {int}
|
||||
*/
|
||||
lockedPageToSwitch: 0,
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
init: function() {
|
||||
|
||||
app.stripe = Stripe( // eslint-disable-line new-cap
|
||||
wpforms_stripe.publishable_key,
|
||||
{ 'locale': wpforms_stripe.data.element_locale }
|
||||
);
|
||||
|
||||
$( document ).on( 'wpformsReady', function() {
|
||||
$( '.wpforms-stripe form' )
|
||||
.filter( ( _, form ) => typeof $( form ).data( 'formid' ) === 'number' ) // filter out forms which are locked (formid changed to 'locked-...').
|
||||
.each( app.setupStripeForm );
|
||||
} );
|
||||
|
||||
$( document ).on( 'wpformsBeforePageChange', app.pageChange );
|
||||
},
|
||||
|
||||
/**
|
||||
* Setup and configure a Stripe form.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
setupStripeForm: function() {
|
||||
|
||||
let $form = $( this );
|
||||
|
||||
app.updateFormSubmitHandler( $form );
|
||||
|
||||
$form.on( 'wpformsAjaxSubmitActionRequired', app.handleCardActionCallback );
|
||||
|
||||
app.updateCardElementStylesModern( $form );
|
||||
},
|
||||
|
||||
/**
|
||||
* Setup, mount and configure Stripe Card Element.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
* @param {object} formValidator jQuery Validator object.
|
||||
*
|
||||
* @returns {card|void} Stripe Card element.
|
||||
*/
|
||||
setupCardElement: function( $form, formValidator ) {
|
||||
|
||||
const $hiddenInput = $form.find( '.wpforms-stripe-credit-card-hidden-input' );
|
||||
|
||||
if ( ! $hiddenInput || $hiddenInput.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cardElement = $hiddenInput.data( 'stripe-element' );
|
||||
|
||||
if ( cardElement ) {
|
||||
return cardElement;
|
||||
}
|
||||
|
||||
let style = wpforms_stripe.data.element_style;
|
||||
|
||||
if ( $.isEmptyObject( style ) ) {
|
||||
style = app.getElementStyleDefault( $hiddenInput );
|
||||
}
|
||||
|
||||
let cardSettings = {
|
||||
classes : wpforms_stripe.data.element_classes,
|
||||
hidePostalCode: true,
|
||||
style : style,
|
||||
};
|
||||
|
||||
cardElement = app.stripe.elements().create( 'card', cardSettings );
|
||||
|
||||
cardElement.mount( $form.find( '.wpforms-field-stripe-credit-card-cardnumber' ).get( 0 ) );
|
||||
|
||||
cardElement.on( 'change', function( e ) {
|
||||
|
||||
if ( ! e.error ) {
|
||||
formValidator.hideThese( formValidator.errorsFor( $hiddenInput.get( 0 ) ) );
|
||||
return;
|
||||
}
|
||||
|
||||
let message = e.error.message;
|
||||
|
||||
if ( 'incomplete_number' === e.error.code || 'invalid_number' === e.error.code ) {
|
||||
message = wpforms_settings.val_creditcard;
|
||||
}
|
||||
|
||||
app.displayStripeError( $form, message );
|
||||
} );
|
||||
|
||||
$hiddenInput.data( 'stripe-element', cardElement );
|
||||
|
||||
return cardElement;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get default styles for card settings.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $hiddenInput Input element.
|
||||
*
|
||||
* @returns {object|void} Base styles.
|
||||
*/
|
||||
getElementStyleDefault: function( $hiddenInput ) {
|
||||
|
||||
if ( ! $hiddenInput || $hiddenInput.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const textColor = $hiddenInput.css( 'color' );
|
||||
const fontSize = $hiddenInput.css( 'font-size' );
|
||||
|
||||
let style = {
|
||||
base: {
|
||||
fontSize : fontSize,
|
||||
color : textColor,
|
||||
'::placeholder' : {
|
||||
fontSize : fontSize,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let fontFamily = $hiddenInput.css( 'font-family' );
|
||||
|
||||
const regExp = /[“”<>!@$%^&*=~`|{}[\]]/;
|
||||
|
||||
if ( regExp.test( fontFamily ) || fontFamily.indexOf( 'MS Shell Dlg' ) !== -1 ) {
|
||||
fontFamily = $( 'p' ).css( 'font-family' );
|
||||
}
|
||||
|
||||
if ( ! regExp.test( fontFamily ) ) {
|
||||
style.base.fontFamily = fontFamily;
|
||||
style.base['::placeholder'].fontFamily = fontFamily;
|
||||
}
|
||||
|
||||
return style;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update submitHandler for the forms containing Stripe.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
*/
|
||||
updateFormSubmitHandler: function( $form ) {
|
||||
|
||||
let formValidator = $form.validate(),
|
||||
formSubmitHandler = formValidator.settings.submitHandler,
|
||||
cardElement = app.setupCardElement( $form, formValidator ),
|
||||
$stripeDiv = $form.find( '.wpforms-field-stripe-credit-card-cardnumber' );
|
||||
|
||||
// Replace the default submit handler.
|
||||
formValidator.settings.submitHandler = function() {
|
||||
|
||||
let valid = $form.validate().form(),
|
||||
ccEmpty = $stripeDiv.hasClass( wpforms_stripe.data.element_classes.empty ),
|
||||
ccRequired = $stripeDiv.data( 'required' ),
|
||||
condHidden = $stripeDiv.closest( '.wpforms-field-stripe-credit-card' ).hasClass( 'wpforms-conditional-hide' ),
|
||||
processCard = false;
|
||||
|
||||
if ( ! condHidden ) {
|
||||
processCard = ccRequired || ( ! ccEmpty && ! ccRequired );
|
||||
}
|
||||
|
||||
if ( valid && processCard ) {
|
||||
|
||||
$form.find( '.wpforms-submit' ).prop( 'disabled', true );
|
||||
app.createPaymentMethod( $form, cardElement, ccRequired, formSubmitHandler );
|
||||
|
||||
} else if ( valid ) {
|
||||
|
||||
// Form is valid, however no credit card to process.
|
||||
$form.find( '.wpforms-submit' ).prop( 'disabled', false );
|
||||
return formSubmitHandler( $form );
|
||||
|
||||
} else {
|
||||
|
||||
$form.find( '.wpforms-submit' ).prop( 'disabled', false );
|
||||
$form.validate().cancelSubmit = true;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a PaymentMethod out of card details provided.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
* @param {card} cardElement Stripe Card element.
|
||||
* @param {boolean} ccRequired Card field is required.
|
||||
* @param {Function} formSubmitHandler jQuery Validation SubmitHandler function.
|
||||
*/
|
||||
createPaymentMethod: function( $form, cardElement, ccRequired, formSubmitHandler ) {
|
||||
|
||||
app.stripe.createPaymentMethod( 'card', cardElement, {
|
||||
billing_details: {
|
||||
name: $form.find( '.wpforms-field-stripe-credit-card-cardname' ).val(),
|
||||
},
|
||||
} ).then( function( result ) {
|
||||
|
||||
if ( result.error && ccRequired ) {
|
||||
$form.find( '.wpforms-submit' ).prop( 'disabled', false );
|
||||
app.displayStripeError( $form, result.error.message );
|
||||
$form.validate().cancelSubmit = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! result.error ) {
|
||||
$form.find( '.wpforms-stripe-payment-method-id' ).remove();
|
||||
if ( result.paymentMethod ) {
|
||||
$form.append( '<input type="hidden" class="wpforms-stripe-payment-method-id" name="wpforms[payment_method_id]" value="' + result.paymentMethod.id + '">' );
|
||||
}
|
||||
}
|
||||
|
||||
formSubmitHandler( $form );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle 'action_required' server response.
|
||||
*
|
||||
* @param {object} e Event object.
|
||||
* @param {object} json Data returned form a server.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
handleCardActionCallback: function( e, json ) {
|
||||
|
||||
const $form = $( this );
|
||||
|
||||
if ( json.success && json.data.action_required ) {
|
||||
app.stripe.handleCardPayment(
|
||||
json.data.payment_intent_client_secret
|
||||
).then( function( result ) {
|
||||
app.handleCardPaymentCallback( $form, result );
|
||||
} );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback for Stripe 'handleCardPayment' method.
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
* @param {object} result Data returned by 'handleCardPayment'.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
handleCardPaymentCallback: function( $form, result ) {
|
||||
|
||||
if ( result.error ) {
|
||||
|
||||
app.formAjaxUnblock( $form );
|
||||
$form.find( '.wpforms-field-stripe-credit-card-cardnumber' ).addClass( wpforms_stripe.data.element_classes.invalid );
|
||||
app.displayStripeError( $form, result.error.message );
|
||||
|
||||
} else if ( result.paymentIntent && 'succeeded' === result.paymentIntent.status ) {
|
||||
|
||||
$form.find( '.wpforms-stripe-payment-method-id' ).remove();
|
||||
$form.find( '.wpforms-stripe-payment-intent-id' ).remove();
|
||||
$form.append( '<input type="hidden" class="wpforms-stripe-payment-intent-id" name="wpforms[payment_intent_id]" value="' + result.paymentIntent.id + '">' );
|
||||
wpforms.formSubmitAjax( $form );
|
||||
|
||||
} else {
|
||||
|
||||
app.formAjaxUnblock( $form );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Display a field error using jQuery Validate library.
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
* @param {object} message Error message.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*/
|
||||
displayStripeError: function( $form, message ) {
|
||||
|
||||
const fieldName = $form.find( '.wpforms-stripe-credit-card-hidden-input' ).attr( 'name' ),
|
||||
$stripeDiv = $form.find( '.wpforms-field-stripe-credit-card-cardnumber' );
|
||||
let errors = {};
|
||||
|
||||
errors[fieldName] = message;
|
||||
|
||||
wpforms.displayFormAjaxFieldErrors( $form, errors );
|
||||
|
||||
// Switch page for the multipage form.
|
||||
if ( ! $stripeDiv.is( ':visible' ) && $form.find( '.wpforms-page-indicator-steps' ).length > 0 ) {
|
||||
// Empty $json object needed to change the page to the first one.
|
||||
wpforms.setCurrentPage( $form, {} );
|
||||
}
|
||||
|
||||
wpforms.scrollToError( $stripeDiv );
|
||||
},
|
||||
|
||||
/**
|
||||
* Unblock the AJAX form.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form element.
|
||||
*/
|
||||
formAjaxUnblock: function( $form ) {
|
||||
|
||||
let $container = $form.closest( '.wpforms-container' ),
|
||||
$spinner = $form.find( '.wpforms-submit-spinner' ),
|
||||
$submit = $form.find( '.wpforms-submit' ),
|
||||
submitText = $submit.data( 'submit-text' );
|
||||
|
||||
if ( submitText ) {
|
||||
$submit.text( submitText );
|
||||
}
|
||||
|
||||
$submit.prop( 'disabled', false );
|
||||
$container.css( 'opacity', '' );
|
||||
$spinner.hide();
|
||||
},
|
||||
|
||||
/**
|
||||
* Callback for a page changing.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {Event} event Event.
|
||||
* @param {int} currentPage Current page.
|
||||
* @param {jQuery} $form Current form.
|
||||
* @param {string} action The navigation action.
|
||||
*/
|
||||
pageChange: function( event, currentPage, $form, action ) {
|
||||
|
||||
const $stripeDiv = $form.find( '.wpforms-field-stripe-credit-card-cardnumber' ),
|
||||
ccComplete = $stripeDiv.hasClass( wpforms_stripe.data.element_classes.complete ),
|
||||
ccEmpty = $stripeDiv.hasClass( wpforms_stripe.data.element_classes.empty ),
|
||||
ccInvalid = $stripeDiv.hasClass( wpforms_stripe.data.element_classes.invalid );
|
||||
|
||||
// Stop navigation through page break pages.
|
||||
if (
|
||||
! $stripeDiv.is( ':visible' ) ||
|
||||
( ! $stripeDiv.data( 'required' ) && ccEmpty ) ||
|
||||
( app.lockedPageToSwitch && app.lockedPageToSwitch !== currentPage ) ||
|
||||
action === 'prev'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ccComplete ) {
|
||||
$stripeDiv.find( '.wpforms-error' ).remove();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
app.lockedPageToSwitch = currentPage;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if ( ccInvalid ) {
|
||||
return;
|
||||
}
|
||||
|
||||
app.displayStripeError( $form, wpforms_stripe.i18n.empty_details );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update Card Element styles in Modern Markup mode.
|
||||
*
|
||||
* @since 1.8.2
|
||||
*
|
||||
* @param {jQuery} $form Form object.
|
||||
*/
|
||||
updateCardElementStylesModern: function( $form ) {
|
||||
|
||||
// Should work only in Modern Markup mode.
|
||||
if ( ! window.WPForms || ! WPForms.FrontendModern || ! $.isEmptyObject( wpforms_stripe.data.element_style ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $form || $form.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cssVars = WPForms.FrontendModern.getCssVars( $form );
|
||||
|
||||
$form.find( '.wpforms-stripe-credit-card-hidden-input' ).each( function() {
|
||||
|
||||
const $hiddenInput = $( this );
|
||||
const cardElement = $hiddenInput.data( 'stripe-element' );
|
||||
|
||||
if ( ! cardElement ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const styles = {
|
||||
base : {
|
||||
color: cssVars['field-text-color'],
|
||||
fontSize: cssVars['field-size-font-size'],
|
||||
'::placeholder': {
|
||||
color: WPForms.FrontendModern.getColorWithOpacity( cssVars['field-text-color'], '0.5' ),
|
||||
fontSize: cssVars['field-size-font-size'],
|
||||
},
|
||||
},
|
||||
invalid: {
|
||||
color: cssVars['field-text-color'],
|
||||
},
|
||||
};
|
||||
|
||||
cardElement.update( { style: styles } );
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
// Provide access to public functions/properties.
|
||||
return app;
|
||||
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsStripeElements.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/wpforms-stripe-elements.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/stripe/wpforms-stripe-elements.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,163 @@
|
||||
/* global wpformsWpcodeVars, List, wpforms_admin */
|
||||
|
||||
/**
|
||||
* @param wpformsWpcodeVars.installing_text
|
||||
*/
|
||||
|
||||
/**
|
||||
* WPCode integration script.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
const WPFormsWPCode = window.WPFormsWPCode || ( function( document, window, $ ) {
|
||||
/**
|
||||
* Public functions and properties.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
const app = {
|
||||
|
||||
/**
|
||||
* Blue spinner HTML.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
spinnerBlue: '<i class="wpforms-loading-spinner wpforms-loading-blue wpforms-loading-inline"></i>',
|
||||
|
||||
/**
|
||||
* White spinner HTML.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
spinnerWhite: '<i class="wpforms-loading-spinner wpforms-loading-white wpforms-loading-inline"></i>',
|
||||
|
||||
/**
|
||||
* List.js object.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
snippetSearch: null,
|
||||
|
||||
/**
|
||||
* Start the engine.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
init() {
|
||||
$( app.ready );
|
||||
},
|
||||
|
||||
/**
|
||||
* Document ready.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
ready() {
|
||||
app.snippetSearch = new List(
|
||||
'wpforms-wpcode-snippets-list',
|
||||
{
|
||||
valueNames: [ 'wpforms-wpcode-snippet-title' ],
|
||||
}
|
||||
);
|
||||
app.events();
|
||||
},
|
||||
|
||||
/**
|
||||
* Events.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
events() {
|
||||
$( '.wpforms-wpcode-snippet-button' ).on( 'click', app.installSnippet );
|
||||
|
||||
$( '.wpforms-wpcode-popup-button' ).on( 'click', app.installPlugin );
|
||||
|
||||
$( '#wpforms-wpcode-snippet-search' ).on( 'keyup search', function() {
|
||||
app.searchSnippet( this );
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Install snippet.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
installSnippet() {
|
||||
const $button = $( this );
|
||||
|
||||
if ( $button.data( 'action' ) === 'edit' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const originalWidth = $button.width();
|
||||
const $badge = $button.prev( '.wpforms-wpcode-snippet-badge' );
|
||||
|
||||
$badge.addClass( 'wpforms-wpcode-installing-in-progress' ).text( wpformsWpcodeVars.installing_text );
|
||||
$button.width( originalWidth ).html( app.spinnerBlue );
|
||||
},
|
||||
|
||||
/**
|
||||
* Search snippet.
|
||||
*
|
||||
* @param {Object} searchField The search field html element.
|
||||
* @since 1.8.5
|
||||
*/
|
||||
searchSnippet( searchField ) {
|
||||
const searchTerm = $( searchField ).val();
|
||||
const searchResults = app.snippetSearch.search( searchTerm );
|
||||
const $noResultsMessage = $( '#wpforms-wpcode-no-results' );
|
||||
|
||||
if ( searchResults.length === 0 ) {
|
||||
$noResultsMessage.show();
|
||||
} else {
|
||||
$noResultsMessage.hide();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Install or activate WPCode plugin by button click.
|
||||
*
|
||||
* @since 1.8.5
|
||||
*/
|
||||
installPlugin() {
|
||||
const $btn = $( this );
|
||||
|
||||
if ( $btn.hasClass( 'disabled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const action = $btn.attr( 'data-action' ),
|
||||
plugin = $btn.attr( 'data-plugin' ),
|
||||
// eslint-disable-next-line camelcase
|
||||
args = JSON.stringify( { overwrite_package: true } ),
|
||||
ajaxAction = action === 'activate' ? 'wpforms_activate_addon' : 'wpforms_install_addon';
|
||||
|
||||
// Fix original button width, add spinner and disable it.
|
||||
$btn.width( $btn.width() ).html( app.spinnerWhite ).addClass( 'disabled' );
|
||||
|
||||
const data = {
|
||||
action: ajaxAction,
|
||||
nonce: wpforms_admin.nonce,
|
||||
plugin,
|
||||
args,
|
||||
type: 'plugin',
|
||||
};
|
||||
|
||||
$.post( wpforms_admin.ajax_url, data )
|
||||
.done( function() {
|
||||
location.reload();
|
||||
} );
|
||||
},
|
||||
};
|
||||
|
||||
return app;
|
||||
}( document, window, jQuery ) );
|
||||
|
||||
// Initialize.
|
||||
WPFormsWPCode.init();
|
1
wp-content/plugins/wpforms-lite/assets/js/integrations/wpcode/wpcode.min.js
vendored
Normal file
1
wp-content/plugins/wpforms-lite/assets/js/integrations/wpcode/wpcode.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
const WPFormsWPCode=window.WPFormsWPCode||function(t){const o={spinnerBlue:'<i class="wpforms-loading-spinner wpforms-loading-blue wpforms-loading-inline"></i>',spinnerWhite:'<i class="wpforms-loading-spinner wpforms-loading-white wpforms-loading-inline"></i>',snippetSearch:null,init(){t(o.ready)},ready(){o.snippetSearch=new List("wpforms-wpcode-snippets-list",{valueNames:["wpforms-wpcode-snippet-title"]}),o.events()},events(){t(".wpforms-wpcode-snippet-button").on("click",o.installSnippet),t(".wpforms-wpcode-popup-button").on("click",o.installPlugin),t("#wpforms-wpcode-snippet-search").on("keyup search",function(){o.searchSnippet(this)})},installSnippet(){var n,i=t(this);"edit"!==i.data("action")&&(n=i.width(),i.prev(".wpforms-wpcode-snippet-badge").addClass("wpforms-wpcode-installing-in-progress").text(wpformsWpcodeVars.installing_text),i.width(n).html(o.spinnerBlue))},searchSnippet(n){var n=t(n).val(),n=o.snippetSearch.search(n),i=t("#wpforms-wpcode-no-results");0===n.length?i.show():i.hide()},installPlugin(){var n,i,e,s=t(this);s.hasClass("disabled")||(e=s.attr("data-action"),n=s.attr("data-plugin"),i=JSON.stringify({overwrite_package:!0}),e="activate"===e?"wpforms_activate_addon":"wpforms_install_addon",s.width(s.width()).html(o.spinnerWhite).addClass("disabled"),s={action:e,nonce:wpforms_admin.nonce,plugin:n,args:i,type:"plugin"},t.post(wpforms_admin.ajax_url,s).done(function(){location.reload()}))}};return o}((document,window,jQuery));WPFormsWPCode.init();
|
Reference in New Issue
Block a user