-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
390 lines (330 loc) · 11.5 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link type="text/css" rel="stylesheet" href="jsmind.css" />
<script type="text/javascript" src="jsmind.js"></script>
<script type="text/javascript" src="jsmind.draggable.js"></script>
<script type="text/javascript" src="jsmind.screenshot.js"></script>
</head>
<body>
<div id="jsmind_container"></div>
<script type="text/javascript">
var _jm = null;
var _cur_nodeid = null;
var options = {
container:'jsmind_container',
editable:true
}
function change_background_color(color) {
var selected_id = get_selected_nodeid();
if(selected_id) {
_jm.set_node_color(selected_id, color, null);
}
}
function change_text_color(color) {
var selected_id = get_selected_nodeid();
if(selected_id) {
_jm.set_node_color(selected_id, null, color);
}
}
function select_root_node() {
_jm.select_node("root");
}
function init_root_node() {
_jm = jsMind.show(options);
}
function init_background(color) {
document.getElementById("jsmind_container").style.backgroundColor = color;
}
function get_root_node_topic() {
return _jm.get_node("root").topic;
}
function get_node_topic() {
var selected_node = _jm.get_selected_node(); // as parent of new node
if (selected_node) {
return selected_node.topic;
} else {
return ""
}
}
function add_sub_node(inline=false){
var selected_node = _jm.get_selected_node(); // as parent of new node
if(!selected_node) {
_jm.move_node(selected_id,'_first_');
}
var nodeid = jsMind.util.uuid.newid();
var node = _jm.add_node(selected_node, nodeid, 'Topic');
_jm.select_node(node);
if (inline) {
_jm.begin_edit(node);
}
}
function add_texted_sub_node(text){
var selected_node = _jm.get_selected_node(); // as parent of new node
if(!selected_node) {
_jm.move_node(selected_id,'_first_');
}
var nodeid = jsMind.util.uuid.newid();
_jm.add_node(selected_node, nodeid, text);
}
function add_brother_node(inline=false){
var selected_node = _jm.get_selected_node(); // as parent of new node
if(!selected_node) {
_jm.move_node(selected_id,'_first_');
}
if(_jm.view.is_editing()) {
_jm.end_edit();
} else {
var nodeid = jsMind.util.uuid.newid();
var node = _jm.insert_node_after(selected_node, nodeid, 'Topic');
_jm.select_node(node);
if (inline) {
_jm.begin_edit(node);
}
}
}
function add_texted_brother_node(text){
var selected_node = _jm.get_selected_node(); // as parent of new node
if(!selected_node) {
_jm.move_node(selected_id,'_first_');
}
if(_jm.view.is_editing()) {
_jm.end_edit();
} else {
var nodeid = jsMind.util.uuid.newid();
_jm.insert_node_after(selected_node, nodeid, text);
}
}
function get_selected_nodeid(){
var selected_node = _jm.get_selected_node();
if(!!selected_node){
return selected_node.id;
}else{
return null;
}
}
function remove_node(){
var selected_id = get_selected_nodeid();
if(selected_id) {
_jm.select_node(_jm.get_selected_node().parent);
_jm.remove_node(selected_id);
}
}
function update_node_topic(topic) {
var selected_id = get_selected_nodeid();
if (selected_id) {
_jm.update_node(selected_id, topic);
}
}
function update_node_topic_inline() {
var selected_id = get_selected_nodeid();
if (selected_id) {
_jm.begin_edit(selected_id);
}
}
function zoom_in() {
_jm.view.zoom_in();
};
function zoom_out() {
_jm.view.zoom_out();
};
function zoom_reset() {
_jm.view.set_zoom(1);
}
function select_up_node(){
var selected_node = _jm.get_selected_node();
if(!!selected_node){
var up_node = _jm.find_node_before(selected_node);
if(!up_node){
var np = _jm.find_node_before(selected_node.parent);
if(!!np && np.children.length > 0){
up_node = np.children[np.children.length-1];
}
}
if(!!up_node){
_jm.select_node(up_node);
}
}
}
function select_down_node(){
var selected_node = _jm.get_selected_node();
if(!!selected_node){
var down_node = _jm.find_node_after(selected_node);
if(!down_node){
var np = _jm.find_node_after(selected_node.parent);
if(!!np && np.children.length > 0){
down_node = np.children[0];
}
}
if(!!down_node){
_jm.select_node(down_node);
}
}
}
function select_left_node(){
select_relative_node(-1);
}
function select_right_node(){
select_relative_node(1);
}
function select_relative_node(d){
var selected_node = _jm.get_selected_node();
var node = null;
if(!!selected_node){
if(selected_node.isroot){
var c = selected_node.children;
var children = [];
for(var i=0;i<c.length;i++){
if(c[i].direction === d){
children.push(i)
}
}
node = c[children[Math.floor((children.length-1)/2)]];
}
else if(selected_node.direction === d){
var children = selected_node.children;
var childrencount = children.length;
if(childrencount > 0){
node = children[Math.floor((childrencount-1)/2)]
}
}else{
node = selected_node.parent;
}
if(!!node){
_jm.select_node(node);
}
}
}
function node_is_focus() {
return _jm.view.is_editing();
}
function toggle_node() {
var selected_node = _jm.get_selected_node(); // as parent of new node
if (selected_node) {
_jm.toggle_node(selected_node);
}
}
function toggle_node_selection() {
var nodeid = get_selected_nodeid();
if (!!nodeid){
_cur_nodeid = nodeid;
_jm.select_clear();
}else{
_jm.select_node(_cur_nodeid || "root");
_cur_nodeid = null;
}
}
function save_screenshot() {
_jm.screenshot.shootDownload();
}
function refresh(file_base64_content) {
var file_data = decodeURIComponent(escape(window.atob(file_base64_content)));
var mind = jsMind.util.json.string2json(file_data);
if(!!mind){
_jm.show(mind);
select_root_node();
}
}
function open_file(file_base64_content, is_freemind=false) {
init_root_node();
var file_data = decodeURIComponent(escape(window.atob(file_base64_content)));
var mind = null;
if (is_freemind) {
mind = convert_freemind_to_jsmind(file_data);
} else {
mind = jsMind.util.json.string2json(file_data);
}
if(!!mind){
_jm.show(mind);
select_root_node();
}
}
function save_file() {
return jsMind.util.json.json2string(_jm.get_data());
}
function save_freemind_file() {
var df = 'freemind';
return _jm.get_data(df).data;
}
function convert_freemind_to_jsmind(freemind) {
return {
"meta":{
"name": _jm.mind.name,
"author": _jm.mind.author,
"version": _jm.mind.version
},
"format": "freemind",
"data": freemind
}
}
function change_node_background(image) {
var selected_id = get_selected_nodeid();
if(selected_id) {
_jm.set_node_background_image(selected_id, "file://" + image);
}
}
function relayout() {
_jm.view.relayout();
}
function paste_node_tree(src_node_id) {
/* var selected_node = _jm.get_selected_node();
* if(!!selected_node){
* var src_node = _jm.get_node(src_node_id);
* _jm.move_node(src_node, selected_node, selected_node.direction);
* } */
var selected_node = _jm.get_selected_node();
if(!!selected_node){
var src_node = _jm.get_node(src_node_id);
_jm.move_node(src_node, src_node_id, selected_node.id, selected_node.direction);
}
}
function remove_middle_node() {
var selected_node = _jm.get_selected_node();
if(!!selected_node){
var children = selected_node.children;
for (var i = 0; i < children.length; i++) {
var child = children[i];
_jm.move_node(child, child.id, selected_node.parent.id, selected_node.parent.direction);
}
_jm.select_node(selected_node.parent);
_jm.remove_node(selected_node.id);
}
}
function add_middle_node(inline=false) {
var selected_node = _jm.get_selected_node(); // as parent of new node
if(!!selected_node) {
var topic = selected_node.topic;
add_brother_node(false);
var brother_node = _jm.get_selected_node();
_jm.update_node(brother_node.id, topic);
_jm.update_node(selected_node.id, "Topic");
_jm.move_node(selected_node, selected_node.id, brother_node.id, brother_node.direction);
_jm.select_node(selected_node);
if (inline) {
_jm.begin_edit(selected_node);
}
}
}
function add_texted_middle_node(text){
var selected_node = _jm.get_selected_node(); // as parent of new node
if(!!selected_node) {
var topic = selected_node.topic;
if(_jm.view.is_editing()) {
_jm.end_edit();
} else {
var nodeid = jsMind.util.uuid.newid();
var node = _jm.insert_node_after(selected_node, nodeid, text);
_jm.select_node(node);
}
var brother_node = _jm.get_selected_node();
_jm.update_node(brother_node.id, topic);
_jm.update_node(selected_node.id, text);
_jm.move_node(selected_node, selected_node.id, brother_node.id, brother_node.direction);
_jm.select_node(selected_node);
}
}
</script>
</body>
</html>