-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjQueryDragDrop.html
86 lines (82 loc) · 3.06 KB
/
jQueryDragDrop.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
<!DOCTYPE html>
<html>
<head>
<title>HTML Drag and Drop</title>
<meta name="description" content="Drag-and-drop HTML elements into a GoJS Diagram using jQuery." />
<!-- Copyright 1998-2016 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="go.js"></script>
<link href="../assets/css/goSamples.css" rel="stylesheet" type="text/css" /> <!-- you don't need to use this -->
<script src="goSamples.js"></script> <!-- this is only for the GoJS Samples framework -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<script id="code">
function init() {
if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this
// Note that we do not use $ here as an alias for go.GraphObject.make because we are using $ for jQuery
var $$ = go.GraphObject.make; // for conciseness in defining templates
myDiagram =
$$(go.Diagram, "myDiagramDiv", // must name or refer to the DIV HTML element
{ initialPosition: new go.Point(0, 0) });
myDiagram.nodeTemplate =
$$(go.Node, "Auto",
{ locationSpot: go.Spot.Center },
new go.Binding("location", "loc", go.Point.parse),
$$(go.Shape, "Ellipse",
{ fill: "white" }),
$$(go.TextBlock,
{ margin: 5 },
new go.Binding("text", "text").makeTwoWay()));
$("li").draggable({
stack: "#myDiagramDiv",
revert: true,
revertDuration: 0
});
$("#myDiagramDiv").droppable({
activeClass: "ui-state-highlight",
drop: function(event, ui) {
var elt = ui.draggable.first();
var text = elt.context.textContent;
var x = ui.offset.left - myDiagram.div.offsetLeft;
var y = ui.offset.top - myDiagram.div.offsetTop;
var p = new go.Point(x, y);
var q = myDiagram.transformViewToDoc(p);
var model = myDiagram.model;
model.startTransaction("drop");
model.addNodeData({
text: text,
loc: go.Point.stringify(q)
});
model.commitTransaction("drop");
}
});
}
</script>
</head>
<body onload="init()">
<div id="sample">
<div style="width:100%; white-space:nowrap;">
<span style="display: inline-block; vertical-align: top; width:20%">
<div id="myItems" style="border: solid 1px black; height: 700px">
<ul>
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
<li>Fifth</li>
</ul>
</div>
</span>
<span style="display: inline-block; vertical-align: top; width:80%">
<div id="myDiagramDiv" style="border: solid 1px black; height: 700px"></div>
</span>
</div>
<div id ="description">
<p>
This demonstrates using jQuery drag-and-drop capability to allow the user to drag HTML list items into a GoJS diagram.
</p>
</div>
</div>
</body>
</html>