| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | /* global console */ |
| 2 | 2 | /* global visualizer */ |
| 3 | 3 | /* global jQuery */ |
| 4 | -window['vizClipboard1'] = window['vizClipboard1'] || null; | |
| 5 | -window['vizClipboard2'] = window['vizClipboard2'] || null; | |
| 4 | +var vizClipboard1=null; | |
| 6 | 5 | (function($, visualizer){ |
| 7 | 6 | |
| 8 | 7 | function initActionsButtons(v) { |
| 9 | 8 | if($('a.visualizer-chart-shortcode').length > 0 && vizClipboard1 === null) { |
| @@ -13,14 +12,14 @@ | ||
| 13 | 12 | |
| 14 | 13 | }); |
| 15 | 14 | } |
| 16 | 15 | |
| 17 | - if($('a.visualizer-action[data-visualizer-type=copy]').length > 0 && vizClipboard2 === null) { | |
| 16 | + if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) { | |
| 18 | 17 | $('a.visualizer-action[data-visualizer-type=copy]').on('click', function(e) { |
| 19 | 18 | e.preventDefault(); |
| 20 | 19 | }); |
| 21 | - vizClipboard2 = new ClipboardJS('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line | |
| 22 | - vizClipboard2.on('success', function(e) { | |
| 20 | + var clipboard = new ClipboardJS('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line | |
| 21 | + clipboard.on('success', function(e) { | |
| 23 | 22 | window.alert(v.i10n['copied']); |
| 24 | 23 | }); |
| 25 | 24 | } |
| 26 | 25 | $('a.visualizer-action[data-visualizer-type!=copy]').off('click').on('click', function(e) { |
| @@ -128,9 +127,9 @@ | ||
| 128 | 127 | $('body').trigger('visualizer:render:chart:start', viz); |
| 129 | 128 | } |
| 130 | 129 | |
| 131 | 130 | function displayChartsOnFrontEnd() { |
| 132 | - function renderVisibleLazyCharts() { | |
| 131 | + $(window).on('scroll', function() { | |
| 133 | 132 | $('div.visualizer-front:not(.viz-facade-loaded):not(.visualizer-lazy):not(.visualizer-cw-error):empty').each(function(index, element){ |
| 134 | 133 | // Do not render charts that are intentionally hidden. |
| 135 | 134 | const style = window.getComputedStyle(element); |
| 136 | 135 | if (style.display === 'none' || style.visibility === 'hidden') { |
| @@ -136,15 +135,8 @@ | ||
| 136 | 135 | if (style.display === 'none' || style.visibility === 'hidden') { |
| 137 | 136 | return; |
| 138 | 137 | } |
| 139 | 138 | |
| 140 | - // Only render charts that are currently within the viewport. | |
| 141 | - const rect = element.getBoundingClientRect(); | |
| 142 | - const inViewport = rect.bottom >= 0 && rect.top <= (window.innerHeight || document.documentElement.clientHeight); | |
| 143 | - if (!inViewport) { | |
| 144 | - return; | |
| 145 | - } | |
| 146 | - | |
| 147 | 139 | const id = $(element).addClass('viz-facade-loaded').attr('id'); |
| 148 | 140 | setTimeout(function(){ |
| 149 | 141 | // Add a short delay between each chart to avoid overloading the browser event loop. |
| 150 | 142 | showChart(id); |
| @@ -149,14 +141,9 @@ | ||
| 149 | 141 | // Add a short delay between each chart to avoid overloading the browser event loop. |
| 150 | 142 | showChart(id); |
| 151 | 143 | }, ( index + 1 ) * 100); |
| 152 | 144 | }); |
| 153 | - } | |
| 154 | - | |
| 155 | - $(window).on('scroll', renderVisibleLazyCharts); | |
| 156 | - | |
| 157 | - // Run once on page load to render any lazy charts already in the viewport. | |
| 158 | - renderVisibleLazyCharts(); | |
| 145 | + }); | |
| 159 | 146 | |
| 160 | 147 | $('div.visualizer-front-container:not(.visualizer-lazy-render)').each(function(index, element){ |
| 161 | 148 | // Do not render charts that are intentionally hidden. |
| 162 | 149 | const style = window.getComputedStyle($(element).find('.visualizer-front')[0]); |