Revisions modules should not rely on global settings:
* Only pass in global settings on `init`, this allows the classes to be used agnostically elsewhere * Clean up some erroneous/weird Backbone syntax Props ericlewis, wonderboymusic. Fixes #30219. git-svn-id: https://develop.svn.wordpress.org/trunk@30131 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8d2595d7ff
commit
0ae3ac0c05
@ -49,19 +49,6 @@ window.wp = window.wp || {};
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// wp_localize_script transforms top-level numbers into strings. Undo that.
|
|
||||||
if ( revisions.settings.to ) {
|
|
||||||
revisions.settings.to = parseInt( revisions.settings.to, 10 );
|
|
||||||
}
|
|
||||||
if ( revisions.settings.from ) {
|
|
||||||
revisions.settings.from = parseInt( revisions.settings.from, 10 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// wp_localize_script does not allow for top-level booleans. Fix that.
|
|
||||||
if ( revisions.settings.compareTwoMode ) {
|
|
||||||
revisions.settings.compareTwoMode = revisions.settings.compareTwoMode === '1';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ========================================================================
|
* ========================================================================
|
||||||
* MODELS
|
* MODELS
|
||||||
@ -87,13 +74,13 @@ window.wp = window.wp || {};
|
|||||||
this.listenTo( this.frame, 'change:compareTwoMode', this.updateMode );
|
this.listenTo( this.frame, 'change:compareTwoMode', this.updateMode );
|
||||||
|
|
||||||
// Listen for internal changes
|
// Listen for internal changes
|
||||||
this.listenTo( this, 'change:from', this.handleLocalChanges );
|
this.on( 'change:from', this.handleLocalChanges );
|
||||||
this.listenTo( this, 'change:to', this.handleLocalChanges );
|
this.on( 'change:to', this.handleLocalChanges );
|
||||||
this.listenTo( this, 'change:compareTwoMode', this.updateSliderSettings );
|
this.on( 'change:compareTwoMode', this.updateSliderSettings );
|
||||||
this.listenTo( this, 'update:revisions', this.updateSliderSettings );
|
this.on( 'update:revisions', this.updateSliderSettings );
|
||||||
|
|
||||||
// Listen for changes to the hovered revision
|
// Listen for changes to the hovered revision
|
||||||
this.listenTo( this, 'change:hoveredRevision', this.hoverRevision );
|
this.on( 'change:hoveredRevision', this.hoverRevision );
|
||||||
|
|
||||||
this.set({
|
this.set({
|
||||||
max: this.revisions.length - 1,
|
max: this.revisions.length - 1,
|
||||||
@ -242,6 +229,7 @@ window.wp = window.wp || {};
|
|||||||
_.bindAll( this, 'getClosestUnloaded' );
|
_.bindAll( this, 'getClosestUnloaded' );
|
||||||
this.loadAll = _.once( this._loadAll );
|
this.loadAll = _.once( this._loadAll );
|
||||||
this.revisions = options.revisions;
|
this.revisions = options.revisions;
|
||||||
|
this.postId = options.postId;
|
||||||
this.requests = {};
|
this.requests = {};
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -339,7 +327,7 @@ window.wp = window.wp || {};
|
|||||||
options.context = this;
|
options.context = this;
|
||||||
options.data = _.extend( options.data || {}, {
|
options.data = _.extend( options.data || {}, {
|
||||||
action: 'get-revision-diffs',
|
action: 'get-revision-diffs',
|
||||||
post_id: revisions.settings.postId
|
post_id: this.postId
|
||||||
});
|
});
|
||||||
|
|
||||||
var deferred = wp.ajax.send( options ),
|
var deferred = wp.ajax.send( options ),
|
||||||
@ -390,16 +378,19 @@ window.wp = window.wp || {};
|
|||||||
},
|
},
|
||||||
|
|
||||||
initialize: function( attributes, options ) {
|
initialize: function( attributes, options ) {
|
||||||
var properties = {};
|
var state = this.get( 'initialDiffState' );
|
||||||
|
|
||||||
_.bindAll( this, 'receiveDiff' );
|
_.bindAll( this, 'receiveDiff' );
|
||||||
this._debouncedEnsureDiff = _.debounce( this._ensureDiff, 200 );
|
this._debouncedEnsureDiff = _.debounce( this._ensureDiff, 200 );
|
||||||
|
|
||||||
this.revisions = options.revisions;
|
this.revisions = options.revisions;
|
||||||
this.diffs = new revisions.model.Diffs( [], { revisions: this.revisions });
|
|
||||||
|
|
||||||
// Set the initial diffs collection provided through the settings
|
this.diffs = new revisions.model.Diffs( [], {
|
||||||
this.diffs.set( revisions.settings.diffData );
|
revisions: this.revisions,
|
||||||
|
postId: this.get( 'postId' )
|
||||||
|
} );
|
||||||
|
|
||||||
|
// Set the initial diffs collection.
|
||||||
|
this.diffs.set( this.get( 'diffData' ) );
|
||||||
|
|
||||||
// Set up internal listeners
|
// Set up internal listeners
|
||||||
this.listenTo( this, 'change:from', this.changeRevisionHandler );
|
this.listenTo( this, 'change:from', this.changeRevisionHandler );
|
||||||
@ -409,12 +400,13 @@ window.wp = window.wp || {};
|
|||||||
this.listenTo( this.diffs, 'ensure:load', this.updateLoadingStatus );
|
this.listenTo( this.diffs, 'ensure:load', this.updateLoadingStatus );
|
||||||
this.listenTo( this, 'update:diff', this.updateLoadingStatus );
|
this.listenTo( this, 'update:diff', this.updateLoadingStatus );
|
||||||
|
|
||||||
// Set the initial revisions, baseUrl, and mode as provided through settings
|
// Set the initial revisions, baseUrl, and mode as provided through attributes.
|
||||||
properties.to = this.revisions.get( revisions.settings.to );
|
|
||||||
properties.from = this.revisions.get( revisions.settings.from );
|
this.set( {
|
||||||
properties.compareTwoMode = revisions.settings.compareTwoMode;
|
to : this.revisions.get( state.to ),
|
||||||
properties.baseUrl = revisions.settings.baseUrl;
|
from : this.revisions.get( state.from ),
|
||||||
this.set( properties );
|
compareTwoMode : this.revisions.get( state.compareTwoMode )
|
||||||
|
} );
|
||||||
|
|
||||||
// Start the router if browser supports History API
|
// Start the router if browser supports History API
|
||||||
if ( window.history && window.history.pushState ) {
|
if ( window.history && window.history.pushState ) {
|
||||||
@ -1143,15 +1135,30 @@ window.wp = window.wp || {};
|
|||||||
* Initialize the revisions UI for revision.php.
|
* Initialize the revisions UI for revision.php.
|
||||||
*/
|
*/
|
||||||
revisions.init = function() {
|
revisions.init = function() {
|
||||||
|
var state;
|
||||||
|
|
||||||
// Bail if the current page is not revision.php.
|
// Bail if the current page is not revision.php.
|
||||||
if ( ! window.adminpage || 'revision-php' !== window.adminpage ) {
|
if ( ! window.adminpage || 'revision-php' !== window.adminpage ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state = new revisions.model.FrameState({
|
||||||
|
initialDiffState: {
|
||||||
|
// wp_localize_script doesn't stringifies ints, so cast them.
|
||||||
|
to: parseInt( revisions.settings.to, 10 ),
|
||||||
|
from: parseInt( revisions.settings.from, 10 ),
|
||||||
|
// wp_localize_script does not allow for top-level booleans so do a comparator here.
|
||||||
|
compareTwoMode: ( revisions.settings.compareTwoMode === '1' )
|
||||||
|
},
|
||||||
|
diffData: revisions.settings.diffData,
|
||||||
|
baseUrl: revisions.settings.baseUrl,
|
||||||
|
postId: parseInt( revisions.settings.postId, 10 )
|
||||||
|
}, {
|
||||||
|
revisions: new revisions.model.Revisions( revisions.settings.revisionData )
|
||||||
|
});
|
||||||
|
|
||||||
revisions.view.frame = new revisions.view.Frame({
|
revisions.view.frame = new revisions.view.Frame({
|
||||||
model: new revisions.model.FrameState({}, {
|
model: state
|
||||||
revisions: new revisions.model.Revisions( revisions.settings.revisionData )
|
|
||||||
})
|
|
||||||
}).render();
|
}).render();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user