Skip to content

Commit

Permalink
fixes #1469
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Jul 17, 2017
1 parent 1f695fe commit 24dc746
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions controls/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ wp.customize.controlConstructor['kirki-image'] = wp.customize.Control.extend({

initKirkiControl: function() {

var control = this,
value = control.getValue(),
saveAs = ( ! _.isUndefined( control.params.choices ) && ! _.isUndefined( control.params.choices.save_as ) ) ? control.params.choices.save_as : 'url',
preview = control.container.find( '.placeholder, .thumbnail' ),
previewImage = ( 'array' === saveAs ) ? value.url : value;
var control = this,
value = control.getValue(),
saveAs = ( ! _.isUndefined( control.params.choices ) && ! _.isUndefined( control.params.choices.save_as ) ) ? control.params.choices.save_as : 'url',
preview = control.container.find( '.placeholder, .thumbnail' ),
previewImage = ( 'array' === saveAs ) ? value.url : value,
removeButton = control.container.find( '.image-upload-remove-button' ),
defaultButton = control.container.find( '.image-default-button' );

control.container.find( '.kirki-controls-loading-spinner' ).hide();

Expand All @@ -30,6 +32,11 @@ wp.customize.controlConstructor['kirki-image'] = wp.customize.Control.extend({
control.container.find( 'image-default-button' ).hide();
}

// If value is empty, hide the "remove" button.
if ( ( 'url' === saveAs && '' === value ) || ( 'array' === saveAs && ( _.isUndefined( value.url ) || '' === value.url ) ) ) {
removeButton.hide();
}

// If value is default, hide the default button.
if ( value === control.params['default'] ) {
control.container.find( 'image-default-button' ).hide();
Expand All @@ -44,9 +51,7 @@ wp.customize.controlConstructor['kirki-image'] = wp.customize.Control.extend({

// This will return the selected image from the Media Uploader, the result is an object.
var uploadedImage = image.state().get( 'selection' ).first(),
previewImage = uploadedImage.toJSON().sizes.full.url,
removeButton,
defaultButton;
previewImage = uploadedImage.toJSON().sizes.full.url;

if ( ! _.isUndefined( uploadedImage.toJSON().sizes.medium ) ) {
previewImage = uploadedImage.toJSON().sizes.medium.url;
Expand All @@ -65,9 +70,6 @@ wp.customize.controlConstructor['kirki-image'] = wp.customize.Control.extend({
control.saveValue( 'url', uploadedImage.toJSON().sizes.full.url );
}

removeButton = control.container.find( '.image-upload-remove-button' );
defaultButton = control.container.find( '.image-default-button' );

if ( preview.length ) {
preview.removeClass().addClass( 'thumbnail thumbnail-image' ).html( '<img src="' + previewImage + '" alt="" />' );
}
Expand Down

0 comments on commit 24dc746

Please sign in to comment.