]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/edit-comments.js
Wordpress 4.6
[autoinstalls/wordpress.git] / wp-admin / js / edit-comments.js
index 7fc62deb73688f65589fe93c5aa64fe8c212cecf..3de031022cb37766c87e766de66e71de18660d2f 100644 (file)
@@ -220,12 +220,15 @@ setCommentsList = function() {
                        if ( settings.data.id == replyID )
                                replyButton.text(adminCommentsL10n.replyApprove);
 
-                       c.find('div.comment_status').html('0');
+                       c.find( '.row-actions span.view' ).addClass( 'hidden' ).end()
+                               .find( 'div.comment_status' ).html( '0' );
+
                } else {
                        if ( settings.data.id == replyID )
                                replyButton.text(adminCommentsL10n.reply);
 
-                       c.find('div.comment_status').html('1');
+                       c.find( '.row-actions span.view' ).removeClass( 'hidden' ).end()
+                               .find( 'div.comment_status' ).html( '1' );
                }
 
                diff = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
@@ -286,6 +289,7 @@ setCommentsList = function() {
 
                        a.click(function( e ){
                                e.preventDefault();
+                               e.stopPropagation(); // ticket #35904
                                list.wpList.del(this);
                                $('#undo-' + id).css( {backgroundColor:'#ceb'} ).fadeOut(350, function(){
                                        $(this).remove();
@@ -313,7 +317,8 @@ setCommentsList = function() {
                        approved = commentRow.hasClass( 'approved' ),
                        unapproved = commentRow.hasClass( 'unapproved' ),
                        spammed = commentRow.hasClass( 'spam' ),
-                       trashed = commentRow.hasClass( 'trash' );
+                       trashed = commentRow.hasClass( 'trash' ),
+                       undoing = false; // ticket #35904
 
                updateDashboardText( newTotal );
 
@@ -347,6 +352,8 @@ setCommentsList = function() {
                                }
                        }
 
+                       undoing = true;
+
                // user clicked "Spam"
                } else if ( targetParent.is( 'span.spam' ) ) {
                        // the comment is currently approved
@@ -481,7 +488,7 @@ setCommentsList = function() {
                        }
                }
 
-               if ( ! theExtraList || theExtraList.size() === 0 || theExtraList.children().size() === 0 ) {
+               if ( ! theExtraList || theExtraList.length === 0 || theExtraList.children().length === 0 || undoing ) {
                        return;
                }
 
@@ -559,6 +566,7 @@ setCommentsList = function() {
 commentReply = {
        cid : '',
        act : '',
+       originalContent : '',
 
        init : function() {
                var row = $('#replyrow');
@@ -642,6 +650,7 @@ commentReply = {
                $( '.spinner', replyrow ).removeClass( 'is-active' );
 
                this.cid = '';
+               this.originalContent = '';
        },
 
        open : function(comment_id, post_id, action) {
@@ -651,6 +660,10 @@ commentReply = {
                        h = c.height(),
                        colspanVal = 0;
 
+               if ( ! this.discardCommentChanges() ) {
+                       return false;
+               }
+
                t.close();
                t.cid = comment_id;
 
@@ -659,6 +672,7 @@ commentReply = {
                action = action || 'replyto';
                act = 'edit' == action ? 'edit' : 'replyto';
                act = t.act = act + '-comment';
+               t.originalContent = $('textarea.comment', rowData).val();
                colspanVal = $( '> th:visible, > td:visible', c ).length;
 
                // Make sure it's actually a table and there's a `colspan` value to apply.
@@ -846,6 +860,22 @@ commentReply = {
                        $('table.comments-box').css('display', '');
                        $('#no-comments').remove();
                });
+       },
+
+       /**
+        * Alert the user if they have unsaved changes on a comment that will be
+        * lost if they proceed.
+        *
+        * @returns {boolean}
+        */
+       discardCommentChanges: function() {
+               var editRow = $( '#replyrow' );
+
+               if  ( this.originalContent === $( '#replycontent', editRow ).val() ) {
+                       return true;
+               }
+
+               return window.confirm( adminCommentsL10n.warnCommentChanges );
        }
 };