Revisions: Clean up JavaScript variable names, see #23901.

git-svn-id: http://core.svn.wordpress.org/trunk@24019 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2013-04-17 19:34:21 +00:00
parent 81b300582e
commit 45a9b723ee
5 changed files with 61 additions and 62 deletions

View File

@ -1483,14 +1483,14 @@ table.diff .diff-addedline ins {
color: #0080aa; color: #0080aa;
} }
.revision-tick.loading-true { .revision-tick.completed-false {
background-color: #9999cc; background-color: #9999cc;
background: url(../images/wpspin_light.gif) no-repeat; background: url(../images/wpspin_light.gif) no-repeat;
background-position: middle; background-position: middle;
background-size: 1px 10px; background-size: 1px 10px;
} }
.revision-tick.loading-false { .revision-tick.completed-true {
background-color: #aaa; background-color: #aaa;
} }

View File

@ -1377,14 +1377,14 @@ table.diff .diff-addedline ins {
background-color: #f7f7f7; background-color: #f7f7f7;
} }
.revision-tick.loading-true { .revision-tick.completed-false {
background-color: #9999cc; background-color: #9999cc;
background: url(../images/wpspin_light.gif) no-repeat; background: url(../images/wpspin_light.gif) no-repeat;
background-position: middle; background-position: middle;
background-size: 1px 10px; background-size: 1px 10px;
} }
.revision-tick.loading-false { .revision-tick.completed-true {
background-color: #aaa; background-color: #aaa;
} }

View File

@ -2164,8 +2164,8 @@ function wp_ajax_revisions_data() {
$all_the_revisions = array ( $all_the_revisions = array (
'diff' => $content, 'diff' => $content,
'lines_deleted' => $lines_deleted, 'linesDeleted' => $lines_deleted,
'lines_added' => $lines_added 'linesAdded' => $lines_added
); );
echo json_encode( $all_the_revisions ); echo json_encode( $all_the_revisions );
@ -2273,14 +2273,13 @@ function wp_ajax_revisions_data() {
if ( ( $compare_two_mode || -1 !== $previous_revision_id ) ) { if ( ( $compare_two_mode || -1 !== $previous_revision_id ) ) {
$all_the_revisions[] = array ( $all_the_revisions[] = array (
'ID' => $revision->ID, 'ID' => $revision->ID,
'titleTo' => $revision_date_author, 'titleTo' => $revision_date_author,
'titleFrom' => $revision_from_date_author, 'titleFrom' => $revision_from_date_author,
'titleTooltip' => $revision_date_author_short, 'titleTooltip' => $revision_date_author_short,
'restoreLink' => urldecode( $restore_link ), 'restoreLink' => urldecode( $restore_link ),
'revision_toload' => true, 'previousID' => $previous_revision_id,
'previous_revision_id' => $previous_revision_id, 'isCurrent' => $is_current_revision,
'is_current_revision' => $is_current_revision,
); );
} }
$previous_revision_id = $revision->ID; $previous_revision_id = $revision->ID;

View File

@ -59,9 +59,9 @@ window.wp = window.wp || {};
} }
}, },
reloadToLoadRevisions: function( models, reverse_direction ) { loadDiffs: function( models ) {
var self = this, var self = this,
revisionsToLoad = models.where( { revision_toload: true } ), revisionsToLoad = models.where( { completed: false } ),
delay = 0; delay = 0;
// match slider to passed revision_id // match slider to passed revision_id
@ -77,29 +77,29 @@ window.wp = window.wp || {};
add: false, add: false,
remove: false, remove: false,
success: function( model ) { success: function( model ) {
model.set( 'revision_toload', 'false' ); model.set( 'completed', true );
// stop spinner when all models are loaded // stop spinner when all models are loaded
if ( 0 === models.where( { revision_toload: true } ).length ) if ( 0 === models.where( { completed: false } ).length )
self.stopModelLoadingSpinner(); self.stopModelLoadingSpinner();
self.tickmarkView.render(); self.tickmarkView.render();
var total_changes = model.get( 'lines_added' ) + model.get( 'lines_deleted'), var totalChanges = model.get( 'linesAdded' ) + model.get( 'linesDeleted' ),
scope_of_changes = 'vsmall'; scopeOfChanges = 'vsmall';
// Note: hard coded scope of changes // Note: hard coded scope of changes
// TODO change to dynamic based on range of values // TODO change to dynamic based on range of values
if ( total_changes > 1 && total_changes <= 3 ) { if ( totalChanges > 1 && totalChanges <= 3 ) {
scope_of_changes = 'small'; scopeOfChanges = 'small';
} else if( total_changes > 3 && total_changes <= 5 ) { } else if ( totalChanges > 3 && totalChanges <= 5 ) {
scope_of_changes = 'med'; scopeOfChanges = 'med';
} else if( total_changes > 5 && total_changes <= 10 ) { } else if ( totalChanges > 5 && totalChanges <= 10 ) {
scope_of_changes = 'large'; scopeOfChanges = 'large';
} else if( total_changes > 10 ) { } else if ( totalChanges > 10 ) {
scope_of_changes = 'vlarge'; scopeOfChanges = 'vlarge';
} }
model.set( 'scope_of_changes', scope_of_changes ); model.set( 'scopeOfChanges', scopeOfChanges );
if ( 0 !== self.rightDiff && if ( 0 !== self.rightDiff &&
model.get( 'ID' ) === self.revisions.at( self.rightDiff - 1 ).get( 'ID' ) ) { model.get( 'ID' ) === self.revisions.at( self.rightDiff - 1 ).get( 'ID' ) ) {
// reload if current model refreshed // reload if current model refreshed
@ -149,19 +149,19 @@ window.wp = window.wp || {};
reloadModelSingle: function() { reloadModelSingle: function() {
var self = this; var self = this;
// TODO: Only updates the query args yet self.startRightModelLoading();
self.revisions.reload({ self.revisions.reload({
options: {
'showAutosaves': self.autosaves, 'showAutosaves': self.autosaves,
'showSplitView': self.showSplitView 'showSplitView': self.showSplitView
}); },
self.startRightModelLoading();
self.revisions.fetch({ // reload revision data
success: function() { success: function() {
var revisionCount = self.revisions.length; var revisionCount = self.revisions.length;
self.revisionView.model = self.revisions; self.revisionView.model = self.revisions;
self.revisionView.render(); self.revisionView.render();
self.reloadToLoadRevisions( self.revisions ); self.loadDiffs( self.revisions );
self.tickmarkView.model = self.revisions; self.tickmarkView.model = self.revisions;
self.tickmarkView.render(); self.tickmarkView.render();
self.slider.refresh({ self.slider.refresh({
@ -173,7 +173,6 @@ window.wp = window.wp || {};
error: function() { error: function() {
self.stopRightModelLoading(); self.stopRightModelLoading();
} }
}); });
}, },
@ -191,7 +190,7 @@ window.wp = window.wp || {};
self.leftHandleRevisions.fetch({ self.leftHandleRevisions.fetch({
success: function(){ success: function(){
self.stopLeftModelLoading(); self.stopLeftModelLoading();
self.reloadToLoadRevisions( self.leftHandleRevisions ); self.loadDiffs( self.leftHandleRevisions );
self.tickmarkView.model = self.leftHandleRevisions; self.tickmarkView.model = self.leftHandleRevisions;
self.slider.refresh({ self.slider.refresh({
'max': self.revisions.length 'max': self.revisions.length
@ -222,7 +221,7 @@ window.wp = window.wp || {};
self.rightHandleRevisions.fetch({ self.rightHandleRevisions.fetch({
success: function(){ success: function(){
self.stopRightModelLoading(); self.stopRightModelLoading();
self.reloadToLoadRevisions( self.rightHandleRevisions ); self.loadDiffs( self.rightHandleRevisions );
self.tickmarkView.model = self.rightHandleRevisions; self.tickmarkView.model = self.rightHandleRevisions;
self.slider.refresh({ self.slider.refresh({
'max': self.revisions.length, 'max': self.revisions.length,
@ -250,7 +249,7 @@ window.wp = window.wp || {};
}); });
this.revisionView.render(); this.revisionView.render();
this.reloadToLoadRevisions( this.revisions ); this.loadDiffs( this.revisions );
this.revisionsInteractions = new revisions.view.Interact({ this.revisionsInteractions = new revisions.view.Interact({
model: this.revisions model: this.revisions
@ -262,7 +261,6 @@ window.wp = window.wp || {};
}); });
this.tickmarkView.render(); this.tickmarkView.render();
this.tickmarkView.resetTicks(); this.tickmarkView.resetTicks();
} }
}); });
@ -449,10 +447,10 @@ window.wp = window.wp || {};
model: Revision, model: Revision,
resetTicks: function() { resetTicks: function() {
var sliderMax = Diff.slider.option( 'max' ); var sliderMax = Diff.slider.option( 'max' );
var sliderWidth = Diff.slider.width(); var sliderWidth = Diff.slider.width();
var adjustMax = Diff.singleRevision ? 0 : 1; var adjustMax = Diff.singleRevision ? 0 : 1;
var tickWidth = Math.floor( sliderWidth / ( sliderMax - adjustMax ) ); var tickWidth = Math.floor( sliderWidth / ( sliderMax - adjustMax ) );
// TODO: adjust right margins for wider ticks so they stay centered on handle stop point // TODO: adjust right margins for wider ticks so they stay centered on handle stop point
@ -473,9 +471,6 @@ window.wp = window.wp || {};
$(this).css( 'margin-right', tickWidth - 1 + 'px'); // space the ticks out using right margin $(this).css( 'margin-right', tickWidth - 1 + 'px'); // space the ticks out using right margin
}); });
if( ! Diff.singleRevision ) {
$( '.revision-tick' ).first().remove(); // TODO - remove the check
}
$( '.revision-tick' ).last().css( 'margin-right', '0' ); // last tick gets no right margin $( '.revision-tick' ).last().css( 'margin-right', '0' ); // last tick gets no right margin
} }
@ -633,7 +628,7 @@ window.wp = window.wp || {};
this.toggleCompareTwoCheckbox(); this.toggleCompareTwoCheckbox();
// hide the restore button when on the last sport/current post data // hide the restore button when on the last sport/current post data
$( '#restore-revision' ).toggle( ! Diff.revisions.at( Diff.rightDiff - 1 ).get( 'is_current_revision' ) ); $( '#restore-revision' ).toggle( ! Diff.revisions.at( Diff.rightDiff - 1 ).get( 'isCurrent' ) );
return this; return this;
}, },
@ -686,8 +681,7 @@ window.wp = window.wp || {};
*/ */
Revision = revisions.model.Revision = Backbone.Model.extend({ Revision = revisions.model.Revision = Backbone.Model.extend({
idAttribute: 'ID', idAttribute: 'ID',
urlRoot: ajaxurl + '?action=revisions-data' +
'&show_autosaves=true&show_split_view=true&nonce=' + revisions.model.settings.nonce,
defaults: { defaults: {
ID: 0, ID: 0,
titleTo: '', titleTo: '',
@ -695,19 +689,23 @@ window.wp = window.wp || {};
titleFrom: '', titleFrom: '',
diff: '<div class="diff-loading"><div class="spinner"></div></div>', diff: '<div class="diff-loading"><div class="spinner"></div></div>',
restoreLink: '', restoreLink: '',
revision_toload: false, completed: false,
lines_added: 0, linesAdded: 0,
lines_deleted: 0, linesDeleted: 0,
scope_of_changes: 'none', scopeOfChanges: 'none',
previous_revision_id: 0, previousID: 0,
is_current_revision: false isCurrent: false
}, },
url: function() { url: function() {
if ( Diff.singleRevision ) { if ( Diff.singleRevision ) {
return this.urlRoot + return ajaxurl +
'?action=revisions-data' +
'&show_autosaves=true' +
'&show_split_view=true' +
'&nonce=' + revisions.model.settings.nonce +
'&single_revision_id=' + this.id + '&single_revision_id=' + this.id +
'&compare_to=' + this.get( 'previous_revision_id' ) + '&compare_to=' + this.get( 'previousID' ) +
'&post_id=' + revisions.model.settings.post_id; '&post_id=' + revisions.model.settings.post_id;
} else { } else {
return this.collection.url() + '&single_revision_id=' + this.id; return this.collection.url() + '&single_revision_id=' + this.id;
@ -721,7 +719,6 @@ window.wp = window.wp || {};
*/ */
Revisions = revisions.Revisions = Backbone.Collection.extend({ Revisions = revisions.Revisions = Backbone.Collection.extend({
model: Revision, model: Revision,
urlRoot: ajaxurl + '?action=revisions-data',
initialize: function( models, options ) { initialize: function( models, options ) {
this.options = _.defaults( options || {}, { this.options = _.defaults( options || {}, {
@ -736,7 +733,8 @@ window.wp = window.wp || {};
}, },
url: function() { url: function() {
return this.urlRoot + return ajaxurl +
'?action=revisions-data' +
'&compare_to=' + this.options.compareTo + '&compare_to=' + this.options.compareTo +
'&post_id=' + this.options.post_id + '&post_id=' + this.options.post_id +
'&show_autosaves=' + this.options.showAutosaves + '&show_autosaves=' + this.options.showAutosaves +
@ -747,10 +745,12 @@ window.wp = window.wp || {};
}, },
reload: function( options ) { reload: function( options ) {
this.options = _.defaults( options || {}, this.options ); this.options = _.defaults( options.options || {}, this.options );
// TODO this.fetch({
//this.fetch(); success: options.success || null,
error: options.error || null
});
} }
} ); } );

View File

@ -157,7 +157,7 @@ require_once( './admin-header.php' );
</script> </script>
<script id="tmpl-revision-ticks" type="text/html"> <script id="tmpl-revision-ticks" type="text/html">
<div class="revision-tick loading-{{{ data.revision_toload }}} scope-of-changes-{{{ data.scope_of_changes }}}"></div> <div class="revision-tick completed-{{{ data.completed }}} scope-of-changes-{{{ data.scopeOfChanges }}}"></div>
</script> </script>
<?php <?php
require_once( './admin-footer.php' ); require_once( './admin-footer.php' );