]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/wp-lists.js
Wordpress 4.6
[autoinstalls/wordpress.git] / wp-includes / js / wp-lists.js
index f3a2b7885a6093840123eccd3849a22f4d69e5e3..2b8e51339bff79fddf2665d6654397b3ea771684 100644 (file)
@@ -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 || {};
@@ -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( $('<a></a>').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 = $( $.trim(e) ); // Trim leading whitespaces
+               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'];