-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathcloud_confirm.js
More file actions
69 lines (56 loc) · 2.23 KB
/
cloud_confirm.js
File metadata and controls
69 lines (56 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
var d3 = require('@plotly/d3');
/**
* Show a styled confirmation dialog before sharing a chart with Plotly Cloud.
*
* The dialog is appended to the plot's positioning container (.svg-container)
* so it is centered over the plot rather than the whole viewport. It can be
* dismissed by clicking Cancel, clicking the backdrop, or pressing Escape.
*
* @param {DOM node} gd - the graph div, used to scope the dialog to the plot
* @param {string} serverUrl - destination shown in the dialog message
* @param {function} onConfirm - called when the user confirms the upload
*/
module.exports = function confirmCloudDialog(gd, serverUrl, onConfirm) {
var container = d3.select(gd._fullLayout._paperdiv.node());
// Never stack dialogs - drop any that is already open.
container.selectAll('.plotly-cloud-dialog').remove();
var overlay = container
.append('div')
.classed('plotly-cloud-dialog', true);
var dialog = overlay.append('div')
.classed('plotly-cloud-dialog-box', true);
dialog.append('div')
.classed('plotly-cloud-dialog-title', true)
.text('Share with Plotly Cloud');
dialog.append('div')
.classed('plotly-cloud-dialog-message', true)
.text('Your chart data will be sent to ' + serverUrl + '.');
var buttons = dialog.append('div')
.classed('plotly-cloud-dialog-buttons', true);
function close() {
overlay.remove();
document.removeEventListener('keydown', onKeydown);
}
function onKeydown(e) {
if(e.key === 'Escape' || e.keyCode === 27) close();
}
document.addEventListener('keydown', onKeydown);
// Clicking the backdrop (but not the dialog box) cancels.
overlay.on('click', function() {
if(d3.event.target === overlay.node()) close();
});
buttons.append('button')
.classed('plotly-cloud-dialog-btn', true)
.classed('plotly-cloud-dialog-btn--cancel', true)
.text('Cancel')
.on('click', close);
buttons.append('button')
.classed('plotly-cloud-dialog-btn', true)
.classed('plotly-cloud-dialog-btn--confirm', true)
.text('Share')
.on('click', function() {
close();
onConfirm();
});
};