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:hovering', this.setHovering );
|
||||||
this.listenTo( this.slider, 'change:scrubbing', this.setScrubbing );
|
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
|
model: slider
|
||||||
}) );
|
}) );
|
||||||
|
|
||||||
// Add the Meta view
|
// Add the Metabox view
|
||||||
this.views.add( new revisions.view.Meta({
|
this.views.add( new revisions.view.Metabox({
|
||||||
model: this.model
|
model: this.model
|
||||||
}) );
|
}) );
|
||||||
},
|
},
|
||||||
|
@ -659,9 +659,26 @@ window.wp = window.wp || {};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// The meta view
|
// The metabox view
|
||||||
revisions.view.Meta = wp.Backbone.View.extend({
|
revisions.view.Metabox = wp.Backbone.View.extend({
|
||||||
className: 'revisions-meta',
|
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'),
|
template: wp.template('revisions-meta'),
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
|
@ -673,7 +690,9 @@ window.wp = window.wp || {};
|
||||||
},
|
},
|
||||||
|
|
||||||
prepare: function() {
|
prepare: function() {
|
||||||
return this.model.toJSON();
|
return _.extend( this.model.toJSON()[this.type] || {}, {
|
||||||
|
type: this.type
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
restoreRevision: function() {
|
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.
|
// The checkbox view.
|
||||||
revisions.view.Checkbox = wp.Backbone.View.extend({
|
revisions.view.Checkbox = wp.Backbone.View.extend({
|
||||||
className: 'revisions-checkbox',
|
className: 'revisions-checkbox',
|
||||||
|
@ -714,7 +745,7 @@ window.wp = window.wp || {};
|
||||||
// Encapsulates the tooltip.
|
// Encapsulates the tooltip.
|
||||||
revisions.view.Tooltip = wp.Backbone.View.extend({
|
revisions.view.Tooltip = wp.Backbone.View.extend({
|
||||||
className: 'revisions-tooltip',
|
className: 'revisions-tooltip',
|
||||||
template: wp.template('revisions-tooltip'),
|
template: wp.template('revisions-meta'),
|
||||||
|
|
||||||
initialize: function( options ) {
|
initialize: function( options ) {
|
||||||
this.listenTo( this.model, 'change:offset', this.render );
|
this.listenTo( this.model, 'change:offset', this.render );
|
||||||
|
@ -723,7 +754,9 @@ window.wp = window.wp || {};
|
||||||
},
|
},
|
||||||
|
|
||||||
prepare: function() {
|
prepare: function() {
|
||||||
return this.model.get('revision').toJSON();
|
return _.extend( { type: 'tooltip' }, {
|
||||||
|
attributes: this.model.get('revision').toJSON()
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
|
@ -130,31 +130,6 @@ require_once( './admin-header.php' );
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</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">
|
<script id="tmpl-revisions-checkbox" type="text/html">
|
||||||
<div class="revision-toggle-compare-mode">
|
<div class="revision-toggle-compare-mode">
|
||||||
<label>
|
<label>
|
||||||
|
@ -171,65 +146,45 @@ require_once( './admin-header.php' );
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="tmpl-revisions-meta" type="text/html">
|
<script id="tmpl-revisions-meta" type="text/html">
|
||||||
<div class="diff-meta diff-meta-from">
|
<# if ( ! _.isUndefined( data.attributes ) ) { #>
|
||||||
<div class="diff-title">
|
<div class="diff-title">
|
||||||
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
|
<# if ( 'from' === data.type ) { #>
|
||||||
<# if ( 'undefined' !== typeof data.from ) { #>
|
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
|
||||||
<div class="author-card<# if ( data.from.attributes.autosave ) { #> autosave<# } #>">
|
<# } else if ( 'to' === data.type ) { #>
|
||||||
{{{ data.from.attributes.author.avatar }}}
|
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
|
||||||
|
<# } #>
|
||||||
|
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
|
||||||
|
{{{ data.attributes.author.avatar }}}
|
||||||
<div class="author-info">
|
<div class="author-info">
|
||||||
<# if ( data.from.attributes.autosave ) { #>
|
<# if ( data.attributes.autosave ) { #>
|
||||||
<span class="byline"><?php printf( __( 'Autosave by %s' ),
|
<span class="byline"><?php printf( __( 'Autosave by %s' ),
|
||||||
'<span class="author-name">{{ data.from.attributes.author.name }}</span>' ); ?></span>
|
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
|
||||||
<# } else if ( data.from.attributes.current ) { #>
|
<# } else if ( data.attributes.current ) { #>
|
||||||
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
|
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
|
||||||
'<span class="author-name">{{ data.from.attributes.author.name }}</span>' ); ?></span>
|
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
|
||||||
<# } else { #>
|
<# } else { #>
|
||||||
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
||||||
'<span class="author-name">{{ data.from.attributes.author.name }}</span>' ); ?></span>
|
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
|
||||||
<# } #>
|
<# } #>
|
||||||
<span class="time-ago">{{ data.from.attributes.timeAgo }}</span>
|
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
|
||||||
<span class="date">({{ data.from.attributes.dateShort }})</span>
|
<span class="date">({{ data.attributes.dateShort }})</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
|
||||||
<# } #>
|
<input
|
||||||
</div>
|
<# if ( data.attributes.current ) { #>
|
||||||
</div>
|
disabled="disabled"
|
||||||
|
<# } #>
|
||||||
<div class="diff-meta diff-meta-to">
|
<# if ( data.attributes.autosave ) { #>
|
||||||
<div class="diff-title">
|
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
|
||||||
<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-info">
|
|
||||||
<# if ( data.to.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="byline"><?php printf( __( 'Current Revision by %s' ),
|
|
||||||
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
|
|
||||||
<# } else { #>
|
<# } else { #>
|
||||||
<span class="byline"><?php printf( __( 'Revision by %s' ),
|
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
|
||||||
'<span class="author-name">{{ data.to.attributes.author.name }}</span>' ); ?></span>
|
|
||||||
<# } #>
|
<# } #>
|
||||||
<span class="time-ago">{{ data.to.attributes.timeAgo }}</span>
|
|
||||||
<span class="date">({{ data.to.attributes.dateShort }})</span>
|
|
||||||
</div>
|
|
||||||
<# } #>
|
|
||||||
<# if ( data.to.attributes.restoreUrl ) { #>
|
|
||||||
<input
|
|
||||||
<# if ( data.to.attributes.current ) { #>
|
|
||||||
disabled="disabled"
|
|
||||||
<# } #>
|
<# } #>
|
||||||
<# if ( data.to.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>
|
||||||
</div>
|
<# if ( 'tooltip' === data.type ) { #>
|
||||||
|
<div class="revisions-tooltip-arrow"><span></span></div>
|
||||||
|
<# } #>
|
||||||
|
<# } #>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script id="tmpl-revisions-diff" type="text/html">
|
<script id="tmpl-revisions-diff" type="text/html">
|
||||||
|
|
Loading…
Reference in New Issue