From 35b08acc8d22c31ab2c2055cb4dda5973b2f3f34 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Tue, 9 Jul 2013 19:21:25 +0000 Subject: [PATCH] Pass back dateUnix (a unix timestamp) for better sorting of revisions in Backbone. Props duck_. See #24425. git-svn-id: http://core.svn.wordpress.org/trunk@24615 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/revision.php | 1 + wp-admin/js/revisions.js | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/revision.php b/wp-admin/includes/revision.php index c64fa416e9..6af781e757 100644 --- a/wp-admin/includes/revision.php +++ b/wp-admin/includes/revision.php @@ -90,6 +90,7 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id ) { ), 'date' => date_i18n( __( 'M j, Y @ G:i' ), $modified_gmt ), 'dateShort' => date_i18n( _x( 'j M @ G:i', 'revision date short format' ), $modified_gmt ), + 'dateUnix' => $modified_gmt, 'timeAgo' => human_time_diff( $modified_gmt, $current ), 'autosave' => wp_is_post_autosave( $revision ), 'current' => $revision->post_modified_gmt === $post->post_modified_gmt, diff --git a/wp-admin/js/revisions.js b/wp-admin/js/revisions.js index e93be21041..7d42418ba5 100644 --- a/wp-admin/js/revisions.js +++ b/wp-admin/js/revisions.js @@ -14,7 +14,7 @@ window.wp = window.wp || {}; revisions.log = function() { if ( revisions.debug ) console.log.apply( console, arguments ); - } + }; // wp_localize_script transforms top-level numbers into strings. Undo that. if ( revisions.settings.selectedRevision ) @@ -47,8 +47,13 @@ window.wp = window.wp || {}; revisions.model.Revisions = Backbone.Collection.extend({ model: revisions.model.Revision, - comparator: function( revision ) { - return revision.id; + comparator: function( a, b ) { + var a_ = a.get('dateUnix'); + var b_ = b.get('dateUnix'); + var cmp = (a_ > b_) - (a_ < b_); + if (cmp === 0 && a.id != b.id) + cmp = a.id < b.id ? -1 : 1; + return cmp; }, next: function( revision ) {