Enqueues script in a different strategy when incustomizer #499
This commit is contained in:
parent
4ada32dd9a
commit
d41a049e29
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue