Skip to content

Commit

Permalink
Merge pull request #212 from linchpin/issue/208
Browse files Browse the repository at this point in the history
#208 Adjust javascript functionality for saving block background and …
  • Loading branch information
aaronware committed May 7, 2018
2 parents e1d1c3e + 63789a6 commit 0770d4f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 48 deletions.
49 changes: 26 additions & 23 deletions assets/js/admin-mesh-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,34 +470,37 @@ mesh.blocks = function ($) {
admin.media_frames[frame_id].open();
},

/**
* Remove selected background from our block
*
* @since 0.3.6
*
* @param event

/**
* Remove selected background from our block
*
* @since 0.3.6
*
* @param event
*/
remove_background: function (event) {
remove_background : function ( event ) {

event.preventDefault();
event.stopPropagation();
event.preventDefault();
event.stopPropagation();

var $button = $(this);

if ($button.prev().hasClass('right') && !$button.prev().hasClass('button')) {
if (!$button.parents('.block-background-container')) {
$button.prev().toggleClass('button right');
} else {
$button.prev().toggleClass('right').attr('data-mesh-block-featured-image', '');
}
}

$button.siblings('input[type="hidden"]').val('');

$button.prev().text(mesh_data.strings.add_image);
$button.remove();

var $button = $(this),
$section = $button.parents('.block'),
section_id = parseInt($section.attr('data-mesh-block-id'));

$.post(ajaxurl, {
'action': 'mesh_update_featured_image',
'mesh_section_id': parseInt(section_id),
'mesh_featured_image_nonce': mesh_data.featured_image_nonce
}, function (response) {
if (response != -1) {
$button.prev().text(mesh_data.strings.add_image);
$button.remove();
}
});
},


show_field: function (event) {
event.preventDefault();
event.stopPropagation();
Expand Down
47 changes: 25 additions & 22 deletions assets/js/admin-mesh.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/js/admin-mesh.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/admin-mesh.min.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion class.mesh.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ function save_post( $post_id, $post ) {
update_post_meta( $section->ID, '_mesh_section_id', $mesh_section_id );
}

// Save Featured Image
// Save Featured Image
$featured_image = $section_data['featured_image'];

if ( empty( $featured_image ) ) {
Expand Down Expand Up @@ -654,6 +654,15 @@ function save_post( $post_id, $post ) {
} else {
update_post_meta( $block_id, '_mesh_css_class', $sanitized_css_classes );
}

// Save Featured Image
$featured_image = $block_data['featured_image'];

if ( empty( $featured_image ) ) {
delete_post_meta( $block_id, '_thumbnail_id' );
} else {
update_post_meta( $block_id, '_thumbnail_id', (int) $featured_image );
}
}
}

Expand Down

0 comments on commit 0770d4f

Please sign in to comment.