| 1 |
/******/ "use strict"; |
| 2 |
|
| 3 |
;// ./js/src/lib/ajax-filter/index.js |
| 4 |
/** |
| 5 |
* @package Polylang |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Adds data to all ajax requests made with jQuery. |
| 10 |
* |
| 11 |
* @since 3.7 |
| 12 |
* |
| 13 |
* @param {Object} data The data to add. |
| 14 |
* @returns {void} |
| 15 |
*/ |
| 16 |
function ajaxFilter( data ) { |
| 17 |
if ( 'undefined' === typeof jQuery || ! data ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
const dataStr = jQuery.param( data ); |
| 22 |
|
| 23 |
jQuery.ajaxPrefilter( function ( options ) { |
| 24 |
if ( -1 === options.url.indexOf( ajaxurl ) && -1 === ajaxurl.indexOf( options.url ) ) { |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
if ( |
| 29 |
'undefined' === typeof options.data || |
| 30 |
null === options.data || |
| 31 |
'string' === typeof options.data && '' === options.data.trim() |
| 32 |
) { |
| 33 |
// An empty string or null/undefined. |
| 34 |
options.data = dataStr; |
| 35 |
} else if ( 'string' === typeof options.data ) { |
| 36 |
// A non-empty string: can be a JSON string or a query string. |
| 37 |
try { |
| 38 |
options.data = JSON.stringify( Object.assign( JSON.parse( options.data ), data ) ); |
| 39 |
} catch ( exception ) { |
| 40 |
// A non-empty non-JSON string is considered a query string. |
| 41 |
options.data = `${ options.data }&${ dataStr }`; |
| 42 |
} |
| 43 |
} else if ( jQuery.isPlainObject( options.data ) ) { |
| 44 |
// An object. |
| 45 |
options.data = Object.assign( options.data, data ); |
| 46 |
} |
| 47 |
} ); |
| 48 |
} |
| 49 |
|
| 50 |
;// ./js/src/admin.js |
| 51 |
/** |
| 52 |
* @package Polylang |
| 53 |
*/ |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
ajaxFilter( pll_admin?.ajax_filter ); |
| 58 |
|
| 59 |
|