Skip to content

Commit c616ffd

Browse files
Merge pull request #1219 from Codeinwp/fix/pro/lazy-loading
Fixed lazy loading when disabled
2 parents 8fd1a60 + 1fc7720 commit c616ffd

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

classes/Visualizer/Module/Frontend.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Visualizer_Module_Frontend extends Visualizer_Module {
4747
* @access private
4848
* @var bool
4949
*/
50-
private $lazy_render_script = false;
50+
private $lazy_render_script = true;
5151

5252
/**
5353
* Constructor.
@@ -383,8 +383,9 @@ public function renderChart( $atts ) {
383383
$lazy_load = isset( $settings['lazy_load_chart'] ) ? $settings['lazy_load_chart'] : false;
384384
$lazy_load = apply_filters( 'visualizer_lazy_load_chart', $lazy_load, $chart->ID );
385385
$container_class = 'visualizer-front-container';
386-
if ( $lazy_load ) {
387-
$this->lazy_render_script = true;
386+
if ( ! $lazy_load ) {
387+
$this->lazy_render_script = false;
388+
} else {
388389
$container_class .= ' visualizer-lazy-render';
389390
}
390391

js/render-facade.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,30 @@ var vizClipboard1=null;
128128
}
129129

130130
function displayChartsOnFrontEnd() {
131+
$(window).on('scroll', function() {
132+
$('div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error):empty').each(function(index, element){
133+
// Do not render charts that are intentionally hidden.
134+
const style = window.getComputedStyle(element);
135+
if (style.display === 'none' || style.visibility === 'hidden') {
136+
return;
137+
}
131138

132-
$('div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error):empty').each(function(index, element){
139+
const id = $(element).addClass('viz-facade-loaded').attr('id');
140+
setTimeout(function(){
141+
// Add a short delay between each chart to avoid overloading the browser event loop.
142+
showChart(id);
143+
}, ( index + 1 ) * 100);
144+
});
145+
});
133146

147+
$('div.visualizer-front-container:not(.visualizer-lazy-render)').each(function(index, element){
134148
// Do not render charts that are intentionally hidden.
135-
var style = window.getComputedStyle(element);
149+
const style = window.getComputedStyle($(element).find('.visualizer-front')[0]);
136150
if (style.display === 'none' || style.visibility === 'hidden') {
137151
return;
138152
}
139-
140-
var id = $(element).addClass('viz-facade-loaded').attr('id');
153+
154+
const id = $(element).find('.visualizer-front').addClass('viz-facade-loaded').attr('id');
141155
setTimeout(function(){
142156
// Add a short delay between each chart to avoid overloading the browser event loop.
143157
showChart(id);

0 commit comments

Comments
 (0)