: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
settings = settings || {};
settings = wpList.pre.call( list, $element, settings, 'dim' );
settings.element = data[2] || settings.element || null;
settings.dimClass = data[3] || settings.dimClass || null;
settings.dimAddColor = data[4] ? '#' + data[4] : settings.dimAddColor;
settings.dimDelColor = data[5] ? '#' + data[5] : settings.dimDelColor;
if ( ! settings || ! settings.element || ! settings.dimClass ) {
settings.action = 'dim-' + settings.what;
settings.nonce = wpList.nonce( $element, settings );
settings.data = $.extend( {
_ajax_nonce: settings.nonce,
id: settings.element.split( '-' ).pop(),
dimClass: settings.dimClass
}, wpAjax.unserialize( data[6] || '' ) );
if ( typeof settings.dimBefore === 'function' ) {
settings = settings.dimBefore( settings );
$eventTarget = $( '#' + settings.element );
isClass = $eventTarget.toggleClass( settings.dimClass ).is( '.' + settings.dimClass );
color = wpList.getColor( $eventTarget );
dimColor = isClass ? settings.dimAddColor : settings.dimDelColor;
$eventTarget.toggleClass( settings.dimClass );
if ( 'none' !== dimColor ) {
.animate( { backgroundColor: dimColor }, 'fast' )
$eventTarget.toggleClass( settings.dimClass );
.animate( { backgroundColor: color }, {
$( this ).css( 'backgroundColor', '' );
$( list ).trigger( 'wpListDimEnd', [ settings, list.wpList ] );
$( list ).trigger( 'wpListDimEnd', [ settings, list.wpList ] );
if ( ! settings.data._ajax_nonce ) {
settings.success = function( response ) {
parsedResponse = wpAjax.parseAjaxResponse( response, settings.response, settings.element );
returnedResponse = response;
if ( true === parsedResponse ) {
if ( ! parsedResponse || parsedResponse.errors ) {
$eventTarget.stop().stop().css( 'backgroundColor', '#ff3333' )[isClass ? 'removeClass' : 'addClass']( settings.dimClass ).show().queue( function() {
/** @property {string} comment_link Link of the comment to be dimmed. */
if ( 'undefined' !== typeof parsedResponse.responses[0].supplemental.comment_link ) {
var $submittedOn = $element.find( '.submitted-on' ),
$commentLink = $submittedOn.find( 'a' );
// Comment is approved; link the date field.
if ( '' !== parsedResponse.responses[0].supplemental.comment_link ) {
$submittedOn.html( $('<a></a>').text( $submittedOn.text() ).prop( 'href', parsedResponse.responses[0].supplemental.comment_link ) );
// Comment is not approved; unlink the date field.
} else if ( $commentLink.length ) {
$submittedOn.text( $commentLink.text() );
settings.complete = function( jqXHR, status ) {
if ( typeof settings.dimAfter === 'function' ) {
$eventTarget.queue( function() {
settings.dimAfter( returnedResponse, $.extend( {
* Returns the background color of the passed element.
* @param {jQuery|string} element Element to check.
* @return {string} Background color value in HEX. Default: '#ffffff'.
getColor: function( element ) {
return $( element ).css( 'backgroundColor' ) || '#ffffff';
* @param {HTMLElement} element A DOM element containing item data.
* @param {Object} settings Settings for this list.
* @return {boolean} Whether the item was added.
add: function( element, settings ) {
if ( 'string' === typeof settings ) {
settings = { what: settings };
settings = $.extend( { position: 0, id: 0, oldId: null }, this.wpList.settings, settings );
if ( ! $element.length || ! settings.what ) {
old = $( '#' + settings.what + '-' + settings.oldId );
if ( settings.id && ( settings.id !== settings.oldId || ! old || ! old.length ) ) {
$( '#' + settings.what + '-' + settings.id ).remove();
if ( old && old.length ) {
} else if ( isNaN( settings.position ) ) {
if ( '-' === settings.position.substr( 0, 1 ) ) {
settings.position = settings.position.substr( 1 );
reference = $list.find( '#' + settings.position );
if ( 1 === reference.length ) {
reference[position]( $element );
$list.append( $element );
} else if ( 'comment' !== settings.what || 0 === $( '#' + settings.element ).length ) {
if ( settings.position < 0 ) {
$list.prepend( $element );
$list.append( $element );
$element.toggleClass( settings.alt, ( $list.children( ':visible' ).index( $element[0] ) + settings.altOffset ) % 2 );
if ( 'none' !== settings.addColor ) {
$element.css( 'backgroundColor', settings.addColor ).animate( { backgroundColor: wpList.getColor( $element ) }, {
$( this ).css( 'backgroundColor', '' );
$list.each( function( index, list ) {
list.wpList.process( $element );
* Clears all input fields within the element passed.
* @param {string} elementId ID of the element to check, including leading #.
clear: function( elementId ) {
$element = $( elementId ),
// Bail if we're within the list.
if ( list.wpList && $element.parents( '#' + list.id ).length ) {
// Check each input field.
$element.find( ':input' ).each( function( index, input ) {
// Bail if the form was marked to not to be cleared.
if ( $( input ).parents( '.form-no-clear' ).length ) {
type = input.type.toLowerCase();
tagName = input.tagName.toLowerCase();
if ( 'text' === type || 'password' === type || 'textarea' === tagName ) {
} else if ( 'checkbox' === type || 'radio' === type ) {
} else if ( 'select' === tagName ) {
input.selectedIndex = null;
* Registers event handlers to add, delete, and dim items.
* @param {string} elementId
process: function( elementId ) {
$element = $( elementId || document );
$element.on( 'submit', 'form[data-wp-lists^="add:' + list.id + ':"]', function() {
return list.wpList.add( this );
$element.on( 'click', '[data-wp-lists^="add:' + list.id + ':"], input[data-wp-lists^="add:' + list.id + ':"]', function() {
return list.wpList.add( this );
$element.on( 'click', '[data-wp-lists^="delete:' + list.id + ':"]', function() {
return list.wpList.del( this );
$element.on( 'click', '[data-wp-lists^="dim:' + list.id + ':"]', function() {
return list.wpList.dim( this );
* Updates list item background colors.
evenOdd = [':even', ':odd'],
// Bail if there is no alternate class name specified.
if ( ! list.wpList.settings.alt ) {
items = $( '.list-item:visible', list );
items = $( list ).children( ':visible' );
if ( list.wpList.settings.altOffset % 2 ) {
items.filter( evenOdd[0] ).addClass( list.wpList.settings.alt ).end();
items.filter( evenOdd[1] ).removeClass( list.wpList.settings.alt );
* Sets up `process()` and `recolor()` functions.
$list.wpList.process = function( element ) {
this.wpList.process( element );
$list.wpList.recolor = function() {
* Initializes wpList object.
* @param {Object} settings
* @param {string} settings.url URL for ajax calls. Default: ajaxurl.
* @param {string} settings.type The HTTP method to use for Ajax requests. Default: 'POST'.
* @param {string} settings.response ID of the element the parsed ajax response will be stored in.
* Default: 'ajax-response'.
* @param {string} settings.what Default: ''.
* @param {string} settings.alt CSS class name for alternate styling. Default: 'alternate'.
* @param {number} settings.altOffset Offset to start alternate styling from. Default: 0.
* @param {string} settings.addColor Hex code or 'none' to disable animation. Default: '#ffff33'.
* @param {string} settings.delColor Hex code or 'none' to disable animation. Default: '#faafaa'.
* @param {string} settings.dimAddColor Hex code or 'none' to disable animation. Default: '#ffff33'.
* @param {string} settings.dimDelColor Hex code or 'none' to disable animation. Default: '#ff3333'.
* @param {wpList~confirm} settings.confirm Callback that's run before a request is made. Default: null.
* @param {wpList~addBefore} settings.addBefore Callback that's run before an item gets added to the list.
* @param {wpList~addAfter} settings.addAfter Callback that's run after an item got added to the list.
* @param {wpList~delBefore} settings.delBefore Callback that's run before an item gets deleted from the list.
* @param {wpList~delAfter} settings.delAfter Callback that's run after an item got deleted from the list.
* @param {wpList~dimBefore} settings.dimBefore Callback that's run before an item gets dim'd. Default: null.
* @param {wpList~dimAfter} settings.dimAfter Callback that's run after an item got dim'd. Default: null.
* @return {$.fn} wpList API function.
$.fn.wpList = function( settings ) {
this.each( function( index, list ) {
settings: $.extend( {}, wpList.settings, { what: wpList.parseData( list, 'list' )[1] || '' }, settings )
$.each( functions, function( func, callback ) {
list.wpList[func] = function( element, setting ) {
return wpList[callback].call( list, element, setting );
wpList.init.call( this );