Revisions: Code and whitespace cleanup.
See #24425. git-svn-id: http://core.svn.wordpress.org/trunk@24679 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9694d47bcf
commit
19d49d39b0
wp-admin/js
|
@ -737,9 +737,7 @@ window.wp = window.wp || {};
|
||||||
currentModelIndex = this.model.revisions.length - 1;
|
currentModelIndex = this.model.revisions.length - 1;
|
||||||
|
|
||||||
// Update the tooltip model
|
// Update the tooltip model
|
||||||
this.model.set({
|
this.model.set({ hoveredRevision: this.model.revisions.at( currentModelIndex ) });
|
||||||
'hoveredRevision': this.model.revisions.at( currentModelIndex )
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mouseLeave: function() {
|
mouseLeave: function() {
|
||||||
|
@ -827,21 +825,20 @@ window.wp = window.wp || {};
|
||||||
|
|
||||||
// Responds to slide events
|
// Responds to slide events
|
||||||
slide: function( event, ui ) {
|
slide: function( event, ui ) {
|
||||||
var attributes, movedRevision;
|
var attributes, movedRevision, sliderPosition;
|
||||||
// Compare two revisions mode
|
// Compare two revisions mode
|
||||||
if ( ! _.isUndefined( ui.values ) && this.model.get('compareTwoMode') ) {
|
if ( 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;
|
||||||
|
|
||||||
attributes = {
|
attributes = {
|
||||||
to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[0] - 1 : ui.values[1] ), // Reverse directions for RTL.
|
to: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[0] - 1 : ui.values[1] ),
|
||||||
from: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[1] - 1 : ui.values[0] ) // Reverse directions for RTL.
|
from: this.model.revisions.at( isRtl ? this.model.revisions.length - ui.values[1] - 1 : ui.values[0] )
|
||||||
};
|
};
|
||||||
movedRevision = ! isRtl && ui.value === ui.values[0] ? attributes.from : attributes.to;
|
movedRevision = ! isRtl && ui.value === ui.values[0] ? attributes.from : attributes.to;
|
||||||
} else {
|
} else {
|
||||||
// Compare single revision mode
|
sliderPosition = this.getSliderPosition( ui );
|
||||||
var sliderPosition = this.getSliderPosition( ui );
|
|
||||||
attributes = {
|
attributes = {
|
||||||
to: this.model.revisions.at( sliderPosition )
|
to: this.model.revisions.at( sliderPosition )
|
||||||
};
|
};
|
||||||
|
@ -884,20 +881,15 @@ window.wp = window.wp || {};
|
||||||
revisions.Router = Backbone.Router.extend({
|
revisions.Router = Backbone.Router.extend({
|
||||||
initialize: function( options ) {
|
initialize: function( options ) {
|
||||||
this.model = options.model;
|
this.model = options.model;
|
||||||
this.routes = this.getRoutes();
|
this.routes = _.object([
|
||||||
|
[ this.baseUrl( '?from=:from&to=:to' ), 'handleRoute' ],
|
||||||
// Maintain state history when dragging/clicking
|
[ this.baseUrl( '?from=:from&to=:to' ), 'handleRoute' ]
|
||||||
|
]);
|
||||||
|
// Maintain state and history when navigating
|
||||||
this.listenTo( this.model, 'update:diff', _.debounce( this.updateUrl, 250 ) );
|
this.listenTo( this.model, 'update:diff', _.debounce( this.updateUrl, 250 ) );
|
||||||
this.listenTo( this.model, 'change:compareTwoMode', this.updateUrl );
|
this.listenTo( this.model, 'change:compareTwoMode', this.updateUrl );
|
||||||
},
|
},
|
||||||
|
|
||||||
getRoutes: function() {
|
|
||||||
var routes = {};
|
|
||||||
routes[this.baseUrl( '?from=:from&to=:to' )] = 'handleRoute';
|
|
||||||
routes[this.baseUrl( '?revision=:to' )] = 'handleRoute';
|
|
||||||
return routes;
|
|
||||||
},
|
|
||||||
|
|
||||||
baseUrl: function( url ) {
|
baseUrl: function( url ) {
|
||||||
return this.model.get('baseUrl') + url;
|
return this.model.get('baseUrl') + url;
|
||||||
},
|
},
|
||||||
|
@ -912,34 +904,20 @@ window.wp = window.wp || {};
|
||||||
},
|
},
|
||||||
|
|
||||||
handleRoute: function( a, b ) {
|
handleRoute: function( a, b ) {
|
||||||
var from, to, compareTwo;
|
var from, to, compareTwo = _.isUndefined( b );
|
||||||
|
|
||||||
// If `b` is undefined, this is an 'at/:to' route, for a single revision
|
if ( ! compareTwo ) {
|
||||||
if ( _.isUndefined( b ) ) {
|
|
||||||
b = this.model.revisions.get( a );
|
b = this.model.revisions.get( a );
|
||||||
a = this.model.revisions.prev( b );
|
a = this.model.revisions.prev( b );
|
||||||
b = b ? b.id : 0;
|
b = b ? b.id : 0;
|
||||||
a = a ? a.id : 0;
|
a = a ? a.id : 0;
|
||||||
compareTwo = false;
|
|
||||||
} else {
|
|
||||||
compareTwo = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
from = parseInt( a, 10 );
|
this.model.set({
|
||||||
to = parseInt( b, 10 );
|
from: this.model.revisions.get( parseInt( a, 10 ) ),
|
||||||
|
to: this.model.revisions.get( parseInt( a, 10 ) ),
|
||||||
this.model.set({ compareTwoMode: compareTwo });
|
compareTwoMode: compareTwo
|
||||||
|
});
|
||||||
if ( ! _.isUndefined( this.model ) ) {
|
|
||||||
var selectedToRevision = this.model.revisions.get( to ),
|
|
||||||
selectedFromRevision = this.model.revisions.get( from );
|
|
||||||
|
|
||||||
this.model.set({
|
|
||||||
to: selectedToRevision,
|
|
||||||
from: selectedFromRevision
|
|
||||||
});
|
|
||||||
}
|
|
||||||
revisions.settings.to = to;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue