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: http://core.svn.wordpress.org/trunk@24814 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3999883feb
commit
174bbc20d8
|
@ -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() {
|
||||
|
|
|
@ -130,31 +130,6 @@ require_once( './admin-header.php' );
|
|||
</div>
|
||||
</script>
|
||||
|
||||
<script id="tmpl-revisions-tooltip" type="text/html">
|
||||
<div class="author-card">
|
||||
<# if ( 'undefined' !== typeof data && 'undefined' !== typeof data.author ) { #>
|
||||
<div class="author-card<# if ( data.autosave ) { #> autosave<# } #>">
|
||||
{{{ data.author.avatar }}}
|
||||
<div class="author-info">
|
||||
<# if ( data.autosave ) { #>
|
||||
<span class="byline"><?php printf( __( 'Autosave by %s' ),
|
||||
'<span class="author-name">{{ data.author.name }}</span>' ); ?></span>
|
||||
<# } else if ( data.current ) { #>
|
||||
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
|
||||
'<span class="author-name">{{ data.author.name }}</span>' ); ?></span>
|
||||
<# } else { #>
|
||||
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
||||
'<span class="author-name">{{ data.author.name }}</span>' ); ?></span>
|
||||
<# } #>
|
||||
<span class="time-ago">{{ data.timeAgo }}</span>
|
||||
<span class="date">({{ data.dateShort }})</span>
|
||||
</div>
|
||||
</div>
|
||||
<# } #>
|
||||
</div>
|
||||
<div class="revisions-tooltip-arrow"><span></span></div>
|
||||
</script>
|
||||
|
||||
<script id="tmpl-revisions-checkbox" type="text/html">
|
||||
<div class="revision-toggle-compare-mode">
|
||||
<label>
|
||||
|
@ -171,65 +146,45 @@ require_once( './admin-header.php' );
|
|||
</script>
|
||||
|
||||
<script id="tmpl-revisions-meta" type="text/html">
|
||||
<div class="diff-meta diff-meta-from">
|
||||
<# if ( ! _.isUndefined( data.attributes ) ) { #>
|
||||
<div class="diff-title">
|
||||
<# if ( 'from' === data.type ) { #>
|
||||
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
|
||||
<# if ( 'undefined' !== typeof data.from ) { #>
|
||||
<div class="author-card<# if ( data.from.attributes.autosave ) { #> autosave<# } #>">
|
||||
{{{ data.from.attributes.author.avatar }}}
|
||||
<div class="author-info">
|
||||
<# if ( data.from.attributes.autosave ) { #>
|
||||
<span class="byline"><?php printf( __( 'Autosave by %s' ),
|
||||
'<span class="author-name">{{ data.from.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } else if ( data.from.attributes.current ) { #>
|
||||
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
|
||||
'<span class="author-name">{{ data.from.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } else { #>
|
||||
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
||||
'<span class="author-name">{{ data.from.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } #>
|
||||
<span class="time-ago">{{ data.from.attributes.timeAgo }}</span>
|
||||
<span class="date">({{ data.from.attributes.dateShort }})</span>
|
||||
</div>
|
||||
</div>
|
||||
<# } #>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="diff-meta diff-meta-to">
|
||||
<div class="diff-title">
|
||||
<# } else if ( 'to' === data.type ) { #>
|
||||
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
|
||||
<# if ( 'undefined' !== typeof data.to ) { #>
|
||||
<div class="author-card<# if ( data.to.attributes.autosave ) { #> autosave<# } #>">
|
||||
{{{ data.to.attributes.author.avatar }}}
|
||||
<# } #>
|
||||
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
|
||||
{{{ data.attributes.author.avatar }}}
|
||||
<div class="author-info">
|
||||
<# if ( data.to.attributes.autosave ) { #>
|
||||
<# if ( data.attributes.autosave ) { #>
|
||||
<span class="byline"><?php printf( __( 'Autosave by %s' ),
|
||||
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } else if ( data.to.attributes.current ) { #>
|
||||
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } else if ( data.attributes.current ) { #>
|
||||
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
|
||||
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
|
||||
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } else { #>
|
||||
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
||||
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
|
||||
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
|
||||
<# } #>
|
||||
<span class="time-ago">{{ data.to.attributes.timeAgo }}</span>
|
||||
<span class="date">({{ data.to.attributes.dateShort }})</span>
|
||||
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
|
||||
<span class="date">({{ data.attributes.dateShort }})</span>
|
||||
</div>
|
||||
<# } #>
|
||||
<# if ( data.to.attributes.restoreUrl ) { #>
|
||||
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
|
||||
<input
|
||||
<# if ( data.to.attributes.current ) { #>
|
||||
<# if ( data.attributes.current ) { #>
|
||||
disabled="disabled"
|
||||
<# } #>
|
||||
<# if ( data.to.attributes.autosave ) { #>
|
||||
<# if ( data.attributes.autosave ) { #>
|
||||
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
|
||||
<# } else { #>
|
||||
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
|
||||
<# } #>
|
||||
<# } #>
|
||||
</div>
|
||||
</div>
|
||||
<# if ( 'tooltip' === data.type ) { #>
|
||||
<div class="revisions-tooltip-arrow"><span></span></div>
|
||||
<# } #>
|
||||
<# } #>
|
||||
</script>
|
||||
|
||||
<script id="tmpl-revisions-diff" type="text/html">
|
||||
|
|
Loading…
Reference in New Issue