Skip to content

Commit 2f4d1af

Browse files
Improve script loader #851
1 parent 4df64b4 commit 2f4d1af

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

classes/Visualizer/Module/Frontend.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -399,22 +399,29 @@ public function renderChart( $atts ) {
399399

400400
$actions_div .= $css;
401401

402+
$_charts = array();
403+
$_charts_type = '';
402404
foreach ( $this->_charts as $id => $array ) {
405+
$_charts = $this->_charts;
403406
$library = $array['library'];
404-
wp_register_script(
405-
"visualizer-render-$library",
406-
VISUALIZER_ABSURL . 'js/render-facade.js',
407-
apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
408-
Visualizer_Plugin::VERSION,
409-
true
410-
);
411-
412-
wp_enqueue_script( "visualizer-render-$library" );
407+
$_charts_type = $library;
408+
if ( ! wp_script_is( "visualizer-render-$library", 'registered' ) ) {
409+
wp_register_script(
410+
"visualizer-render-$library",
411+
VISUALIZER_ABSURL . 'js/render-facade.js',
412+
apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
413+
Visualizer_Plugin::VERSION,
414+
true
415+
);
416+
wp_enqueue_script( "visualizer-render-$library" );
417+
}
418+
}
419+
if ( wp_script_is( "visualizer-render-$_charts_type" ) ) {
413420
wp_localize_script(
414-
"visualizer-render-$library",
421+
"visualizer-render-$_charts_type",
415422
'visualizer',
416423
array(
417-
'charts' => $this->_charts,
424+
'charts' => $_charts,
418425
'language' => $this->get_language(),
419426
'map_api_key' => get_option( 'visualizer-map-api-key' ),
420427
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
@@ -426,8 +433,8 @@ public function renderChart( $atts ) {
426433
'is_front' => true,
427434
)
428435
);
429-
wp_enqueue_style( 'visualizer-front' );
430436
}
437+
wp_enqueue_style( 'visualizer-front' );
431438

432439
// return placeholder div
433440
return $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID );

0 commit comments

Comments
 (0)