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
This commit is contained in:
Mark Jaquith 2013-07-09 19:21:25 +00:00
parent c80a049db3
commit 35b08acc8d
2 changed files with 9 additions and 3 deletions

View File

@ -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,

View File

@ -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 ) {