Merge branch 'feature/499' of https://github.com/tainacan/tainacan into feature/499

This commit is contained in:
vnmedeiros 2021-04-05 15:12:09 -03:00
commit 1b57727bda
2 changed files with 13 additions and 9 deletions

View File

@ -409,14 +409,18 @@ function tainacan_get_the_media_component(
<?php endif; ?>
</div>
<?php
<?php if ( isset( $_REQUEST['wp_customize'] ) ) : ?>
<script>
tainacan_plugin.tainacan_media_components = (typeof tainacan_plugin != undefined && typeof tainacan_plugin.tainacan_media_components != "undefined") ? tainacan_plugin.tainacan_media_components : {};
tainacan_plugin.tainacan_media_components['<?php echo $args['media_id'] ?>'] = <?php echo json_encode($args) ?>;
</script>
<?php else :
wp_add_inline_script( 'tainacan-media-component', '
tainacan_plugin.tainacan_media_components = (typeof tainacan_plugin != undefined && typeof tainacan_plugin.tainacan_media_components != "undefined") ? tainacan_plugin.tainacan_media_components : [];
tainacan_plugin.tainacan_media_components.push('. json_encode($args) . ');
', 'before' );
?>
tainacan_plugin.tainacan_media_components = (typeof tainacan_plugin != undefined && typeof tainacan_plugin.tainacan_media_components != "undefined") ? tainacan_plugin.tainacan_media_components : {};
tainacan_plugin.tainacan_media_components["' . $args['media_id'] . '"] = '. json_encode($args) . ';
', 'before' );
endif; ?>
<?php endif; ?> <!-- End of if ($args['has_media_main'] || $args['has_media_thumbs'] ) -->
<?php

View File

@ -364,8 +364,8 @@ tainacan_plugin.classes.TainacanMediaGallery = class TainacanMediaGallery {
/* Loads and instantiates media components passed to the global variable */
document.addEventListener('DOMContentLoaded', function() {
if (tainacan_plugin?.classes?.TainacanMediaGallery) {
(tainacan_plugin?.tainacan_media_components || []).forEach((component) => {
if (tainacan_plugin?.classes?.TainacanMediaGallery && tainacan_plugin?.tainacan_media_components) {
(Object.values(tainacan_plugin.tainacan_media_components) || []).forEach((component) => {
new tainacan_plugin.classes.TainacanMediaGallery(
component.has_media_thumbs ? '#' + component.media_thumbs_id : null,
component.has_media_main ? '#' + component.media_main_id : null,