forked from bpmn-io/bpmn-js-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
109 lines (84 loc) · 2.32 KB
/
index.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
<html>
<head>
<title>bpmn-js url viewer demo</title>
<!-- required viewer styles -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/assets/bpmn-js.css">
<style>
body {
font-family: 'Arial', sans-serif;
}
.header input[type=text] {
width: 500px;
max-width: 100%;
}
.console textarea {
width: 100%;
min-height: 80px;
border: none;
padding: 0;
}
.canvas {
border: solid 1px black;
}
</style>
</head>
<body>
<div class="header">
<h3>Open BPMN 2.0 diagram from URL</h3>
<p>
<input type="text" id="js-url" placeholder="path to diagram" /><button id="js-open">Open</button>
</p>
<p>
<strong>Hint:</strong> try <code>https://cdn.staticaly.com/gh/bpmn-io/bpmn-js-examples/dfceecba/url-viewer/resources/pizza-collaboration.bpmn</code></strong>
</p>
</div>
<div class="canvas">
<div id="js-canvas"></div>
</div>
<div class="console">
<h3>Console</h3>
<textarea id="js-console"></textarea>
</div>
<!-- viewer -->
<script src="https://unpkg.com/[email protected]/dist/bpmn-viewer.development.js"></script>
<!-- jquery (required for example only) -->
<script src="https://unpkg.com/[email protected]/dist/jquery.js"></script>
<!-- app -->
<script>
var viewer = new BpmnJS({
container: $('#js-canvas'),
height: 600
});
function log(str) {
var console = $('#js-console');
console.val(console.val() + str + '\n');
}
function openFromUrl(url) {
log('attempting to open <' + url + '>');
$.ajax(url, { dataType : 'text' }).done(async function(xml) {
try {
await viewer.importXML(xml);
viewer.get('canvas').zoom('fit-viewport');
log('success');
} catch (err) {
log('error: ' + err.message);
console.error(err);
}
});
}
$('#js-open').click(function() {
var url = $('#js-url').val();
openFromUrl(url);
});
///// auto open ?url=diagram-url ///////////////////////
(function() {
var str = window.location.search;
var match = /(?:\&|\?)url=([^&]+)/.exec(str);
if (match) {
var url = decodeURIComponent(match[1]);
$('#js-url').val(url);
openFromUrl(url);
}
})();
</script>
</html>