File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed
classes/Visualizer/Module Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ class Visualizer_Module_Frontend extends Visualizer_Module {
47
47
* @access private
48
48
* @var bool
49
49
*/
50
- private $ lazy_render_script = false ;
50
+ private $ lazy_render_script = true ;
51
51
52
52
/**
53
53
* Constructor.
@@ -383,8 +383,9 @@ public function renderChart( $atts ) {
383
383
$ lazy_load = isset ( $ settings ['lazy_load_chart ' ] ) ? $ settings ['lazy_load_chart ' ] : false ;
384
384
$ lazy_load = apply_filters ( 'visualizer_lazy_load_chart ' , $ lazy_load , $ chart ->ID );
385
385
$ 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 {
388
389
$ container_class .= ' visualizer-lazy-render ' ;
389
390
}
390
391
Original file line number Diff line number Diff line change @@ -128,16 +128,30 @@ var vizClipboard1=null;
128
128
}
129
129
130
130
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
+ }
131
138
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
+ } ) ;
133
146
147
+ $ ( 'div.visualizer-front-container:not(.visualizer-lazy-render)' ) . each ( function ( index , element ) {
134
148
// Do not render charts that are intentionally hidden.
135
- var style = window . getComputedStyle ( element ) ;
149
+ const style = window . getComputedStyle ( $ ( element ) . find ( '.visualizer-front' ) [ 0 ] ) ;
136
150
if ( style . display === 'none' || style . visibility === 'hidden' ) {
137
151
return ;
138
152
}
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' ) ;
141
155
setTimeout ( function ( ) {
142
156
// Add a short delay between each chart to avoid overloading the browser event loop.
143
157
showChart ( id ) ;
You can’t perform that action at this time.
0 commit comments