forked from evolu8/seqwin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
255 lines (208 loc) · 12.3 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen">
<link rel="stylesheet" type="text/css" href="https://raw.githubusercontent.com/yuku-t/jquery-textcomplete/master/dist/jquery.textcomplete.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/pygment_trac.css" media="screen">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.2/raphael-min.js"></script>
<script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script src="http://bramp.github.io/js-sequence-diagrams/sequence-diagram-min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<!--script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script-->
<script src="https://togetherjs.com/togetherjs-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.4.0/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Base64/0.3.0/base64.min.js"></script>
<script src="./javascripts/jquery.textcomplete.js"></script>
<script src="./javascripts/jquery.autotype.js"></script>
<style>
/* Sample */
.dropdown-menu {
border: 1px solid #ddd;
background-color: white;
}
.dropdown-menu li {
border-top: 1px solid #ddd;
padding: 2px 5px;
}
.dropdown-menu li:first-child {
border-top: none;
}
.dropdown-menu li:hover,
.dropdown-menu .active {
background-color: rgb(110, 183, 219);
}
/* SHOULD not modify */
.dropdown-menu {
list-style: none;
padding: 0;
margin: 0;
}
.dropdown-menu a:hover {
cursor: pointer;
}
</style>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<title>Seqwin by evolu8</title>
</head>
<body>
<header>
<div class="inner">
<h1>Seqwin</h1>
<h2>Collaborative, sharable sequence diagrams</h2>
<a href="https://github.com/evolu8/seqwin" class="button"><small>View project on</small> GitHub</a>
</div>
</header>
<div id="content-wrapper">
<div class="inner clearfix">
<section id="main-content">
<p>
This is really just a cobbling togather of some real projects. Primarily (plus some usual suspects):
<ul>
<li>
<a href="http://bramp.github.io/js-sequence-diagrams/">JS Sequence Diagrams</a>
</li>
<li>
<a href="https://togetherjs.com/">TogetherJS</a>
</li>
</ul>
<button onclick="TogetherJS(this); return false;">
Collaborate
</button>
<a id="downloadToTHML" download="sequin-launcher.html" href="data:text/plain;charset=utf-8,">
Download sharable file
</a>
</p>
<section id="demo">
<table align="center" class="inner">
<tr>
<td><h3>Demo. Try editing me below</h3>
<div class="editor-wrapper">
<textarea style = "width:400px; height:90%px; padding:20px; line-height:2;" class="editor"></textarea>
</div> Theme:
<select class="theme">
<option value="simple" selected>Simple</option>
<option value="hand" >Hand drawn</option>
</select> | <a href="#" class="download">Download as SVG</a></td>
<td class="diagram">This should be a diagram! If you don't see it you need Javascript enabled</td>
</tr>
</table>
<p>
The long hash contains the data for the diagram, so it can be shared and used, even without any dynamic server. Your data does not get passed to us, or github.
</p>
<p>If you want total control and security, then host the dependancies yourself and use your own copy of the TogetherJS server (this really isn't required, as your data doesn't go to Mozilla either)</p>
<script type="text/javascript">
var seqwin = {};
window.seqwin = seqwin;
function setup_editor(div) {
var editor_div = div.find(".editor");
var diagram_div = div.find(".diagram");
var theme_div = div.find(".theme");
var download_link = div.find('.download');
editor_div.keyup = function() {
_.debounce(on_change(), 100);
};
download_link.click(function(ev) {
var svg = diagram_div.find('svg')[0];
var width = parseInt(svg.width.baseVal.value);
var height = parseInt(svg.height.baseVal.value);
var data = $(".editor").val();
var xml = '<?xml version="1.0" encoding="utf-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"><svg xmlns="http://www.w3.org/2000/svg" width="' + width + '" height="' + height + '" xmlns:xlink="http://www.w3.org/1999/xlink"><source><![CDATA[' + data + ']]></source>' + svg.innerHTML + '</svg>';
var a = $(this);
a.attr("download", "diagram.svg");
// TODO I could put title here
a.attr("href", "data:image/svg+xml," + encodeURIComponent(xml));
});
theme_div.change(on_change);
if (location.hash) {
var payload = location.hash.substr(1);
payload = payload.split("&")[0];
var zip = new JSZip();
zip.load(payload, {
base64 : true
});
var unzipped = zip.generate({
type : "string"
});
unzipped = unzipped.substr(unzipped.indexOf("temp") + 4);
var content = unzipped.substr(0, unzipped.indexOf("eof"));
$(".editor").val(content)
}
on_change();
$("textarea").keyup(_.debounce(on_change, 100));
//$("textarea").click(_.debounce(editor_div.click, 100));
//$("textarea").change(_.debounce(editor_div.click, 100));
function on_change() {
try {
var zip = new JSZip();
var str = $(".editor").val();
seqwin = Diagram.parse(str);
var zipped = zip.file('temp', str + "eof");
window.location.hash = zip.generate('temp', {
type : "base64",
compression : "DEFLATE"
});
$.get("./template.html", function(data){
var tmpl = _.template(data);
$("#downloadToTHML").attr("href", "data:text/plain;charset=utf-8," + encodeURIComponent(tmpl({'redirecturl':location.href})));
})
// Clear out old diagram
diagram_div.html('');
var options = {
theme : theme_div.val(),
scale : 1
};
// Draw
seqwin.drawSVG(diagram_div.get(0), options);
//adding textcomplete
$('textarea').textcomplete([{
match: /\b(\w{2,})$/,
search: function (term, callback) {
var words = ['title:', 'note over', 'note right'].concat(_.pluck(seqwin.actors, "alias"));
callback($.map(words, function (word) {
return word.indexOf(term) === 0 ? word : null;
}));
},
replace: function (word) {
return word + ' ';
}
}], { appendTo: $('body') });
} catch(err) {
var annotation = {
type : "error", // also warning and information
column : 0,
row : 0,
text : err.message
};
if ( err instanceof Diagram.ParseError) {
annotation.row = err.loc.first_line - 1;
annotation.column = err.loc.first_column;
}
}
}
}
$(document).ready(function() {
setup_editor($('#demo'));
setInterval(function(){$("textarea").height( $("textarea")[0].scrollHeight - 50 );}, 1);
if ($('textarea').val()==""){
$('textarea').focus();
$('textarea').autotype('title: Hello World!{{enter}}' +
'Me -> World: "Hello!"{{enter}}' +
'Wor{{down}}', {delay: 125}
);
}
});
$('textarea').focus();
</script>
</section>
</div>
</div>
</body>
</html>