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;
}
#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 */
#customize-control-header_image .current .container {
overflow: hidden;
-webkit-border-radius: 2px;
border: 1px solid #eee;
border-radius: 2px;
}
#customize-control-header_image .placeholder {
width: 100%;
position: relative;
background: #262626;
text-align: center;
cursor: default;
}
@ -485,18 +501,49 @@ body {
display: none;
position: absolute;
width: 100%;
height: 18px;
margin-top: -9px;
top: 50%;
color: #eee;
color: #555;
white-space: nowrap;
text-overflow: ellipsis;
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 {
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 {
font-size: 2em;
color: grey;
@ -575,21 +622,10 @@ body {
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 {
margin-bottom: 0;
}
#customize-control-header_image .choices hr {
visibility: hidden;
}
#customize-control-header_image img {
width: 100%;
-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() {
$header_images = get_uploaded_header_images();
$timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
$alt_text_key = '_wp_attachment_image_alt';
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;

View File

@ -774,13 +774,13 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
<div class="placeholder random">
<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' ) { #>
<?php _e( 'Randomize uploaded headers' ); ?>
<# } else if ( data.type === 'default' ) { #>
<?php _e( 'Randomize suggested headers' ); ?>
<# } #>
</span>
</button>
</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>
<# } #>
<a href="#" class="choice thumbnail #>"
<button type="button" class="choice thumbnail"
data-customize-image-value="{{{data.header.url}}}"
data-customize-header-image-data="{{JSON.stringify(data.header)}}">
<img src="{{{data.header.thumbnail_url}}}">
</a>
<span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
</button>
<# } #>
</script>
@ -803,7 +804,7 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
<# if (data.choice) { #>
<# if (data.random) { #>
<div class="placeholder">
<div class="placeholder" tabindex="0">
<div class="inner">
<span><span class="dashicons dashicons-randomize dice"></span>
<# if ( data.type === 'uploaded' ) { #>
@ -817,12 +818,12 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
<# } else { #>
<img src="{{{data.header.thumbnail_url}}}" />
<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" tabindex="0"/>
<# } #>
<# } else { #>
<div class="placeholder">
<div class="placeholder" tabindex="0">
<div class="inner">
<span>
<?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">
<p class="customizer-section-intro">
<p class="customizer-section-intro" tabindex="0">
<?php
// @todo translate (and look to custom-header.php for inspiration)
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>
<div class="current">
<span class="customize-control-title">
<span class="customize-control-title" tabindex="0">
<?php _e( 'Current header' ); ?>
</span>
<div class="container">
@ -875,20 +876,20 @@ final class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control
</div>
<div class="actions">
<?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 */ ?>
<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>
<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' ); ?>
</span>
<div class="uploaded">
<div class="list">
</div>
</div>
<span class="customize-control-title header-default">
<span class="customize-control-title header-default" tabindex="0">
<?php _ex( 'Suggested', 'custom headers' ); ?>
</span>
<div class="default">

View File

@ -26,7 +26,7 @@
thumbnail_url: ''
},
choice: '',
hidden: false,
selected: false,
random: false
};
},
@ -160,10 +160,14 @@
elt.defaultName = index;
}
if (typeof elt.timestamp === 'undefined') {
elt.timestamp = 0;
}
this.add({
header: elt,
choice: elt.url.split('/').pop(),
hidden: current === elt.url.replace(/^https?:\/\//, '')
selected: current === elt.url.replace(/^https?:\/\//, '')
}, { silent: true });
}, this);
@ -191,7 +195,7 @@
},
choice: randomChoice,
random: true,
hidden: isRandomSameType
selected: isRandomSameType
});
},
@ -200,33 +204,23 @@
},
shouldHideTitle: function() {
return _.every(this.pluck('hidden'));
return this.size() < 2;
},
setImage: function(model) {
this.each(function(m) {
m.set('hidden', false);
m.set('selected', false);
});
if (model) {
model.set('hidden', true);
// Bump images to top except for special "Randomize" images
if (!model.get('random')) {
model.get('header').timestamp = _.now();
this.sort();
}
model.set('selected', true);
}
},
removeImage: function() {
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() {
var image = this.$el.find('img'),
saved = this.model.get('savedHeight'),
height = image.height() || saved,
headerImageData;
saved, height, headerImageData;
if (image.length) {
this.$el.find('.inner').hide();
} else {
this.$el.find('.inner').show();
return 40;
}
saved = this.model.get('savedHeight');
height = image.height() || saved;
// happens at ready
if (!height) {
headerImageData = api.get().header_image_data;
@ -92,8 +94,6 @@
* @constructor
* @augments wp.Backbone.View
*/
(function () { // closures FTW
var lastHeight = 0;
api.HeaderTool.ChoiceView = wp.Backbone.View.extend({
template: wp.template('header-choice'),
@ -110,7 +110,7 @@
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)) {
api.HeaderTool.currentHeader.set(this.extendedModel());
@ -118,21 +118,21 @@
},
render: function() {
var model = this.model;
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);
}
else {
lastHeight = this.getHeight();
}
this.$el.toggleClass('hidden', model.get('hidden'));
this.toggleSelected();
return this;
},
toggleSelected: function() {
this.$el.toggleClass('selected', this.model.get('selected'));
},
extendedModel: function() {
var c = this.model.get('collection');
return _.extend(this.model.toJSON(), {
@ -145,17 +145,26 @@
setPlaceholder: api.HeaderTool.CurrentView.prototype.setPlaceholder,
select: function() {
this.preventJump();
this.model.save();
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) {
e.stopPropagation();
this.model.destroy();
this.remove();
}
});
})();
/**
@ -174,15 +183,14 @@
this.listenTo(this.collection, 'add', this.addOne);
this.listenTo(this.collection, 'remove', this.render);
this.listenTo(this.collection, 'sort', this.render);
this.listenTo(this.collection, 'change:hidden', this.toggleTitle);
this.listenTo(this.collection, 'change:hidden', this.setMaxListHeight);
this.listenTo(this.collection, 'change', this.toggleList);
this.render();
},
render: function() {
this.$el.empty();
this.collection.each(this.addOne, this);
this.toggleTitle();
this.toggleList();
},
addOne: function(choice) {
@ -192,12 +200,13 @@
this.$el.append(view.render().el);
},
toggleTitle: function() {
var title = this.$el.parents().prev('.customize-control-title');
toggleList: function() {
var title = this.$el.parents().prev('.customize-control-title'),
randomButton = this.$el.find('.random').parent();
if (this.collection.shouldHideTitle()) {
title.hide();
title.add(randomButton).hide();
} else {
title.show();
title.add(randomButton).show();
}
}
});