/home/altere25/infinet.finance/wp-content/plugins/wpforms/assets/js
Edit: /home/altere25/infinet.finance/wp-content/plugins/wpforms/assets/js/admin-builder.js (252097B)
/* global wpforms_builder, wpf, jconfirm, wpforms_panel_switch, Choices, WPForms, WPFormsFormEmbedWizard, wpCookies, tinyMCE, WPFormsUtils, List */
var WPFormsBuilder = window.WPFormsBuilder || ( function( document, window, $ ) {
var s,
$builder,
elements = {};
/**
* Whether to show the close confirmation dialog or not.
*
* @since 1.6.0
*
* @type {boolean}
*/
var closeConfirmation = true;
/**
* A field is adding.
*
* @since 1.7.1
*
* @type {boolean}
*/
var adding = false;
var app = {
settings: {
spinner: '
',
spinnerInline: '
',
tinymceDefaults: { tinymce: { toolbar1: 'bold,italic,underline,blockquote,strikethrough,bullist,numlist,alignleft,aligncenter,alignright,undo,redo,link' }, quicktags: true },
pagebreakTop: false,
pagebreakBottom: false,
upload_img_modal: false,
},
/**
* Start the engine.
*
* @since 1.0.0
*/
init: function() {
var that = this;
wpforms_panel_switch = true;
s = this.settings;
// Document ready.
$( app.ready );
// Page load.
$( window ).on( 'load', function() {
// In the case of jQuery 3.+, we need to wait for a ready event first.
if ( typeof $.ready.then === 'function' ) {
$.ready.then( app.load );
} else {
app.load();
}
} );
$( window ).on( 'beforeunload', function() {
if ( ! that.formIsSaved() && closeConfirmation ) {
return wpforms_builder.are_you_sure_to_close;
}
} );
},
/**
* Page load.
*
* @since 1.0.0
* @since 1.7.9 Added `wpformsBuilderReady` hook.
*/
load: function() {
// Trigger initial save for new forms.
if ( wpf.getQueryString( 'newform' ) ) {
app.formSave( false );
}
var panel = $( '#wpforms-panels-toggle .active' ).data( 'panel' );
// Render form preview on the Revisions panel if the panel is active.
if ( panel === 'revisions' ) {
app.updateRevisionPreview();
}
// Allow callbacks to prevent making Form Builder ready...
const event = WPFormsUtils.triggerEvent( $builder, 'wpformsBuilderReady' );
// ...by triggering `event.preventDefault()`.
if ( event.isDefaultPrevented() ) {
return false;
}
// Hide loading overlay and make the Form Builder ready to use.
app.hideLoadingOverlay();
// Maybe display informational modal.
if ( wpforms_builder.template_modal_display == '1' && 'fields' === wpf.getQueryString( 'view' ) ) { // eslint-disable-line
$.alert( {
title: wpforms_builder.template_modal_title,
content: wpforms_builder.template_modal_msg,
icon: 'fa fa-info-circle',
type: 'blue',
buttons: {
confirm: {
text: wpforms_builder.close,
btnClass: 'btn-confirm',
keys: [ 'enter' ],
},
},
} );
}
},
/**
* Document ready.
*
* @since 1.0.0
*/
ready: function() {
if ( app.isVisitedViaBackButton() ) {
location.reload();
return;
}
// Cache builder element.
$builder = $( '#wpforms-builder' );
// Action buttons.
elements.$helpButton = $( '#wpforms-help' );
elements.$previewButton = $( '#wpforms-preview-btn' );
elements.$embedButton = $( '#wpforms-embed' );
elements.$saveButton = $( '#wpforms-save' );
elements.$exitButton = $( '#wpforms-exit' );
// Cache other elements.
elements.$noFieldsOptions = $( '#wpforms-panel-fields .wpforms-no-fields-holder .no-fields' );
elements.$noFieldsPreview = $( '#wpforms-panel-fields .wpforms-no-fields-holder .no-fields-preview' );
elements.$formPreview = $( '#wpforms-panel-fields .wpforms-preview-wrap' );
elements.$revisionPreview = $( '#wpforms-panel-revisions .wpforms-panel-content' );
elements.defaultEmailSelector = '.wpforms-field-option-email .wpforms-field-option-row-default_value input';
elements.$defaultEmail = $( elements.defaultEmailSelector );
elements.$focusOutTarget = null;
elements.$nextFieldId = $( '#wpforms-field-id' );
elements.$fieldOptions = $( '#wpforms-field-options' );
elements.$fieldsPreviewWrap = $( '#wpforms-panel-fields .wpforms-panel-content-wrap' ),
elements.$sortableFieldsWrap = $( '#wpforms-panel-fields .wpforms-field-wrap' );
elements.$addFieldsButtons = $( '.wpforms-add-fields-button' ).not( '.not-draggable' ).not( '.warning-modal' ).not( '.education-modal' );
// Remove Embed button if builder opened in popup.
if ( app.isBuilderInPopup() ) {
elements.$embedButton.remove();
elements.$previewButton.addClass( 'wpforms-alone' );
}
app.loadMsWinCSS();
// Bind all actions.
app.bindUIActions();
// Setup/cache some vars not available before
s.formID = $( '#wpforms-builder-form' ).data( 'id' );
s.pagebreakTop = $( '.wpforms-pagebreak-top' ).length;
s.pagebreakBottom = $( '.wpforms-pagebreak-bottom' ).length;
// Disable implicit submission for every form inside the builder.
// All form values are managed by JS and should not be submitted by pressing Enter.
$builder.on( 'keypress', '#wpforms-builder-form :input:not(textarea)', function( e ) {
if ( e.keyCode === 13 ) {
e.preventDefault();
}
} );
// If there is a section configured, display it.
// Otherwise, we show the first panel by default.
$( '.wpforms-panel' ).each( function( index, el ) {
var $this = $( this ),
$configured = $this.find( '.wpforms-panel-sidebar-section.configured' ).first();
if ( $configured.length ) {
var section = $configured.data( 'section' );
$configured.addClass( 'active' );
$this.find( '.wpforms-panel-content-section-' + section ).show().addClass( 'active' );
$this.find( '.wpforms-panel-content-section-default' ).hide();
} else {
$this.find( '.wpforms-panel-content-section:first-of-type' ).show().addClass( 'active' );
$this.find( '.wpforms-panel-sidebar-section:first-of-type' ).addClass( 'active' );
}
} );
app.loadEntryPreviewFields();
// Drag and drop sortable elements.
app.fieldChoiceSortable( 'select' );
app.fieldChoiceSortable( 'radio' );
app.fieldChoiceSortable( 'checkbox' );
app.fieldChoiceSortable( 'payment-multiple' );
app.fieldChoiceSortable( 'payment-checkbox' );
app.fieldChoiceSortable( 'payment-select' );
// Set field group visibility.
$( '.wpforms-add-fields-group' ).each( function( index, el ) {
app.fieldGroupToggle( $( this ), 'load' );
} );
app.registerTemplates();
// Trim long form titles.
app.trimFormTitle();
// Load Tooltips.
wpf.initTooltips();
// Load Color Pickers.
app.loadColorPickers();
// Hide/Show CAPTCHA in form.
app.captchaToggle();
// Confirmations initial setup
app.confirmationsSetup();
// Notification settings.
app.notificationToggle();
app.notificationsByStatusAlerts();
// Secret builder hotkeys.
app.builderHotkeys();
// Clone form title to the Setup page.
$( '#wpforms-setup-name' ).val( $( '#wpforms-panel-field-settings-form_title' ).val() );
// jquery-confirm defaults.
jconfirm.defaults = {
closeIcon: false,
backgroundDismiss: false,
escapeKey: true,
animationBounce: 1,
useBootstrap: false,
theme: 'modern',
boxWidth: '400px',
animateFromElement: false,
content: wpforms_builder.something_went_wrong,
};
app.dropdownField.init();
app.iconChoices.init();
app.initSomeFieldOptions();
app.dismissNotice();
},
/**
* Load Microsoft Windows specific stylesheet.
*
* @since 1.6.8
*/
loadMsWinCSS: function() {
var ua = navigator.userAgent;
// Detect OS & browsers.
if (
ua.indexOf( 'Windows' ) < 0 || (
ua.indexOf( 'Chrome' ) < 0 &&
ua.indexOf( 'Firefox' ) < 0
)
) {
return;
}
$( '
' )
.appendTo( 'head' )
.attr( {
type: 'text/css',
rel: 'stylesheet',
href: wpforms_builder.ms_win_css_url,
} );
},
/**
* Builder was visited via back button in browser.
*
* @since 1.6.5
*
* @returns {boolean} True if the builder was visited via back button in browser.
*/
isVisitedViaBackButton: function() {
if ( ! performance ) {
return false;
}
var isVisitedViaBackButton = false;
performance.getEntriesByType( 'navigation' ).forEach( function( nav ) {
if ( nav.type === 'back_forward' ) {
isVisitedViaBackButton = true;
}
} );
return isVisitedViaBackButton;
},
/**
* Remove loading overlay.
*
* @since 1.6.8
*/
hideLoadingOverlay: function() {
var $overlay = $( '#wpforms-builder-overlay' );
$overlay.addClass( 'fade-out' );
setTimeout( function() {
$overlay.hide();
}, 250 );
},
/**
* Show loading overlay.
*
* @since 1.6.8
*/
showLoadingOverlay: function() {
var $overlay = $( '#wpforms-builder-overlay' );
$overlay.removeClass( 'fade-out' );
$overlay.show();
},
/**
* Initialize some fields options controls.
*
* @since 1.6.3
*/
initSomeFieldOptions: function() {
// Show a toggled options groups.
app.toggleAllOptionGroups( $builder );
// Date/Time field Date type option.
$builder.find( '.wpforms-field-option-row-date .type select' ).trigger( 'change' );
},
/**
* Dropdown field component.
*
* @since 1.6.1
*/
dropdownField: {
/**
* Field configuration.
*
* @since 1.6.1
*/
config: {
modernClass: 'choicesjs-select',
args: {
searchEnabled: false,
searchChoices: false,
renderChoiceLimit : 1,
shouldSort: false,
callbackOnInit: function() {
var $element = $( this.containerOuter.element ),
$previewSelect = $element.closest( '.wpforms-field' ).find( 'select' );
// Turn off disabled styles.
if ( $element.hasClass( 'is-disabled' ) ) {
$element.removeClass( 'is-disabled' );
}
// Disable instances on the preview panel.
if ( $previewSelect.is( '[readonly]' ) ) {
this.disable();
$previewSelect.prop( 'disabled', false );
}
if ( this.passedElement.element.multiple ) {
// Hide a placeholder if field has selected choices.
if ( this.getValue( true ).length ) {
$( this.input.element ).addClass( 'choices__input--hidden' );
}
}
},
},
},
/**
* Initialization for field component.
*
* @since 1.6.1
*/
init: function() {
// Choices.js init.
$builder.find( '.' + app.dropdownField.config.modernClass ).each( function() {
app.dropdownField.events.choicesInit( $( this ) );
} );
// Multiple option.
$builder.on(
'change',
'.wpforms-field-option-select .wpforms-field-option-row-multiple input',
app.dropdownField.events.multiple
);
// Style option.
$builder.on(
'change',
'.wpforms-field-option-select .wpforms-field-option-row-style select, .wpforms-field-option-payment-select .wpforms-field-option-row-style select',
app.dropdownField.events.applyStyle
);
// Add ability to close the drop-down menu.
$builder.on( 'click', '.choices', function( e ) {
var $choices = $( this ),
choicesObj = $choices.find( 'select' ).data( 'choicesjs' );
if (
choicesObj &&
$choices.hasClass( 'is-open' ) &&
e.target.classList.contains( 'choices__inner' )
) {
choicesObj.hideDropdown();
}
} );
},
/**
* Field events.
*
* @since 1.6.1
*/
events: {
/**
* Load Choices.js library.
*
* @since 1.6.1
*
* @param {object} $element jQuery element selector.
*/
choicesInit: function( $element ) {
let useAjax = $element.data( 'choicesjs-use-ajax' ) === 1,
instance;
if ( $element.data( 'choicesjs-callback-fn' ) === 'select_pages' ) {
instance = WPForms.Admin.Builder.WPFormsChoicesJS.setup(
$element[0],
app.dropdownField.config.args,
{
action: 'wpforms_ajax_search_pages_for_dropdown',
nonce: useAjax ? wpforms_builder.nonce : null,
}
);
} else {
instance = new Choices( $element[0], app.dropdownField.config.args );
}
app.dropdownField.helpers.setInstance( $element, instance );
app.dropdownField.helpers.addPlaceholderChoice( $element, instance );
$element.closest( '.choices' ).toggleClass( 'wpforms-hidden', ! instance.config.choices.length );
},
/**
* Multiple option callback.
*
* @since 1.6.1
*
* @param {object} event Event object.
*/
multiple: function( event ) {
var fieldId = $( this ).closest( '.wpforms-field-option-row-multiple' ).data().fieldId,
$primary = app.dropdownField.helpers.getPrimarySelector( fieldId ),
$optionChoicesItems = $( '#wpforms-field-option-row-' + fieldId + '-choices input.default' ),
$placeholder = $primary.find( '.placeholder' ),
isDynamicChoices = app.dropdownField.helpers.isDynamicChoices( fieldId ),
isMultiple = event.target.checked,
choicesType = isMultiple ? 'checkbox' : 'radio',
selectedChoices;
// Add/remove a `multiple` attribute.
$primary.prop( 'multiple', isMultiple );
// Change a `Choices` fields type:
// checkbox - needed for multiple selection
// radio - needed for single selection
$optionChoicesItems.prop( 'type', choicesType );
// Dynamic Choices doesn't have default choices (selected options) - make all as unselected.
if ( isDynamicChoices ) {
$primary.find( 'option:selected' ).prop( 'selected', false );
}
// Gets default choices.
selectedChoices = $optionChoicesItems.filter( ':checked' );
if ( ! isMultiple && selectedChoices.length ) {
// Uncheck all choices.
$optionChoicesItems.prop( 'checked', false );
// For single selection we can choose only one.
$( selectedChoices.get( 0 ) ).prop( 'checked', true );
}
// Toggle selection for a placeholder option based on a select type.
if ( $placeholder.length ) {
$placeholder.prop( 'selected', ! isMultiple );
}
// Update a primary field.
app.dropdownField.helpers.update( fieldId, isDynamicChoices );
},
/**
* Apply a style to