Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking Copy shows the Copied message multiple times #692

Merged
merged 5 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion classes/Visualizer/Module/Frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public function renderChart( $atts ) {
'map_api_key' => get_option( 'visualizer-map-api-key' ),
'rest_url' => version_compare( $wp_version, '4.7.0', '>=' ) ? rest_url( 'visualizer/v' . VISUALIZER_REST_VERSION . '/action/#id#/#type#/' ) : '',
'i10n' => array(
'copied' => __( 'Copied!', 'visualizer' ),
'copied' => __( 'The data has been copied to your clipboard. Hit Ctrl-V/Cmd-V in your spreadsheet editor to paste the data.', 'visualizer' ),
),
'page_type' => 'frontend',
'is_front' => true,
Expand Down
24 changes: 13 additions & 11 deletions js/render-facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

function initActionsButtons(v) {
if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) {
$('a.visualizer-action[data-visualizer-type=copy]').on('click', function(e) {
e.preventDefault();
});
var clipboard = new Clipboard('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
clipboard.on('success', function(e) {
window.alert(v.i10n['copied']);
Expand Down Expand Up @@ -88,24 +91,23 @@
document.body.dispatchEvent(event);
};

// facade loads N times in the library (where N = the number of different chart libraries supported)
// facade loads N times in the library and front end (where N = the number of different chart libraries supported)
// so all charts are also loaded N times
// this will ensure that no matter how many times facade is loaded, it initializes all charts only once.
// fixed as part of the issue to add annotations.
if(visualizer.page_type === 'library'){
if(localStorage.getItem( 'viz-facade-loaded' ) === '1'){
// prevent library from hanging.
setTimeout( function(){
localStorage.removeItem( 'viz-facade-loaded' );
}, 2000);
return;
}
localStorage.setItem( 'viz-facade-loaded', '1');
// remove the flag so that repeated loading of the library does not cause problems.
if(localStorage.getItem( 'viz-facade-loaded' ) === '1'){
// prevent library from hanging.
setTimeout( function(){
localStorage.removeItem( 'viz-facade-loaded' );
}, 2000);
return;
}
localStorage.setItem( 'viz-facade-loaded', '1');
// remove the flag so that repeated loading of the library does not cause problems.
setTimeout( function(){
localStorage.removeItem( 'viz-facade-loaded' );
}, 2000);

$('body').trigger('visualizer:render:chart:start', visualizer);
initActionsButtons(visualizer);
registerDefaultActions();
Expand Down
Loading