Header images: Accessibility and style improvements. Headers no longer jump around when chosen.
props mcsf, ehg. see #21785. Built from https://develop.svn.wordpress.org/trunk@27947 git-svn-id: http://core.svn.wordpress.org/trunk@27777 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5e79b94d81
commit
27c422364c
|
@ -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; right: 0; bottom: 0; left: 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);
|
|
||||||
right: 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;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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;
|
||||||
|
|
|
@ -774,27 +774,28 @@ 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>
|
||||||
|
|
||||||
<# } else { #>
|
<# } else { #>
|
||||||
|
|
||||||
<# if (data.type === 'uploaded') { #>
|
<# if (data.type === 'uploaded') { #>
|
||||||
<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">
|
||||||
|
|
|
@ -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 );
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
!function(a,b){var c=b.customize;c.HeaderTool={},c.HeaderTool.ImageModel=Backbone.Model.extend({defaults:function(){return{header:{attachment_id:0,url:"",timestamp:_.now(),thumbnail_url:""},choice:"",hidden:!1,random:!1}},initialize:function(){this.on("hide",this.hide,this)},hide:function(){this.set("choice",""),c("header_image").set("remove-header"),c("header_image_data").set("remove-header")},destroy:function(){var a=this.get("header"),d=c.HeaderTool.currentHeader.get("header").attachment_id;d&&a.attachment_id===d&&c.HeaderTool.currentHeader.trigger("hide"),b.ajax.post("custom-header-remove",{nonce:_wpCustomizeHeader.nonces.remove,wp_customize:"on",theme:c.settings.theme.stylesheet,attachment_id:a.attachment_id}),this.trigger("destroy",this,this.collection)},save:function(){this.get("random")?(c("header_image").set(this.get("header").random),c("header_image_data").set(this.get("header").random)):this.get("header").defaultName?(c("header_image").set(this.get("header").url),c("header_image_data").set(this.get("header").defaultName)):(c("header_image").set(this.get("header").url),c("header_image_data").set(this.get("header"))),c.HeaderTool.combinedList.trigger("control:setImage",this)},importImage:function(){var a=this.get("header");void 0!==a.attachment_id&&b.ajax.post("custom-header-add",{nonce:_wpCustomizeHeader.nonces.add,wp_customize:"on",theme:c.settings.theme.stylesheet,attachment_id:a.attachment_id})},shouldBeCropped:function(){return this.get("themeFlexWidth")===!0&&this.get("themeFlexHeight")===!0?!1:this.get("themeFlexWidth")===!0&&this.get("themeHeight")===this.get("imageHeight")?!1:this.get("themeFlexHeight")===!0&&this.get("themeWidth")===this.get("imageWidth")?!1:this.get("themeWidth")===this.get("imageWidth")&&this.get("themeHeight")===this.get("imageHeight")?!1:!0}}),c.HeaderTool.ChoiceList=Backbone.Collection.extend({model:c.HeaderTool.ImageModel,comparator:function(a){return-a.get("header").timestamp},initialize:function(){var a=c.HeaderTool.currentHeader.get("choice").replace(/^https?:\/\//,""),b=this.isRandomChoice(c.get().header_image);this.type||(this.type="uploaded"),this.data||(this.data=_wpCustomizeHeader.uploads),b&&(a=c.get().header_image),this.on("control:setImage",this.setImage,this),this.on("control:removeImage",this.removeImage,this),this.on("add",this.maybeAddRandomChoice,this),_.each(this.data,function(b,c){b.attachment_id||(b.defaultName=c),this.add({header:b,choice:b.url.split("/").pop(),hidden:a===b.url.replace(/^https?:\/\//,"")},{silent:!0})},this),this.size()>0&&this.addRandomChoice(a)},maybeAddRandomChoice:function(){1===this.size()&&this.addRandomChoice()},addRandomChoice:function(a){var b=RegExp(this.type).test(a),c="random-"+this.type+"-image";this.add({header:{timestamp:0,random:c,width:245,height:41},choice:c,random:!0,hidden:b})},isRandomChoice:function(a){return/^random-(uploaded|default)-image$/.test(a)},shouldHideTitle:function(){return _.every(this.pluck("hidden"))},setImage:function(a){this.each(function(a){a.set("hidden",!1)}),a&&(a.set("hidden",!0),a.get("random")||(a.get("header").timestamp=_.now(),this.sort()))},removeImage:function(){this.each(function(a){a.set("hidden",!1)})},shown:function(){var a=this.where({hidden:!1});return new c.HeaderTool.ChoiceList(a)}}),c.HeaderTool.DefaultsList=c.HeaderTool.ChoiceList.extend({initialize:function(){this.type="default",this.data=_wpCustomizeHeader.defaults,c.HeaderTool.ChoiceList.prototype.initialize.apply(this)}})}(jQuery,window.wp);
|
!function(a,b){var c=b.customize;c.HeaderTool={},c.HeaderTool.ImageModel=Backbone.Model.extend({defaults:function(){return{header:{attachment_id:0,url:"",timestamp:_.now(),thumbnail_url:""},choice:"",selected:!1,random:!1}},initialize:function(){this.on("hide",this.hide,this)},hide:function(){this.set("choice",""),c("header_image").set("remove-header"),c("header_image_data").set("remove-header")},destroy:function(){var a=this.get("header"),d=c.HeaderTool.currentHeader.get("header").attachment_id;d&&a.attachment_id===d&&c.HeaderTool.currentHeader.trigger("hide"),b.ajax.post("custom-header-remove",{nonce:_wpCustomizeHeader.nonces.remove,wp_customize:"on",theme:c.settings.theme.stylesheet,attachment_id:a.attachment_id}),this.trigger("destroy",this,this.collection)},save:function(){this.get("random")?(c("header_image").set(this.get("header").random),c("header_image_data").set(this.get("header").random)):this.get("header").defaultName?(c("header_image").set(this.get("header").url),c("header_image_data").set(this.get("header").defaultName)):(c("header_image").set(this.get("header").url),c("header_image_data").set(this.get("header"))),c.HeaderTool.combinedList.trigger("control:setImage",this)},importImage:function(){var a=this.get("header");void 0!==a.attachment_id&&b.ajax.post("custom-header-add",{nonce:_wpCustomizeHeader.nonces.add,wp_customize:"on",theme:c.settings.theme.stylesheet,attachment_id:a.attachment_id})},shouldBeCropped:function(){return this.get("themeFlexWidth")===!0&&this.get("themeFlexHeight")===!0?!1:this.get("themeFlexWidth")===!0&&this.get("themeHeight")===this.get("imageHeight")?!1:this.get("themeFlexHeight")===!0&&this.get("themeWidth")===this.get("imageWidth")?!1:this.get("themeWidth")===this.get("imageWidth")&&this.get("themeHeight")===this.get("imageHeight")?!1:!0}}),c.HeaderTool.ChoiceList=Backbone.Collection.extend({model:c.HeaderTool.ImageModel,comparator:function(a){return-a.get("header").timestamp},initialize:function(){var a=c.HeaderTool.currentHeader.get("choice").replace(/^https?:\/\//,""),b=this.isRandomChoice(c.get().header_image);this.type||(this.type="uploaded"),this.data||(this.data=_wpCustomizeHeader.uploads),b&&(a=c.get().header_image),this.on("control:setImage",this.setImage,this),this.on("control:removeImage",this.removeImage,this),this.on("add",this.maybeAddRandomChoice,this),_.each(this.data,function(b,c){b.attachment_id||(b.defaultName=c),"undefined"==typeof b.timestamp&&(b.timestamp=0),this.add({header:b,choice:b.url.split("/").pop(),selected:a===b.url.replace(/^https?:\/\//,"")},{silent:!0})},this),this.size()>0&&this.addRandomChoice(a)},maybeAddRandomChoice:function(){1===this.size()&&this.addRandomChoice()},addRandomChoice:function(a){var b=RegExp(this.type).test(a),c="random-"+this.type+"-image";this.add({header:{timestamp:0,random:c,width:245,height:41},choice:c,random:!0,selected:b})},isRandomChoice:function(a){return/^random-(uploaded|default)-image$/.test(a)},shouldHideTitle:function(){return this.size()<2},setImage:function(a){this.each(function(a){a.set("selected",!1)}),a&&a.set("selected",!0)},removeImage:function(){this.each(function(a){a.set("selected",!1)})}}),c.HeaderTool.DefaultsList=c.HeaderTool.ChoiceList.extend({initialize:function(){this.type="default",this.data=_wpCustomizeHeader.defaults,c.HeaderTool.ChoiceList.prototype.initialize.apply(this)}})}(jQuery,window.wp);
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
!function(a,b,c){if(b&&b.customize){var d=b.customize;d.HeaderTool.CurrentView=b.Backbone.View.extend({template:b.template("header-current"),initialize:function(){this.listenTo(this.model,"change",this.render),this.render()},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.setPlaceholder(),this.setButtons(),this},getHeight:function(){var a,b=this.$el.find("img"),c=this.model.get("savedHeight"),e=b.height()||c;return b.length?this.$el.find(".inner").hide():this.$el.find(".inner").show(),e||(a=d.get().header_image_data,e=a&&a.width&&a.height?260/a.width*a.height:40),e},setPlaceholder:function(a){var b=a||this.getHeight();this.model.set("savedHeight",b),this.$el.add(this.$el.find(".placeholder")).height(b)},setButtons:function(){var b=a(".actions .remove");this.model.get("choice")?b.show():b.hide()}}),function(){var a=0;d.HeaderTool.ChoiceView=b.Backbone.View.extend({template:b.template("header-choice"),className:"header-view",events:{"click .choice,.random":"select","click .close":"removeImage"},initialize:function(){var a=[this.model.get("header").url,this.model.get("choice")];this.listenTo(this.model,"change",this.render),c.contains(a,d.get().header_image)&&d.HeaderTool.currentHeader.set(this.extendedModel())},render:function(){var b=this.model;return this.$el.html(this.template(this.extendedModel())),b.get("random")?this.setPlaceholder(40):a=this.getHeight(),this.$el.toggleClass("hidden",b.get("hidden")),this},extendedModel:function(){var a=this.model.get("collection");return c.extend(this.model.toJSON(),{type:a.type})},getHeight:d.HeaderTool.CurrentView.prototype.getHeight,setPlaceholder:d.HeaderTool.CurrentView.prototype.setPlaceholder,select:function(){this.model.save(),d.HeaderTool.currentHeader.set(this.extendedModel())},removeImage:function(a){a.stopPropagation(),this.model.destroy(),this.remove()}})}(),d.HeaderTool.ChoiceListView=b.Backbone.View.extend({initialize:function(){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.render()},render:function(){this.$el.empty(),this.collection.each(this.addOne,this),this.toggleTitle()},addOne:function(a){var b;a.set({collection:this.collection}),b=new d.HeaderTool.ChoiceView({model:a}),this.$el.append(b.render().el)},toggleTitle:function(){var a=this.$el.parents().prev(".customize-control-title");this.collection.shouldHideTitle()?a.hide():a.show()}}),d.HeaderTool.CombinedList=b.Backbone.View.extend({initialize:function(a){this.collections=a,this.on("all",this.propagate,this)},propagate:function(a,b){c.each(this.collections,function(c){c.trigger(a,b)})}})}}(jQuery,window.wp,_);
|
!function(a,b,c){if(b&&b.customize){var d=b.customize;d.HeaderTool.CurrentView=b.Backbone.View.extend({template:b.template("header-current"),initialize:function(){this.listenTo(this.model,"change",this.render),this.render()},render:function(){return this.$el.html(this.template(this.model.toJSON())),this.setPlaceholder(),this.setButtons(),this},getHeight:function(){var a,b,c,e=this.$el.find("img");return e.length?(this.$el.find(".inner").hide(),a=this.model.get("savedHeight"),b=e.height()||a,b||(c=d.get().header_image_data,b=c&&c.width&&c.height?260/c.width*c.height:40),b):(this.$el.find(".inner").show(),40)},setPlaceholder:function(a){var b=a||this.getHeight();this.model.set("savedHeight",b),this.$el.add(this.$el.find(".placeholder")).height(b)},setButtons:function(){var b=a(".actions .remove");this.model.get("choice")?b.show():b.hide()}}),d.HeaderTool.ChoiceView=b.Backbone.View.extend({template:b.template("header-choice"),className:"header-view",events:{"click .choice,.random":"select","click .close":"removeImage"},initialize:function(){var a=[this.model.get("header").url,this.model.get("choice")];this.listenTo(this.model,"change:selected",this.toggleSelected),c.contains(a,d.get().header_image)&&d.HeaderTool.currentHeader.set(this.extendedModel())},render:function(){return this.$el.html(this.template(this.extendedModel())),this.model.get("random")&&(this.$el.addClass("button display-options"),this.setPlaceholder(40)),this.toggleSelected(),this},toggleSelected:function(){this.$el.toggleClass("selected",this.model.get("selected"))},extendedModel:function(){var a=this.model.get("collection");return c.extend(this.model.toJSON(),{type:a.type})},getHeight:d.HeaderTool.CurrentView.prototype.getHeight,setPlaceholder:d.HeaderTool.CurrentView.prototype.setPlaceholder,select:function(){this.preventJump(),this.model.save(),d.HeaderTool.currentHeader.set(this.extendedModel())},preventJump:function(){var b=a(".wp-full-overlay-sidebar-content"),d=b.scrollTop();c.defer(function(){b.scrollTop(d)})},removeImage:function(a){a.stopPropagation(),this.model.destroy(),this.remove()}}),d.HeaderTool.ChoiceListView=b.Backbone.View.extend({initialize:function(){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",this.toggleList),this.render()},render:function(){this.$el.empty(),this.collection.each(this.addOne,this),this.toggleList()},addOne:function(a){var b;a.set({collection:this.collection}),b=new d.HeaderTool.ChoiceView({model:a}),this.$el.append(b.render().el)},toggleList:function(){var a=this.$el.parents().prev(".customize-control-title"),b=this.$el.find(".random").parent();this.collection.shouldHideTitle()?a.add(b).hide():a.add(b).show()}}),d.HeaderTool.CombinedList=b.Backbone.View.extend({initialize:function(a){this.collections=a,this.on("all",this.propagate,this)},propagate:function(a,b){c.each(this.collections,function(c){c.trigger(a,b)})}})}}(jQuery,window.wp,_);
|
Loading…
Reference in New Issue