Revisions: simpler hash URLs. Misc refactoring.

* Single mode: `#at/:to`
* Compare two mode: `#from/:from/to/:to`
* Make use of `_.isUndefined()`

See #24425.

git-svn-id: http://core.svn.wordpress.org/trunk@24638 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-07-10 06:08:56 +00:00
parent 33c7a89f91
commit 80c7cd0e0a
1 changed files with 25 additions and 12 deletions

View File

@ -6,7 +6,7 @@ window.wp = window.wp || {};
revisions = wp.revisions = { model: {}, view: {}, controller: {} }; revisions = wp.revisions = { model: {}, view: {}, controller: {} };
// Link settings. // Link settings.
revisions.settings = typeof _wpRevisionsSettings === 'undefined' ? {} : _wpRevisionsSettings; revisions.settings = _.isUndefined( _wpRevisionsSettings ) ? {} : _wpRevisionsSettings;
// For debugging // For debugging
revisions.debug = true; revisions.debug = true;
@ -718,7 +718,7 @@ window.wp = window.wp || {};
// In single handle mode, the 1st stored revision is 'blank' and the 'from' model is not set // In single handle mode, the 1st stored revision is 'blank' and the 'from' model is not set
// In this case we move the to index over one // In this case we move the to index over one
if ( 'undefined' == typeof this.model.get('from') ) { if ( _.isUndefined( this.model.get('from') ) ) {
if ( isRtl ) { if ( isRtl ) {
leftValue = this.model.revisions.length - this.model.revisions.indexOf( this.model.get('to') ) - 2; leftValue = this.model.revisions.length - this.model.revisions.indexOf( this.model.get('to') ) - 2;
rightValue = leftValue + 1; rightValue = leftValue + 1;
@ -836,7 +836,7 @@ window.wp = window.wp || {};
slide: function( event, ui ) { slide: function( event, ui ) {
var attributes; var attributes;
// Compare two revisions mode // Compare two revisions mode
if ( 'undefined' !== typeof ui.values && this.model.get('compareTwoMode') ) { if ( ! _.isUndefined( ui.values ) && this.model.get('compareTwoMode') ) {
// Prevent sliders from occupying same spot // Prevent sliders from occupying same spot
if ( ui.values[1] === ui.values[0] ) if ( ui.values[1] === ui.values[0] )
return false; return false;
@ -893,24 +893,37 @@ window.wp = window.wp || {};
}, },
routes: { routes: {
'revision/from/:from/to/:to/handles/:handles': 'gotoRevisionId' 'from/:from/to/:to': 'handleRoute',
'at/:to': 'routeSingle'
}, },
updateUrl: function() { updateUrl: function() {
var from = this.model.has('from') ? this.model.get('from').id : 0; var from = this.model.has('from') ? this.model.get('from').id : 0;
var to = this.model.get('to').id; var to = this.model.get('to').id;
var handles = this.model.get('compareTwoMode') ? '2' : '1'; if ( this.model.get('compareTwoMode' ) )
this.navigate( 'from/' + from + '/to/' + to );
this.navigate( '/revision/from/' + from + '/to/' + to + '/handles/' + handles ); else
this.navigate( 'at/' + to );
}, },
gotoRevisionId: function( from, to, handles ) { handleRoute: function( a, b ) {
from = parseInt( from, 10 ); var from, to, compareTwo;
to = parseInt( to, 10 );
this.model.set({ compareTwoMode: ( '2' === handles ) }); // If `b` is undefined, this was a 'revision/:to' route
if ( _.isUndefined( b ) ) {
b = a;
a = 0;
compareTwo = true;
} else {
compareTwo = false;
}
if ( 'undefined' !== typeof this.model ) { from = parseInt( a, 10 );
to = parseInt( b, 10 );
this.model.set({ compareTwoMode: compareTwo });
if ( ! _.isUndefined( this.model ) ) {
var selectedToRevision = this.model.revisions.findWhere({ id: to }), var selectedToRevision = this.model.revisions.findWhere({ id: to }),
selectedFromRevision = this.model.revisions.findWhere({ id: from }); selectedFromRevision = this.model.revisions.findWhere({ id: from });