111 * @param {object} this |
111 * @param {object} this |
112 * @param {HTMLElement} list The list DOM element. |
112 * @param {HTMLElement} list The list DOM element. |
113 * @param {object} settings Settings for the current list. |
113 * @param {object} settings Settings for the current list. |
114 * @param {string} action The type of action to perform: 'add', 'delete', or 'dim'. |
114 * @param {string} action The type of action to perform: 'add', 'delete', or 'dim'. |
115 * @param {string} backgroundColor Background color of the list's DOM element. |
115 * @param {string} backgroundColor Background color of the list's DOM element. |
116 * @returns {boolean} Whether to proceed with the action or not. |
116 * @return {boolean} Whether to proceed with the action or not. |
117 */ |
117 */ |
118 confirm: null, |
118 confirm: null, |
119 |
119 |
120 /** |
120 /** |
121 * Callback that's run before an item gets added to the list. |
121 * Callback that's run before an item gets added to the list. |
122 * |
122 * |
123 * Allows to cancel the request. |
123 * Allows to cancel the request. |
124 * |
124 * |
125 * @callback wpList~addBefore |
125 * @callback wpList~addBefore |
126 * @param {object} settings Settings for the Ajax request. |
126 * @param {object} settings Settings for the Ajax request. |
127 * @returns {object|boolean} Settings for the Ajax request or false to abort. |
127 * @return {object|boolean} Settings for the Ajax request or false to abort. |
128 */ |
128 */ |
129 addBefore: null, |
129 addBefore: null, |
130 |
130 |
131 /** |
131 /** |
132 * Callback that's run after an item got added to the list. |
132 * Callback that's run after an item got added to the list. |
147 * Allows to cancel the request. |
147 * Allows to cancel the request. |
148 * |
148 * |
149 * @callback wpList~delBefore |
149 * @callback wpList~delBefore |
150 * @param {object} settings Settings for the Ajax request. |
150 * @param {object} settings Settings for the Ajax request. |
151 * @param {HTMLElement} list The list DOM element. |
151 * @param {HTMLElement} list The list DOM element. |
152 * @returns {object|boolean} Settings for the Ajax request or false to abort. |
152 * @return {object|boolean} Settings for the Ajax request or false to abort. |
153 */ |
153 */ |
154 delBefore: null, |
154 delBefore: null, |
155 |
155 |
156 /** |
156 /** |
157 * Callback that's run after an item got deleted from the list. |
157 * Callback that's run after an item got deleted from the list. |
171 * |
171 * |
172 * Allows to cancel the request. |
172 * Allows to cancel the request. |
173 * |
173 * |
174 * @callback wpList~dimBefore |
174 * @callback wpList~dimBefore |
175 * @param {object} settings Settings for the Ajax request. |
175 * @param {object} settings Settings for the Ajax request. |
176 * @returns {object|boolean} Settings for the Ajax request or false to abort. |
176 * @return {object|boolean} Settings for the Ajax request or false to abort. |
177 */ |
177 */ |
178 dimBefore: null, |
178 dimBefore: null, |
179 |
179 |
180 /** |
180 /** |
181 * Callback that's run after an item got dim'd. |
181 * Callback that's run after an item got dim'd. |
200 * 4. `_wpnonce` value in element's href attribute. |
200 * 4. `_wpnonce` value in element's href attribute. |
201 * 5. `_wpnonce` input field that is a descendant of element. |
201 * 5. `_wpnonce` input field that is a descendant of element. |
202 * 6. 0 if none can be found. |
202 * 6. 0 if none can be found. |
203 * |
203 * |
204 * @param {jQuery} element Element that triggered the request. |
204 * @param {jQuery} element Element that triggered the request. |
205 * @param {object} settings Settings for the Ajax request. |
205 * @param {Object} settings Settings for the Ajax request. |
206 * @returns {string|number} Nonce |
206 * @return {string|number} Nonce |
207 */ |
207 */ |
208 nonce: function( element, settings ) { |
208 nonce: function( element, settings ) { |
209 var url = wpAjax.unserialize( element.attr( 'href' ) ), |
209 var url = wpAjax.unserialize( element.attr( 'href' ) ), |
210 $element = $( '#' + settings.element ); |
210 $element = $( '#' + settings.element ); |
211 |
211 |
233 * data[1] - the-comment-list |
233 * data[1] - the-comment-list |
234 * data[2] - comment-{comment_ID} |
234 * data[2] - comment-{comment_ID} |
235 * data[3] - 66cc66 |
235 * data[3] - 66cc66 |
236 * data[4] - unspam=1 |
236 * data[4] - unspam=1 |
237 * |
237 * |
238 * @param {HTMLElement} element The DOM element. |
238 * @param {HTMLElement} element The DOM element. |
239 * @param {string} type The type of data to look for: 'list', 'add', 'delete', or 'dim'. |
239 * @param {string} type The type of data to look for: 'list', 'add', 'delete', or 'dim'. |
240 * @returns {Array} Extracted list item data. |
240 * @return {Array} Extracted list item data. |
241 */ |
241 */ |
242 parseData: function( element, type ) { |
242 parseData: function( element, type ) { |
243 var data = [], wpListsData; |
243 var data = [], wpListsData; |
244 |
244 |
245 try { |
245 try { |
256 |
256 |
257 /** |
257 /** |
258 * Calls a confirm callback to verify the action that is about to be performed. |
258 * Calls a confirm callback to verify the action that is about to be performed. |
259 * |
259 * |
260 * @param {HTMLElement} list The DOM element. |
260 * @param {HTMLElement} list The DOM element. |
261 * @param {object} settings Settings for this list. |
261 * @param {Object} settings Settings for this list. |
262 * @param {string} action The type of action to perform: 'add', 'delete', or 'dim'. |
262 * @param {string} action The type of action to perform: 'add', 'delete', or 'dim'. |
263 * @returns {object|boolean} Settings if confirmed, false if not. |
263 * @return {Object|boolean} Settings if confirmed, false if not. |
264 */ |
264 */ |
265 pre: function( list, settings, action ) { |
265 pre: function( list, settings, action ) { |
266 var $element, backgroundColor, confirmed; |
266 var $element, backgroundColor, confirmed; |
267 |
267 |
268 settings = $.extend( {}, this.wpList.settings, { |
268 settings = $.extend( {}, this.wpList.settings, { |
292 |
292 |
293 return settings; |
293 return settings; |
294 }, |
294 }, |
295 |
295 |
296 /** |
296 /** |
297 * Adds an item to the list via AJAX. |
297 * Adds an item to the list via Ajax. |
298 * |
298 * |
299 * @param {HTMLElement} element The DOM element. |
299 * @param {HTMLElement} element The DOM element. |
300 * @param {object} settings Settings for this list. |
300 * @param {Object} settings Settings for this list. |
301 * @returns {boolean} Whether the item was added. |
301 * @return {boolean} Whether the item was added. |
302 */ |
302 */ |
303 ajaxAdd: function( element, settings ) { |
303 ajaxAdd: function( element, settings ) { |
304 var list = this, |
304 var list = this, |
305 $element = $( element ), |
305 $element = $( element ), |
306 data = wpList.parseData( $element, 'add' ), |
306 data = wpList.parseData( $element, 'add' ), |
394 |
394 |
395 return false; |
395 return false; |
396 }, |
396 }, |
397 |
397 |
398 /** |
398 /** |
399 * Delete an item in the list via AJAX. |
399 * Delete an item in the list via Ajax. |
400 * |
400 * |
401 * @param {HTMLElement} element A DOM element containing item data. |
401 * @param {HTMLElement} element A DOM element containing item data. |
402 * @param {object} settings Settings for this list. |
402 * @param {Object} settings Settings for this list. |
403 * @returns {boolean} Whether the item was deleted. |
403 * @return {boolean} Whether the item was deleted. |
404 */ |
404 */ |
405 ajaxDel: function( element, settings ) { |
405 ajaxDel: function( element, settings ) { |
406 var list = this, |
406 var list = this, |
407 $element = $( element ), |
407 $element = $( element ), |
408 data = wpList.parseData( $element, 'delete' ), |
408 data = wpList.parseData( $element, 'delete' ), |
481 |
481 |
482 return false; |
482 return false; |
483 }, |
483 }, |
484 |
484 |
485 /** |
485 /** |
486 * Dim an item in the list via AJAX. |
486 * Dim an item in the list via Ajax. |
487 * |
487 * |
488 * @param {HTMLElement} element A DOM element containing item data. |
488 * @param {HTMLElement} element A DOM element containing item data. |
489 * @param {object} settings Settings for this list. |
489 * @param {Object} settings Settings for this list. |
490 * @returns {boolean} Whether the item was dim'ed. |
490 * @return {boolean} Whether the item was dim'ed. |
491 */ |
491 */ |
492 ajaxDim: function( element, settings ) { |
492 ajaxDim: function( element, settings ) { |
493 var list = this, |
493 var list = this, |
494 $element = $( element ), |
494 $element = $( element ), |
495 data = wpList.parseData( $element, 'dim' ), |
495 data = wpList.parseData( $element, 'dim' ), |
609 |
609 |
610 /** |
610 /** |
611 * Returns the background color of the passed element. |
611 * Returns the background color of the passed element. |
612 * |
612 * |
613 * @param {jQuery|string} element Element to check. |
613 * @param {jQuery|string} element Element to check. |
614 * @returns {string} Background color value in HEX. Default: '#ffffff'. |
614 * @return {string} Background color value in HEX. Default: '#ffffff'. |
615 */ |
615 */ |
616 getColor: function( element ) { |
616 getColor: function( element ) { |
617 return $( element ).css( 'backgroundColor' ) || '#ffffff'; |
617 return $( element ).css( 'backgroundColor' ) || '#ffffff'; |
618 }, |
618 }, |
619 |
619 |
620 /** |
620 /** |
621 * Adds something. |
621 * Adds something. |
622 * |
622 * |
623 * @param {HTMLElement} element A DOM element containing item data. |
623 * @param {HTMLElement} element A DOM element containing item data. |
624 * @param {object} settings Settings for this list. |
624 * @param {Object} settings Settings for this list. |
625 * @returns {boolean} Whether the item was added. |
625 * @return {boolean} Whether the item was added. |
626 */ |
626 */ |
627 add: function( element, settings ) { |
627 add: function( element, settings ) { |
628 var $list = $( this ), |
628 var $list = $( this ), |
629 $element = $( element ), |
629 $element = $( element ), |
630 old = false, |
630 old = false, |
833 * Default: null. |
833 * Default: null. |
834 * @param {wpList~delAfter} settings.delAfter Callback that's run after an item got deleted from the list. |
834 * @param {wpList~delAfter} settings.delAfter Callback that's run after an item got deleted from the list. |
835 * Default: null. |
835 * Default: null. |
836 * @param {wpList~dimBefore} settings.dimBefore Callback that's run before an item gets dim'd. Default: null. |
836 * @param {wpList~dimBefore} settings.dimBefore Callback that's run before an item gets dim'd. Default: null. |
837 * @param {wpList~dimAfter} settings.dimAfter Callback that's run after an item got dim'd. Default: null. |
837 * @param {wpList~dimAfter} settings.dimAfter Callback that's run after an item got dim'd. Default: null. |
838 * @returns {$.fn} wpList API function. |
838 * @return {$.fn} wpList API function. |
839 */ |
839 */ |
840 $.fn.wpList = function( settings ) { |
840 $.fn.wpList = function( settings ) { |
841 this.each( function( index, list ) { |
841 this.each( function( index, list ) { |
842 list.wpList = { |
842 list.wpList = { |
843 settings: $.extend( {}, wpList.settings, { what: wpList.parseData( list, 'list' )[1] || '' }, settings ) |
843 settings: $.extend( {}, wpList.settings, { what: wpList.parseData( list, 'list' )[1] || '' }, settings ) |