Skip to content

Commit 1f94ba8

Browse files
render scripts once all charts have been collected
1 parent e1dddd8 commit 1f94ba8

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

classes/Visualizer/Module/Frontend.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -283,32 +283,6 @@ public function renderChart( $atts ) {
283283
'library' => $library,
284284
);
285285

286-
wp_register_script(
287-
"visualizer-render-$library",
288-
VISUALIZER_ABSURL . 'js/render-facade.js',
289-
apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
290-
Visualizer_Plugin::VERSION,
291-
true
292-
);
293-
294-
wp_enqueue_script( "visualizer-render-$library" );
295-
wp_localize_script(
296-
"visualizer-render-$library",
297-
'visualizer',
298-
array(
299-
'charts' => $this->_charts,
300-
'language' => $this->get_language(),
301-
'map_api_key' => get_option( 'visualizer-map-api-key' ),
302-
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
303-
'i10n' => array(
304-
'copied' => __( 'Copied!', 'visualizer' ),
305-
),
306-
'page_type' => 'frontend',
307-
'is_front' => true,
308-
)
309-
);
310-
wp_enqueue_style( 'visualizer-front' );
311-
312286
$actions_div = '';
313287
$actions_visible = apply_filters( 'visualizer_pro_add_actions', isset( $settings['actions'] ) ? $settings['actions'] : array(), $atts['id'] );
314288
if ( ! empty( $actions_visible ) ) {
@@ -340,6 +314,35 @@ public function renderChart( $atts ) {
340314

341315
$actions_div .= $css;
342316

317+
foreach ( $this->_charts as $id => $attributes ) {
318+
$library = $attributes['library'];
319+
wp_register_script(
320+
"visualizer-render-$library",
321+
VISUALIZER_ABSURL . 'js/render-facade.js',
322+
apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
323+
Visualizer_Plugin::VERSION,
324+
true
325+
);
326+
327+
wp_enqueue_script( "visualizer-render-$library" );
328+
wp_localize_script(
329+
"visualizer-render-$library",
330+
'visualizer',
331+
array(
332+
'charts' => $this->_charts,
333+
'language' => $this->get_language(),
334+
'map_api_key' => get_option( 'visualizer-map-api-key' ),
335+
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
336+
'i10n' => array(
337+
'copied' => __( 'Copied!', 'visualizer' ),
338+
),
339+
'page_type' => 'frontend',
340+
'is_front' => true,
341+
)
342+
);
343+
wp_enqueue_style( 'visualizer-front' );
344+
}
345+
343346
// return placeholder div
344347
return $actions_div . '<div id="' . $id . '"' . $class . '></div>';
345348
}

0 commit comments

Comments
 (0)