Commit realizado el 12:13:52 08-04-2024

This commit is contained in:
Pagina Web Monito
2024-04-08 12:13:55 -04:00
commit 0c33094de9
7815 changed files with 1365694 additions and 0 deletions

View File

@@ -0,0 +1,156 @@
/* global wpforms_builder, Choices */
/**
* WPForms ChoicesJS utility methods for the Admin Builder.
*
* @since 1.7.9
*/
'use strict';
var WPForms = window.WPForms || {};
WPForms.Admin = WPForms.Admin || {};
WPForms.Admin.Builder = WPForms.Admin.Builder || {};
WPForms.Admin.Builder.WPFormsChoicesJS = WPForms.Admin.Builder.WPFormsChoicesJS || ( function( document, window, $ ) {
/**
* Public functions and properties.
*
* @since 1.7.9
*
* @type {object}
*/
const app = {
/**
* Setup the Select Page ChoicesJS instance.
*
* @since 1.7.9
*
* @param {object} element DOM Element where to init ChoicesJS.
* @param {object} choicesJSArgs ChoicesJS init options.
* @param {object} ajaxArgs Object containing `action` and `nonce` to perform AJAX search.
*
* @returns {Choices} ChoicesJS instance.
*/
setup: function( element, choicesJSArgs, ajaxArgs ) {
choicesJSArgs.searchEnabled = true;
choicesJSArgs.searchChoices = ajaxArgs.nonce === null; // Enable searchChoices when not using AJAX.
choicesJSArgs.renderChoiceLimit = -1;
choicesJSArgs.noChoicesText = wpforms_builder.no_pages_found;
choicesJSArgs.noResultsText = wpforms_builder.no_pages_found;
const choicesJS = new Choices( element, choicesJSArgs );
if ( ajaxArgs.nonce === null ) {
return choicesJS;
}
/*
* ChoicesJS doesn't handle empty string search with it's `search` event handler,
* so we work around it by detecting empty string search with `keyup` event.
*/
choicesJS.input.element.addEventListener( 'keyup', function( ev ) {
// Only capture backspace and delete keypress that results to empty string.
if (
( ev.which !== 8 && ev.which !== 46 ) ||
ev.target.value.length > 0
) {
return;
}
app.performSearch( choicesJS, '', ajaxArgs );
} );
choicesJS.passedElement.element.addEventListener( 'search', _.debounce( function( ev ) {
// Make sure that the search term is actually changed.
if ( choicesJS.input.element.value.length === 0 ) {
return;
}
app.performSearch( choicesJS, ev.detail.value, ajaxArgs );
}, 800 ) );
return choicesJS;
},
/**
* Perform search in ChoicesJS instance.
*
* @since 1.7.9
*
* @param {Choices} choicesJS ChoicesJS instance.
* @param {string} searchTerm Search term.
* @param {object} ajaxArgs Object containing `action` and `nonce` to perform AJAX search.
*/
performSearch: function( choicesJS, searchTerm, ajaxArgs ) {
if ( ! ajaxArgs.action || ! ajaxArgs.nonce ) {
return;
}
app.displayLoading( choicesJS );
const requestSearchPages = app.ajaxSearchPages( ajaxArgs.action, searchTerm, ajaxArgs.nonce );
requestSearchPages.done( function( response ) {
choicesJS.setChoices( response.data, 'value', 'label', true );
} );
},
/**
* Display "Loading" in ChoicesJS instance.
*
* @since 1.7.9
*
* @param {Choices} choicesJS ChoicesJS instance.
*/
displayLoading: function( choicesJS ) {
choicesJS.setChoices(
[
{ value: '', label: `${wpforms_builder.loading}...`, disabled: true },
],
'value',
'label',
true
);
},
/**
* Perform AJAX search request.
*
* @since 1.7.9
*
* @param {string} action Action to be used when doing ajax request for search.
* @param {string} searchTerm Search term.
* @param {string} nonce Nonce to be used when doing ajax request.
*
* @returns {Promise} jQuery ajax call promise.
*/
ajaxSearchPages: function( action, searchTerm, nonce ) {
return $.get(
wpforms_builder.ajax_url,
{
action: action,
search: searchTerm,
_wpnonce: nonce,
}
).fail(
function( err ) {
console.error( err );
}
);
},
};
// Provide access to public functions/properties.
return app;
}( document, window, jQuery ) );

View File

@@ -0,0 +1 @@
"use strict";var WPForms=window.WPForms||{};WPForms.Admin=WPForms.Admin||{},WPForms.Admin.Builder=WPForms.Admin.Builder||{},WPForms.Admin.Builder.WPFormsChoicesJS=WPForms.Admin.Builder.WPFormsChoicesJS||function(r){const i={setup:function(e,n,o){n.searchEnabled=!0,n.searchChoices=null===o.nonce,n.renderChoiceLimit=-1,n.noChoicesText=wpforms_builder.no_pages_found,n.noResultsText=wpforms_builder.no_pages_found;const r=new Choices(e,n);return null!==o.nonce&&(r.input.element.addEventListener("keyup",function(e){8!==e.which&&46!==e.which||0<e.target.value.length||i.performSearch(r,"",o)}),r.passedElement.element.addEventListener("search",_.debounce(function(e){0!==r.input.element.value.length&&i.performSearch(r,e.detail.value,o)},800))),r},performSearch:function(n,e,o){o.action&&o.nonce&&(i.displayLoading(n),i.ajaxSearchPages(o.action,e,o.nonce).done(function(e){n.setChoices(e.data,"value","label",!0)}))},displayLoading:function(e){e.setChoices([{value:"",label:wpforms_builder.loading+"...",disabled:!0}],"value","label",!0)},ajaxSearchPages:function(e,n,o){return r.get(wpforms_builder.ajax_url,{action:e,search:n,_wpnonce:o}).fail(function(e){console.error(e)})}};return i}((document,window,jQuery));