Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
130 lines (102 sloc) 2.92 KB
<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">
var options = ['To do', 'In progress', 'Done'];
jsPlumb.ready(function() {
var i = 0;
var saveState = function(state) {
$.post('http://www.example.com/saveState', {
id: $(state).attr('id'),
top: $(state).position().top,
left: $(state).position().left
});
}
$('#container').dblclick(function(e) {
var newState = $('<div>').attr('id', 'state' + i).addClass('item');
var title = $('<div>').addClass('title');
var stateName = $('<select>');
stateName.append($('<option></option>').attr('value', '#').text('Select an option'));
$.each(options, function(key, value) {
if ($('#container').find('#state-' + key).length == 0) {
stateName.append($('<option></option>')
.attr('value', key)
.text(value));
}
});
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.draggable(newState, {
containment: 'parent',
stop: function(event) {
if ($(event.target).find('select').length == 0) {
saveState(event.target);
}
}
});
newState.dblclick(function(e) {
jsPlumb.detachAllConnections($(this));
$(this).remove();
e.stopPropagation();
});
stateName.change(function(e) {
if (this.value !== '#') {
var state = $(this).closest('.item');
state.children('.title').text($(this).find(':selected').text());
state.attr('id', 'state-' + this.value);
$("select option[value='" + this.value + "']").remove();
jsPlumb.makeTarget(newState, {
anchor: 'Continuous'
});
jsPlumb.makeSource(connect, {
parent: newState,
anchor: 'Continuous'
});
saveState(state);
}
});
stateName.focus();
i++;
});
jsPlumb.bind('connection', function(info) {
$.post('http://www.example.com/saveConnection', { from: info.sourceId, to: info.targetId});
});
});
</script>
</html>
You can’t perform that action at this time.