| @@ -1,16 +1,15 @@ | ||
| 1 | 1 | /* global console */ |
| 2 | 2 | /* global visualizer */ |
| 3 | 3 | /* global jQuery */ |
| 4 | -var vizClipboard1=null; | |
| 4 | + | |
| 5 | 5 | (function($, visualizer){ |
| 6 | - | |
| 6 | + | |
| 7 | 7 | function initActionsButtons(v) { |
| 8 | - if($('a.visualizer-chart-shortcode').length > 0 && vizClipboard1 === null) { | |
| 9 | - vizClipboard1 = new ClipboardJS('a.visualizer-chart-shortcode'); // jshint ignore:line | |
| 10 | - vizClipboard1.on('success', function(e) { | |
| 8 | + if($('a.visualizer-chart-shortcode').length > 0) { | |
| 9 | + var clipboard1 = new ClipboardJS('a.visualizer-chart-shortcode'); // jshint ignore:line | |
| 10 | + clipboard1.on('success', function(e) { | |
| 11 | 11 | window.alert(v.i10n['copied']); |
| 12 | - | |
| 13 | 12 | }); |
| 14 | 13 | } |
| 15 | 14 | |
| 16 | 15 | if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) { |
| @@ -106,12 +105,19 @@ | ||
| 106 | 105 | initActionsButtons(visualizer); |
| 107 | 106 | registerDefaultActions(); |
| 108 | 107 | }); |
| 109 | 108 | |
| 109 | + // Refresh charts if chart not generated. | |
| 110 | + function refreshEachCharts() { | |
| 111 | + setTimeout( function() { | |
| 112 | + displayChartsOnFrontEnd(); | |
| 113 | + }, 100 ); | |
| 114 | + } | |
| 115 | + | |
| 110 | 116 | function initChartDisplay() { |
| 111 | 117 | if(visualizer.is_front == true){ // jshint ignore:line |
| 112 | 118 | displayChartsOnFrontEnd(); |
| 113 | - } else { | |
| 119 | + }else{ | |
| 114 | 120 | showChart(); |
| 115 | 121 | } |
| 116 | 122 | } |
| 117 | 123 | |
| @@ -127,22 +133,16 @@ | ||
| 127 | 133 | $('body').trigger('visualizer:render:chart:start', viz); |
| 128 | 134 | } |
| 129 | 135 | |
| 130 | 136 | function displayChartsOnFrontEnd() { |
| 131 | - | |
| 132 | - $('div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error):empty').each(function(index, element){ | |
| 133 | - | |
| 134 | - // Do not render charts that are intentionally hidden. | |
| 135 | - var style = window.getComputedStyle(element); | |
| 136 | - if (style.display === 'none' || style.visibility === 'hidden') { | |
| 137 | - return; | |
| 137 | + // display all charts that are NOT to be lazy-loaded. | |
| 138 | + $( 'div.viz-facade-loaded:not(.visualizer-lazy):empty' ).removeClass( 'viz-facade-loaded' ); | |
| 139 | + $('div.visualizer-front:not(.visualizer-lazy):not(.viz-facade-loaded)').each(function(index, element){ | |
| 140 | + if ( $(element).is(':visible') ) { | |
| 141 | + var id = $(element).addClass('viz-facade-loaded').attr('id'); | |
| 142 | + showChart(id); | |
| 138 | 143 | } |
| 139 | - | |
| 140 | - var id = $(element).addClass('viz-facade-loaded').attr('id'); | |
| 141 | - setTimeout(function(){ | |
| 142 | - // Add a short delay between each chart to avoid overloading the browser event loop. | |
| 143 | - showChart(id); | |
| 144 | - }, ( index + 1 ) * 100); | |
| 144 | + refreshEachCharts(); | |
| 145 | 145 | }); |
| 146 | 146 | |
| 147 | 147 | // interate through all charts that are to be lazy-loaded and observe each one. |
| 148 | 148 | $('div.visualizer-front.visualizer-lazy').each(function(index, element){ |