Header images: Accessibility and style improvements. Headers no longer jump around when chosen.

props mcsf, ehg.
see #21785.


git-svn-id: https://develop.svn.wordpress.org/trunk@27947 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2014-04-04 15:48:34 +00:00
parent 96e15acb2e
commit 6ec7a5a52b
5 changed files with 114 additions and 71 deletions

View File

@ -465,18 +465,34 @@ body {
margin-bottom: 18px; margin-bottom: 18px;
} }
#customize-control-header_image .uploaded button,
#customize-control-header_image .default button {
width: 100%;
padding: 0;
margin: 0;
background: none;
border: none;
color: inherit;
cursor: pointer;
outline: none;
}
#customize-control-header_image button img {
display: block;
}
/* Header control: current image container */ /* Header control: current image container */
#customize-control-header_image .current .container { #customize-control-header_image .current .container {
overflow: hidden; overflow: hidden;
-webkit-border-radius: 2px; -webkit-border-radius: 2px;
border: 1px solid #eee;
border-radius: 2px; border-radius: 2px;
} }
#customize-control-header_image .placeholder { #customize-control-header_image .placeholder {
width: 100%; width: 100%;
position: relative; position: relative;
background: #262626;
text-align: center; text-align: center;
cursor: default; cursor: default;
} }
@ -485,18 +501,49 @@ body {
display: none; display: none;
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 18px; color: #555;
margin-top: -9px; white-space: nowrap;
top: 50%; text-overflow: ellipsis;
color: #eee; overflow: hidden;
} }
/* Header control: overlay "close" button */ #customize-control-header_image .inner,
#customize-control-header_image .inner .dashicons {
line-height: 20px;
top: 10px;
}
#customize-control-header_image .list .inner,
#customize-control-header_image .list .inner .dashicons {
top: 9px;
}
#customize-control-header_image .header-view { #customize-control-header_image .header-view {
position: relative; position: relative;
width: 100%;
margin-bottom: 5px;
} }
#customize-control-header_image .header-view:last-child {
margin-bottom: 0px;
}
/* Convoluted, but 'outline' support isn't good enough yet */
#customize-control-header_image .header-view:after {
border: 0;
}
#customize-control-header_image .header-view.selected:after {
content: '';
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
border: 4px solid #2ea2cc;
border-radius: 2px;
}
#customize-control-header_image .header-view.button.selected {
border: 0;
}
/* Header control: overlay "close" button */
#customize-control-header_image .uploaded .header-view .close { #customize-control-header_image .uploaded .header-view .close {
font-size: 2em; font-size: 2em;
color: grey; color: grey;
@ -575,21 +622,10 @@ body {
margin-bottom: 9px; margin-bottom: 9px;
} }
#customize-control-header_image .choice.random:before {
position: absolute;
content: attr(data-label);
left: 0;
top: 0;
}
#customize-control-header_image .uploaded div:last-child > .choice { #customize-control-header_image .uploaded div:last-child > .choice {
margin-bottom: 0; margin-bottom: 0;
} }
#customize-control-header_image .choices hr {
visibility: hidden;
}
#customize-control-header_image img { #customize-control-header_image img {
width: 100%; width: 100%;
-webkit-border-radius: 2px; -webkit-border-radius: 2px;

View File

@ -1272,9 +1272,12 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
public function get_uploaded_header_images() { public function get_uploaded_header_images() {
$header_images = get_uploaded_header_images(); $header_images = get_uploaded_header_images();
$timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); $timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
$alt_text_key = '_wp_attachment_image_alt';
foreach ( $header_images as &$header_image ) { foreach ( $header_images as &$header_image ) {
$header_image['timestamp'] = get_post_meta( $header_image['attachment_id'], $timestamp_key, true ); $header_meta = get_post_meta( $header_image['attachment_id'] );
$header_image['timestamp'] = isset( $header_meta[ $timestamp_key ] ) ? $header_meta[ $timestamp_key ] : '';
$header_image['alt_text'] = isset( $header_meta[ $alt_text_key ] ) ? $header_meta[ $alt_text_key ] : '';
} }
return $header_images; return $header_images;

View File

@ -774,13 +774,13 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
<div class="placeholder random"> <div class="placeholder random">
<div class="inner"> <div class="inner">
<span><span class="dashicons dashicons-randomize dice"></span> <button type="button"><span class="dashicons dashicons-randomize dice"></span>
<# if ( data.type === 'uploaded' ) { #> <# if ( data.type === 'uploaded' ) { #>
<?php _e( 'Randomize uploaded headers' ); ?> <?php _e( 'Randomize uploaded headers' ); ?>
<# } else if ( data.type === 'default' ) { #> <# } else if ( data.type === 'default' ) { #>
<?php _e( 'Randomize suggested headers' ); ?> <?php _e( 'Randomize suggested headers' ); ?>
<# } #> <# } #>
</span> </button>
</div> </div>
</div> </div>
@ -790,11 +790,12 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
<div class="dashicons dashicons-no close"></div> <div class="dashicons dashicons-no close"></div>
<# } #> <# } #>
<a href="#" class="choice thumbnail #>" <button type="button" class="choice thumbnail"
data-customize-image-value="{{{data.header.url}}}" data-customize-image-value="{{{data.header.url}}}"
data-customize-header-image-data="{{JSON.stringify(data.header)}}"> data-customize-header-image-data="{{JSON.stringify(data.header)}}">
<img src="{{{data.header.thumbnail_url}}}"> <span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
</a> <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
</button>
<# } #> <# } #>
</script> </script>
@ -803,7 +804,7 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
<# if (data.choice) { #> <# if (data.choice) { #>
<# if (data.random) { #> <# if (data.random) { #>
<div class="placeholder"> <div class="placeholder" tabindex="0">
<div class="inner"> <div class="inner">
<span><span class="dashicons dashicons-randomize dice"></span> <span><span class="dashicons dashicons-randomize dice"></span>
<# if ( data.type === 'uploaded' ) { #> <# if ( data.type === 'uploaded' ) { #>
@ -817,12 +818,12 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
<# } else { #> <# } else { #>
<img src="{{{data.header.thumbnail_url}}}" /> <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" tabindex="0"/>
<# } #> <# } #>
<# } else { #> <# } else { #>
<div class="placeholder"> <div class="placeholder" tabindex="0">
<div class="inner"> <div class="inner">
<span> <span>
<?php _e( 'No image set' ); ?> <?php _e( 'No image set' ); ?>
@ -853,7 +854,7 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
<div class="customize-control-content"> <div class="customize-control-content">
<p class="customizer-section-intro"> <p class="customizer-section-intro" tabindex="0">
<?php <?php
// @todo translate (and look to custom-header.php for inspiration) // @todo translate (and look to custom-header.php for inspiration)
echo ( 'Personalize your site with your own header image.' ) . ' '; echo ( 'Personalize your site with your own header image.' ) . ' ';
@ -867,7 +868,7 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
?> ?>
</p> </p>
<div class="current"> <div class="current">
<span class="customize-control-title"> <span class="customize-control-title" tabindex="0">
<?php _e( 'Current header' ); ?> <?php _e( 'Current header' ); ?>
</span> </span>
<div class="container"> <div class="container">
@ -875,20 +876,20 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
</div> </div>
<div class="actions"> <div class="actions">
<?php /* translators: Hide as in hide header image via the Customizer */ ?> <?php /* translators: Hide as in hide header image via the Customizer */ ?>
<a href="#" <?php echo $visibility ?> class="button remove"><?php _ex( 'Hide', 'custom header' ); ?></a> <button type="button"<?php echo $visibility ?> class="button remove"><?php _ex( 'Hide image', 'custom header' ); ?></button>
<?php /* translators: New as in add new header image via the Customizer */ ?> <?php /* translators: New as in add new header image via the Customizer */ ?>
<a href="#" class="button new"><?php _ex( 'Add new', 'header image' ); ?></a> <button type="button" class="button new"><?php _ex( 'Add new image', 'header image' ); ?></button>
<div style="clear:both"></div> <div style="clear:both"></div>
</div> </div>
<div class="choices"> <div class="choices">
<span class="customize-control-title header-previously-uploaded"> <span class="customize-control-title header-previously-uploaded" tabindex="0">
<?php _ex( 'Previously uploaded', 'custom headers' ); ?> <?php _ex( 'Previously uploaded', 'custom headers' ); ?>
</span> </span>
<div class="uploaded"> <div class="uploaded">
<div class="list"> <div class="list">
</div> </div>
</div> </div>
<span class="customize-control-title header-default"> <span class="customize-control-title header-default" tabindex="0">
<?php _ex( 'Suggested', 'custom headers' ); ?> <?php _ex( 'Suggested', 'custom headers' ); ?>
</span> </span>
<div class="default"> <div class="default">

View File

@ -26,7 +26,7 @@
thumbnail_url: '' thumbnail_url: ''
}, },
choice: '', choice: '',
hidden: false, selected: false,
random: false random: false
}; };
}, },
@ -160,10 +160,14 @@
elt.defaultName = index; elt.defaultName = index;
} }
if (typeof elt.timestamp === 'undefined') {
elt.timestamp = 0;
}
this.add({ this.add({
header: elt, header: elt,
choice: elt.url.split('/').pop(), choice: elt.url.split('/').pop(),
hidden: current === elt.url.replace(/^https?:\/\//, '') selected: current === elt.url.replace(/^https?:\/\//, '')
}, { silent: true }); }, { silent: true });
}, this); }, this);
@ -191,7 +195,7 @@
}, },
choice: randomChoice, choice: randomChoice,
random: true, random: true,
hidden: isRandomSameType selected: isRandomSameType
}); });
}, },
@ -200,33 +204,23 @@
}, },
shouldHideTitle: function() { shouldHideTitle: function() {
return _.every(this.pluck('hidden')); return this.size() < 2;
}, },
setImage: function(model) { setImage: function(model) {
this.each(function(m) { this.each(function(m) {
m.set('hidden', false); m.set('selected', false);
}); });
if (model) { if (model) {
model.set('hidden', true); model.set('selected', true);
// Bump images to top except for special "Randomize" images
if (!model.get('random')) {
model.get('header').timestamp = _.now();
this.sort();
}
} }
}, },
removeImage: function() { removeImage: function() {
this.each(function(m) { this.each(function(m) {
m.set('hidden', false); m.set('selected', false);
}); });
},
shown: function() {
var filtered = this.where({ hidden: false });
return new api.HeaderTool.ChoiceList( filtered );
} }
}); });

View File

@ -32,16 +32,18 @@
getHeight: function() { getHeight: function() {
var image = this.$el.find('img'), var image = this.$el.find('img'),
saved = this.model.get('savedHeight'), saved, height, headerImageData;
height = image.height() || saved,
headerImageData;
if (image.length) { if (image.length) {
this.$el.find('.inner').hide(); this.$el.find('.inner').hide();
} else { } else {
this.$el.find('.inner').show(); this.$el.find('.inner').show();
return 40;
} }
saved = this.model.get('savedHeight');
height = image.height() || saved;
// happens at ready // happens at ready
if (!height) { if (!height) {
headerImageData = api.get().header_image_data; headerImageData = api.get().header_image_data;
@ -92,8 +94,6 @@
* @constructor * @constructor
* @augments wp.Backbone.View * @augments wp.Backbone.View
*/ */
(function () { // closures FTW
var lastHeight = 0;
api.HeaderTool.ChoiceView = wp.Backbone.View.extend({ api.HeaderTool.ChoiceView = wp.Backbone.View.extend({
template: wp.template('header-choice'), template: wp.template('header-choice'),
@ -110,7 +110,7 @@
this.model.get('choice') this.model.get('choice')
]; ];
this.listenTo(this.model, 'change', this.render); this.listenTo(this.model, 'change:selected', this.toggleSelected);
if (_.contains(properties, api.get().header_image)) { if (_.contains(properties, api.get().header_image)) {
api.HeaderTool.currentHeader.set(this.extendedModel()); api.HeaderTool.currentHeader.set(this.extendedModel());
@ -118,21 +118,21 @@
}, },
render: function() { render: function() {
var model = this.model;
this.$el.html(this.template(this.extendedModel())); this.$el.html(this.template(this.extendedModel()));
if (model.get('random')) { if (this.model.get('random')) {
this.$el.addClass('button display-options');
this.setPlaceholder(40); this.setPlaceholder(40);
} }
else {
lastHeight = this.getHeight();
}
this.$el.toggleClass('hidden', model.get('hidden')); this.toggleSelected();
return this; return this;
}, },
toggleSelected: function() {
this.$el.toggleClass('selected', this.model.get('selected'));
},
extendedModel: function() { extendedModel: function() {
var c = this.model.get('collection'); var c = this.model.get('collection');
return _.extend(this.model.toJSON(), { return _.extend(this.model.toJSON(), {
@ -145,17 +145,26 @@
setPlaceholder: api.HeaderTool.CurrentView.prototype.setPlaceholder, setPlaceholder: api.HeaderTool.CurrentView.prototype.setPlaceholder,
select: function() { select: function() {
this.preventJump();
this.model.save(); this.model.save();
api.HeaderTool.currentHeader.set(this.extendedModel()); api.HeaderTool.currentHeader.set(this.extendedModel());
}, },
preventJump: function() {
var container = $('.wp-full-overlay-sidebar-content'),
scroll = container.scrollTop();
_.defer(function() {
container.scrollTop(scroll);
});
},
removeImage: function(e) { removeImage: function(e) {
e.stopPropagation(); e.stopPropagation();
this.model.destroy(); this.model.destroy();
this.remove(); this.remove();
} }
}); });
})();
/** /**
@ -174,15 +183,14 @@
this.listenTo(this.collection, 'add', this.addOne); this.listenTo(this.collection, 'add', this.addOne);
this.listenTo(this.collection, 'remove', this.render); this.listenTo(this.collection, 'remove', this.render);
this.listenTo(this.collection, 'sort', this.render); this.listenTo(this.collection, 'sort', this.render);
this.listenTo(this.collection, 'change:hidden', this.toggleTitle); this.listenTo(this.collection, 'change', this.toggleList);
this.listenTo(this.collection, 'change:hidden', this.setMaxListHeight);
this.render(); this.render();
}, },
render: function() { render: function() {
this.$el.empty(); this.$el.empty();
this.collection.each(this.addOne, this); this.collection.each(this.addOne, this);
this.toggleTitle(); this.toggleList();
}, },
addOne: function(choice) { addOne: function(choice) {
@ -192,12 +200,13 @@
this.$el.append(view.render().el); this.$el.append(view.render().el);
}, },
toggleTitle: function() { toggleList: function() {
var title = this.$el.parents().prev('.customize-control-title'); var title = this.$el.parents().prev('.customize-control-title'),
randomButton = this.$el.find('.random').parent();
if (this.collection.shouldHideTitle()) { if (this.collection.shouldHideTitle()) {
title.hide(); title.add(randomButton).hide();
} else { } else {
title.show(); title.add(randomButton).show();
} }
} }
}); });