Revisions: Combine our tooltip and from/to templates into one generic template

We had three copies of essentially the same template. Now just one, with minor logic inside.

Also fixes a bug where tooltip.revision was being initially set to a diff instead of a revision.

For trunk. See #24804.

git-svn-id: https://develop.svn.wordpress.org/trunk@24814 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mark Jaquith
2013-07-28 20:15:28 +00:00
parent 05cbd5ec91
commit c7ef7b482b
2 changed files with 68 additions and 80 deletions
+41 -8
View File
@@ -156,7 +156,7 @@ window.wp = window.wp || {};
this.listenTo( this.slider, 'change:hovering', this.setHovering );
this.listenTo( this.slider, 'change:scrubbing', this.setScrubbing );
this.set({ revision: this.frame.diff() });
this.set({ revision: this.revisions.get( this.frame.get('to') ) });
},
@@ -571,8 +571,8 @@ window.wp = window.wp || {};
model: slider
}) );
// Add the Meta view
this.views.add( new revisions.view.Meta({
// Add the Metabox view
this.views.add( new revisions.view.Metabox({
model: this.model
}) );
},
@@ -659,9 +659,26 @@ window.wp = window.wp || {};
}
});
// The meta view
revisions.view.Meta = wp.Backbone.View.extend({
// The metabox view
revisions.view.Metabox = wp.Backbone.View.extend({
className: 'revisions-meta',
initialize: function() {
// Add the 'from' view
this.views.add( new revisions.view.MetaFrom({
model: this.model,
className: 'diff-meta diff-meta-from'
}) );
// Add the 'to' view
this.views.add( new revisions.view.MetaTo({
model: this.model
}) );
}
});
// The revision meta view (to be extended)
revisions.view.Meta = wp.Backbone.View.extend({
template: wp.template('revisions-meta'),
events: {
@@ -673,7 +690,9 @@ window.wp = window.wp || {};
},
prepare: function() {
return this.model.toJSON();
return _.extend( this.model.toJSON()[this.type] || {}, {
type: this.type
});
},
restoreRevision: function() {
@@ -681,6 +700,18 @@ window.wp = window.wp || {};
}
});
// The revision meta 'from' view
revisions.view.MetaFrom = revisions.view.Meta.extend({
className: 'diff-meta diff-meta-from',
type: 'from'
});
// The revision meta 'to' view
revisions.view.MetaTo = revisions.view.Meta.extend({
className: 'diff-meta diff-meta-to',
type: 'to'
});
// The checkbox view.
revisions.view.Checkbox = wp.Backbone.View.extend({
className: 'revisions-checkbox',
@@ -714,7 +745,7 @@ window.wp = window.wp || {};
// Encapsulates the tooltip.
revisions.view.Tooltip = wp.Backbone.View.extend({
className: 'revisions-tooltip',
template: wp.template('revisions-tooltip'),
template: wp.template('revisions-meta'),
initialize: function( options ) {
this.listenTo( this.model, 'change:offset', this.render );
@@ -723,7 +754,9 @@ window.wp = window.wp || {};
},
prepare: function() {
return this.model.get('revision').toJSON();
return _.extend( { type: 'tooltip' }, {
attributes: this.model.get('revision').toJSON()
});
},
render: function() {