forked from EmielH/jsplumb-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
naming-states-input-text.html
99 lines (76 loc) · 1.89 KB
/
naming-states-input-text.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
<html>
<head>
<script type="text/javascript" src="js/jquery-2.1.1.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.11.1.js"></script>
<script type="text/javascript" src="js/jquery.jsPlumb-1.6.4.js"></script>
<style type="text/css">
.item {
position: absolute;
border: 1px solid black;
background-color: #ddddff;
}
#container {
border: 1px solid gray;
width: 500px;
height: 500px;
}
.title {
padding: 10px;
cursor: move;
}
.connect {
width: 100%;
height: 20px;
background-color: white;
cursor: pointer;
}
</style>
<title>Getting started with jsPlumb</title>
</head>
<body>
<div id="container"></div>
</body>
<script type="text/javascript">
jsPlumb.ready(function() {
var i = 0;
$('#container').dblclick(function(e) {
var newState = $('<div>').attr('id', 'state' + i).addClass('item');
var title = $('<div>').addClass('title');
var stateName = $('<input>').attr('type', 'text');
title.append(stateName);
var connect = $('<div>').addClass('connect');
newState.css({
'top': e.pageY,
'left': e.pageX
});
newState.append(title);
newState.append(connect);
$('#container').append(newState);
jsPlumb.makeTarget(newState, {
anchor: 'Continuous'
});
jsPlumb.makeSource(connect, {
parent: newState,
anchor: 'Continuous'
});
jsPlumb.draggable(newState, {
containment: 'parent'
});
newState.dblclick(function(e) {
jsPlumb.detachAllConnections($(this));
$(this).remove();
e.stopPropagation();
});
stateName.keyup(function(e) {
if (e.keyCode === 13) {
//var state = $(this).closest('.item');
//state.children('.title').text(this.value);
$(this).parent().text(this.value);
}
});
stateName.focus();
i++;
});
});
</script>
</html>