X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/5964d2279dc52bdfe105f9bfa17e04337d47a3fa..7160a0bb85708fe18beae56a6dfd046520f300bd:/wp-includes/js/wp-lists.js diff --git a/wp-includes/js/wp-lists.js b/wp-includes/js/wp-lists.js index 5decd3a8..2b8e5133 100644 --- a/wp-includes/js/wp-lists.js +++ b/wp-includes/js/wp-lists.js @@ -1,3 +1,4 @@ +/* global ajaxurl, wpAjax */ (function($) { var fs = {add:'ajaxAdd',del:'ajaxDel',dim:'ajaxDim',process:'process',recolor:'recolor'}, wpList; @@ -21,6 +22,13 @@ wpList = { return s.nonce || url._ajax_nonce || $('#' + s.element + ' input[name="_ajax_nonce"]').val() || url._wpnonce || $('#' + s.element + ' input[name="_wpnonce"]').val() || 0; }, + /** + * Extract list item data from a DOM element. + * + * @param {HTMLElement} e The DOM element. + * @param {string} t + * @return {array} + */ parseData: function(e,t) { var d = [], wpListsData; @@ -144,6 +152,13 @@ wpList = { return false; }, + /** + * Delete an item in the list via AJAX. + * + * @param {HTMLElement} e A DOM element containing item data. + * @param {Object} s + * @return {boolean} + */ ajaxDel: function( e, s ) { e = $(e); s = s || {}; @@ -208,7 +223,7 @@ wpList = { s.delAfter( rres, _s ); }).dequeue(); } - } + }; $.ajax( s ); return false; @@ -282,10 +297,28 @@ wpList = { res = wpAjax.parseAjaxResponse(r, s.response, s.element); rres = r; - if ( !res || res.errors ) { + if ( true === res ) { + return true; + } + + if ( ! res || res.errors ) { element.stop().stop().css( 'backgroundColor', '#FF3333' )[isClass?'removeClass':'addClass'](s.dimClass).show().queue( function() { list.wpList.recolor(); $(this).dequeue(); } ); return false; } + + if ( 'undefined' !== typeof res.responses[0].supplemental.comment_link ) { + var submittedOn = element.find( '.submitted-on' ), + commentLink = submittedOn.find( 'a' ); + + // Comment is approved; link the date field. + if ( '' !== res.responses[0].supplemental.comment_link ) { + submittedOn.html( $('').text( submittedOn.text() ).prop( 'href', res.responses[0].supplemental.comment_link ) ); + + // Comment is not approved; unlink the date field. + } else if ( commentLink.length ) { + submittedOn.text( commentLink.text() ); + } + } }; s.complete = function(x, st) { @@ -308,7 +341,11 @@ wpList = { }, add: function( e, s ) { - e = $(e); + if ( 'string' == typeof e ) { + e = $( $.trim( e ) ); // Trim leading whitespaces + } else { + e = $( e ); + } var list = $(this), old = false, _s = { pos: 0, id: 0, oldId: null }, ba, ref, color; @@ -317,16 +354,16 @@ wpList = { s = $.extend(_s, this.wpList.settings, s); - if ( !e.size() || !s.what ) + if ( !e.length || !s.what ) return false; if ( s.oldId ) old = $('#' + s.what + '-' + s.oldId); - if ( s.id && ( s.id != s.oldId || !old || !old.size() ) ) + if ( s.id && ( s.id != s.oldId || !old || !old.length ) ) $('#' + s.what + '-' + s.id).remove(); - if ( old && old.size() ) { + if ( old && old.length ) { old.before(e); old.remove(); } else if ( isNaN(s.pos) ) { @@ -339,7 +376,7 @@ wpList = { ref = list.find( '#' + s.pos ); - if ( 1 === ref.size() ) + if ( 1 === ref.length ) ref[ba](e); else list.append(e); @@ -370,11 +407,11 @@ wpList = { e = $(e); - if ( list.wpList && e.parents( '#' + list.id ).size() ) + if ( list.wpList && e.parents( '#' + list.id ).length ) return; e.find(':input').each( function() { - if ( $(this).parents('.form-no-clear').size() ) + if ( $(this).parents('.form-no-clear').length ) return; t = this.type.toLowerCase(); @@ -418,7 +455,7 @@ wpList = { items = $('.list-item:visible', list); - if ( !items.size() ) + if ( !items.length ) items = $(list).children(':visible'); eo = [':even',':odd'];