Pass back dateUnix (a unix timestamp) for better sorting of revisions in Backbone.

Props duck_. See #24425.

git-svn-id: https://develop.svn.wordpress.org/trunk@24615 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith 2013-07-09 19:21:25 +00:00
parent 7d0019d495
commit 8dfbe56e79
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 ) {