-
Notifications
You must be signed in to change notification settings - Fork 4
/
demo.html
124 lines (101 loc) · 2.68 KB
/
demo.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE>
<html>
<head>
<title>cytoscape-clipboard demo</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script src=" https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>
<!-- for testing with local version of cytoscape.js -->
<!--<script src="../cytoscape.js/build/cytoscape.js"></script>-->
<script src="src/cytoscape-undo-redo.js"></script>
<script src="cytoscape-clipboard.js"></script>
<style>
body {
font-family: helvetica neue, helvetica, liberation sans, arial, sans-serif;
font-size: 14px;
}
#cy {
z-index: 999;
width: 85%;
height: 85%;
float: left;
}
h1 {
opacity: 0.5;
font-size: 1em;
font-weight: bold;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function(){
var cy = window.cy = cytoscape({
container: document.getElementById('cy'),
style: [
{
selector: 'node',
style: {
'content': 'data(name)'
}
},
{
selector: 'edge',
style: {
'target-arrow-shape': 'triangle'
}
},
{
selector: ':selected',
style: {
}
}
],
elements: {
nodes: [
{ data: { id: 'j', name: 'Jerry' } },
{ data: { id: 'e', name: 'Elaine' } },
{ data: { id: 'k', name: 'Kramer', parent: "e" } },
{ data: { id: 'g', name: 'George' } },
{ data: { id: 's', name: 'Sara', parent: "a"} },
{ data: { id: 'a', name: 'Amy', parent: "r"} },
{ data: { id: 'r', name: 'Ross' } }
],
edges: [
{ data: { source: 'j', target: 'e' } },
{ data: { source: 'j', target: 'k' } },
{ data: { source: 'j', target: 'g' } },
{ data: { source: 'k', target: 'g' } }
],
},
});
var ur = cy.undoRedo({
undoableDrag: false
});
var cb = cy.clipboard();
document.addEventListener("keydown", function (e) {
if (e.ctrlKey && e.target.nodeName === 'BODY')
if (e.which == 67) // CTRL + C
{
cy.clipboard().copy(cy.$(":selected"));
}
else if (e.which == 86 ){ // CTRL + V
ur.do("paste");
}
else if (e.which == 65) {
cy.elements().select();
e.preventDefault();
}
else if(e.which==88){ // CTRL + X //
ur.do("cut");
}
});
});
</script>
</head>
<body>
<h1>cytoscape-clipboard demo</h1>
<b style="color: darkblue">CTRL+Z</b> to undo, <b style="color: darkblue">CTRL+Y</b> to redo <br/>
<b style="color: darkred">CTRL+X</b> to cut
<b style="color: darkred">CTRL+C</b> to copy, <b style="color: darkred">CTRL+V</b> to paste
<div id="cy"></div>
</body>
</html>