2013-02-28 10:14:34 -05:00
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
|
|
|
(function($) {
|
2013-05-02 06:12:19 -04:00
|
|
|
var Revision, Revisions, Diff, revisions;
|
2013-03-07 10:32:26 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
revisions = wp.revisions = function() {
|
|
|
|
Diff = revisions.Diff = new Diff();
|
|
|
|
};
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
_.extend( revisions, { model: {}, view: {}, controller: {} } );
|
|
|
|
|
2013-05-02 06:12:19 -04:00
|
|
|
// Link settings.
|
|
|
|
revisions.model.settings = typeof wpRevisionsSettings === 'undefined' ? {} : wpRevisionsSettings;
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ========================================================================
|
|
|
|
* CONTROLLERS
|
|
|
|
* ========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.revisions.controller.Diff
|
|
|
|
*
|
|
|
|
* Controlls the diff
|
|
|
|
*/
|
|
|
|
Diff = revisions.controller.Diff = Backbone.Model.extend( {
|
|
|
|
rightDiff: 1,
|
|
|
|
leftDiff: 1,
|
|
|
|
revisions: null,
|
|
|
|
leftHandleRevisions: null,
|
|
|
|
rightHandleRevisions: null,
|
|
|
|
revisionsInteractions: null,
|
|
|
|
autosaves: true,
|
|
|
|
showSplitView: true,
|
|
|
|
singleRevision: true,
|
|
|
|
leftModelLoading: false, // keep track of model loads
|
|
|
|
rightModelLoading: false, // disallow slider interaction, also repeat loads, while loading
|
|
|
|
tickmarkView: null, // the slider tickmarks
|
|
|
|
slider: null, // the slider instance
|
|
|
|
|
|
|
|
constructor: function() {
|
2013-05-03 19:17:06 -04:00
|
|
|
var self = this;
|
2013-04-04 03:53:49 -04:00
|
|
|
this.slider = new revisions.view.Slider();
|
2013-05-03 19:17:06 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( null === this.revisions ) {
|
|
|
|
this.revisions = new Revisions(); // set up collection
|
|
|
|
this.startRightModelLoading();
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
this.revisions.fetch({ // load revision data
|
2013-03-27 08:59:41 -04:00
|
|
|
success: function() {
|
|
|
|
self.stopRightModelLoading();
|
2013-04-04 03:53:49 -04:00
|
|
|
self.completeApplicationSetup();
|
2013-02-28 10:14:34 -05:00
|
|
|
}
|
|
|
|
});
|
2013-04-04 03:53:49 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-04-17 15:34:21 -04:00
|
|
|
loadDiffs: function( models ) {
|
2013-04-04 03:53:49 -04:00
|
|
|
var self = this,
|
2013-04-17 15:34:21 -04:00
|
|
|
revisionsToLoad = models.where( { completed: false } ),
|
2013-05-03 19:17:06 -04:00
|
|
|
delay = 0,
|
|
|
|
totalChanges;
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
// match slider to passed revision_id
|
|
|
|
_.each( revisionsToLoad, function( revision ) {
|
|
|
|
if ( revision.get( 'ID' ) == revisions.model.settings.revision_id )
|
|
|
|
self.rightDiff = self.revisions.indexOf( revision ) + 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each( revisionsToLoad, function( revision ) {
|
|
|
|
_.delay( function() {
|
|
|
|
revision.fetch( {
|
|
|
|
update: true,
|
|
|
|
add: false,
|
|
|
|
remove: false,
|
|
|
|
success: function( model ) {
|
2013-04-17 15:34:21 -04:00
|
|
|
model.set( 'completed', true );
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
// stop spinner when all models are loaded
|
2013-04-17 15:34:21 -04:00
|
|
|
if ( 0 === models.where( { completed: false } ).length )
|
2013-04-04 03:53:49 -04:00
|
|
|
self.stopModelLoadingSpinner();
|
|
|
|
|
2013-05-03 19:17:06 -04:00
|
|
|
totalChanges = model.get( 'linesAdded' ) + model.get( 'linesDeleted' ),
|
2013-04-17 15:34:21 -04:00
|
|
|
scopeOfChanges = 'vsmall';
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
// Note: hard coded scope of changes
|
|
|
|
// TODO change to dynamic based on range of values
|
2013-04-17 15:34:21 -04:00
|
|
|
if ( totalChanges > 1 && totalChanges <= 3 ) {
|
|
|
|
scopeOfChanges = 'small';
|
|
|
|
} else if ( totalChanges > 3 && totalChanges <= 5 ) {
|
|
|
|
scopeOfChanges = 'med';
|
|
|
|
} else if ( totalChanges > 5 && totalChanges <= 10 ) {
|
|
|
|
scopeOfChanges = 'large';
|
|
|
|
} else if ( totalChanges > 10 ) {
|
|
|
|
scopeOfChanges = 'vlarge';
|
2013-04-04 03:53:49 -04:00
|
|
|
}
|
2013-04-17 15:34:21 -04:00
|
|
|
model.set( 'scopeOfChanges', scopeOfChanges );
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( 0 !== self.rightDiff &&
|
|
|
|
model.get( 'ID' ) === self.revisions.at( self.rightDiff - 1 ).get( 'ID' ) ) {
|
|
|
|
// reload if current model refreshed
|
|
|
|
self.revisionView.render();
|
|
|
|
}
|
2013-05-03 19:17:06 -04:00
|
|
|
self.tickmarkView.render();
|
2013-04-04 03:53:49 -04:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
}, delay ) ;
|
|
|
|
delay = delay + 150; // stagger model loads to avoid hammering server with requests
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
startLeftModelLoading: function() {
|
|
|
|
this.leftModelLoading = true;
|
2013-04-04 11:49:28 -04:00
|
|
|
$('#revision-diff-container').addClass('left-model-loading');
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
stopLeftModelLoading: function() {
|
|
|
|
this.leftModelLoading = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
startRightModelLoading: function() {
|
|
|
|
this.rightModelLoading = true;
|
2013-04-04 11:49:28 -04:00
|
|
|
$('#revision-diff-container').addClass('right-model-loading');
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
stopRightModelLoading: function() {
|
|
|
|
this.rightModelLoading = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
stopModelLoadingSpinner: function() {
|
2013-04-04 11:49:28 -04:00
|
|
|
$('#revision-diff-container').removeClass('right-model-loading');
|
|
|
|
$('#revision-diff-container').removeClass('left-model-loading');
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
reloadModel: function() {
|
|
|
|
if ( this.singleRevision ) {
|
|
|
|
this.reloadModelSingle();
|
|
|
|
} else {
|
|
|
|
this.reloadLeftRight();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// load the models for the single handle mode
|
|
|
|
reloadModelSingle: function() {
|
|
|
|
var self = this;
|
|
|
|
|
2013-04-17 15:34:21 -04:00
|
|
|
self.startRightModelLoading();
|
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
self.revisions.reload({
|
2013-04-17 15:34:21 -04:00
|
|
|
options: {
|
2013-04-04 03:53:49 -04:00
|
|
|
'showAutosaves': self.autosaves,
|
|
|
|
'showSplitView': self.showSplitView
|
2013-04-17 15:34:21 -04:00
|
|
|
},
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
success: function() {
|
|
|
|
var revisionCount = self.revisions.length;
|
|
|
|
self.revisionView.model = self.revisions;
|
|
|
|
self.revisionView.render();
|
2013-04-17 15:34:21 -04:00
|
|
|
self.loadDiffs( self.revisions );
|
2013-04-04 03:53:49 -04:00
|
|
|
self.tickmarkView.model = self.revisions;
|
|
|
|
self.tickmarkView.render();
|
|
|
|
self.slider.refresh({
|
2013-05-08 17:22:01 -04:00
|
|
|
'max': revisionCount - 1, // slider starts at 0 in single handle mode
|
|
|
|
'value': self.rightDiff - 1 // slider starts at 0 in single handle mode
|
2013-04-04 03:53:49 -04:00
|
|
|
}, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
error: function() {
|
|
|
|
self.stopRightModelLoading();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
// load the models for the left handle (the right handler has moved)
|
2013-04-04 03:53:49 -04:00
|
|
|
reloadLeft: function() {
|
|
|
|
var self = this;
|
|
|
|
self.startLeftModelLoading();
|
|
|
|
self.leftHandleRevisions = new Revisions( {}, {
|
2013-05-08 17:22:01 -04:00
|
|
|
'compareTo': self.revisions.at( self.rightDiff - 1 ).get( 'ID' ), // diff and model count off by 1
|
2013-04-04 03:53:49 -04:00
|
|
|
'showAutosaves': self.autosaves,
|
|
|
|
'showSplitView': self.showSplitView,
|
|
|
|
'rightHandleAt': self.rightDiff
|
|
|
|
});
|
|
|
|
|
|
|
|
self.leftHandleRevisions.fetch({
|
|
|
|
success: function(){
|
|
|
|
self.stopLeftModelLoading();
|
2013-04-17 15:34:21 -04:00
|
|
|
self.loadDiffs( self.leftHandleRevisions );
|
2013-04-04 03:53:49 -04:00
|
|
|
self.tickmarkView.model = self.leftHandleRevisions;
|
|
|
|
self.slider.refresh({
|
|
|
|
'max': self.revisions.length
|
2013-02-28 10:14:34 -05:00
|
|
|
});
|
2013-05-03 19:17:06 -04:00
|
|
|
// ensure right handle not beyond length
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( self.rightDiff > self.revisions.length )
|
|
|
|
self.rightDiff = self.revisions.length;
|
2013-03-21 11:54:11 -04:00
|
|
|
},
|
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
error: function() {
|
|
|
|
self.stopLeftModelLoading();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
// load the models for the right handle (the left handle has moved)
|
2013-04-04 03:53:49 -04:00
|
|
|
reloadRight: function() {
|
|
|
|
var self = this;
|
|
|
|
self.startRightModelLoading();
|
|
|
|
self.rightHandleRevisions = new Revisions( {}, {
|
2013-05-08 17:22:01 -04:00
|
|
|
'compareTo': self.revisions.at( self.leftDiff - 1 ).get( 'ID' ), // diff and model count off by 1
|
2013-04-04 03:53:49 -04:00
|
|
|
'showAutosaves': self.autosaves,
|
|
|
|
'showSplitView': self.showSplitView,
|
|
|
|
'leftHandleAt': self.leftDiff
|
|
|
|
});
|
|
|
|
|
|
|
|
self.rightHandleRevisions.fetch({
|
|
|
|
success: function(){
|
|
|
|
self.stopRightModelLoading();
|
2013-04-17 15:34:21 -04:00
|
|
|
self.loadDiffs( self.rightHandleRevisions );
|
2013-04-04 03:53:49 -04:00
|
|
|
self.tickmarkView.model = self.rightHandleRevisions;
|
|
|
|
self.slider.refresh({
|
2013-05-08 17:22:01 -04:00
|
|
|
'max': self.revisions.length
|
2013-04-04 03:53:49 -04:00
|
|
|
}, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
error: function( response ) {
|
|
|
|
self.stopRightModelLoading();
|
|
|
|
}
|
|
|
|
});
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
/**
|
|
|
|
* reloadLeftRight reload models for both the left and right handles
|
|
|
|
*/
|
2013-04-04 03:53:49 -04:00
|
|
|
reloadLeftRight: function() {
|
|
|
|
this.startRightModelLoading();
|
|
|
|
this.startLeftModelLoading();
|
|
|
|
this.reloadLeft();
|
|
|
|
this.reloadRight();
|
|
|
|
},
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-17 16:12:25 -04:00
|
|
|
disabledButtonCheck: function( val ) {
|
|
|
|
var maxVal = this.revisions.length - 1,
|
2013-05-08 17:22:01 -04:00
|
|
|
next = ! isRtl ? $( '#next' ) : $( '#previous' ),
|
|
|
|
prev = ! isRtl ? $( '#previous' ) : $( '#next' );
|
2013-04-17 16:12:25 -04:00
|
|
|
|
|
|
|
// Disable "Next" button if you're on the last node
|
|
|
|
if ( maxVal === val )
|
|
|
|
next.prop( 'disabled', true );
|
|
|
|
else
|
|
|
|
next.prop( 'disabled', false );
|
|
|
|
|
|
|
|
// Disable "Previous" button if you're on the 0 node
|
|
|
|
if ( 0 === val )
|
|
|
|
prev.prop( 'disabled', true );
|
|
|
|
else
|
|
|
|
prev.prop( 'disabled', false );
|
|
|
|
},
|
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
/**
|
|
|
|
* completeApplicationSetup finishes loading all views once the initial model load is complete
|
|
|
|
*/
|
2013-04-04 03:53:49 -04:00
|
|
|
completeApplicationSetup: function() {
|
|
|
|
this.revisionView = new revisions.view.Diff({
|
|
|
|
model: this.revisions
|
|
|
|
});
|
2013-05-08 17:22:01 -04:00
|
|
|
this.revisionView.render(); // render the revision view
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
this.loadDiffs( this.revisions ); // get the actual revisions data
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
this.revisionsInteractions = new revisions.view.Interact({
|
|
|
|
model: this.revisions
|
|
|
|
});
|
2013-05-08 17:22:01 -04:00
|
|
|
this.revisionsInteractions.render(); // render the interaction view
|
2013-03-07 10:32:26 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
this.tickmarkView = new revisions.view.Tickmarks({
|
|
|
|
model: this.revisions
|
|
|
|
});
|
2013-05-08 17:22:01 -04:00
|
|
|
this.tickmarkView.render(); // render the tickmark view
|
2013-04-04 03:53:49 -04:00
|
|
|
}
|
|
|
|
});
|
2013-03-21 11:54:11 -04:00
|
|
|
|
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
/**
|
|
|
|
* ========================================================================
|
|
|
|
* VIEWS
|
|
|
|
* ========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.revisions.view.Slider
|
|
|
|
*
|
|
|
|
* The slider
|
|
|
|
*/
|
|
|
|
revisions.view.Slider = Backbone.View.extend({
|
2013-04-04 11:49:28 -04:00
|
|
|
el: $( '#diff-slider' ),
|
2013-04-04 03:53:49 -04:00
|
|
|
singleRevision: true,
|
|
|
|
|
|
|
|
initialize: function( options ) {
|
|
|
|
this.options = _.defaults( options || {}, {
|
|
|
|
value: 0,
|
|
|
|
min: 0,
|
|
|
|
max: 1,
|
|
|
|
step: 1
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
/**
|
|
|
|
* respond to slider slide events
|
|
|
|
* Note: in one handle mode, jQuery UI reports leftmost position as 0
|
|
|
|
* in two handle mode, jQuery UI Slider reports leftmost position as 1
|
|
|
|
*/
|
2013-04-04 03:53:49 -04:00
|
|
|
slide: function( event, ui ) {
|
|
|
|
if ( this.singleRevision ) {
|
|
|
|
Diff.rightDiff = ( ui.value + 1 );
|
|
|
|
Diff.revisionView.render();
|
2013-04-17 16:12:25 -04:00
|
|
|
Diff.disabledButtonCheck( ui.value );
|
2013-04-04 03:53:49 -04:00
|
|
|
} else {
|
|
|
|
if ( ui.values[0] === ui.values[1] ) // prevent compare to self
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( $( ui.handle ).hasClass( 'left-handle' ) ) {
|
|
|
|
// Left handler
|
|
|
|
if ( Diff.leftModelLoading ) // left model still loading, prevent sliding left handle
|
|
|
|
return false;
|
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
Diff.leftDiff = isRtl ? ui.values[1] : ui.values[0]; // handles are reversed in RTL mode
|
2013-04-04 03:53:49 -04:00
|
|
|
} else {
|
|
|
|
// Right handler
|
|
|
|
if ( Diff.rightModelLoading ) // right model still loading, prevent sliding right handle
|
|
|
|
return false;
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
Diff.rightDiff = isRtl ? ui.values[0] : ui.values[1]; // handles are reversed in RTL mode
|
2013-04-04 03:53:49 -04:00
|
|
|
}
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.revisionView.render();
|
|
|
|
}
|
|
|
|
},
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
/**
|
|
|
|
* responds to slider start sliding events
|
|
|
|
* in two handle mode stores start position, so if unchanged at stop event no need to reload diffs
|
|
|
|
* also swaps in the appropriate models - left handled or right handled
|
|
|
|
*/
|
2013-04-04 03:53:49 -04:00
|
|
|
start: function( event, ui ) {
|
|
|
|
// Not needed in one mode
|
|
|
|
if ( this.singleRevision )
|
|
|
|
return;
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( $( ui.handle ).hasClass( 'left-handle' ) ) {
|
|
|
|
// Left handler
|
|
|
|
if ( Diff.leftModelLoading ) // left model still loading, prevent sliding left handle
|
|
|
|
return false;
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.revisionView.draggingLeft = true;
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( Diff.revisionView.model !== Diff.leftHandleRevisions &&
|
|
|
|
null !== Diff.leftHandleRevisions ) {
|
2013-05-08 17:22:01 -04:00
|
|
|
Diff.revisionView.model = Diff.leftHandleRevisions; // use the left handle models
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.tickmarkView.model = Diff.leftHandleRevisions;
|
|
|
|
Diff.tickmarkView.render();
|
2013-03-21 11:54:11 -04:00
|
|
|
}
|
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
Diff.leftDiffStart = isRtl ? ui.values[1] : ui.values[0]; // in RTL mode the 'left handle' is the second in the slider, 'right' is first
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
} else {
|
|
|
|
// Right handler
|
|
|
|
if ( Diff.rightModelLoading || 0 === Diff.rightHandleRevisions.length) // right model still loading, prevent sliding right handle
|
|
|
|
return false;
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( Diff.revisionView.model !== Diff.rightHandleRevisions &&
|
|
|
|
null !== Diff.rightHandleRevisions ) {
|
2013-05-08 17:22:01 -04:00
|
|
|
Diff.revisionView.model = Diff.rightHandleRevisions; // use the right handle models
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.tickmarkView.model = Diff.rightHandleRevisions;
|
|
|
|
Diff.tickmarkView.render();
|
2013-03-21 11:54:11 -04:00
|
|
|
}
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
Diff.revisionView.draggingLeft = false;
|
2013-05-08 17:22:01 -04:00
|
|
|
Diff.rightDiffStart = isRtl ? ui.values[0] : ui.values[1]; // in RTL mode the 'left handle' is the second in the slider, 'right' is first
|
2013-03-21 11:54:11 -04:00
|
|
|
}
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
/**
|
|
|
|
* responds to slider stop events
|
|
|
|
* in two handled mode, if the handle that stopped has moved, reload the diffs for the other handle
|
|
|
|
* the other handle compares to this handle's position, so if it changes they need to be recalculated
|
|
|
|
*/
|
2013-04-04 03:53:49 -04:00
|
|
|
stop: function( event, ui ) {
|
|
|
|
// Not needed in one mode
|
|
|
|
if ( this.singleRevision )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// calculate and generate a diff for comparing to the left handle
|
|
|
|
// and the right handle, swap out when dragging
|
|
|
|
if ( $( ui.handle ).hasClass( 'left-handle' ) ) {
|
2013-05-08 17:22:01 -04:00
|
|
|
// Left handler
|
|
|
|
if ( Diff.leftDiffStart !== isRtl ? ui.values[1] : ui.values[0] ) // in RTL mode the 'left handle' is the second in the slider, 'right' is first
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.reloadRight();
|
|
|
|
} else {
|
|
|
|
// Right handler
|
2013-05-08 17:22:01 -04:00
|
|
|
if ( Diff.rightDiffStart !== isRtl ? ui.values[0] : ui.values[1] ) // in RTL mode the 'left handle' is the second in the slider, 'right' is first
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.reloadLeft();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addTooltip: function( handle, message ) {
|
2013-04-28 06:56:57 -04:00
|
|
|
handle.find( '.ui-slider-tooltip' ).html( message );
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
width: function() {
|
2013-04-04 11:49:28 -04:00
|
|
|
return $( '#diff-slider' ).width();
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
setWidth: function( width ) {
|
2013-04-28 06:56:57 -04:00
|
|
|
$( '#diff-slider' ).width( width );
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
refresh: function( options, slide ) {
|
2013-04-04 11:49:28 -04:00
|
|
|
$( '#diff-slider' ).slider( 'option', options );
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
// Triggers the slide event
|
|
|
|
if ( slide )
|
2013-04-04 11:49:28 -04:00
|
|
|
$( '#diff-slider' ).trigger( 'slide' );
|
2013-04-17 16:12:25 -04:00
|
|
|
|
|
|
|
Diff.disabledButtonCheck( options.value );
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
option: function( key ) {
|
2013-04-04 11:49:28 -04:00
|
|
|
return $( '#diff-slider' ).slider( 'option', key );
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var self = this;
|
|
|
|
// this.$el doesn't work, why?
|
2013-04-04 11:49:28 -04:00
|
|
|
$( '#diff-slider' ).slider( {
|
2013-04-04 03:53:49 -04:00
|
|
|
slide: $.proxy( self.slide, self ),
|
|
|
|
start: $.proxy( self.start, self ),
|
2013-05-08 17:22:01 -04:00
|
|
|
stop: $.proxy( self.stop, self )
|
2013-04-04 03:53:49 -04:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Set options
|
|
|
|
this.refresh( this.options );
|
|
|
|
}
|
|
|
|
});
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
/**
|
|
|
|
* wp.revisions.view.Tickmarks
|
|
|
|
*
|
|
|
|
* The slider tickmarks.
|
|
|
|
*/
|
|
|
|
revisions.view.Tickmarks = Backbone.View.extend({
|
|
|
|
el: $('#diff-slider-ticks'),
|
|
|
|
template: wp.template('revision-ticks'),
|
|
|
|
model: Revision,
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
resetTicks: function() {
|
2013-05-03 19:17:06 -04:00
|
|
|
var sliderMax, sliderWidth, adjustMax, tickWidth, tickCount = 0, aTickWidth, tickMargin, self = this, firstTick, lastTick;
|
|
|
|
sliderMax = Diff.slider.option( 'max' );
|
|
|
|
sliderWidth = Diff.slider.width();
|
|
|
|
adjustMax = Diff.singleRevision ? 0 : 1;
|
|
|
|
tickWidth = Math.floor( sliderWidth / ( sliderMax - adjustMax ) );
|
|
|
|
tickWidth = ( tickWidth > 50 ) ? 50 : tickWidth; // set minimum and maximum widths for tick marks
|
|
|
|
tickWidth = ( tickWidth < 10 ) ? 10 : tickWidth;
|
2013-05-08 17:22:01 -04:00
|
|
|
sliderWidth = tickWidth * ( sliderMax - adjustMax ); // calculate the slider width
|
2013-05-03 19:17:06 -04:00
|
|
|
aTickWidth = $( '.revision-tick' ).width();
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-05-03 19:17:06 -04:00
|
|
|
if ( tickWidth !== aTickWidth ) { // is the width already set correctly?
|
|
|
|
$( '.revision-tick' ).each( function() {
|
|
|
|
tickMargin = Math.floor( ( tickWidth - $( this ).width() ) / 2 ) + 1;
|
|
|
|
$( this ).css( 'border-left', tickMargin + 'px solid #f7f7f7'); // space the ticks out using margins
|
|
|
|
$( this ).css( 'border-right', ( tickWidth - tickMargin - $( this ).width() ) + 'px solid #f7f7f7'); // space the ticks out using margins
|
|
|
|
});
|
|
|
|
firstTick = $( '.revision-tick' ).first(); //cache selectors for optimization
|
|
|
|
lastTick = $( '.revision-tick' ).last();
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-05-03 19:17:06 -04:00
|
|
|
sliderWidth = sliderWidth + Math.ceil( ( tickWidth - ( lastTick.outerWidth() - lastTick.innerWidth() ) ) / 2 ); // room for the last tick
|
|
|
|
sliderWidth = sliderWidth + Math.ceil( ( tickWidth - ( firstTick.outerWidth() - firstTick.innerWidth() ) ) / 2 ); // room for the first tick
|
|
|
|
firstTick.css( 'border-left', 'none' ); // first tick gets no left border
|
|
|
|
lastTick.css( 'border-right', 'none' ); // last tick gets no right border
|
|
|
|
}
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-05-03 19:17:06 -04:00
|
|
|
/**
|
|
|
|
* reset the slider width
|
|
|
|
*/
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.slider.setWidth( sliderWidth );
|
|
|
|
$( '.diff-slider-ticks-wrapper' ).width( sliderWidth );
|
|
|
|
$( '#diff-slider-ticks' ).width( sliderWidth );
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-05-03 19:17:06 -04:00
|
|
|
/**
|
|
|
|
* go through all ticks, add hover and click interactions
|
|
|
|
*/
|
|
|
|
$( '.revision-tick' ).each( function() {
|
|
|
|
Diff.slider.addTooltip ( $( this ), Diff.revisions.at( tickCount++ ).get( 'titleTooltip' ) );
|
|
|
|
$( this ).hover(
|
|
|
|
function() {
|
|
|
|
$( this ).find( '.ui-slider-tooltip' ).show().append('<div class="arrow"></div>');
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
$( this ).find( '.ui-slider-tooltip' ).hide().find( '.arrow' ).remove();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* move the slider handle when the tick marks are clicked
|
|
|
|
*/
|
|
|
|
$( this ).on( 'click',
|
2013-05-08 17:22:01 -04:00
|
|
|
{ tickCount: tickCount }, // pass the tick through so we know where to move the handle
|
2013-05-03 19:17:06 -04:00
|
|
|
function( event ) {
|
2013-05-08 17:22:01 -04:00
|
|
|
if ( Diff.slider.singleRevision ) { // single handle mode
|
|
|
|
Diff.rightDiff = event.data.tickCount; // reposition the right handle
|
2013-05-03 19:17:06 -04:00
|
|
|
Diff.slider.refresh({
|
|
|
|
value: Diff.rightDiff - 1
|
|
|
|
} );
|
|
|
|
} else { //compare two mode
|
2013-05-08 17:22:01 -04:00
|
|
|
if ( isRtl ) {
|
|
|
|
if ( event.data.tickCount < Diff.leftDiff ) { // click was on the 'left' side
|
|
|
|
Diff.rightDiff = event.data.tickCount; // set the 'right' handle location
|
|
|
|
Diff.reloadLeft(); // reload the left handle comparison models
|
|
|
|
} else { // middle or 'right' clicks
|
|
|
|
Diff.leftDiff = event.data.tickCount; // set the 'left' handle location
|
|
|
|
Diff.reloadRight(); // reload right handle models
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( event.data.tickCount < Diff.leftDiff ) { // click was on the 'left' side
|
|
|
|
Diff.leftDiff = event.data.tickCount; // set the left handle location
|
|
|
|
Diff.reloadRight(); // reload the right handle comparison models
|
|
|
|
} else { // middle or 'right' clicks
|
|
|
|
Diff.rightDiff = event.data.tickCount; // set the right handle location
|
|
|
|
Diff.reloadLeft(); // reload left handle models
|
|
|
|
}
|
2013-05-03 19:17:06 -04:00
|
|
|
}
|
|
|
|
Diff.slider.refresh( { // set the slider handle positions
|
2013-05-08 17:22:01 -04:00
|
|
|
values: [ isRtl ? Diff.rightDiff : Diff.leftDiff, isRtl ? Diff.leftDiff : Diff.rightDiff ]
|
2013-05-03 19:17:06 -04:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
Diff.revisionView.render(); // render the main view
|
|
|
|
} );
|
|
|
|
} );
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-05-03 19:17:06 -04:00
|
|
|
// render the tick mark view
|
2013-04-04 03:53:49 -04:00
|
|
|
render: function() {
|
2013-05-03 19:17:06 -04:00
|
|
|
var self = this, addHtml;
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( null !== self.model ) {
|
2013-05-03 19:17:06 -04:00
|
|
|
addHtml = "";
|
2013-04-04 03:53:49 -04:00
|
|
|
_.each ( self.model.models, function( theModel ) {
|
|
|
|
addHtml = addHtml + self.template ( theModel.toJSON() );
|
|
|
|
});
|
|
|
|
self.$el.html( addHtml );
|
2013-02-28 10:14:34 -05:00
|
|
|
|
|
|
|
}
|
2013-04-04 03:53:49 -04:00
|
|
|
self.resetTicks();
|
|
|
|
return self;
|
|
|
|
}
|
2013-05-03 19:17:06 -04:00
|
|
|
} );
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
/**
|
|
|
|
* wp.revisions.view.Interact
|
|
|
|
*
|
|
|
|
* Next/Prev buttons and the slider
|
|
|
|
*/
|
|
|
|
// TODO: Change Interact to something else.
|
|
|
|
revisions.view.Interact = Backbone.View.extend({
|
2013-04-04 11:49:28 -04:00
|
|
|
el: $( '#revision-interact' ),
|
|
|
|
template: wp.template( 'revision-interact' ),
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
// next and previous buttons, only available in compare one mode
|
|
|
|
events: {
|
2013-05-08 17:22:01 -04:00
|
|
|
'click #next': ! isRtl ? 'nextRevision' : 'previousRevision',
|
|
|
|
'click #previous': ! isRtl ? 'previousRevision' : 'nextRevision'
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2013-05-03 19:17:06 -04:00
|
|
|
var modelcount;
|
2013-04-04 11:49:28 -04:00
|
|
|
this.$el.html( this.template );
|
2013-04-04 03:53:49 -04:00
|
|
|
|
2013-05-03 19:17:06 -04:00
|
|
|
modelcount = Diff.revisions.length;
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
Diff.slider.singleRevision = Diff.singleRevision;
|
|
|
|
Diff.slider.render();
|
|
|
|
|
|
|
|
if ( Diff.singleRevision ) {
|
|
|
|
Diff.slider.refresh({
|
2013-05-08 17:22:01 -04:00
|
|
|
value: Diff.rightDiff - 1, // rightDiff value is off model index by 1
|
2013-04-04 03:53:49 -04:00
|
|
|
min: 0,
|
|
|
|
max: modelcount - 1
|
|
|
|
});
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 11:49:28 -04:00
|
|
|
$( '#revision-diff-container' ).removeClass( 'comparing-two-revisions' );
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
} else {
|
|
|
|
Diff.slider.refresh({
|
2013-05-08 17:22:01 -04:00
|
|
|
// in RTL mode the 'left handle' is the second in the slider, 'right' is first
|
|
|
|
values: [ isRtl ? Diff.rightDiff : Diff.leftDiff, isRtl ? Diff.leftDiff : Diff.rightDiff ],
|
2013-04-04 03:53:49 -04:00
|
|
|
min: 1,
|
|
|
|
max: modelcount + 1,
|
|
|
|
range: true
|
|
|
|
});
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 11:49:28 -04:00
|
|
|
$( '#revision-diff-container' ).addClass( 'comparing-two-revisions' );
|
2013-05-08 17:22:01 -04:00
|
|
|
// in RTL mode the 'left handle' is the second in the slider, 'right' is first
|
|
|
|
$( '#diff-slider a.ui-slider-handle' ).first().addClass( isRtl ? 'right-handle' : 'left-handle' );
|
|
|
|
$( '#diff-slider a.ui-slider-handle' ).last().addClass( isRtl ? 'left-handle' : 'right-handle' );
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
}
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
return this;
|
|
|
|
},
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
// go to the next revision
|
|
|
|
nextRevision: function() {
|
|
|
|
if ( Diff.rightDiff < this.model.length ) // unless at right boundry
|
|
|
|
Diff.rightDiff = Diff.rightDiff + 1 ;
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.revisionView.render();
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.slider.refresh({
|
|
|
|
value: Diff.rightDiff - 1
|
|
|
|
}, true );
|
|
|
|
},
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-05-09 21:39:30 -04:00
|
|
|
// go to the previous revision
|
2013-04-04 03:53:49 -04:00
|
|
|
previousRevision: function() {
|
|
|
|
if ( Diff.rightDiff > 1 ) // unless at left boundry
|
|
|
|
Diff.rightDiff = Diff.rightDiff - 1 ;
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.revisionView.render();
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.slider.refresh({
|
|
|
|
value: Diff.rightDiff - 1
|
|
|
|
}, true );
|
|
|
|
}
|
|
|
|
});
|
2013-03-07 10:32:26 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
/**
|
|
|
|
* wp.revisions.view.Diff
|
|
|
|
*
|
|
|
|
* Next/Prev buttons and the slider
|
|
|
|
*/
|
|
|
|
revisions.view.Diff = Backbone.View.extend({
|
2013-04-04 11:49:28 -04:00
|
|
|
el: $( '#revisions-diff' ),
|
|
|
|
template: wp.template( 'revisions-diff' ),
|
2013-04-04 03:53:49 -04:00
|
|
|
draggingLeft: false,
|
|
|
|
|
|
|
|
// the compare two button is in this view, add the interaction here
|
|
|
|
events: {
|
2013-04-04 11:49:28 -04:00
|
|
|
'click #compare-two-revisions': 'compareTwo',
|
|
|
|
'click #restore-revision': 'restore'
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// render the revisions
|
|
|
|
render: function() {
|
2013-05-03 19:17:06 -04:00
|
|
|
var addHtml = '', thediff;
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
// compare two revisions mode?
|
|
|
|
if ( ! Diff.singleRevision ) {
|
|
|
|
if ( this.draggingLeft ) {
|
2013-05-08 17:22:01 -04:00
|
|
|
thediff = Diff.leftDiff - 1; //leftDiff value is off model index by 1
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( this.model.at( thediff ) ) {
|
|
|
|
addHtml = this.template( this.model.at( thediff ).toJSON() );
|
|
|
|
}
|
|
|
|
} else { // dragging right handle
|
2013-05-08 17:22:01 -04:00
|
|
|
thediff = Diff.rightDiff - 1; // rightDiff value is off model index by 1
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( this.model.at( thediff ) ) {
|
|
|
|
addHtml = this.template( this.model.at( thediff ).toJSON() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { // end compare two revisions mode, eg only one slider handle
|
2013-05-08 17:22:01 -04:00
|
|
|
if ( this.model.at( Diff.rightDiff - 1 ) ) { // rightDiff value is off model index by 1
|
2013-04-04 03:53:49 -04:00
|
|
|
addHtml = this.template( this.model.at( Diff.rightDiff - 1 ).toJSON() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.$el.html( addHtml );
|
2013-03-07 10:32:26 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
if ( this.model.length < 2 ) {
|
2013-04-04 11:49:28 -04:00
|
|
|
$( '#diff-slider' ).hide(); // don't allow compare two if fewer than three revisions
|
2013-04-04 03:53:49 -04:00
|
|
|
$( '.diff-slider-ticks-wrapper' ).hide();
|
|
|
|
}
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 16:49:26 -04:00
|
|
|
this.toggleCompareTwoCheckbox();
|
2013-03-07 10:32:26 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
// hide the restore button when on the last sport/current post data
|
2013-04-17 15:34:21 -04:00
|
|
|
$( '#restore-revision' ).toggle( ! Diff.revisions.at( Diff.rightDiff - 1 ).get( 'isCurrent' ) );
|
2013-03-21 11:54:11 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2013-04-04 16:49:26 -04:00
|
|
|
toggleCompareTwoCheckbox: function() {
|
2013-04-04 03:53:49 -04:00
|
|
|
// don't allow compare two if fewer than three revisions
|
|
|
|
if ( this.model.length < 3 )
|
2013-04-04 16:49:26 -04:00
|
|
|
$( '#toggle-revision-compare-mode' ).hide();
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 11:49:28 -04:00
|
|
|
$( '#compare-two-revisions' ).prop( 'checked', ! Diff.singleRevision );
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
// turn on/off the compare two mode
|
|
|
|
compareTwo: function() {
|
2013-04-04 11:49:28 -04:00
|
|
|
if ( $( '#compare-two-revisions' ).is( ':checked' ) ) { // compare 2 mode
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.singleRevision = false ;
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-05-08 17:22:01 -04:00
|
|
|
// in RTL mode handles are swapped, so boundary checks are different;
|
|
|
|
if ( isRtl ){
|
|
|
|
Diff.leftDiff = Diff.revisions.length; // put the left handle at the rightmost position, representing current revision
|
|
|
|
|
|
|
|
if ( Diff.revisions.length === Diff.rightDiff ) // make sure 'left' handle not in rightmost slot
|
|
|
|
Diff.rightDiff = Diff.rightDiff - 1;
|
|
|
|
} else {
|
|
|
|
if ( 1 === Diff.rightDiff ) // make sure right handle not in leftmost slot
|
|
|
|
Diff.rightDiff = 2;
|
|
|
|
}
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.revisionView.draggingLeft = false;
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
revisions.model.settings.revision_id = ''; // reset passed revision id so switching back to one handle mode doesn't re-select revision
|
2013-05-08 17:22:01 -04:00
|
|
|
Diff.reloadLeftRight(); // load diffs for left and right handles
|
2013-04-04 03:53:49 -04:00
|
|
|
Diff.revisionView.model = Diff.rightHandleRevisions;
|
2013-02-28 10:14:34 -05:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
} else { // compare one mode
|
|
|
|
Diff.singleRevision = true;
|
|
|
|
Diff.revisionView.draggingLeft = false;
|
|
|
|
Diff.reloadModelSingle();
|
|
|
|
}
|
|
|
|
Diff.revisionsInteractions.render();
|
|
|
|
Diff.tickmarkView.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
restore: function() {
|
2013-04-04 16:58:33 -04:00
|
|
|
document.location = $( '#restore-revision' ).data( 'restoreLink' );
|
2013-04-04 03:53:49 -04:00
|
|
|
}
|
|
|
|
});
|
2013-02-28 10:14:34 -05:00
|
|
|
|
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
/**
|
|
|
|
* ========================================================================
|
|
|
|
* MODELS
|
|
|
|
* ========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.revisions.Revision
|
|
|
|
*/
|
|
|
|
Revision = revisions.model.Revision = Backbone.Model.extend({
|
|
|
|
idAttribute: 'ID',
|
2013-04-17 15:34:21 -04:00
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
defaults: {
|
|
|
|
ID: 0,
|
|
|
|
titleTo: '',
|
|
|
|
titleTooltip: '',
|
|
|
|
titleFrom: '',
|
|
|
|
diff: '<div class="diff-loading"><div class="spinner"></div></div>',
|
|
|
|
restoreLink: '',
|
2013-04-17 15:34:21 -04:00
|
|
|
completed: false,
|
|
|
|
linesAdded: 0,
|
|
|
|
linesDeleted: 0,
|
|
|
|
scopeOfChanges: 'none',
|
|
|
|
previousID: 0,
|
|
|
|
isCurrent: false
|
2013-04-04 03:53:49 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
url: function() {
|
|
|
|
if ( Diff.singleRevision ) {
|
2013-04-17 15:34:21 -04:00
|
|
|
return ajaxurl +
|
|
|
|
'?action=revisions-data' +
|
|
|
|
'&show_autosaves=true' +
|
|
|
|
'&show_split_view=true' +
|
|
|
|
'&nonce=' + revisions.model.settings.nonce +
|
2013-04-04 03:53:49 -04:00
|
|
|
'&single_revision_id=' + this.id +
|
2013-04-17 15:34:21 -04:00
|
|
|
'&compare_to=' + this.get( 'previousID' ) +
|
2013-04-04 03:53:49 -04:00
|
|
|
'&post_id=' + revisions.model.settings.post_id;
|
|
|
|
} else {
|
|
|
|
return this.collection.url() + '&single_revision_id=' + this.id;
|
2013-02-28 10:14:34 -05:00
|
|
|
}
|
2013-04-04 03:53:49 -04:00
|
|
|
|
|
|
|
}
|
2013-02-28 10:14:34 -05:00
|
|
|
});
|
|
|
|
|
2013-04-04 03:53:49 -04:00
|
|
|
/**
|
|
|
|
* wp.revisions.Revisions
|
|
|
|
*/
|
|
|
|
Revisions = revisions.Revisions = Backbone.Collection.extend({
|
|
|
|
model: Revision,
|
|
|
|
|
|
|
|
initialize: function( models, options ) {
|
|
|
|
this.options = _.defaults( options || {}, {
|
|
|
|
'compareTo': revisions.model.settings.post_id,
|
|
|
|
'post_id': revisions.model.settings.post_id,
|
|
|
|
'showAutosaves': true,
|
|
|
|
'showSplitView': true,
|
|
|
|
'rightHandleAt': 0,
|
|
|
|
'leftHandleAt': 0,
|
|
|
|
'nonce': revisions.model.settings.nonce
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
url: function() {
|
2013-04-17 15:34:21 -04:00
|
|
|
return ajaxurl +
|
|
|
|
'?action=revisions-data' +
|
2013-05-08 17:22:01 -04:00
|
|
|
'&compare_to=' + this.options.compareTo + // revision are we comparing to
|
|
|
|
'&post_id=' + this.options.post_id + // the post id
|
|
|
|
'&show_autosaves=' + this.options.showAutosaves + // show or hide autosaves
|
|
|
|
'&show_split_view=' + this.options.showSplitView + // show in split view or single column view
|
|
|
|
'&right_handle_at=' + this.options.rightHandleAt + // mark point for comparison list
|
|
|
|
'&left_handle_at=' + this.options.leftHandleAt + // mark point for comparison list
|
2013-04-04 03:53:49 -04:00
|
|
|
'&nonce=' + this.options.nonce;
|
|
|
|
},
|
|
|
|
|
|
|
|
reload: function( options ) {
|
2013-04-17 15:34:21 -04:00
|
|
|
this.options = _.defaults( options.options || {}, this.options );
|
2013-04-04 03:53:49 -04:00
|
|
|
|
2013-04-17 15:34:21 -04:00
|
|
|
this.fetch({
|
|
|
|
success: options.success || null,
|
|
|
|
error: options.error || null
|
|
|
|
});
|
2013-04-04 03:53:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( wp.revisions );
|
2013-02-28 10:14:34 -05:00
|
|
|
|
|
|
|
}(jQuery));
|