Skip to content

Commit 184ae3e

Browse files
fix: prevent double clipboard alert on copy action (#1265)
* fix: prevent double clipboard alert on copy action render-facade.js could be loaded more than once (registered under multiple handles when charts from different libraries appear on the same page). The copy ClipboardJS instance had no guard against double-initialization, causing the success alert to fire twice. Added vizClipboard2 guard to mirror the existing vizClipboard1 pattern already used for the shortcode copy button. * fix: copy still happening twice * chore: bump version for dev builds * chore: bump version for dev builds * chore: bump version for dev builds * chore: bump version for dev builds
1 parent 5101ede commit 184ae3e

4 files changed

Lines changed: 214 additions & 95 deletions

File tree

.github/workflows/build-dev-artifacts.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ jobs:
2828
run: |
2929
composer install --no-dev --prefer-dist --no-progress
3030
- name: Create zip
31-
run: npm run dist
31+
run: |
32+
npm ci
33+
CURRENT_VERSION=$(node -p -e "require('./package.json').version")
34+
COMMIT_HASH=$(git rev-parse --short HEAD)
35+
DEV_VERSION="${CURRENT_VERSION}-dev.${COMMIT_HASH}"
36+
npm run grunt version::${DEV_VERSION}
37+
npm run dist
3238
- name: Retrieve branch name
3339
id: retrieve-branch-name
3440
run: echo "::set-output name=branch_name::$(REF=${GITHUB_HEAD_REF:-$GITHUB_REF} && echo ${REF#refs/heads/} | sed 's/\//-/g')"

js/render-facade.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* global console */
22
/* global visualizer */
33
/* global jQuery */
4-
var vizClipboard1=null;
4+
window['vizClipboard1'] = window['vizClipboard1'] || null;
5+
window['vizClipboard2'] = window['vizClipboard2'] || null;
56
(function($, visualizer){
67

78
function initActionsButtons(v) {
@@ -13,12 +14,12 @@ var vizClipboard1=null;
1314
});
1415
}
1516

16-
if($('a.visualizer-action[data-visualizer-type=copy]').length > 0) {
17+
if($('a.visualizer-action[data-visualizer-type=copy]').length > 0 && vizClipboard2 === null) {
1718
$('a.visualizer-action[data-visualizer-type=copy]').on('click', function(e) {
1819
e.preventDefault();
1920
});
20-
var clipboard = new ClipboardJS('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
21-
clipboard.on('success', function(e) {
21+
vizClipboard2 = new ClipboardJS('a.visualizer-action[data-visualizer-type=copy]'); // jshint ignore:line
22+
vizClipboard2.on('success', function(e) {
2223
window.alert(v.i10n['copied']);
2324
});
2425
}

0 commit comments

Comments
 (0)