3
3
/* global jQuery */
4
4
var vizClipboard1 = null ;
5
5
( function ( $ , visualizer ) {
6
-
7
- // Once the facade is loaded, we need to refresh the charts. But we need to it one time only per chart.
8
- var chartReloadedAfterFacade = [ ] ;
9
-
6
+
10
7
function initActionsButtons ( v ) {
11
8
if ( $ ( 'a.visualizer-chart-shortcode' ) . length > 0 && vizClipboard1 === null ) {
12
9
vizClipboard1 = new ClipboardJS ( 'a.visualizer-chart-shortcode' ) ; // jshint ignore:line
@@ -116,13 +113,13 @@ var vizClipboard1=null;
116
113
return ;
117
114
}
118
115
setTimeout ( function ( ) {
119
- displayChartsOnFrontEnd ( ) ;
116
+ displayChartsOnFrontEnd ( ) ;
120
117
} , 100 ) ;
121
118
}
122
119
123
120
function initChartDisplay ( ) {
124
121
if ( visualizer . is_front == true ) { // jshint ignore:line
125
- displayChartsOnFrontEnd ( ) ;
122
+ displayChartsOnFrontEnd ( ) ;
126
123
} else {
127
124
showChart ( ) ;
128
125
}
@@ -141,20 +138,23 @@ var vizClipboard1=null;
141
138
}
142
139
143
140
function displayChartsOnFrontEnd ( ) {
144
- // display all charts that are NOT to be lazy-loaded.
145
- $ ( 'div.viz-facade-loaded:not(.visualizer-lazy):not(.visualizer-cw-error):empty' ) . removeClass ( 'viz-facade-loaded' ) ;
146
- $ ( 'div.visualizer-front:not(.visualizer-lazy):not(.viz-facade-loaded)' ) . each ( function ( index , element ) {
147
- if ( $ ( element ) . is ( ':visible' ) ) {
148
- var id = $ ( element ) . addClass ( 'viz-facade-loaded' ) . attr ( 'id' ) ;
149
- showChart ( id ) ;
150
-
151
- // Reload the chart and mark it as reloaded.
152
- if ( chartReloadedAfterFacade . indexOf ( id ) === - 1 ) {
153
- refreshEachCharts ( ) ;
154
- chartReloadedAfterFacade . push ( id ) ;
141
+
142
+ // Render the charts that are not lazy-loaded and with no errors.
143
+ var nonLazyLoadedCharts = $ ( 'div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error' ) ;
144
+
145
+ if ( nonLazyLoadedCharts . length ) {
146
+ nonLazyLoadedCharts . each ( function ( index , element ) {
147
+ if ( $ ( element ) . is ( ':visible' ) ) {
148
+ var id = $ ( element ) . addClass ( 'viz-facade-loaded' ) . attr ( 'id' ) ;
149
+ showChart ( id ) ;
155
150
}
156
- }
157
- } ) ;
151
+ } ) ;
152
+
153
+ refreshEachCharts ( ) ;
154
+ } else {
155
+ // Remove the loaded status for charts that are empty.
156
+ $ ( 'div.viz-facade-loaded:not(.visualizer-lazy):not(.visualizer-cw-error):empty' ) . removeClass ( 'viz-facade-loaded' ) ;
157
+ }
158
158
159
159
// interate through all charts that are to be lazy-loaded and observe each one.
160
160
$ ( 'div.visualizer-front.visualizer-lazy' ) . each ( function ( index , element ) {
0 commit comments