PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.6.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.6.1
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
← All changes | classes/Visualizer/Module/Frontend.php +57 -347 4.0.73.6.1 View file →
@@ -41,16 +41,8 @@
41 41 */
42 42 private $_charts = array();
43 43
44 44 /**
45 - * Lazy render script.
46 - *
47 - * @access private
48 - * @var bool
49 - */
50 - private $lazy_render_script = true;
51 -
52 - /**
53 45 * Constructor.
54 46 *
55 47 * @since 1.0.0
56 48 * @uses add_filter() To add "do_shortcode" hook for "widget_text" and "term_description" filters.
@@ -60,12 +52,9 @@
60 52 */
61 53 public function __construct( Visualizer_Plugin $plugin ) {
62 54 parent::__construct( $plugin );
63 55
64 - $this->_addAction( 'wp_print_footer_scripts', 'printFooterScripts' );
65 56 $this->_addAction( 'wp_enqueue_scripts', 'enqueueScripts' );
66 - $this->_addAction( 'load-index.php', 'enqueueScripts' );
67 - $this->_addAction( 'load-visualizer_page_visualizer-setup-wizard', 'enqueueScripts' );
68 57 $this->_addAction( 'visualizer_enqueue_scripts', 'enqueueScripts' );
69 58 $this->_addFilter( 'visualizer_get_language', 'getLanguage' );
70 59 $this->_addShortcode( 'visualizer', 'renderChart' );
71 60
@@ -86,39 +75,21 @@
86 75
87 76 /**
88 77 * Adds the async attribute to certain scripts.
89 78 */
90 - public function script_loader_tag( $tag, $handle, $src ) {
79 + function script_loader_tag( $tag, $handle, $src ) {
91 80 if ( is_admin() ) {
92 81 return $tag;
93 82 }
94 - // Async scripts.
95 - $async_scripts = array( 'google-jsapi', 'chartjs', 'visualizer-datatables' );
96 - foreach ( $async_scripts as $async ) {
83 +
84 + $scripts = array( 'google-jsapi', 'visualizer-render-google-lib', 'visualizer-render-google' );
85 +
86 + foreach ( $scripts as $async ) {
97 87 if ( $async === $handle ) {
98 - $tag = str_replace( ' src', ' async src', $tag );
88 + $tag = str_replace( ' src', ' defer="defer" src', $tag );
99 89 break;
100 90 }
101 91 }
102 -
103 - // Async scripts.
104 - $scripts = array( 'dom-to-image' );
105 - foreach ( array( 'async', 'defer' ) as $attr ) {
106 - if ( wp_scripts()->get_data( $handle, $attr ) ) {
107 - break;
108 - }
109 - if ( in_array( $handle, $async_scripts, true ) || false === strpos( $handle, 'visualizer-' ) ) {
110 - break;
111 - }
112 - if ( ! preg_match( ":\s$attr(=|>|\s):", $tag ) ) {
113 - $tag = preg_replace( ':(?=></script>):', " $attr", $tag, 1 );
114 - if ( $this->lazy_render_script ) {
115 - $tag = str_replace( ' src', ' data-visualizer-script', $tag );
116 - }
117 - }
118 - // Only allow async or defer, not both.
119 - break;
120 - }
121 92 return $tag;
122 93 }
123 94
124 95 /**
@@ -123,9 +94,9 @@
123 94
124 95 /**
125 96 * Returns the language/locale.
126 97 */
127 - public function getLanguage( $dummy, $only_language ) {
98 + function getLanguage( $dummy, $only_language ) {
128 99 return $this->get_language();
129 100 }
130 101
131 102
@@ -131,9 +102,9 @@
131 102
132 103 /**
133 104 * Registers the endpoints
134 105 */
135 - public function endpoint_register() {
106 + function endpoint_register() {
136 107 register_rest_route(
137 108 'visualizer/v' . VISUALIZER_REST_VERSION,
138 109 '/action/(?P<chart>\d+)/(?P<type>.+)/',
139 110 array(
@@ -141,9 +112,9 @@
141 112 'methods' => array( 'POST', 'GET' ),
142 113 'args' => array(
143 114 'chart' => array(
144 115 'required' => true,
145 - 'sanitize_callback' => function ( $param ) {
116 + 'sanitize_callback' => function( $param ) {
146 117 return is_numeric( $param ) ? $param : null;
147 118 },
148 119 ),
149 120 'type' => array(
@@ -152,27 +123,16 @@
152 123 'enum' => array_merge( array( 'save', 'cancel' ), array_keys( $this->get_actions() ) ),
153 124 ),
154 125 ),
155 126 'permission_callback' => function ( WP_REST_Request $request ) {
156 - $chart_id = absint( $request->get_param( 'chart' ) );
157 - if ( ! $chart_id ) {
158 - return false;
127 + $chart_id = filter_var( sanitize_text_field( $request->get_param( 'chart' ), FILTER_VALIDATE_INT ) );
128 + if ( ! empty( $chart_id ) && in_array( $request->get_param( 'type' ), array( 'save', 'cancel' ), true ) ) {
129 + // let save and cancel go without any check as past version of pro
130 + // did not send the X-WP-Nonce
131 + // we can change this at a later date.
132 + return true;
159 133 }
160 -
161 - $chart = get_post( $chart_id );
162 - if ( ! $chart || Visualizer_Plugin::CPT_VISUALIZER !== $chart->post_type ) {
163 - return false;
164 - }
165 -
166 - if ( in_array( $request->get_param( 'type' ), array( 'save', 'cancel' ), true ) ) {
167 - return current_user_can( 'edit_post', $chart_id );
168 - }
169 -
170 - if ( 'publish' !== $chart->post_status ) {
171 - return current_user_can( 'edit_post', $chart_id );
172 - }
173 -
174 - return apply_filters( 'visualizer_pro_show_chart', true, $chart_id );
134 + return ! empty( $chart_id ) && apply_filters( 'visualizer_pro_show_chart', true, $chart_id );
175 135 },
176 136 'callback' => array( $this, 'perform_action' ),
177 137 )
178 138 );
@@ -282,8 +242,9 @@
282 242 * @access public
283 243 */
284 244 public function enqueueScripts() {
285 245 wp_register_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true );
246 + wp_register_style( 'visualizer-front', VISUALIZER_ABSURL . 'css/front.css', array(), Visualizer_Plugin::VERSION );
286 247 do_action( 'visualizer_pro_frontend_load_resources' );
287 248 }
288 249
289 250 /**
@@ -315,53 +276,24 @@
315 276 'use_image' => 'no',
316 277 ),
317 278 $atts
318 279 );
319 -
320 - $atts['id'] = (int) $atts['id'];
321 - $atts['class'] = esc_attr( $atts['class'] );
322 - $atts['lazy'] = esc_attr( $atts['lazy'] );
323 - $atts['use_image'] = esc_attr( $atts['use_image'] );
324 -
325 - global $sitepress;
326 - if ( Visualizer_Module::is_pro() && ( function_exists( 'icl_get_languages' ) && $sitepress instanceof \SitePress ) ) {
327 - global $sitepress;
328 - $locale = icl_get_current_language();
329 - $locale = strtolower( str_replace( '_', '-', $locale ) );
330 - $trid = $sitepress->get_element_trid( $atts['id'], 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
331 - $translations = $sitepress->get_element_translations( $trid );
332 - if ( isset( $translations[ $locale ] ) && is_object( $translations[ $locale ] ) ) {
333 - $atts['id'] = $translations[ $locale ]->element_id;
334 - }
335 - }
336 -
337 - $chart_data = $this->getChartData( Visualizer_Plugin::CF_CHART_CACHE, $atts['id'] );
338 - // if empty chart does not exists, then return empty string.
339 - if ( ! $chart_data ) {
280 + // if empty id or chart does not exists, then return empty string
281 + if ( ! $atts['id'] || ! ( $chart = get_post( $atts['id'] ) ) || $chart->post_type !== Visualizer_Plugin::CPT_VISUALIZER ) {
340 282 return '';
341 283 }
342 284
343 - $chart = $chart_data['chart'];
344 - $type = $chart_data['type'];
345 - $series = $chart_data['series'];
346 285 // do not show the chart?
347 286 if ( ! apply_filters( 'visualizer_pro_show_chart', true, $atts['id'] ) ) {
348 287 return '';
349 288 }
350 289
351 - if ( ! is_admin() && ! empty( $chart_data['is_woocommerce_report'] ) ) {
352 - return '';
290 + // in case revisions exist.
291 + // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found
292 + if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) {
293 + $chart = get_post( $chart->ID );
353 294 }
354 295
355 - // in case revisions exist (skip D3 charts to avoid reverting AI data).
356 - $chart_library = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_LIBRARY, true );
357 - if ( 'd3' !== $chart_library ) {
358 - $revisions = $this->undoRevisions( $chart->ID, true );
359 - if ( true === $revisions ) {
360 - $chart = get_post( $chart->ID );
361 - }
362 - }
363 -
364 296 $id = 'visualizer-' . $atts['id'];
365 297 $defaultClass = 'visualizer-front';
366 298 $class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );
367 299
@@ -376,34 +308,24 @@
376 308 if ( ctype_digit( $atts['lazy'] ) ) {
377 309 $attributes['data-lazy-limit'] = $atts['lazy'];
378 310 }
379 311
380 - $attributes = apply_filters( 'visualizer_container_attributes', $attributes, $chart->ID );
312 + $type = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true );
381 313
382 314 $chart = apply_filters( 'visualizer_schedule_refresh_chart', $chart, $chart->ID, false );
383 315
384 - // Get and update settings.
385 - $settings = $chart_data['settings'];
386 - $settings = ! empty( $settings ) ? $settings : array();
316 + // fetch and update settings
317 + $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
387 318 if ( empty( $settings['height'] ) ) {
388 319 $settings['height'] = '400';
389 320 }
390 321
391 322 // handle series filter hooks
392 - $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, $series, $chart->ID, $type );
323 + $series = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SERIES, get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ), $chart->ID, $type );
393 324
394 325 // handle settings filter hooks
395 326 $settings = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_SETTINGS, $settings, $chart->ID, $type );
396 327
397 - $lazy_load = isset( $settings['lazy_load_chart'] ) ? $settings['lazy_load_chart'] : false;
398 - $lazy_load = apply_filters( 'visualizer_lazy_load_chart', $lazy_load, $chart->ID );
399 - $container_class = 'visualizer-front-container';
400 - if ( ! $lazy_load ) {
401 - $this->lazy_render_script = false;
402 - } else {
403 - $container_class .= ' visualizer-lazy-render';
404 - }
405 -
406 328 // handle data filter hooks
407 329 $data = self::get_chart_data( $chart, $type );
408 330
409 331 $css = '';
@@ -422,33 +344,16 @@
422 344 return '<div data-amp-auto-lightbox-disable id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '>' . $amp->get_chart( $chart, $data, $series, $settings ) . '</div>';
423 345 }
424 346
425 347 if ( 'yes' === $atts['use_image'] ) {
426 - $chart_image = $chart_data['chart_image'];
348 + $chart_image = get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true );
427 349 if ( $chart_image ) {
428 350 return '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '>' . wp_get_attachment_image( $chart_image, 'full' ) . '</div>';
429 351 }
430 352 }
431 - // Unset chart image base64 string.
432 - if ( isset( $settings['chart-img'] ) ) {
433 - unset( $settings['chart-img'] );
434 - }
435 353
436 - $enable_controls = false;
437 - if ( isset( $settings['controls'] ) && ! empty( $settings['controls']['controlType'] ) ) {
438 - $column_index = $settings['controls']['filterColumnIndex'];
439 - $column_label = $settings['controls']['filterColumnLabel'];
440 - if ( 'false' !== $column_index || 'false' !== $column_label ) {
441 - $enable_controls = true;
442 - }
443 - }
444 -
445 - if ( ! $enable_controls ) {
446 - unset( $settings['controls'] );
447 - }
448 -
449 354 // add chart to the array
450 - $chart_entry = array(
355 + $this->_charts[ $id ] = array(
451 356 'type' => $type,
452 357 'series' => $series,
453 358 'settings' => $settings,
454 359 'data' => $data,
@@ -454,15 +359,8 @@
454 359 'data' => $data,
455 360 'library' => $library,
456 361 );
457 362
458 - // For D3 charts, include the stored code so the renderer can execute it.
459 - if ( 'd3' === $library ) {
460 - $chart_entry['code'] = get_post_meta( $chart->ID, Visualizer_Module_AIBuilder::CF_D3_CODE, true );
461 - }
462 -
463 - $this->_charts[ $id ] = $chart_entry;
464 -
465 363 $actions_div = '';
466 364 $actions_visible = apply_filters( 'visualizer_pro_add_actions', isset( $settings['actions'] ) ? $settings['actions'] : array(), $atts['id'] );
467 365 if ( ! empty( $actions_visible ) ) {
468 366 $actions = $this->get_actions();
@@ -493,117 +391,40 @@
493 391 }
494 392
495 393 $actions_div .= $css;
496 394
497 - $_charts = array();
498 - $_charts_type = '';
499 - $count = 0;
500 - static $visualizer_localized = false;
501 - static $visualizer_charts = array();
502 - static $d3_localized = false;
503 - $facade_handle = 'visualizer-render-facade';
504 395 foreach ( $this->_charts as $id => $array ) {
505 - $_charts = $this->_charts;
506 396 $library = $array['library'];
507 - $_charts_type = $library;
508 - $facade_deps = apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true );
509 - if ( ! wp_script_is( $facade_handle, 'registered' ) ) {
510 - wp_register_script(
511 - $facade_handle,
512 - VISUALIZER_ABSURL . 'js/render-facade.js',
513 - $facade_deps,
514 - Visualizer_Plugin::VERSION,
515 - true
516 - );
517 - wp_enqueue_script( $facade_handle );
518 - } else {
519 - // Ensure newly discovered dependencies are attached to the facade.
520 - global $wp_scripts;
521 - if ( isset( $wp_scripts->registered[ $facade_handle ] ) ) {
522 - $wp_scripts->registered[ $facade_handle ]->deps = array_unique(
523 - array_merge( $wp_scripts->registered[ $facade_handle ]->deps, $facade_deps )
524 - );
525 - }
526 - foreach ( $facade_deps as $dep_handle ) {
527 - wp_enqueue_script( $dep_handle );
528 - }
529 - }
397 + wp_register_script(
398 + "visualizer-render-$library",
399 + VISUALIZER_ABSURL . 'js/render-facade.js',
400 + apply_filters( 'visualizer_assets_render', array( 'jquery', 'visualizer-customization' ), true ),
401 + Visualizer_Plugin::VERSION,
402 + true
403 + );
530 404
531 - // For D3 charts, also enqueue the dedicated renderer bundle.
532 - if ( 'd3' === $library ) {
533 - $d3_renderer_asset = VISUALIZER_ABSPATH . '/classes/Visualizer/D3Renderer/build/index.asset.php';
534 - if ( file_exists( $d3_renderer_asset ) && ! wp_script_is( 'visualizer-d3-renderer', 'registered' ) ) {
535 - /**
536 - * Ignore missing build asset in source checkout.
537 - *
538 - * @phpstan-ignore-next-line
539 - */
540 - $d3_asset = include $d3_renderer_asset;
541 - wp_register_script(
542 - 'visualizer-d3-renderer',
543 - VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/index.js',
544 - array_merge( $d3_asset['dependencies'], array( 'jquery' ) ),
545 - $d3_asset['version'],
546 - true
547 - );
548 - wp_enqueue_script( 'visualizer-d3-renderer' );
549 - }
550 - if ( ! $d3_localized ) {
551 - wp_localize_script(
552 - 'visualizer-d3-renderer',
553 - 'vizD3Renderer',
554 - array(
555 - 'iframeJsUrl' => VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/iframe.js',
556 - )
557 - );
558 - $d3_localized = true;
559 - }
560 - }
405 + wp_enqueue_script( "visualizer-render-$library" );
406 + wp_localize_script(
407 + "visualizer-render-$library",
408 + 'visualizer',
409 + array(
410 + 'charts' => $this->_charts,
411 + 'language' => $this->get_language(),
412 + 'map_api_key' => get_option( 'visualizer-map-api-key' ),
413 + 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
414 + 'wp_nonce' => wp_create_nonce( 'wp_rest' ),
415 + 'i10n' => array(
416 + 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
417 + ),
418 + 'page_type' => 'frontend',
419 + 'is_front' => true,
420 + )
421 + );
422 + wp_enqueue_style( 'visualizer-front' );
423 + }
561 424
562 - if ( wp_script_is( $facade_handle ) && 0 === $count ) {
563 - if ( ! $visualizer_localized ) {
564 - $visualizer_charts = $this->_charts;
565 - wp_localize_script(
566 - $facade_handle,
567 - 'visualizer',
568 - array(
569 - 'charts' => $this->_charts,
570 - 'language' => $this->get_language(),
571 - 'map_api_key' => get_option( 'visualizer-map-api-key' ),
572 - 'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
573 - 'wp_nonce' => wp_create_nonce( 'wp_rest' ),
574 - 'i10n' => array(
575 - 'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
576 - ),
577 - 'page_type' => 'frontend',
578 - 'is_front' => true,
579 - )
580 - );
581 - $visualizer_localized = true;
582 - } else {
583 - $new_charts = array_diff_key( $this->_charts, $visualizer_charts );
584 - if ( ! empty( $new_charts ) ) {
585 - wp_add_inline_script(
586 - $facade_handle,
587 - 'window.visualizer = window.visualizer || {};' .
588 - 'window.visualizer.charts = Object.assign(window.visualizer.charts || {}, ' . wp_json_encode( $new_charts ) . ');',
589 - 'before'
590 - );
591 - $visualizer_charts = array_merge( $visualizer_charts, $new_charts );
592 - }
593 - }
594 - }
595 - ++$count;
596 - }
597 - $prefix = 'C' . 'h' . 'a' . 'rt';
598 - if ( $type === 'tabular' ) {
599 - $prefix = 'T' . 'a' . 'bl' . 'e';
600 - }
601 - if ( Visualizer_Module::is_pro() && $enable_controls ) {
602 - $actions_div .= '<div id="control_wrapper_' . $id . '"></div>';
603 - }
604 425 // return placeholder div
605 - return '<div class="' . $container_class . '" id="chart_wrapper_' . $id . '">' . $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID ) . '</div>';
426 + return $actions_div . '<div id="' . $id . '"' . $this->getHtmlAttributes( $attributes ) . '></div>' . $this->addSchema( $chart->ID );
606 427 }
607 428
608 429 /**
609 430 * Converts the array of attributes to a string of HTML attributes.
@@ -618,9 +439,9 @@
618 439 return $string;
619 440 }
620 441
621 442 foreach ( $attributes as $name => $value ) {
622 - $string .= sprintf( ' %s="%s"', esc_attr( $name ), esc_attr( $value ) );
443 + $string .= sprintf( '%s="%s"', esc_attr( $name ), esc_attr( $value ) );
623 444 }
624 445 return $string;
625 446 }
626 447
@@ -721,117 +542,6 @@
721 542 return '';
722 543 }
723 544
724 545 return '<script type="application/ld+json">' . $schema . '</script>';
725 - }
726 -
727 - /**
728 - * Get chart by ID.
729 - *
730 - * @param string $cache_key Cache key.
731 - * @param int $chart_id Chart ID.
732 - * @return mixed
733 - */
734 - private function getChartData( $cache_key = '', $chart_id = 0 ) {
735 - if ( ! $chart_id ) {
736 - return false;
737 - }
738 - // Create unique cache key of each chart.
739 - $cache_key .= '_' . $chart_id;
740 - // Get chart from cache.
741 - $chart = get_transient( $cache_key );
742 - if ( $chart ) {
743 - return $chart;
744 - }
745 -
746 - // Get chart by ID.
747 - $chart = get_post( $chart_id );
748 - if ( $chart && Visualizer_Plugin::CPT_VISUALIZER === $chart->post_type ) {
749 - $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
750 - $series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true );
751 - $is_woocommerce_report = get_post_meta( $chart->ID, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );
752 -
753 - if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $series ) > 1 ) ) {
754 - $diff_total_series = abs( count( $settings['series'] ) - count( $series ) );
755 - if ( $diff_total_series ) {
756 - foreach ( range( 1, $diff_total_series ) as $k => $diff_series ) {
757 - $settings['series'][] = end( $settings['series'] );
758 - }
759 - }
760 - }
761 - $chart_data = array(
762 - 'chart' => $chart,
763 - 'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ),
764 - 'settings' => $settings,
765 - 'series' => $series,
766 - 'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ),
767 - 'is_woocommerce_report' => $is_woocommerce_report,
768 - );
769 -
770 - // Put the results in a transient. Expire after 12 hours.
771 - set_transient( $cache_key, $chart_data, apply_filters( Visualizer_Plugin::FILTER_HANDLE_CACHE_EXPIRATION_TIME, 12 * HOUR_IN_SECONDS ) );
772 - return $chart_data;
773 - }
774 -
775 - return false;
776 - }
777 -
778 - /**
779 - * Print footer script.
780 - */
781 - public function printFooterScripts() {
782 - if ( $this->lazy_render_script ) {
783 - ?>
784 - <script type="text/javascript">
785 - var visualizerUserInteractionEvents = [
786 - "scroll",
787 - "mouseover",
788 - "keydown",
789 - "touchmove",
790 - "touchstart"
791 - ];
792 -
793 - visualizerUserInteractionEvents.forEach(function(event) {
794 - window.addEventListener(event, visualizerTriggerScriptLoader, { passive: true });
795 - });
796 -
797 - function visualizerTriggerScriptLoader() {
798 - visualizerLoadScripts();
799 - visualizerUserInteractionEvents.forEach(function(event) {
800 - window.removeEventListener(event, visualizerTriggerScriptLoader, { passive: true });
801 - });
802 - }
803 -
804 - function visualizerLoadScripts() {
805 - document.querySelectorAll("script[data-visualizer-script]").forEach(function(elem) {
806 - // Replace the placeholder with a real script tag using async=false:
807 - // scripts download in parallel but execute in insertion order, which
808 - // preserves the WordPress dependency order. Parallel jQuery.getScript
809 - // calls could execute render-facade.js before the chart renderer had
810 - // registered its render event listener, leaving charts blank.
811 - var script = document.createElement("script");
812 - script.src = elem.getAttribute("data-visualizer-script");
813 - script.async = false;
814 - script.onload = function() {
815 - setTimeout( function() {
816 - visualizerRefreshChart();
817 - } );
818 - };
819 - elem.parentNode.replaceChild(script, elem);
820 - });
821 - }
822 -
823 - function visualizerRefreshChart() {
824 - jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize();
825 - if ( jQuery( 'div.viz-facade-loaded:not(.visualizer-lazy):empty' ).length > 0 ) {
826 - visualizerUserInteractionEvents.forEach( function( event ) {
827 - window.addEventListener( event, function() {
828 - jQuery( '.visualizer-front:not(.visualizer-chart-loaded)' ).resize();
829 - }, { passive: true } );
830 - } );
831 - }
832 - }
833 - </script>
834 - <?php
835 - }
836 546 }
837 547 }