jsmind 0.4.4 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +1 -0
- package/docs/en/1.usage.md +7 -8
- package/docs/en/2.options.md +208 -1
- package/docs/en/3.operation.md +136 -1
- package/docs/en/4.contribution.md +34 -0
- package/docs/en/index.md +22 -12
- package/docs/zh/1.usage.md +18 -17
- package/docs/zh/2.options.md +47 -7
- package/docs/zh/3.operation.md +13 -5
- package/docs/zh/4.contribution.md +34 -0
- package/docs/zh/index.md +1 -1
- package/example/2_features.html +6 -4
- package/example/3_mathjax.html +104 -0
- package/features/jsmind.shell.js +40 -40
- package/js/jsmind.draggable.js +124 -120
- package/js/jsmind.js +1163 -995
- package/js/jsmind.screenshot.js +137 -135
- package/package.json +1 -1
- package/style/jsmind.css +4 -3
package/js/jsmind.js
CHANGED
|
@@ -1,88 +1,100 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Released under BSD License
|
|
3
|
-
* Copyright (c) 2014-
|
|
4
|
-
*
|
|
3
|
+
* Copyright (c) 2014-2021 hizzgdev@163.com
|
|
4
|
+
*
|
|
5
5
|
* Project Home:
|
|
6
6
|
* https://github.com/hizzgdev/jsmind/
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
(function($w){
|
|
10
|
-
'use strict';
|
|
9
|
+
; (function ($w) {
|
|
10
|
+
'use strict';
|
|
11
11
|
// set 'jsMind' as the library name.
|
|
12
12
|
// __name__ should be a const value, Never try to change it easily.
|
|
13
13
|
var __name__ = 'jsMind';
|
|
14
14
|
// library version
|
|
15
|
-
var __version__ = '0.4.
|
|
15
|
+
var __version__ = '0.4.8';
|
|
16
16
|
// author
|
|
17
17
|
var __author__ = 'hizzgdev@163.com';
|
|
18
18
|
|
|
19
19
|
// an noop function define
|
|
20
|
-
var _noop = function(){};
|
|
21
|
-
var logger = (typeof console === 'undefined')?{
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
var _noop = function () { };
|
|
21
|
+
var logger = (typeof console === 'undefined') ? {
|
|
22
|
+
log: _noop, debug: _noop, error: _noop, warn: _noop, info: _noop
|
|
23
|
+
} : console;
|
|
24
24
|
|
|
25
25
|
// check global variables
|
|
26
|
-
if(typeof module === 'undefined' || !module.exports){
|
|
27
|
-
if(typeof $w[__name__] != 'undefined'){
|
|
28
|
-
logger.log(__name__+' has been already exist.');
|
|
26
|
+
if (typeof module === 'undefined' || !module.exports) {
|
|
27
|
+
if (typeof $w[__name__] != 'undefined') {
|
|
28
|
+
logger.log(__name__ + ' has been already exist.');
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// shortcut of methods in dom
|
|
34
34
|
var $d = $w.document;
|
|
35
|
-
var $g = function(id){return $d.getElementById(id);};
|
|
36
|
-
var $c = function(tag){return $d.createElement(tag);};
|
|
37
|
-
var $t = function(n,t){if(n.hasChildNodes()){n.firstChild.nodeValue = t;}else{n.appendChild($d.createTextNode(t));}};
|
|
38
|
-
|
|
35
|
+
var $g = function (id) { return $d.getElementById(id); };
|
|
36
|
+
var $c = function (tag) { return $d.createElement(tag); };
|
|
37
|
+
var $t = function (n, t) { if (n.hasChildNodes()) { n.firstChild.nodeValue = t; } else { n.appendChild($d.createTextNode(t)); } };
|
|
38
|
+
|
|
39
|
+
var $h = function (n, t) {
|
|
40
|
+
if (t instanceof HTMLElement) {
|
|
41
|
+
n.innerHTML = '';
|
|
42
|
+
n.appendChild(t);
|
|
43
|
+
} else {
|
|
44
|
+
n.innerHTML = t;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
39
47
|
// detect isElement
|
|
40
|
-
var $i = function(el){return !!el&&(typeof el==='object')&&(el.nodeType===1)&&(typeof el.style==='object')&&(typeof el.ownerDocument==='object');};
|
|
41
|
-
if(typeof String.prototype.startsWith != 'function'){String.prototype.startsWith=function(p){return this.slice(0,p.length)===p;};}
|
|
48
|
+
var $i = function (el) { return !!el && (typeof el === 'object') && (el.nodeType === 1) && (typeof el.style === 'object') && (typeof el.ownerDocument === 'object'); };
|
|
49
|
+
if (typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function (p) { return this.slice(0, p.length) === p; }; }
|
|
42
50
|
|
|
43
51
|
var DEFAULT_OPTIONS = {
|
|
44
|
-
container
|
|
45
|
-
editable
|
|
46
|
-
theme
|
|
47
|
-
mode
|
|
48
|
-
support_html
|
|
49
|
-
|
|
50
|
-
view:{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
container: '', // id of the container
|
|
53
|
+
editable: false, // you can change it in your options
|
|
54
|
+
theme: null,
|
|
55
|
+
mode: 'full', // full or side
|
|
56
|
+
support_html: true,
|
|
57
|
+
|
|
58
|
+
view: {
|
|
59
|
+
engine: 'canvas',
|
|
60
|
+
hmargin: 100,
|
|
61
|
+
vmargin: 50,
|
|
62
|
+
line_width: 2,
|
|
63
|
+
line_color: '#555',
|
|
64
|
+
draggable: false, // drag the mind map with your mouse, when it's larger that the container
|
|
65
|
+
hide_scrollbars_when_draggable: false // hide container scrollbars, when mind map is larger than container and draggable option is true.
|
|
66
|
+
},
|
|
67
|
+
layout: {
|
|
68
|
+
hspace: 30,
|
|
69
|
+
vspace: 20,
|
|
70
|
+
pspace: 13
|
|
71
|
+
},
|
|
72
|
+
default_event_handle: {
|
|
73
|
+
enable_mousedown_handle: true,
|
|
74
|
+
enable_click_handle: true,
|
|
75
|
+
enable_dblclick_handle: true,
|
|
76
|
+
enable_mousewheel_handle: true
|
|
77
|
+
},
|
|
78
|
+
shortcut: {
|
|
79
|
+
enable: true,
|
|
80
|
+
handles: {
|
|
69
81
|
},
|
|
70
|
-
mapping:{
|
|
71
|
-
addchild
|
|
72
|
-
addbrother
|
|
73
|
-
editnode
|
|
74
|
-
delnode
|
|
75
|
-
toggle
|
|
76
|
-
left
|
|
77
|
-
up
|
|
78
|
-
right
|
|
79
|
-
down
|
|
82
|
+
mapping: {
|
|
83
|
+
addchild: 45, // Insert
|
|
84
|
+
addbrother: 13, // Enter
|
|
85
|
+
editnode: 113,// F2
|
|
86
|
+
delnode: 46, // Delete
|
|
87
|
+
toggle: 32, // Space
|
|
88
|
+
left: 37, // Left
|
|
89
|
+
up: 38, // Up
|
|
90
|
+
right: 39, // Right
|
|
91
|
+
down: 40, // Down
|
|
80
92
|
}
|
|
81
93
|
},
|
|
82
94
|
};
|
|
83
95
|
|
|
84
96
|
// core object
|
|
85
|
-
var jm = function(options){
|
|
97
|
+
var jm = function (options) {
|
|
86
98
|
jm.current = this;
|
|
87
99
|
|
|
88
100
|
this.version = __version__;
|
|
@@ -90,7 +102,7 @@
|
|
|
90
102
|
jm.util.json.merge(opts, DEFAULT_OPTIONS);
|
|
91
103
|
jm.util.json.merge(opts, options);
|
|
92
104
|
|
|
93
|
-
if(!opts.container){
|
|
105
|
+
if (!opts.container) {
|
|
94
106
|
logger.error('the options.container should not be null or empty.');
|
|
95
107
|
return;
|
|
96
108
|
}
|
|
@@ -102,13 +114,14 @@
|
|
|
102
114
|
};
|
|
103
115
|
|
|
104
116
|
// ============= static object =============================================
|
|
105
|
-
jm.direction = {left
|
|
106
|
-
jm.event_type = {show:1,resize:2,edit:3,select:4};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if(
|
|
111
|
-
if(typeof
|
|
117
|
+
jm.direction = { left: -1, center: 0, right: 1 };
|
|
118
|
+
jm.event_type = { show: 1, resize: 2, edit: 3, select: 4 };
|
|
119
|
+
jm.key = { meta: 1 << 13, ctrl: 1 << 12, alt: 1 << 11, shift: 1 << 10 };
|
|
120
|
+
|
|
121
|
+
jm.node = function (sId, iIndex, sTopic, oData, bIsRoot, oParent, eDirection, bExpanded) {
|
|
122
|
+
if (!sId) { logger.error('invalid nodeid'); return; }
|
|
123
|
+
if (typeof iIndex != 'number') { logger.error('invalid node index'); return; }
|
|
124
|
+
if (typeof bExpanded === 'undefined') { bExpanded = true; }
|
|
112
125
|
this.id = sId;
|
|
113
126
|
this.index = iIndex;
|
|
114
127
|
this.topic = sTopic;
|
|
@@ -121,39 +134,39 @@
|
|
|
121
134
|
this._data = {};
|
|
122
135
|
};
|
|
123
136
|
|
|
124
|
-
jm.node.compare=function(node1,node2){
|
|
137
|
+
jm.node.compare = function (node1, node2) {
|
|
125
138
|
// '-1' is alwary the last
|
|
126
139
|
var r = 0;
|
|
127
140
|
var i1 = node1.index;
|
|
128
141
|
var i2 = node2.index;
|
|
129
|
-
if(i1>=0 && i2>=0){
|
|
130
|
-
r = i1-i2;
|
|
131
|
-
}else if(i1
|
|
142
|
+
if (i1 >= 0 && i2 >= 0) {
|
|
143
|
+
r = i1 - i2;
|
|
144
|
+
} else if (i1 == -1 && i2 == -1) {
|
|
132
145
|
r = 0;
|
|
133
|
-
}else if(i1
|
|
146
|
+
} else if (i1 == -1) {
|
|
134
147
|
r = 1;
|
|
135
|
-
}else if(i2
|
|
148
|
+
} else if (i2 == -1) {
|
|
136
149
|
r = -1;
|
|
137
|
-
}else{
|
|
150
|
+
} else {
|
|
138
151
|
r = 0;
|
|
139
152
|
}
|
|
140
153
|
//logger.debug(i1+' <> '+i2+' = '+r);
|
|
141
154
|
return r;
|
|
142
155
|
};
|
|
143
156
|
|
|
144
|
-
jm.node.inherited=function(pnode,node){
|
|
145
|
-
if(!!pnode && !!node){
|
|
146
|
-
if(pnode.id === node.id){
|
|
157
|
+
jm.node.inherited = function (pnode, node) {
|
|
158
|
+
if (!!pnode && !!node) {
|
|
159
|
+
if (pnode.id === node.id) {
|
|
147
160
|
return true;
|
|
148
161
|
}
|
|
149
|
-
if(pnode.isroot){
|
|
162
|
+
if (pnode.isroot) {
|
|
150
163
|
return true;
|
|
151
164
|
}
|
|
152
165
|
var pid = pnode.id;
|
|
153
166
|
var p = node;
|
|
154
|
-
while(!p.isroot){
|
|
167
|
+
while (!p.isroot) {
|
|
155
168
|
p = p.parent;
|
|
156
|
-
if(p.id === pid){
|
|
169
|
+
if (p.id === pid) {
|
|
157
170
|
return true;
|
|
158
171
|
}
|
|
159
172
|
}
|
|
@@ -162,24 +175,24 @@
|
|
|
162
175
|
};
|
|
163
176
|
|
|
164
177
|
jm.node.prototype = {
|
|
165
|
-
get_location:function(){
|
|
178
|
+
get_location: function () {
|
|
166
179
|
var vd = this._data.view;
|
|
167
180
|
return {
|
|
168
|
-
x:vd.abs_x,
|
|
169
|
-
y:vd.abs_y
|
|
181
|
+
x: vd.abs_x,
|
|
182
|
+
y: vd.abs_y
|
|
170
183
|
};
|
|
171
184
|
},
|
|
172
|
-
get_size:function(){
|
|
185
|
+
get_size: function () {
|
|
173
186
|
var vd = this._data.view;
|
|
174
187
|
return {
|
|
175
|
-
w:vd.width,
|
|
176
|
-
h:vd.height
|
|
188
|
+
w: vd.width,
|
|
189
|
+
h: vd.height
|
|
177
190
|
}
|
|
178
191
|
}
|
|
179
192
|
};
|
|
180
193
|
|
|
181
194
|
|
|
182
|
-
jm.mind = function(){
|
|
195
|
+
jm.mind = function () {
|
|
183
196
|
this.name = null;
|
|
184
197
|
this.author = null;
|
|
185
198
|
this.version = null;
|
|
@@ -189,101 +202,103 @@
|
|
|
189
202
|
};
|
|
190
203
|
|
|
191
204
|
jm.mind.prototype = {
|
|
192
|
-
get_node:function(nodeid){
|
|
193
|
-
if(nodeid in this.nodes){
|
|
205
|
+
get_node: function (nodeid) {
|
|
206
|
+
if (nodeid in this.nodes) {
|
|
194
207
|
return this.nodes[nodeid];
|
|
195
|
-
}else{
|
|
196
|
-
logger.warn('the node[id='+nodeid+'] can not be found');
|
|
208
|
+
} else {
|
|
209
|
+
logger.warn('the node[id=' + nodeid + '] can not be found');
|
|
197
210
|
return null;
|
|
198
211
|
}
|
|
199
212
|
},
|
|
200
213
|
|
|
201
|
-
set_root:function(nodeid, topic, data){
|
|
202
|
-
if(this.root == null){
|
|
214
|
+
set_root: function (nodeid, topic, data) {
|
|
215
|
+
if (this.root == null) {
|
|
203
216
|
this.root = new jm.node(nodeid, 0, topic, data, true);
|
|
204
217
|
this._put_node(this.root);
|
|
205
|
-
}else{
|
|
218
|
+
} else {
|
|
206
219
|
logger.error('root node is already exist');
|
|
207
220
|
}
|
|
208
221
|
},
|
|
209
222
|
|
|
210
|
-
add_node:function(parent_node, nodeid, topic, data, idx, direction, expanded){
|
|
211
|
-
if(!jm.util.is_node(parent_node)){
|
|
223
|
+
add_node: function (parent_node, nodeid, topic, data, idx, direction, expanded) {
|
|
224
|
+
if (!jm.util.is_node(parent_node)) {
|
|
212
225
|
var the_parent_node = this.get_node(parent_node);
|
|
213
|
-
if(!the_parent_node){
|
|
214
|
-
logger.error('the parent_node[id='+parent_node+'] can not be found.');
|
|
226
|
+
if (!the_parent_node) {
|
|
227
|
+
logger.error('the parent_node[id=' + parent_node + '] can not be found.');
|
|
215
228
|
return null;
|
|
216
|
-
}else{
|
|
229
|
+
} else {
|
|
217
230
|
return this.add_node(the_parent_node, nodeid, topic, data, idx, direction, expanded);
|
|
218
231
|
}
|
|
219
232
|
}
|
|
220
233
|
var nodeindex = idx || -1;
|
|
221
234
|
var node = null;
|
|
222
|
-
if(parent_node.isroot){
|
|
235
|
+
if (parent_node.isroot) {
|
|
223
236
|
var d = jm.direction.right;
|
|
224
|
-
if(isNaN(direction)){
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
237
|
+
if (isNaN(direction)) {
|
|
238
|
+
if (jm.current.options.mode !== 'side') {
|
|
239
|
+
var children = parent_node.children;
|
|
240
|
+
var children_len = children.length;
|
|
241
|
+
var r = 0;
|
|
242
|
+
for (var i = 0; i < children_len; i++) { if (children[i].direction === jm.direction.left) { r--; } else { r++; } }
|
|
243
|
+
d = (children_len > 1 && r > 0) ? jm.direction.left : jm.direction.right;
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
231
246
|
d = (direction != jm.direction.left) ? jm.direction.right : jm.direction.left;
|
|
232
247
|
}
|
|
233
|
-
node = new jm.node(nodeid,nodeindex,topic,data,false,parent_node,d,expanded);
|
|
234
|
-
}else{
|
|
235
|
-
node = new jm.node(nodeid,nodeindex,topic,data,false,parent_node,parent_node.direction,expanded);
|
|
248
|
+
node = new jm.node(nodeid, nodeindex, topic, data, false, parent_node, d, expanded);
|
|
249
|
+
} else {
|
|
250
|
+
node = new jm.node(nodeid, nodeindex, topic, data, false, parent_node, parent_node.direction, expanded);
|
|
236
251
|
}
|
|
237
|
-
if(this._put_node(node)){
|
|
252
|
+
if (this._put_node(node)) {
|
|
238
253
|
parent_node.children.push(node);
|
|
239
254
|
this._reindex(parent_node);
|
|
240
|
-
}else{
|
|
241
|
-
logger.error('fail, the nodeid \''+node.id+'\' has been already exist.');
|
|
255
|
+
} else {
|
|
256
|
+
logger.error('fail, the nodeid \'' + node.id + '\' has been already exist.');
|
|
242
257
|
node = null;
|
|
243
258
|
}
|
|
244
259
|
return node;
|
|
245
260
|
},
|
|
246
261
|
|
|
247
|
-
insert_node_before:function(node_before, nodeid, topic, data){
|
|
248
|
-
if(!jm.util.is_node(node_before)){
|
|
262
|
+
insert_node_before: function (node_before, nodeid, topic, data) {
|
|
263
|
+
if (!jm.util.is_node(node_before)) {
|
|
249
264
|
var the_node_before = this.get_node(node_before);
|
|
250
|
-
if(!the_node_before){
|
|
251
|
-
logger.error('the node_before[id='+node_before+'] can not be found.');
|
|
265
|
+
if (!the_node_before) {
|
|
266
|
+
logger.error('the node_before[id=' + node_before + '] can not be found.');
|
|
252
267
|
return null;
|
|
253
|
-
}else{
|
|
268
|
+
} else {
|
|
254
269
|
return this.insert_node_before(the_node_before, nodeid, topic, data);
|
|
255
270
|
}
|
|
256
271
|
}
|
|
257
|
-
var node_index = node_before.index-0.5;
|
|
272
|
+
var node_index = node_before.index - 0.5;
|
|
258
273
|
return this.add_node(node_before.parent, nodeid, topic, data, node_index);
|
|
259
274
|
},
|
|
260
275
|
|
|
261
|
-
get_node_before:function(node){
|
|
262
|
-
if(!jm.util.is_node(node)){
|
|
276
|
+
get_node_before: function (node) {
|
|
277
|
+
if (!jm.util.is_node(node)) {
|
|
263
278
|
var the_node = this.get_node(node);
|
|
264
|
-
if(!the_node){
|
|
265
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
279
|
+
if (!the_node) {
|
|
280
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
266
281
|
return null;
|
|
267
|
-
}else{
|
|
282
|
+
} else {
|
|
268
283
|
return this.get_node_before(the_node);
|
|
269
284
|
}
|
|
270
285
|
}
|
|
271
|
-
if(node.isroot){return null;}
|
|
286
|
+
if (node.isroot) { return null; }
|
|
272
287
|
var idx = node.index - 2;
|
|
273
|
-
if(idx >= 0){
|
|
288
|
+
if (idx >= 0) {
|
|
274
289
|
return node.parent.children[idx];
|
|
275
|
-
}else{
|
|
290
|
+
} else {
|
|
276
291
|
return null;
|
|
277
292
|
}
|
|
278
293
|
},
|
|
279
294
|
|
|
280
|
-
insert_node_after:function(node_after, nodeid, topic, data){
|
|
281
|
-
if(!jm.util.is_node(node_after)){
|
|
282
|
-
var the_node_after = this.get_node(
|
|
283
|
-
if(!the_node_after){
|
|
284
|
-
logger.error('the node_after[id='+node_after+'] can not be found.');
|
|
295
|
+
insert_node_after: function (node_after, nodeid, topic, data) {
|
|
296
|
+
if (!jm.util.is_node(node_after)) {
|
|
297
|
+
var the_node_after = this.get_node(node_after);
|
|
298
|
+
if (!the_node_after) {
|
|
299
|
+
logger.error('the node_after[id=' + node_after + '] can not be found.');
|
|
285
300
|
return null;
|
|
286
|
-
}else{
|
|
301
|
+
} else {
|
|
287
302
|
return this.insert_node_after(the_node_after, nodeid, topic, data);
|
|
288
303
|
}
|
|
289
304
|
}
|
|
@@ -291,65 +306,65 @@
|
|
|
291
306
|
return this.add_node(node_after.parent, nodeid, topic, data, node_index);
|
|
292
307
|
},
|
|
293
308
|
|
|
294
|
-
get_node_after:function(node){
|
|
295
|
-
if(!jm.util.is_node(node)){
|
|
309
|
+
get_node_after: function (node) {
|
|
310
|
+
if (!jm.util.is_node(node)) {
|
|
296
311
|
var the_node = this.get_node(node);
|
|
297
|
-
if(!the_node){
|
|
298
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
312
|
+
if (!the_node) {
|
|
313
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
299
314
|
return null;
|
|
300
|
-
}else{
|
|
315
|
+
} else {
|
|
301
316
|
return this.get_node_after(the_node);
|
|
302
317
|
}
|
|
303
318
|
}
|
|
304
|
-
if(node.isroot){return null;}
|
|
319
|
+
if (node.isroot) { return null; }
|
|
305
320
|
var idx = node.index;
|
|
306
321
|
var brothers = node.parent.children;
|
|
307
|
-
if(brothers.length >= idx){
|
|
322
|
+
if (brothers.length >= idx) {
|
|
308
323
|
return node.parent.children[idx];
|
|
309
|
-
}else{
|
|
324
|
+
} else {
|
|
310
325
|
return null;
|
|
311
326
|
}
|
|
312
327
|
},
|
|
313
328
|
|
|
314
|
-
move_node:function(node, beforeid, parentid, direction){
|
|
315
|
-
if(!jm.util.is_node(node)){
|
|
329
|
+
move_node: function (node, beforeid, parentid, direction) {
|
|
330
|
+
if (!jm.util.is_node(node)) {
|
|
316
331
|
var the_node = this.get_node(node);
|
|
317
|
-
if(!the_node){
|
|
318
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
332
|
+
if (!the_node) {
|
|
333
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
319
334
|
return null;
|
|
320
|
-
}else{
|
|
335
|
+
} else {
|
|
321
336
|
return this.move_node(the_node, beforeid, parentid, direction);
|
|
322
337
|
}
|
|
323
338
|
}
|
|
324
|
-
if(!parentid){
|
|
339
|
+
if (!parentid) {
|
|
325
340
|
parentid = node.parent.id;
|
|
326
341
|
}
|
|
327
342
|
return this._move_node(node, beforeid, parentid, direction);
|
|
328
343
|
},
|
|
329
344
|
|
|
330
|
-
_flow_node_direction:function(node,direction){
|
|
331
|
-
if(typeof direction === 'undefined'){
|
|
345
|
+
_flow_node_direction: function (node, direction) {
|
|
346
|
+
if (typeof direction === 'undefined') {
|
|
332
347
|
direction = node.direction;
|
|
333
|
-
}else{
|
|
348
|
+
} else {
|
|
334
349
|
node.direction = direction;
|
|
335
350
|
}
|
|
336
351
|
var len = node.children.length;
|
|
337
|
-
while(len--){
|
|
338
|
-
this._flow_node_direction(node.children[len],direction);
|
|
352
|
+
while (len--) {
|
|
353
|
+
this._flow_node_direction(node.children[len], direction);
|
|
339
354
|
}
|
|
340
355
|
},
|
|
341
356
|
|
|
342
|
-
_move_node_internal:function(node, beforeid){
|
|
343
|
-
if(!!node && !!beforeid){
|
|
344
|
-
if(beforeid == '_last_'){
|
|
357
|
+
_move_node_internal: function (node, beforeid) {
|
|
358
|
+
if (!!node && !!beforeid) {
|
|
359
|
+
if (beforeid == '_last_') {
|
|
345
360
|
node.index = -1;
|
|
346
361
|
this._reindex(node.parent);
|
|
347
|
-
}else if(beforeid == '_first_'){
|
|
362
|
+
} else if (beforeid == '_first_') {
|
|
348
363
|
node.index = 0;
|
|
349
364
|
this._reindex(node.parent);
|
|
350
|
-
}else{
|
|
351
|
-
var node_before = (!!beforeid)?this.get_node(beforeid):null;
|
|
352
|
-
if(node_before!=null && node_before.parent!=null && node_before.parent.id==node.parent.id){
|
|
365
|
+
} else {
|
|
366
|
+
var node_before = (!!beforeid) ? this.get_node(beforeid) : null;
|
|
367
|
+
if (node_before != null && node_before.parent != null && node_before.parent.id == node.parent.id) {
|
|
353
368
|
node.index = node_before.index - 0.5;
|
|
354
369
|
this._reindex(node.parent);
|
|
355
370
|
}
|
|
@@ -358,15 +373,15 @@
|
|
|
358
373
|
return node;
|
|
359
374
|
},
|
|
360
375
|
|
|
361
|
-
_move_node:function(node, beforeid, parentid, direction){
|
|
362
|
-
if(!!node && !!parentid){
|
|
363
|
-
if(node.parent.id != parentid){
|
|
376
|
+
_move_node: function (node, beforeid, parentid, direction) {
|
|
377
|
+
if (!!node && !!parentid) {
|
|
378
|
+
if (node.parent.id != parentid) {
|
|
364
379
|
// remove from parent's children
|
|
365
380
|
var sibling = node.parent.children;
|
|
366
381
|
var si = sibling.length;
|
|
367
|
-
while(si--){
|
|
368
|
-
if(sibling[si].id == node.id){
|
|
369
|
-
sibling.splice(si,1);
|
|
382
|
+
while (si--) {
|
|
383
|
+
if (sibling[si].id == node.id) {
|
|
384
|
+
sibling.splice(si, 1);
|
|
370
385
|
break;
|
|
371
386
|
}
|
|
372
387
|
}
|
|
@@ -374,13 +389,13 @@
|
|
|
374
389
|
node.parent.children.push(node);
|
|
375
390
|
}
|
|
376
391
|
|
|
377
|
-
if(node.parent.isroot){
|
|
378
|
-
if(direction ==
|
|
392
|
+
if (node.parent.isroot) {
|
|
393
|
+
if (direction == jm.direction.left) {
|
|
379
394
|
node.direction = direction;
|
|
380
|
-
}else{
|
|
395
|
+
} else {
|
|
381
396
|
node.direction = jm.direction.right;
|
|
382
397
|
}
|
|
383
|
-
}else{
|
|
398
|
+
} else {
|
|
384
399
|
node.direction = node.parent.direction;
|
|
385
400
|
}
|
|
386
401
|
this._move_node_internal(node, beforeid);
|
|
@@ -389,31 +404,31 @@
|
|
|
389
404
|
return node;
|
|
390
405
|
},
|
|
391
406
|
|
|
392
|
-
remove_node:function(node){
|
|
393
|
-
if(!jm.util.is_node(node)){
|
|
407
|
+
remove_node: function (node) {
|
|
408
|
+
if (!jm.util.is_node(node)) {
|
|
394
409
|
var the_node = this.get_node(node);
|
|
395
|
-
if(!the_node){
|
|
396
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
410
|
+
if (!the_node) {
|
|
411
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
397
412
|
return false;
|
|
398
|
-
}else{
|
|
413
|
+
} else {
|
|
399
414
|
return this.remove_node(the_node);
|
|
400
415
|
}
|
|
401
416
|
}
|
|
402
|
-
if(!node){
|
|
417
|
+
if (!node) {
|
|
403
418
|
logger.error('fail, the node can not be found');
|
|
404
419
|
return false;
|
|
405
420
|
}
|
|
406
|
-
if(node.isroot){
|
|
421
|
+
if (node.isroot) {
|
|
407
422
|
logger.error('fail, can not remove root node');
|
|
408
423
|
return false;
|
|
409
424
|
}
|
|
410
|
-
if(this.selected!=null && this.selected.id == node.id){
|
|
425
|
+
if (this.selected != null && this.selected.id == node.id) {
|
|
411
426
|
this.selected = null;
|
|
412
427
|
}
|
|
413
428
|
// clean all subordinate nodes
|
|
414
429
|
var children = node.children;
|
|
415
430
|
var ci = children.length;
|
|
416
|
-
while(ci--){
|
|
431
|
+
while (ci--) {
|
|
417
432
|
this.remove_node(children[ci]);
|
|
418
433
|
}
|
|
419
434
|
// clean all children
|
|
@@ -421,16 +436,16 @@
|
|
|
421
436
|
// remove from parent's children
|
|
422
437
|
var sibling = node.parent.children;
|
|
423
438
|
var si = sibling.length;
|
|
424
|
-
while(si--){
|
|
425
|
-
if(sibling[si].id == node.id){
|
|
426
|
-
sibling.splice(si,1);
|
|
439
|
+
while (si--) {
|
|
440
|
+
if (sibling[si].id == node.id) {
|
|
441
|
+
sibling.splice(si, 1);
|
|
427
442
|
break;
|
|
428
443
|
}
|
|
429
444
|
}
|
|
430
445
|
// remove from global nodes
|
|
431
446
|
delete this.nodes[node.id];
|
|
432
447
|
// clean all properties
|
|
433
|
-
for(var k in node){
|
|
448
|
+
for (var k in node) {
|
|
434
449
|
delete node[k];
|
|
435
450
|
}
|
|
436
451
|
// remove it's self
|
|
@@ -439,75 +454,75 @@
|
|
|
439
454
|
return true;
|
|
440
455
|
},
|
|
441
456
|
|
|
442
|
-
_put_node:function(node){
|
|
443
|
-
if(node.id in this.nodes){
|
|
444
|
-
logger.warn('the nodeid \''+node.id+'\' has been already exist.');
|
|
457
|
+
_put_node: function (node) {
|
|
458
|
+
if (node.id in this.nodes) {
|
|
459
|
+
logger.warn('the nodeid \'' + node.id + '\' has been already exist.');
|
|
445
460
|
return false;
|
|
446
|
-
}else{
|
|
461
|
+
} else {
|
|
447
462
|
this.nodes[node.id] = node;
|
|
448
463
|
return true;
|
|
449
464
|
}
|
|
450
465
|
},
|
|
451
466
|
|
|
452
|
-
_reindex:function(node){
|
|
453
|
-
if(node instanceof jm.node){
|
|
467
|
+
_reindex: function (node) {
|
|
468
|
+
if (node instanceof jm.node) {
|
|
454
469
|
node.children.sort(jm.node.compare);
|
|
455
|
-
for(var i=0;i<node.children.length;i++){
|
|
456
|
-
node.children[i].index = i+1;
|
|
470
|
+
for (var i = 0; i < node.children.length; i++) {
|
|
471
|
+
node.children[i].index = i + 1;
|
|
457
472
|
}
|
|
458
473
|
}
|
|
459
474
|
},
|
|
460
475
|
};
|
|
461
476
|
|
|
462
477
|
jm.format = {
|
|
463
|
-
node_tree:{
|
|
464
|
-
example:{
|
|
465
|
-
"meta":{
|
|
466
|
-
"name":__name__,
|
|
467
|
-
"author":__author__,
|
|
468
|
-
"version":__version__
|
|
478
|
+
node_tree: {
|
|
479
|
+
example: {
|
|
480
|
+
"meta": {
|
|
481
|
+
"name": __name__,
|
|
482
|
+
"author": __author__,
|
|
483
|
+
"version": __version__
|
|
469
484
|
},
|
|
470
|
-
"format":"node_tree",
|
|
471
|
-
"data":{"id":"root","topic":"jsMind Example"}
|
|
485
|
+
"format": "node_tree",
|
|
486
|
+
"data": { "id": "root", "topic": "jsMind Example" }
|
|
472
487
|
},
|
|
473
|
-
get_mind:function(source){
|
|
488
|
+
get_mind: function (source) {
|
|
474
489
|
var df = jm.format.node_tree;
|
|
475
490
|
var mind = new jm.mind();
|
|
476
491
|
mind.name = source.meta.name;
|
|
477
492
|
mind.author = source.meta.author;
|
|
478
493
|
mind.version = source.meta.version;
|
|
479
|
-
df._parse(mind,source.data);
|
|
494
|
+
df._parse(mind, source.data);
|
|
480
495
|
return mind;
|
|
481
496
|
},
|
|
482
|
-
get_data:function(mind){
|
|
497
|
+
get_data: function (mind) {
|
|
483
498
|
var df = jm.format.node_tree;
|
|
484
499
|
var json = {};
|
|
485
500
|
json.meta = {
|
|
486
|
-
name
|
|
487
|
-
author
|
|
488
|
-
version
|
|
501
|
+
name: mind.name,
|
|
502
|
+
author: mind.author,
|
|
503
|
+
version: mind.version
|
|
489
504
|
};
|
|
490
505
|
json.format = 'node_tree';
|
|
491
506
|
json.data = df._buildnode(mind.root);
|
|
492
507
|
return json;
|
|
493
508
|
},
|
|
494
509
|
|
|
495
|
-
_parse:function(mind, node_root){
|
|
510
|
+
_parse: function (mind, node_root) {
|
|
496
511
|
var df = jm.format.node_tree;
|
|
497
512
|
var data = df._extract_data(node_root);
|
|
498
513
|
mind.set_root(node_root.id, node_root.topic, data);
|
|
499
|
-
if('children' in node_root){
|
|
514
|
+
if ('children' in node_root) {
|
|
500
515
|
var children = node_root.children;
|
|
501
|
-
for(var i=0;i<children.length;i++){
|
|
516
|
+
for (var i = 0; i < children.length; i++) {
|
|
502
517
|
df._extract_subnode(mind, mind.root, children[i]);
|
|
503
518
|
}
|
|
504
519
|
}
|
|
505
520
|
},
|
|
506
521
|
|
|
507
|
-
_extract_data:function(node_json){
|
|
522
|
+
_extract_data: function (node_json) {
|
|
508
523
|
var data = {};
|
|
509
|
-
for(var k in node_json){
|
|
510
|
-
if(k == 'id' || k=='topic' || k=='children' || k=='direction' || k=='expanded'){
|
|
524
|
+
for (var k in node_json) {
|
|
525
|
+
if (k == 'id' || k == 'topic' || k == 'children' || k == 'direction' || k == 'expanded') {
|
|
511
526
|
continue;
|
|
512
527
|
}
|
|
513
528
|
data[k] = node_json[k];
|
|
@@ -515,43 +530,43 @@
|
|
|
515
530
|
return data;
|
|
516
531
|
},
|
|
517
532
|
|
|
518
|
-
_extract_subnode:function(mind, node_parent, node_json){
|
|
533
|
+
_extract_subnode: function (mind, node_parent, node_json) {
|
|
519
534
|
var df = jm.format.node_tree;
|
|
520
535
|
var data = df._extract_data(node_json);
|
|
521
536
|
var d = null;
|
|
522
|
-
if(node_parent.isroot){
|
|
523
|
-
d = node_json.direction == 'left'?jm.direction.left:jm.direction.right;
|
|
537
|
+
if (node_parent.isroot) {
|
|
538
|
+
d = node_json.direction == 'left' ? jm.direction.left : jm.direction.right;
|
|
524
539
|
}
|
|
525
540
|
var node = mind.add_node(node_parent, node_json.id, node_json.topic, data, null, d, node_json.expanded);
|
|
526
|
-
if('children'
|
|
541
|
+
if (!!node_json['children']) {
|
|
527
542
|
var children = node_json.children;
|
|
528
|
-
for(var i=0;i<children.length;i++){
|
|
543
|
+
for (var i = 0; i < children.length; i++) {
|
|
529
544
|
df._extract_subnode(mind, node, children[i]);
|
|
530
545
|
}
|
|
531
546
|
}
|
|
532
547
|
},
|
|
533
548
|
|
|
534
|
-
_buildnode:function(node){
|
|
549
|
+
_buildnode: function (node) {
|
|
535
550
|
var df = jm.format.node_tree;
|
|
536
|
-
if(!(node instanceof jm.node)){return;}
|
|
551
|
+
if (!(node instanceof jm.node)) { return; }
|
|
537
552
|
var o = {
|
|
538
|
-
id
|
|
539
|
-
topic
|
|
540
|
-
expanded
|
|
553
|
+
id: node.id,
|
|
554
|
+
topic: node.topic,
|
|
555
|
+
expanded: node.expanded
|
|
541
556
|
};
|
|
542
|
-
if(!!node.parent && node.parent.isroot){
|
|
543
|
-
o.direction = node.direction == jm.direction.left?'left':'right';
|
|
557
|
+
if (!!node.parent && node.parent.isroot) {
|
|
558
|
+
o.direction = node.direction == jm.direction.left ? 'left' : 'right';
|
|
544
559
|
}
|
|
545
|
-
if(node.data != null){
|
|
560
|
+
if (node.data != null) {
|
|
546
561
|
var node_data = node.data;
|
|
547
|
-
for(var k in node_data){
|
|
562
|
+
for (var k in node_data) {
|
|
548
563
|
o[k] = node_data[k];
|
|
549
564
|
}
|
|
550
565
|
}
|
|
551
566
|
var children = node.children;
|
|
552
|
-
if(children.length > 0){
|
|
567
|
+
if (children.length > 0) {
|
|
553
568
|
o.children = [];
|
|
554
|
-
for(var i=0;i<children.length;i++){
|
|
569
|
+
for (var i = 0; i < children.length; i++) {
|
|
555
570
|
o.children.push(df._buildnode(children[i]));
|
|
556
571
|
}
|
|
557
572
|
}
|
|
@@ -559,91 +574,91 @@
|
|
|
559
574
|
}
|
|
560
575
|
},
|
|
561
576
|
|
|
562
|
-
node_array:{
|
|
563
|
-
example:{
|
|
564
|
-
"meta":{
|
|
565
|
-
"name":__name__,
|
|
566
|
-
"author":__author__,
|
|
567
|
-
"version":__version__
|
|
577
|
+
node_array: {
|
|
578
|
+
example: {
|
|
579
|
+
"meta": {
|
|
580
|
+
"name": __name__,
|
|
581
|
+
"author": __author__,
|
|
582
|
+
"version": __version__
|
|
568
583
|
},
|
|
569
|
-
"format":"node_array",
|
|
570
|
-
"data":[
|
|
571
|
-
{"id":"root","topic":"jsMind Example", "isroot":true}
|
|
584
|
+
"format": "node_array",
|
|
585
|
+
"data": [
|
|
586
|
+
{ "id": "root", "topic": "jsMind Example", "isroot": true }
|
|
572
587
|
]
|
|
573
588
|
},
|
|
574
589
|
|
|
575
|
-
get_mind:function(source){
|
|
590
|
+
get_mind: function (source) {
|
|
576
591
|
var df = jm.format.node_array;
|
|
577
592
|
var mind = new jm.mind();
|
|
578
593
|
mind.name = source.meta.name;
|
|
579
594
|
mind.author = source.meta.author;
|
|
580
595
|
mind.version = source.meta.version;
|
|
581
|
-
df._parse(mind,source.data);
|
|
596
|
+
df._parse(mind, source.data);
|
|
582
597
|
return mind;
|
|
583
598
|
},
|
|
584
599
|
|
|
585
|
-
get_data:function(mind){
|
|
600
|
+
get_data: function (mind) {
|
|
586
601
|
var df = jm.format.node_array;
|
|
587
602
|
var json = {};
|
|
588
603
|
json.meta = {
|
|
589
|
-
name
|
|
590
|
-
author
|
|
591
|
-
version
|
|
604
|
+
name: mind.name,
|
|
605
|
+
author: mind.author,
|
|
606
|
+
version: mind.version
|
|
592
607
|
};
|
|
593
608
|
json.format = 'node_array';
|
|
594
609
|
json.data = [];
|
|
595
|
-
df._array(mind,json.data);
|
|
610
|
+
df._array(mind, json.data);
|
|
596
611
|
return json;
|
|
597
612
|
},
|
|
598
613
|
|
|
599
|
-
_parse:function(mind, node_array){
|
|
614
|
+
_parse: function (mind, node_array) {
|
|
600
615
|
var df = jm.format.node_array;
|
|
601
616
|
var narray = node_array.slice(0);
|
|
602
617
|
// reverse array for improving looping performance
|
|
603
618
|
narray.reverse();
|
|
604
619
|
var root_id = df._extract_root(mind, narray);
|
|
605
|
-
if(!!root_id){
|
|
620
|
+
if (!!root_id) {
|
|
606
621
|
df._extract_subnode(mind, root_id, narray);
|
|
607
|
-
}else{
|
|
622
|
+
} else {
|
|
608
623
|
logger.error('root node can not be found');
|
|
609
624
|
}
|
|
610
625
|
},
|
|
611
626
|
|
|
612
|
-
_extract_root:function(mind, node_array){
|
|
627
|
+
_extract_root: function (mind, node_array) {
|
|
613
628
|
var df = jm.format.node_array;
|
|
614
629
|
var i = node_array.length;
|
|
615
|
-
while(i--){
|
|
616
|
-
if('isroot' in node_array[i] && node_array[i].isroot){
|
|
630
|
+
while (i--) {
|
|
631
|
+
if ('isroot' in node_array[i] && node_array[i].isroot) {
|
|
617
632
|
var root_json = node_array[i];
|
|
618
633
|
var data = df._extract_data(root_json);
|
|
619
|
-
mind.set_root(root_json.id,root_json.topic,data);
|
|
620
|
-
node_array.splice(i,1);
|
|
634
|
+
mind.set_root(root_json.id, root_json.topic, data);
|
|
635
|
+
node_array.splice(i, 1);
|
|
621
636
|
return root_json.id;
|
|
622
637
|
}
|
|
623
638
|
}
|
|
624
639
|
return null;
|
|
625
640
|
},
|
|
626
641
|
|
|
627
|
-
_extract_subnode:function(mind, parentid, node_array){
|
|
642
|
+
_extract_subnode: function (mind, parentid, node_array) {
|
|
628
643
|
var df = jm.format.node_array;
|
|
629
644
|
var i = node_array.length;
|
|
630
645
|
var node_json = null;
|
|
631
646
|
var data = null;
|
|
632
647
|
var extract_count = 0;
|
|
633
|
-
while(i--){
|
|
648
|
+
while (i--) {
|
|
634
649
|
node_json = node_array[i];
|
|
635
|
-
if(node_json.parentid == parentid){
|
|
650
|
+
if (node_json.parentid == parentid) {
|
|
636
651
|
data = df._extract_data(node_json);
|
|
637
652
|
var d = null;
|
|
638
653
|
var node_direction = node_json.direction;
|
|
639
|
-
if(!!node_direction){
|
|
640
|
-
d = node_direction == 'left'?jm.direction.left:jm.direction.right;
|
|
654
|
+
if (!!node_direction) {
|
|
655
|
+
d = node_direction == 'left' ? jm.direction.left : jm.direction.right;
|
|
641
656
|
}
|
|
642
657
|
mind.add_node(parentid, node_json.id, node_json.topic, data, null, d, node_json.expanded);
|
|
643
|
-
node_array.splice(i,1);
|
|
644
|
-
extract_count
|
|
658
|
+
node_array.splice(i, 1);
|
|
659
|
+
extract_count++;
|
|
645
660
|
var sub_extract_count = df._extract_subnode(mind, node_json.id, node_array);
|
|
646
|
-
if(sub_extract_count > 0){
|
|
661
|
+
if (sub_extract_count > 0) {
|
|
647
662
|
// reset loop index after extract subordinate node
|
|
648
663
|
i = node_array.length;
|
|
649
664
|
extract_count += sub_extract_count;
|
|
@@ -653,10 +668,10 @@
|
|
|
653
668
|
return extract_count;
|
|
654
669
|
},
|
|
655
670
|
|
|
656
|
-
_extract_data:function(node_json){
|
|
671
|
+
_extract_data: function (node_json) {
|
|
657
672
|
var data = {};
|
|
658
|
-
for(var k in node_json){
|
|
659
|
-
if(k == 'id' || k=='topic' || k=='parentid' || k=='isroot' || k=='direction' || k=='expanded'){
|
|
673
|
+
for (var k in node_json) {
|
|
674
|
+
if (k == 'id' || k == 'topic' || k == 'parentid' || k == 'isroot' || k == 'direction' || k == 'expanded') {
|
|
660
675
|
continue;
|
|
661
676
|
}
|
|
662
677
|
data[k] = node_json[k];
|
|
@@ -664,53 +679,53 @@
|
|
|
664
679
|
return data;
|
|
665
680
|
},
|
|
666
681
|
|
|
667
|
-
_array:function(mind, node_array){
|
|
682
|
+
_array: function (mind, node_array) {
|
|
668
683
|
var df = jm.format.node_array;
|
|
669
684
|
df._array_node(mind.root, node_array);
|
|
670
685
|
},
|
|
671
686
|
|
|
672
|
-
_array_node:function(node, node_array){
|
|
687
|
+
_array_node: function (node, node_array) {
|
|
673
688
|
var df = jm.format.node_array;
|
|
674
|
-
if(!(node instanceof jm.node)){return;}
|
|
689
|
+
if (!(node instanceof jm.node)) { return; }
|
|
675
690
|
var o = {
|
|
676
|
-
id
|
|
677
|
-
topic
|
|
678
|
-
expanded
|
|
691
|
+
id: node.id,
|
|
692
|
+
topic: node.topic,
|
|
693
|
+
expanded: node.expanded
|
|
679
694
|
};
|
|
680
|
-
if(!!node.parent){
|
|
695
|
+
if (!!node.parent) {
|
|
681
696
|
o.parentid = node.parent.id;
|
|
682
697
|
}
|
|
683
|
-
if(node.isroot){
|
|
698
|
+
if (node.isroot) {
|
|
684
699
|
o.isroot = true;
|
|
685
700
|
}
|
|
686
|
-
if(!!node.parent && node.parent.isroot){
|
|
687
|
-
o.direction = node.direction == jm.direction.left?'left':'right';
|
|
701
|
+
if (!!node.parent && node.parent.isroot) {
|
|
702
|
+
o.direction = node.direction == jm.direction.left ? 'left' : 'right';
|
|
688
703
|
}
|
|
689
|
-
if(node.data != null){
|
|
704
|
+
if (node.data != null) {
|
|
690
705
|
var node_data = node.data;
|
|
691
|
-
for(var k in node_data){
|
|
706
|
+
for (var k in node_data) {
|
|
692
707
|
o[k] = node_data[k];
|
|
693
708
|
}
|
|
694
709
|
}
|
|
695
710
|
node_array.push(o);
|
|
696
711
|
var ci = node.children.length;
|
|
697
|
-
for(var i=0;i<ci;i++){
|
|
712
|
+
for (var i = 0; i < ci; i++) {
|
|
698
713
|
df._array_node(node.children[i], node_array);
|
|
699
714
|
}
|
|
700
715
|
},
|
|
701
716
|
},
|
|
702
717
|
|
|
703
|
-
freemind:{
|
|
704
|
-
example:{
|
|
705
|
-
"meta":{
|
|
706
|
-
"name":__name__,
|
|
707
|
-
"author":__author__,
|
|
708
|
-
"version":__version__
|
|
718
|
+
freemind: {
|
|
719
|
+
example: {
|
|
720
|
+
"meta": {
|
|
721
|
+
"name": __name__,
|
|
722
|
+
"author": __author__,
|
|
723
|
+
"version": __version__
|
|
709
724
|
},
|
|
710
|
-
"format":"freemind",
|
|
711
|
-
"data":"<map version=\"1.0.1\"><node ID=\"root\" TEXT=\"freemind Example\"/></map>"
|
|
725
|
+
"format": "freemind",
|
|
726
|
+
"data": "<map version=\"1.0.1\"><node ID=\"root\" TEXT=\"freemind Example\"/></map>"
|
|
712
727
|
},
|
|
713
|
-
get_mind:function(source){
|
|
728
|
+
get_mind: function (source) {
|
|
714
729
|
var df = jm.format.freemind;
|
|
715
730
|
var mind = new jm.mind();
|
|
716
731
|
mind.name = source.meta.name;
|
|
@@ -723,13 +738,13 @@
|
|
|
723
738
|
return mind;
|
|
724
739
|
},
|
|
725
740
|
|
|
726
|
-
get_data:function(mind){
|
|
741
|
+
get_data: function (mind) {
|
|
727
742
|
var df = jm.format.freemind;
|
|
728
743
|
var json = {};
|
|
729
744
|
json.meta = {
|
|
730
|
-
name
|
|
731
|
-
author
|
|
732
|
-
version
|
|
745
|
+
name: mind.name,
|
|
746
|
+
author: mind.author,
|
|
747
|
+
version: mind.version
|
|
733
748
|
};
|
|
734
749
|
json.format = 'freemind';
|
|
735
750
|
var xmllines = [];
|
|
@@ -740,37 +755,37 @@
|
|
|
740
755
|
return json;
|
|
741
756
|
},
|
|
742
757
|
|
|
743
|
-
_parse_xml:function(xml){
|
|
758
|
+
_parse_xml: function (xml) {
|
|
744
759
|
var xml_doc = null;
|
|
745
|
-
if (window.DOMParser){
|
|
760
|
+
if (window.DOMParser) {
|
|
746
761
|
var parser = new DOMParser();
|
|
747
|
-
xml_doc = parser.parseFromString(xml,'text/xml');
|
|
748
|
-
}else{ // Internet Explorer
|
|
762
|
+
xml_doc = parser.parseFromString(xml, 'text/xml');
|
|
763
|
+
} else { // Internet Explorer
|
|
749
764
|
xml_doc = new ActiveXObject('Microsoft.XMLDOM');
|
|
750
765
|
xml_doc.async = false;
|
|
751
|
-
xml_doc.loadXML(xml);
|
|
766
|
+
xml_doc.loadXML(xml);
|
|
752
767
|
}
|
|
753
768
|
return xml_doc;
|
|
754
769
|
},
|
|
755
770
|
|
|
756
|
-
_find_root:function(xml_doc){
|
|
771
|
+
_find_root: function (xml_doc) {
|
|
757
772
|
var nodes = xml_doc.childNodes;
|
|
758
773
|
var node = null;
|
|
759
774
|
var root = null;
|
|
760
775
|
var n = null;
|
|
761
|
-
for(var i=0;i<nodes.length;i++){
|
|
776
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
762
777
|
n = nodes[i];
|
|
763
|
-
if(n.nodeType == 1 && n.tagName == 'map'){
|
|
778
|
+
if (n.nodeType == 1 && n.tagName == 'map') {
|
|
764
779
|
node = n;
|
|
765
780
|
break;
|
|
766
781
|
}
|
|
767
782
|
}
|
|
768
|
-
if(!!node){
|
|
783
|
+
if (!!node) {
|
|
769
784
|
var ns = node.childNodes;
|
|
770
785
|
node = null;
|
|
771
|
-
for(var i=0;i<ns.length;i++){
|
|
786
|
+
for (var i = 0; i < ns.length; i++) {
|
|
772
787
|
n = ns[i];
|
|
773
|
-
if(n.nodeType == 1 && n.tagName == 'node'){
|
|
788
|
+
if (n.nodeType == 1 && n.tagName == 'node') {
|
|
774
789
|
node = n;
|
|
775
790
|
break;
|
|
776
791
|
}
|
|
@@ -779,88 +794,88 @@
|
|
|
779
794
|
return node;
|
|
780
795
|
},
|
|
781
796
|
|
|
782
|
-
_load_node:function(mind, parent_id, xml_node){
|
|
797
|
+
_load_node: function (mind, parent_id, xml_node) {
|
|
783
798
|
var df = jm.format.freemind;
|
|
784
799
|
var node_id = xml_node.getAttribute('ID');
|
|
785
800
|
var node_topic = xml_node.getAttribute('TEXT');
|
|
786
801
|
// look for richcontent
|
|
787
|
-
if(node_topic == null){
|
|
802
|
+
if (node_topic == null) {
|
|
788
803
|
var topic_children = xml_node.childNodes;
|
|
789
804
|
var topic_child = null;
|
|
790
|
-
for(var i=0;i<topic_children.length;i++){
|
|
805
|
+
for (var i = 0; i < topic_children.length; i++) {
|
|
791
806
|
topic_child = topic_children[i];
|
|
792
807
|
//logger.debug(topic_child.tagName);
|
|
793
|
-
if(topic_child.nodeType == 1 && topic_child.tagName === 'richcontent'){
|
|
808
|
+
if (topic_child.nodeType == 1 && topic_child.tagName === 'richcontent') {
|
|
794
809
|
node_topic = topic_child.textContent;
|
|
795
810
|
break;
|
|
796
811
|
}
|
|
797
812
|
}
|
|
798
813
|
}
|
|
799
814
|
var node_data = df._load_attributes(xml_node);
|
|
800
|
-
var node_expanded = ('expanded' in node_data)?(node_data.expanded == 'true') : true;
|
|
815
|
+
var node_expanded = ('expanded' in node_data) ? (node_data.expanded == 'true') : true;
|
|
801
816
|
delete node_data.expanded;
|
|
802
817
|
|
|
803
818
|
var node_position = xml_node.getAttribute('POSITION');
|
|
804
819
|
var node_direction = null;
|
|
805
|
-
if(!!node_position){
|
|
806
|
-
node_direction = node_position=='left'?jm.direction.left:jm.direction.right;
|
|
820
|
+
if (!!node_position) {
|
|
821
|
+
node_direction = node_position == 'left' ? jm.direction.left : jm.direction.right;
|
|
807
822
|
}
|
|
808
823
|
//logger.debug(node_position +':'+ node_direction);
|
|
809
|
-
if(!!parent_id){
|
|
824
|
+
if (!!parent_id) {
|
|
810
825
|
mind.add_node(parent_id, node_id, node_topic, node_data, null, node_direction, node_expanded);
|
|
811
|
-
}else{
|
|
826
|
+
} else {
|
|
812
827
|
mind.set_root(node_id, node_topic, node_data);
|
|
813
828
|
}
|
|
814
829
|
var children = xml_node.childNodes;
|
|
815
830
|
var child = null;
|
|
816
|
-
for(var i=0;i<children.length;i++){
|
|
831
|
+
for (var i = 0; i < children.length; i++) {
|
|
817
832
|
child = children[i];
|
|
818
|
-
if(child.nodeType == 1 && child.tagName == 'node'){
|
|
833
|
+
if (child.nodeType == 1 && child.tagName == 'node') {
|
|
819
834
|
df._load_node(mind, node_id, child);
|
|
820
835
|
}
|
|
821
836
|
}
|
|
822
837
|
},
|
|
823
838
|
|
|
824
|
-
_load_attributes:function(xml_node){
|
|
839
|
+
_load_attributes: function (xml_node) {
|
|
825
840
|
var children = xml_node.childNodes;
|
|
826
841
|
var attr = null;
|
|
827
842
|
var attr_data = {};
|
|
828
|
-
for(var i=0;i<children.length;i++){
|
|
843
|
+
for (var i = 0; i < children.length; i++) {
|
|
829
844
|
attr = children[i];
|
|
830
|
-
if(attr.nodeType == 1 && attr.tagName === 'attribute'){
|
|
845
|
+
if (attr.nodeType == 1 && attr.tagName === 'attribute') {
|
|
831
846
|
attr_data[attr.getAttribute('NAME')] = attr.getAttribute('VALUE');
|
|
832
847
|
}
|
|
833
848
|
}
|
|
834
849
|
return attr_data;
|
|
835
850
|
},
|
|
836
851
|
|
|
837
|
-
_buildmap:function(node, xmllines){
|
|
852
|
+
_buildmap: function (node, xmllines) {
|
|
838
853
|
var df = jm.format.freemind;
|
|
839
854
|
var pos = null;
|
|
840
|
-
if(!!node.parent && node.parent.isroot){
|
|
841
|
-
pos = node.direction === jm.direction.left?'left':'right';
|
|
855
|
+
if (!!node.parent && node.parent.isroot) {
|
|
856
|
+
pos = node.direction === jm.direction.left ? 'left' : 'right';
|
|
842
857
|
}
|
|
843
858
|
xmllines.push('<node');
|
|
844
|
-
xmllines.push('ID=\"'+node.id+'\"');
|
|
845
|
-
if(!!pos){
|
|
846
|
-
xmllines.push('POSITION=\"'+pos+'\"');
|
|
859
|
+
xmllines.push('ID=\"' + node.id + '\"');
|
|
860
|
+
if (!!pos) {
|
|
861
|
+
xmllines.push('POSITION=\"' + pos + '\"');
|
|
847
862
|
}
|
|
848
|
-
xmllines.push('TEXT=\"'+node.topic+'\">');
|
|
863
|
+
xmllines.push('TEXT=\"' + node.topic + '\">');
|
|
849
864
|
|
|
850
865
|
// store expanded status as an attribute
|
|
851
|
-
xmllines.push('<attribute NAME=\"expanded\" VALUE=\"'+node.expanded+'\"/>');
|
|
866
|
+
xmllines.push('<attribute NAME=\"expanded\" VALUE=\"' + node.expanded + '\"/>');
|
|
852
867
|
|
|
853
868
|
// for attributes
|
|
854
869
|
var node_data = node.data;
|
|
855
|
-
if(node_data != null){
|
|
856
|
-
for(var k in node_data){
|
|
857
|
-
xmllines.push('<attribute NAME=\"'+k+'\" VALUE=\"'+node_data[k]+'\"/>');
|
|
870
|
+
if (node_data != null) {
|
|
871
|
+
for (var k in node_data) {
|
|
872
|
+
xmllines.push('<attribute NAME=\"' + k + '\" VALUE=\"' + node_data[k] + '\"/>');
|
|
858
873
|
}
|
|
859
874
|
}
|
|
860
875
|
|
|
861
876
|
// for children
|
|
862
877
|
var children = node.children;
|
|
863
|
-
for(var i=0;i<children.length;i++){
|
|
878
|
+
for (var i = 0; i < children.length; i++) {
|
|
864
879
|
df._buildmap(children[i], xmllines);
|
|
865
880
|
}
|
|
866
881
|
|
|
@@ -872,118 +887,100 @@
|
|
|
872
887
|
// ============= utility object =============================================
|
|
873
888
|
|
|
874
889
|
jm.util = {
|
|
875
|
-
is_node: function(node){
|
|
890
|
+
is_node: function (node) {
|
|
876
891
|
return !!node && node instanceof jm.node;
|
|
877
892
|
},
|
|
878
|
-
ajax:{
|
|
879
|
-
_xhr:function(){
|
|
893
|
+
ajax: {
|
|
894
|
+
_xhr: function () {
|
|
880
895
|
var xhr = null;
|
|
881
|
-
if(window.XMLHttpRequest){
|
|
896
|
+
if (window.XMLHttpRequest) {
|
|
882
897
|
xhr = new XMLHttpRequest();
|
|
883
|
-
}else{
|
|
884
|
-
try{
|
|
898
|
+
} else {
|
|
899
|
+
try {
|
|
885
900
|
xhr = new ActiveXObject('Microsoft.XMLHTTP');
|
|
886
|
-
}catch(e){}
|
|
901
|
+
} catch (e) { }
|
|
887
902
|
}
|
|
888
903
|
return xhr;
|
|
889
904
|
},
|
|
890
|
-
_eurl:function(url){
|
|
905
|
+
_eurl: function (url) {
|
|
891
906
|
return encodeURIComponent(url);
|
|
892
907
|
},
|
|
893
|
-
request:function(url,param,method,callback,fail_callback){
|
|
908
|
+
request: function (url, param, method, callback, fail_callback) {
|
|
894
909
|
var a = jm.util.ajax;
|
|
895
910
|
var p = null;
|
|
896
911
|
var tmp_param = [];
|
|
897
|
-
for(var k in param){
|
|
898
|
-
tmp_param.push(a._eurl(k)+'='+a._eurl(param[k]));
|
|
912
|
+
for (var k in param) {
|
|
913
|
+
tmp_param.push(a._eurl(k) + '=' + a._eurl(param[k]));
|
|
899
914
|
}
|
|
900
|
-
if(tmp_param.length>0){
|
|
915
|
+
if (tmp_param.length > 0) {
|
|
901
916
|
p = tmp_param.join('&');
|
|
902
917
|
}
|
|
903
918
|
var xhr = a._xhr();
|
|
904
|
-
if(!xhr){return;}
|
|
905
|
-
xhr.onreadystatechange = function(){
|
|
906
|
-
if(xhr.readyState == 4){
|
|
907
|
-
if(xhr.status == 200 || xhr.status == 0){
|
|
908
|
-
if(typeof callback === 'function'){
|
|
919
|
+
if (!xhr) { return; }
|
|
920
|
+
xhr.onreadystatechange = function () {
|
|
921
|
+
if (xhr.readyState == 4) {
|
|
922
|
+
if (xhr.status == 200 || xhr.status == 0) {
|
|
923
|
+
if (typeof callback === 'function') {
|
|
909
924
|
var data = jm.util.json.string2json(xhr.responseText);
|
|
910
|
-
if(data != null){
|
|
925
|
+
if (data != null) {
|
|
911
926
|
callback(data);
|
|
912
|
-
}else{
|
|
927
|
+
} else {
|
|
913
928
|
callback(xhr.responseText);
|
|
914
929
|
}
|
|
915
930
|
}
|
|
916
|
-
}else{
|
|
917
|
-
if(typeof fail_callback === 'function'){
|
|
931
|
+
} else {
|
|
932
|
+
if (typeof fail_callback === 'function') {
|
|
918
933
|
fail_callback(xhr);
|
|
919
|
-
}else{
|
|
920
|
-
logger.error('xhr request failed.',xhr);
|
|
934
|
+
} else {
|
|
935
|
+
logger.error('xhr request failed.', xhr);
|
|
921
936
|
}
|
|
922
937
|
}
|
|
923
938
|
}
|
|
924
939
|
}
|
|
925
940
|
method = method || 'GET';
|
|
926
|
-
xhr.open(method,url,true);
|
|
927
|
-
xhr.setRequestHeader('If-Modified-Since','0');
|
|
928
|
-
if(method == 'POST'){
|
|
929
|
-
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8');
|
|
941
|
+
xhr.open(method, url, true);
|
|
942
|
+
xhr.setRequestHeader('If-Modified-Since', '0');
|
|
943
|
+
if (method == 'POST') {
|
|
944
|
+
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
|
|
930
945
|
xhr.send(p);
|
|
931
|
-
}else{
|
|
946
|
+
} else {
|
|
932
947
|
xhr.send();
|
|
933
948
|
}
|
|
934
949
|
},
|
|
935
|
-
get:function(url,callback){
|
|
936
|
-
return jm.util.ajax.request(url,{},'GET',callback);
|
|
950
|
+
get: function (url, callback) {
|
|
951
|
+
return jm.util.ajax.request(url, {}, 'GET', callback);
|
|
937
952
|
},
|
|
938
|
-
post:function(url,param,callback){
|
|
939
|
-
return jm.util.ajax.request(url,param,'POST',callback);
|
|
953
|
+
post: function (url, param, callback) {
|
|
954
|
+
return jm.util.ajax.request(url, param, 'POST', callback);
|
|
940
955
|
}
|
|
941
956
|
},
|
|
942
957
|
|
|
943
|
-
dom:{
|
|
958
|
+
dom: {
|
|
944
959
|
//target,eventType,handler
|
|
945
|
-
add_event:function(t,e,h){
|
|
946
|
-
if(!!t.addEventListener){
|
|
947
|
-
t.addEventListener(e,h,false);
|
|
948
|
-
}else{
|
|
949
|
-
t.attachEvent('on'+e,h);
|
|
960
|
+
add_event: function (t, e, h) {
|
|
961
|
+
if (!!t.addEventListener) {
|
|
962
|
+
t.addEventListener(e, h, false);
|
|
963
|
+
} else {
|
|
964
|
+
t.attachEvent('on' + e, h);
|
|
950
965
|
}
|
|
951
966
|
}
|
|
952
967
|
},
|
|
953
968
|
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
ctx.beginPath();
|
|
957
|
-
ctx.moveTo(x1,y1);
|
|
958
|
-
ctx.bezierCurveTo(x1+(x2-x1)*2/3,y1,x1,y2,x2,y2);
|
|
959
|
-
ctx.stroke();
|
|
960
|
-
},
|
|
961
|
-
lineto : function(ctx,x1,y1,x2,y2){
|
|
962
|
-
ctx.beginPath();
|
|
963
|
-
ctx.moveTo(x1,y1);
|
|
964
|
-
ctx.lineTo(x2,y2);
|
|
965
|
-
ctx.stroke();
|
|
966
|
-
},
|
|
967
|
-
clear:function(ctx,x,y,w,h){
|
|
968
|
-
ctx.clearRect(x,y,w,h);
|
|
969
|
-
}
|
|
970
|
-
},
|
|
971
|
-
|
|
972
|
-
file:{
|
|
973
|
-
read:function(file_data,fn_callback){
|
|
969
|
+
file: {
|
|
970
|
+
read: function (file_data, fn_callback) {
|
|
974
971
|
var reader = new FileReader();
|
|
975
|
-
reader.onload = function(){
|
|
976
|
-
if(typeof fn_callback === 'function'){
|
|
972
|
+
reader.onload = function () {
|
|
973
|
+
if (typeof fn_callback === 'function') {
|
|
977
974
|
fn_callback(this.result, file_data.name);
|
|
978
975
|
}
|
|
979
976
|
};
|
|
980
977
|
reader.readAsText(file_data);
|
|
981
978
|
},
|
|
982
979
|
|
|
983
|
-
save:function(file_data, type, name) {
|
|
980
|
+
save: function (file_data, type, name) {
|
|
984
981
|
var blob;
|
|
985
982
|
if (typeof $w.Blob === 'function') {
|
|
986
|
-
blob = new Blob([file_data], {type: type});
|
|
983
|
+
blob = new Blob([file_data], { type: type });
|
|
987
984
|
} else {
|
|
988
985
|
var BlobBuilder = $w.BlobBuilder || $w.MozBlobBuilder || $w.WebKitBlobBuilder || $w.MSBlobBuilder;
|
|
989
986
|
var bb = new BlobBuilder();
|
|
@@ -1012,42 +1009,42 @@
|
|
|
1012
1009
|
}
|
|
1013
1010
|
},
|
|
1014
1011
|
|
|
1015
|
-
json:{
|
|
1016
|
-
json2string:function(json){
|
|
1017
|
-
if(!!JSON){
|
|
1018
|
-
try{
|
|
1012
|
+
json: {
|
|
1013
|
+
json2string: function (json) {
|
|
1014
|
+
if (!!JSON) {
|
|
1015
|
+
try {
|
|
1019
1016
|
var json_str = JSON.stringify(json);
|
|
1020
1017
|
return json_str;
|
|
1021
|
-
}catch(e){
|
|
1018
|
+
} catch (e) {
|
|
1022
1019
|
logger.warn(e);
|
|
1023
1020
|
logger.warn('can not convert to string');
|
|
1024
1021
|
return null;
|
|
1025
1022
|
}
|
|
1026
1023
|
}
|
|
1027
1024
|
},
|
|
1028
|
-
string2json:function(json_str){
|
|
1029
|
-
if(!!JSON){
|
|
1030
|
-
try{
|
|
1025
|
+
string2json: function (json_str) {
|
|
1026
|
+
if (!!JSON) {
|
|
1027
|
+
try {
|
|
1031
1028
|
var json = JSON.parse(json_str);
|
|
1032
1029
|
return json;
|
|
1033
|
-
}catch(e){
|
|
1030
|
+
} catch (e) {
|
|
1034
1031
|
logger.warn(e);
|
|
1035
1032
|
logger.warn('can not parse to json');
|
|
1036
1033
|
return null;
|
|
1037
1034
|
}
|
|
1038
1035
|
}
|
|
1039
1036
|
},
|
|
1040
|
-
merge:function(b,a){
|
|
1041
|
-
for(var o in a){
|
|
1042
|
-
if(o in b){
|
|
1043
|
-
if(typeof b[o] === 'object' &&
|
|
1037
|
+
merge: function (b, a) {
|
|
1038
|
+
for (var o in a) {
|
|
1039
|
+
if (o in b) {
|
|
1040
|
+
if (typeof b[o] === 'object' &&
|
|
1044
1041
|
Object.prototype.toString.call(b[o]).toLowerCase() == '[object object]' &&
|
|
1045
|
-
!b[o].length){
|
|
1042
|
+
!b[o].length) {
|
|
1046
1043
|
jm.util.json.merge(b[o], a[o]);
|
|
1047
|
-
}else{
|
|
1044
|
+
} else {
|
|
1048
1045
|
b[o] = a[o];
|
|
1049
1046
|
}
|
|
1050
|
-
}else{
|
|
1047
|
+
} else {
|
|
1051
1048
|
b[o] = a[o];
|
|
1052
1049
|
}
|
|
1053
1050
|
}
|
|
@@ -1055,42 +1052,45 @@
|
|
|
1055
1052
|
}
|
|
1056
1053
|
},
|
|
1057
1054
|
|
|
1058
|
-
uuid:{
|
|
1059
|
-
newid:function(){
|
|
1060
|
-
return (new Date().getTime().toString(16)+Math.random().toString(16).substr(2)).substr(2,16);
|
|
1055
|
+
uuid: {
|
|
1056
|
+
newid: function () {
|
|
1057
|
+
return (new Date().getTime().toString(16) + Math.random().toString(16).substr(2)).substr(2, 16);
|
|
1061
1058
|
}
|
|
1062
1059
|
},
|
|
1063
1060
|
|
|
1064
|
-
text:{
|
|
1065
|
-
is_empty:function(s){
|
|
1066
|
-
if(!s){return true;}
|
|
1067
|
-
return s.replace(/\s*/,'').length == 0;
|
|
1061
|
+
text: {
|
|
1062
|
+
is_empty: function (s) {
|
|
1063
|
+
if (!s) { return true; }
|
|
1064
|
+
return s.replace(/\s*/, '').length == 0;
|
|
1068
1065
|
}
|
|
1069
1066
|
}
|
|
1070
1067
|
};
|
|
1071
1068
|
|
|
1072
|
-
jm.prototype={
|
|
1073
|
-
init
|
|
1074
|
-
if(this.inited){return;}
|
|
1069
|
+
jm.prototype = {
|
|
1070
|
+
init: function () {
|
|
1071
|
+
if (this.inited) { return; }
|
|
1075
1072
|
this.inited = true;
|
|
1076
1073
|
|
|
1077
1074
|
var opts = this.options;
|
|
1078
1075
|
|
|
1079
1076
|
var opts_layout = {
|
|
1080
|
-
mode:opts.mode,
|
|
1081
|
-
hspace:opts.layout.hspace,
|
|
1082
|
-
vspace:opts.layout.vspace,
|
|
1083
|
-
pspace:opts.layout.pspace
|
|
1077
|
+
mode: opts.mode,
|
|
1078
|
+
hspace: opts.layout.hspace,
|
|
1079
|
+
vspace: opts.layout.vspace,
|
|
1080
|
+
pspace: opts.layout.pspace
|
|
1084
1081
|
}
|
|
1085
1082
|
var opts_view = {
|
|
1086
|
-
container:opts.container,
|
|
1087
|
-
support_html:opts.support_html,
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1083
|
+
container: opts.container,
|
|
1084
|
+
support_html: opts.support_html,
|
|
1085
|
+
engine: opts.view.engine,
|
|
1086
|
+
hmargin: opts.view.hmargin,
|
|
1087
|
+
vmargin: opts.view.vmargin,
|
|
1088
|
+
line_width: opts.view.line_width,
|
|
1089
|
+
line_color: opts.view.line_color,
|
|
1090
|
+
draggable: opts.view.draggable,
|
|
1091
|
+
hide_scrollbars_when_draggable: opts.view.hide_scrollbars_when_draggable
|
|
1092
1092
|
};
|
|
1093
|
-
// create instance of function provider
|
|
1093
|
+
// create instance of function provider
|
|
1094
1094
|
this.data = new jm.data_provider(this);
|
|
1095
1095
|
this.layout = new jm.layout_provider(this, opts_layout);
|
|
1096
1096
|
this.view = new jm.view_provider(this, opts_view);
|
|
@@ -1106,186 +1106,206 @@
|
|
|
1106
1106
|
jm.init_plugins(this);
|
|
1107
1107
|
},
|
|
1108
1108
|
|
|
1109
|
-
enable_edit:function(){
|
|
1109
|
+
enable_edit: function () {
|
|
1110
1110
|
this.options.editable = true;
|
|
1111
1111
|
},
|
|
1112
1112
|
|
|
1113
|
-
disable_edit:function(){
|
|
1113
|
+
disable_edit: function () {
|
|
1114
1114
|
this.options.editable = false;
|
|
1115
1115
|
},
|
|
1116
1116
|
|
|
1117
1117
|
// call enable_event_handle('dblclick')
|
|
1118
1118
|
// options are 'mousedown', 'click', 'dblclick'
|
|
1119
|
-
enable_event_handle: function(event_handle){
|
|
1120
|
-
this.options.default_event_handle['enable_'+event_handle+'_handle'] = true;
|
|
1119
|
+
enable_event_handle: function (event_handle) {
|
|
1120
|
+
this.options.default_event_handle['enable_' + event_handle + '_handle'] = true;
|
|
1121
1121
|
},
|
|
1122
1122
|
|
|
1123
1123
|
// call disable_event_handle('dblclick')
|
|
1124
1124
|
// options are 'mousedown', 'click', 'dblclick'
|
|
1125
|
-
disable_event_handle: function(event_handle){
|
|
1126
|
-
this.options.default_event_handle['enable_'+event_handle+'_handle'] = false;
|
|
1125
|
+
disable_event_handle: function (event_handle) {
|
|
1126
|
+
this.options.default_event_handle['enable_' + event_handle + '_handle'] = false;
|
|
1127
1127
|
},
|
|
1128
1128
|
|
|
1129
|
-
get_editable:function(){
|
|
1129
|
+
get_editable: function () {
|
|
1130
1130
|
return this.options.editable;
|
|
1131
1131
|
},
|
|
1132
1132
|
|
|
1133
|
-
set_theme:function(theme){
|
|
1133
|
+
set_theme: function (theme) {
|
|
1134
1134
|
var theme_old = this.options.theme;
|
|
1135
1135
|
this.options.theme = (!!theme) ? theme : null;
|
|
1136
|
-
if(theme_old != this.options.theme){
|
|
1136
|
+
if (theme_old != this.options.theme) {
|
|
1137
1137
|
this.view.reset_theme();
|
|
1138
1138
|
this.view.reset_custom_style();
|
|
1139
1139
|
}
|
|
1140
1140
|
},
|
|
1141
|
-
_event_bind:function(){
|
|
1142
|
-
this.view.add_event(this,'mousedown',this.mousedown_handle);
|
|
1143
|
-
this.view.add_event(this,'click',this.click_handle);
|
|
1144
|
-
this.view.add_event(this,'dblclick',this.dblclick_handle);
|
|
1141
|
+
_event_bind: function () {
|
|
1142
|
+
this.view.add_event(this, 'mousedown', this.mousedown_handle);
|
|
1143
|
+
this.view.add_event(this, 'click', this.click_handle);
|
|
1144
|
+
this.view.add_event(this, 'dblclick', this.dblclick_handle);
|
|
1145
|
+
this.view.add_event(this, "mousewheel", this.mousewheel_handle)
|
|
1145
1146
|
},
|
|
1146
1147
|
|
|
1147
|
-
mousedown_handle:function(e){
|
|
1148
|
+
mousedown_handle: function (e) {
|
|
1148
1149
|
if (!this.options.default_event_handle['enable_mousedown_handle']) {
|
|
1149
1150
|
return;
|
|
1150
1151
|
}
|
|
1151
1152
|
var element = e.target || event.srcElement;
|
|
1152
1153
|
var nodeid = this.view.get_binded_nodeid(element);
|
|
1153
|
-
if(!!nodeid){
|
|
1154
|
-
|
|
1155
|
-
|
|
1154
|
+
if (!!nodeid) {
|
|
1155
|
+
if (element.tagName.toLowerCase() == 'jmnode') {
|
|
1156
|
+
this.select_node(nodeid);
|
|
1157
|
+
}
|
|
1158
|
+
} else {
|
|
1156
1159
|
this.select_clear();
|
|
1157
1160
|
}
|
|
1158
1161
|
},
|
|
1159
1162
|
|
|
1160
|
-
click_handle:function(e){
|
|
1163
|
+
click_handle: function (e) {
|
|
1161
1164
|
if (!this.options.default_event_handle['enable_click_handle']) {
|
|
1162
1165
|
return;
|
|
1163
1166
|
}
|
|
1164
1167
|
var element = e.target || event.srcElement;
|
|
1165
1168
|
var isexpander = this.view.is_expander(element);
|
|
1166
|
-
if(isexpander){
|
|
1169
|
+
if (isexpander) {
|
|
1167
1170
|
var nodeid = this.view.get_binded_nodeid(element);
|
|
1168
|
-
if(!!nodeid){
|
|
1171
|
+
if (!!nodeid) {
|
|
1169
1172
|
this.toggle_node(nodeid);
|
|
1170
|
-
}
|
|
1173
|
+
}
|
|
1171
1174
|
}
|
|
1172
1175
|
},
|
|
1173
1176
|
|
|
1174
|
-
dblclick_handle:function(e){
|
|
1177
|
+
dblclick_handle: function (e) {
|
|
1175
1178
|
if (!this.options.default_event_handle['enable_dblclick_handle']) {
|
|
1176
1179
|
return;
|
|
1177
1180
|
}
|
|
1178
|
-
if(this.get_editable()){
|
|
1181
|
+
if (this.get_editable()) {
|
|
1179
1182
|
var element = e.target || event.srcElement;
|
|
1180
1183
|
var nodeid = this.view.get_binded_nodeid(element);
|
|
1181
|
-
if(!!nodeid){
|
|
1184
|
+
if (!!nodeid) {
|
|
1182
1185
|
this.begin_edit(nodeid);
|
|
1183
1186
|
}
|
|
1184
1187
|
}
|
|
1185
1188
|
},
|
|
1186
1189
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1190
|
+
// Use [Ctrl] + Mousewheel, to zoom in/out.
|
|
1191
|
+
mousewheel_handle: function(event) {
|
|
1192
|
+
// Test if mousewheel option is enabled and Ctrl key is pressed.
|
|
1193
|
+
if (!this.options.default_event_handle["enable_mousewheel_handle"] || !window.event.ctrlKey) {
|
|
1194
|
+
return
|
|
1195
|
+
}
|
|
1196
|
+
// Avoid default page scrolling behavior.
|
|
1197
|
+
event.preventDefault()
|
|
1198
|
+
|
|
1199
|
+
var dir = event.deltaY > 0 ? "Up" : "Down"
|
|
1200
|
+
if (dir == "Up") {
|
|
1201
|
+
this.view.zoomIn()
|
|
1202
|
+
} else {
|
|
1203
|
+
this.view.zoomOut()
|
|
1204
|
+
}
|
|
1205
|
+
},
|
|
1206
|
+
|
|
1207
|
+
begin_edit: function (node) {
|
|
1208
|
+
if (!jm.util.is_node(node)) {
|
|
1189
1209
|
var the_node = this.get_node(node);
|
|
1190
|
-
if(!the_node){
|
|
1191
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
1210
|
+
if (!the_node) {
|
|
1211
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
1192
1212
|
return false;
|
|
1193
|
-
}else{
|
|
1213
|
+
} else {
|
|
1194
1214
|
return this.begin_edit(the_node);
|
|
1195
1215
|
}
|
|
1196
1216
|
}
|
|
1197
|
-
if(this.get_editable()){
|
|
1217
|
+
if (this.get_editable()) {
|
|
1198
1218
|
this.view.edit_node_begin(node);
|
|
1199
|
-
}else{
|
|
1219
|
+
} else {
|
|
1200
1220
|
logger.error('fail, this mind map is not editable.');
|
|
1201
1221
|
return;
|
|
1202
1222
|
}
|
|
1203
1223
|
},
|
|
1204
1224
|
|
|
1205
|
-
end_edit:function(){
|
|
1225
|
+
end_edit: function () {
|
|
1206
1226
|
this.view.edit_node_end();
|
|
1207
1227
|
},
|
|
1208
1228
|
|
|
1209
|
-
toggle_node:function(node){
|
|
1210
|
-
if(!jm.util.is_node(node)){
|
|
1229
|
+
toggle_node: function (node) {
|
|
1230
|
+
if (!jm.util.is_node(node)) {
|
|
1211
1231
|
var the_node = this.get_node(node);
|
|
1212
|
-
if(!the_node){
|
|
1213
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
1232
|
+
if (!the_node) {
|
|
1233
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
1214
1234
|
return;
|
|
1215
|
-
}else{
|
|
1235
|
+
} else {
|
|
1216
1236
|
return this.toggle_node(the_node);
|
|
1217
1237
|
}
|
|
1218
1238
|
}
|
|
1219
|
-
if(node.isroot){return;}
|
|
1239
|
+
if (node.isroot) { return; }
|
|
1220
1240
|
this.view.save_location(node);
|
|
1221
1241
|
this.layout.toggle_node(node);
|
|
1222
1242
|
this.view.relayout();
|
|
1223
1243
|
this.view.restore_location(node);
|
|
1224
1244
|
},
|
|
1225
1245
|
|
|
1226
|
-
expand_node:function(node){
|
|
1227
|
-
if(!jm.util.is_node(node)){
|
|
1246
|
+
expand_node: function (node) {
|
|
1247
|
+
if (!jm.util.is_node(node)) {
|
|
1228
1248
|
var the_node = this.get_node(node);
|
|
1229
|
-
if(!the_node){
|
|
1230
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
1249
|
+
if (!the_node) {
|
|
1250
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
1231
1251
|
return;
|
|
1232
|
-
}else{
|
|
1252
|
+
} else {
|
|
1233
1253
|
return this.expand_node(the_node);
|
|
1234
1254
|
}
|
|
1235
1255
|
}
|
|
1236
|
-
if(node.isroot){return;}
|
|
1256
|
+
if (node.isroot) { return; }
|
|
1237
1257
|
this.view.save_location(node);
|
|
1238
1258
|
this.layout.expand_node(node);
|
|
1239
1259
|
this.view.relayout();
|
|
1240
1260
|
this.view.restore_location(node);
|
|
1241
1261
|
},
|
|
1242
1262
|
|
|
1243
|
-
collapse_node:function(node){
|
|
1244
|
-
if(!jm.util.is_node(node)){
|
|
1263
|
+
collapse_node: function (node) {
|
|
1264
|
+
if (!jm.util.is_node(node)) {
|
|
1245
1265
|
var the_node = this.get_node(node);
|
|
1246
|
-
if(!the_node){
|
|
1247
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
1266
|
+
if (!the_node) {
|
|
1267
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
1248
1268
|
return;
|
|
1249
|
-
}else{
|
|
1269
|
+
} else {
|
|
1250
1270
|
return this.collapse_node(the_node);
|
|
1251
1271
|
}
|
|
1252
1272
|
}
|
|
1253
|
-
if(node.isroot){return;}
|
|
1273
|
+
if (node.isroot) { return; }
|
|
1254
1274
|
this.view.save_location(node);
|
|
1255
1275
|
this.layout.collapse_node(node);
|
|
1256
1276
|
this.view.relayout();
|
|
1257
1277
|
this.view.restore_location(node);
|
|
1258
1278
|
},
|
|
1259
1279
|
|
|
1260
|
-
expand_all:function(){
|
|
1280
|
+
expand_all: function () {
|
|
1261
1281
|
this.layout.expand_all();
|
|
1262
1282
|
this.view.relayout();
|
|
1263
1283
|
},
|
|
1264
1284
|
|
|
1265
|
-
collapse_all:function(){
|
|
1285
|
+
collapse_all: function () {
|
|
1266
1286
|
this.layout.collapse_all();
|
|
1267
1287
|
this.view.relayout();
|
|
1268
1288
|
},
|
|
1269
1289
|
|
|
1270
|
-
expand_to_depth:function(depth){
|
|
1290
|
+
expand_to_depth: function (depth) {
|
|
1271
1291
|
this.layout.expand_to_depth(depth);
|
|
1272
1292
|
this.view.relayout();
|
|
1273
1293
|
},
|
|
1274
1294
|
|
|
1275
|
-
_reset:function(){
|
|
1295
|
+
_reset: function () {
|
|
1276
1296
|
this.view.reset();
|
|
1277
1297
|
this.layout.reset();
|
|
1278
1298
|
this.data.reset();
|
|
1279
1299
|
},
|
|
1280
1300
|
|
|
1281
|
-
_show:function(mind){
|
|
1301
|
+
_show: function (mind) {
|
|
1282
1302
|
var m = mind || jm.format.node_array.example;
|
|
1283
1303
|
|
|
1284
1304
|
this.mind = this.data.load(m);
|
|
1285
|
-
if(!this.mind){
|
|
1305
|
+
if (!this.mind) {
|
|
1286
1306
|
logger.error('data.load error');
|
|
1287
1307
|
return;
|
|
1288
|
-
}else{
|
|
1308
|
+
} else {
|
|
1289
1309
|
logger.debug('data.load ok');
|
|
1290
1310
|
}
|
|
1291
1311
|
|
|
@@ -1298,99 +1318,99 @@
|
|
|
1298
1318
|
this.view.show(true);
|
|
1299
1319
|
logger.debug('view.show ok');
|
|
1300
1320
|
|
|
1301
|
-
this.invoke_event_handle(jm.event_type.show,{data:[mind]});
|
|
1321
|
+
this.invoke_event_handle(jm.event_type.show, { data: [mind] });
|
|
1302
1322
|
},
|
|
1303
1323
|
|
|
1304
|
-
show
|
|
1324
|
+
show: function (mind) {
|
|
1305
1325
|
this._reset();
|
|
1306
1326
|
this._show(mind);
|
|
1307
1327
|
},
|
|
1308
1328
|
|
|
1309
|
-
get_meta: function(){
|
|
1329
|
+
get_meta: function () {
|
|
1310
1330
|
return {
|
|
1311
|
-
name
|
|
1312
|
-
author
|
|
1313
|
-
version
|
|
1331
|
+
name: this.mind.name,
|
|
1332
|
+
author: this.mind.author,
|
|
1333
|
+
version: this.mind.version
|
|
1314
1334
|
};
|
|
1315
1335
|
},
|
|
1316
1336
|
|
|
1317
|
-
get_data: function(data_format){
|
|
1337
|
+
get_data: function (data_format) {
|
|
1318
1338
|
var df = data_format || 'node_tree';
|
|
1319
1339
|
return this.data.get_data(df);
|
|
1320
1340
|
},
|
|
1321
1341
|
|
|
1322
|
-
get_root:function(){
|
|
1342
|
+
get_root: function () {
|
|
1323
1343
|
return this.mind.root;
|
|
1324
1344
|
},
|
|
1325
1345
|
|
|
1326
|
-
get_node:function(nodeid){
|
|
1346
|
+
get_node: function (nodeid) {
|
|
1327
1347
|
return this.mind.get_node(nodeid);
|
|
1328
1348
|
},
|
|
1329
1349
|
|
|
1330
|
-
add_node:function(parent_node, nodeid, topic, data){
|
|
1331
|
-
if(this.get_editable()){
|
|
1350
|
+
add_node: function (parent_node, nodeid, topic, data) {
|
|
1351
|
+
if (this.get_editable()) {
|
|
1332
1352
|
var node = this.mind.add_node(parent_node, nodeid, topic, data);
|
|
1333
|
-
if(!!node){
|
|
1353
|
+
if (!!node) {
|
|
1334
1354
|
this.view.add_node(node);
|
|
1335
1355
|
this.layout.layout();
|
|
1336
1356
|
this.view.show(false);
|
|
1337
1357
|
this.view.reset_node_custom_style(node);
|
|
1338
1358
|
this.expand_node(parent_node);
|
|
1339
|
-
this.invoke_event_handle(jm.event_type.edit,{evt:'add_node',data:[parent_node.id,nodeid,topic,data],node:nodeid});
|
|
1359
|
+
this.invoke_event_handle(jm.event_type.edit, { evt: 'add_node', data: [parent_node.id, nodeid, topic, data], node: nodeid });
|
|
1340
1360
|
}
|
|
1341
1361
|
return node;
|
|
1342
|
-
}else{
|
|
1362
|
+
} else {
|
|
1343
1363
|
logger.error('fail, this mind map is not editable');
|
|
1344
1364
|
return null;
|
|
1345
1365
|
}
|
|
1346
1366
|
},
|
|
1347
1367
|
|
|
1348
|
-
insert_node_before:function(node_before, nodeid, topic, data){
|
|
1349
|
-
if(this.get_editable()){
|
|
1368
|
+
insert_node_before: function (node_before, nodeid, topic, data) {
|
|
1369
|
+
if (this.get_editable()) {
|
|
1350
1370
|
var beforeid = jm.util.is_node(node_before) ? node_before.id : node_before;
|
|
1351
1371
|
var node = this.mind.insert_node_before(node_before, nodeid, topic, data);
|
|
1352
|
-
if(!!node){
|
|
1372
|
+
if (!!node) {
|
|
1353
1373
|
this.view.add_node(node);
|
|
1354
1374
|
this.layout.layout();
|
|
1355
1375
|
this.view.show(false);
|
|
1356
|
-
this.invoke_event_handle(jm.event_type.edit,{evt:'insert_node_before',data:[beforeid,nodeid,topic,data],node:nodeid});
|
|
1376
|
+
this.invoke_event_handle(jm.event_type.edit, { evt: 'insert_node_before', data: [beforeid, nodeid, topic, data], node: nodeid });
|
|
1357
1377
|
}
|
|
1358
1378
|
return node;
|
|
1359
|
-
}else{
|
|
1379
|
+
} else {
|
|
1360
1380
|
logger.error('fail, this mind map is not editable');
|
|
1361
1381
|
return null;
|
|
1362
1382
|
}
|
|
1363
1383
|
},
|
|
1364
1384
|
|
|
1365
|
-
insert_node_after:function(node_after, nodeid, topic, data){
|
|
1366
|
-
if(this.get_editable()){
|
|
1385
|
+
insert_node_after: function (node_after, nodeid, topic, data) {
|
|
1386
|
+
if (this.get_editable()) {
|
|
1367
1387
|
var afterid = jm.util.is_node(node_after) ? node_after.id : node_after;
|
|
1368
1388
|
var node = this.mind.insert_node_after(node_after, nodeid, topic, data);
|
|
1369
|
-
if(!!node){
|
|
1389
|
+
if (!!node) {
|
|
1370
1390
|
this.view.add_node(node);
|
|
1371
1391
|
this.layout.layout();
|
|
1372
1392
|
this.view.show(false);
|
|
1373
|
-
this.invoke_event_handle(jm.event_type.edit,{evt:'insert_node_after',data:[afterid,nodeid,topic,data],node:nodeid});
|
|
1393
|
+
this.invoke_event_handle(jm.event_type.edit, { evt: 'insert_node_after', data: [afterid, nodeid, topic, data], node: nodeid });
|
|
1374
1394
|
}
|
|
1375
1395
|
return node;
|
|
1376
|
-
}else{
|
|
1396
|
+
} else {
|
|
1377
1397
|
logger.error('fail, this mind map is not editable');
|
|
1378
1398
|
return null;
|
|
1379
1399
|
}
|
|
1380
1400
|
},
|
|
1381
1401
|
|
|
1382
|
-
remove_node:function(node){
|
|
1383
|
-
if(!jm.util.is_node(node)){
|
|
1402
|
+
remove_node: function (node) {
|
|
1403
|
+
if (!jm.util.is_node(node)) {
|
|
1384
1404
|
var the_node = this.get_node(node);
|
|
1385
|
-
if(!the_node){
|
|
1386
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
1405
|
+
if (!the_node) {
|
|
1406
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
1387
1407
|
return false;
|
|
1388
|
-
}else{
|
|
1408
|
+
} else {
|
|
1389
1409
|
return this.remove_node(the_node);
|
|
1390
1410
|
}
|
|
1391
1411
|
}
|
|
1392
|
-
if(this.get_editable()){
|
|
1393
|
-
if(node.isroot){
|
|
1412
|
+
if (this.get_editable()) {
|
|
1413
|
+
if (node.isroot) {
|
|
1394
1414
|
logger.error('fail, can not remove root node');
|
|
1395
1415
|
return false;
|
|
1396
1416
|
}
|
|
@@ -1403,23 +1423,23 @@
|
|
|
1403
1423
|
this.layout.layout();
|
|
1404
1424
|
this.view.show(false);
|
|
1405
1425
|
this.view.restore_location(parent_node);
|
|
1406
|
-
this.invoke_event_handle(jm.event_type.edit,{evt:'remove_node',data:[nodeid],node:parentid});
|
|
1426
|
+
this.invoke_event_handle(jm.event_type.edit, { evt: 'remove_node', data: [nodeid], node: parentid });
|
|
1407
1427
|
return true;
|
|
1408
|
-
}else{
|
|
1428
|
+
} else {
|
|
1409
1429
|
logger.error('fail, this mind map is not editable');
|
|
1410
1430
|
return false;
|
|
1411
1431
|
}
|
|
1412
1432
|
},
|
|
1413
1433
|
|
|
1414
|
-
update_node:function(nodeid, topic){
|
|
1415
|
-
if(this.get_editable()){
|
|
1416
|
-
if(jm.util.text.is_empty(topic)){
|
|
1434
|
+
update_node: function (nodeid, topic) {
|
|
1435
|
+
if (this.get_editable()) {
|
|
1436
|
+
if (jm.util.text.is_empty(topic)) {
|
|
1417
1437
|
logger.warn('fail, topic can not be empty');
|
|
1418
1438
|
return;
|
|
1419
1439
|
}
|
|
1420
1440
|
var node = this.get_node(nodeid);
|
|
1421
|
-
if(!!node){
|
|
1422
|
-
if(node.topic === topic){
|
|
1441
|
+
if (!!node) {
|
|
1442
|
+
if (node.topic === topic) {
|
|
1423
1443
|
logger.info('nothing changed');
|
|
1424
1444
|
this.view.update_node(node);
|
|
1425
1445
|
return;
|
|
@@ -1428,159 +1448,160 @@
|
|
|
1428
1448
|
this.view.update_node(node);
|
|
1429
1449
|
this.layout.layout();
|
|
1430
1450
|
this.view.show(false);
|
|
1431
|
-
this.invoke_event_handle(jm.event_type.edit,{evt:'update_node',data:[nodeid,topic],node:nodeid});
|
|
1451
|
+
this.invoke_event_handle(jm.event_type.edit, { evt: 'update_node', data: [nodeid, topic], node: nodeid });
|
|
1432
1452
|
}
|
|
1433
|
-
}else{
|
|
1453
|
+
} else {
|
|
1434
1454
|
logger.error('fail, this mind map is not editable');
|
|
1435
1455
|
return;
|
|
1436
1456
|
}
|
|
1437
1457
|
},
|
|
1438
1458
|
|
|
1439
|
-
move_node:function(nodeid, beforeid, parentid, direction){
|
|
1440
|
-
if(this.get_editable()){
|
|
1441
|
-
var node = this.mind.move_node(nodeid,beforeid,parentid,direction);
|
|
1442
|
-
if(!!node){
|
|
1459
|
+
move_node: function (nodeid, beforeid, parentid, direction) {
|
|
1460
|
+
if (this.get_editable()) {
|
|
1461
|
+
var node = this.mind.move_node(nodeid, beforeid, parentid, direction);
|
|
1462
|
+
if (!!node) {
|
|
1443
1463
|
this.view.update_node(node);
|
|
1444
1464
|
this.layout.layout();
|
|
1445
1465
|
this.view.show(false);
|
|
1446
|
-
this.invoke_event_handle(jm.event_type.edit,{evt:'move_node',data:[nodeid,beforeid,parentid,direction],node:nodeid});
|
|
1466
|
+
this.invoke_event_handle(jm.event_type.edit, { evt: 'move_node', data: [nodeid, beforeid, parentid, direction], node: nodeid });
|
|
1447
1467
|
}
|
|
1448
|
-
}else{
|
|
1468
|
+
} else {
|
|
1449
1469
|
logger.error('fail, this mind map is not editable');
|
|
1450
1470
|
return;
|
|
1451
1471
|
}
|
|
1452
1472
|
},
|
|
1453
1473
|
|
|
1454
|
-
select_node:function(node){
|
|
1455
|
-
if(!jm.util.is_node(node)){
|
|
1474
|
+
select_node: function (node) {
|
|
1475
|
+
if (!jm.util.is_node(node)) {
|
|
1456
1476
|
var the_node = this.get_node(node);
|
|
1457
|
-
if(!the_node){
|
|
1458
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
1477
|
+
if (!the_node) {
|
|
1478
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
1459
1479
|
return;
|
|
1460
|
-
}else{
|
|
1480
|
+
} else {
|
|
1461
1481
|
return this.select_node(the_node);
|
|
1462
1482
|
}
|
|
1463
1483
|
}
|
|
1464
|
-
if(!this.layout.is_visible(node)){
|
|
1484
|
+
if (!this.layout.is_visible(node)) {
|
|
1465
1485
|
return;
|
|
1466
1486
|
}
|
|
1467
1487
|
this.mind.selected = node;
|
|
1468
1488
|
this.view.select_node(node);
|
|
1489
|
+
this.invoke_event_handle(jm.event_type.select, { evt: 'select_node', data: [], node: node.id });
|
|
1469
1490
|
},
|
|
1470
1491
|
|
|
1471
|
-
get_selected_node:function(){
|
|
1472
|
-
if(!!this.mind){
|
|
1492
|
+
get_selected_node: function () {
|
|
1493
|
+
if (!!this.mind) {
|
|
1473
1494
|
return this.mind.selected;
|
|
1474
|
-
}else{
|
|
1495
|
+
} else {
|
|
1475
1496
|
return null;
|
|
1476
1497
|
}
|
|
1477
1498
|
},
|
|
1478
1499
|
|
|
1479
|
-
select_clear:function(){
|
|
1480
|
-
if(!!this.mind){
|
|
1500
|
+
select_clear: function () {
|
|
1501
|
+
if (!!this.mind) {
|
|
1481
1502
|
this.mind.selected = null;
|
|
1482
1503
|
this.view.select_clear();
|
|
1483
1504
|
}
|
|
1484
1505
|
},
|
|
1485
1506
|
|
|
1486
|
-
is_node_visible:function(node){
|
|
1507
|
+
is_node_visible: function (node) {
|
|
1487
1508
|
return this.layout.is_visible(node);
|
|
1488
1509
|
},
|
|
1489
1510
|
|
|
1490
|
-
find_node_before:function(node){
|
|
1491
|
-
if(!jm.util.is_node(node)){
|
|
1511
|
+
find_node_before: function (node) {
|
|
1512
|
+
if (!jm.util.is_node(node)) {
|
|
1492
1513
|
var the_node = this.get_node(node);
|
|
1493
|
-
if(!the_node){
|
|
1494
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
1514
|
+
if (!the_node) {
|
|
1515
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
1495
1516
|
return;
|
|
1496
|
-
}else{
|
|
1517
|
+
} else {
|
|
1497
1518
|
return this.find_node_before(the_node);
|
|
1498
1519
|
}
|
|
1499
1520
|
}
|
|
1500
|
-
if(node.isroot){return null;}
|
|
1521
|
+
if (node.isroot) { return null; }
|
|
1501
1522
|
var n = null;
|
|
1502
|
-
if(node.parent.isroot){
|
|
1523
|
+
if (node.parent.isroot) {
|
|
1503
1524
|
var c = node.parent.children;
|
|
1504
1525
|
var prev = null;
|
|
1505
1526
|
var ni = null;
|
|
1506
|
-
for(var i=0;i<c.length;i++){
|
|
1527
|
+
for (var i = 0; i < c.length; i++) {
|
|
1507
1528
|
ni = c[i];
|
|
1508
|
-
if(node.direction === ni.direction){
|
|
1509
|
-
if(node.id === ni.id){
|
|
1529
|
+
if (node.direction === ni.direction) {
|
|
1530
|
+
if (node.id === ni.id) {
|
|
1510
1531
|
n = prev;
|
|
1511
1532
|
}
|
|
1512
1533
|
prev = ni;
|
|
1513
1534
|
}
|
|
1514
1535
|
}
|
|
1515
|
-
}else{
|
|
1536
|
+
} else {
|
|
1516
1537
|
n = this.mind.get_node_before(node);
|
|
1517
1538
|
}
|
|
1518
1539
|
return n;
|
|
1519
1540
|
},
|
|
1520
1541
|
|
|
1521
|
-
find_node_after:function(node){
|
|
1522
|
-
if(!jm.util.is_node(node)){
|
|
1542
|
+
find_node_after: function (node) {
|
|
1543
|
+
if (!jm.util.is_node(node)) {
|
|
1523
1544
|
var the_node = this.get_node(node);
|
|
1524
|
-
if(!the_node){
|
|
1525
|
-
logger.error('the node[id='+node+'] can not be found.');
|
|
1545
|
+
if (!the_node) {
|
|
1546
|
+
logger.error('the node[id=' + node + '] can not be found.');
|
|
1526
1547
|
return;
|
|
1527
|
-
}else{
|
|
1548
|
+
} else {
|
|
1528
1549
|
return this.find_node_after(the_node);
|
|
1529
1550
|
}
|
|
1530
1551
|
}
|
|
1531
|
-
if(node.isroot){return null;}
|
|
1552
|
+
if (node.isroot) { return null; }
|
|
1532
1553
|
var n = null;
|
|
1533
|
-
if(node.parent.isroot){
|
|
1554
|
+
if (node.parent.isroot) {
|
|
1534
1555
|
var c = node.parent.children;
|
|
1535
1556
|
var getthis = false;
|
|
1536
1557
|
var ni = null;
|
|
1537
|
-
for(var i=0;i<c.length;i++){
|
|
1558
|
+
for (var i = 0; i < c.length; i++) {
|
|
1538
1559
|
ni = c[i];
|
|
1539
|
-
if(node.direction === ni.direction){
|
|
1540
|
-
if(getthis){
|
|
1560
|
+
if (node.direction === ni.direction) {
|
|
1561
|
+
if (getthis) {
|
|
1541
1562
|
n = ni;
|
|
1542
1563
|
break;
|
|
1543
1564
|
}
|
|
1544
|
-
if(node.id === ni.id){
|
|
1565
|
+
if (node.id === ni.id) {
|
|
1545
1566
|
getthis = true;
|
|
1546
1567
|
}
|
|
1547
1568
|
}
|
|
1548
1569
|
}
|
|
1549
|
-
}else{
|
|
1570
|
+
} else {
|
|
1550
1571
|
n = this.mind.get_node_after(node);
|
|
1551
1572
|
}
|
|
1552
1573
|
return n;
|
|
1553
1574
|
},
|
|
1554
1575
|
|
|
1555
|
-
set_node_color:function(nodeid, bgcolor, fgcolor){
|
|
1556
|
-
if(this.get_editable()){
|
|
1576
|
+
set_node_color: function (nodeid, bgcolor, fgcolor) {
|
|
1577
|
+
if (this.get_editable()) {
|
|
1557
1578
|
var node = this.mind.get_node(nodeid);
|
|
1558
|
-
if(!!node){
|
|
1559
|
-
if(!!bgcolor){
|
|
1579
|
+
if (!!node) {
|
|
1580
|
+
if (!!bgcolor) {
|
|
1560
1581
|
node.data['background-color'] = bgcolor;
|
|
1561
1582
|
}
|
|
1562
|
-
if(!!fgcolor){
|
|
1583
|
+
if (!!fgcolor) {
|
|
1563
1584
|
node.data['foreground-color'] = fgcolor;
|
|
1564
1585
|
}
|
|
1565
1586
|
this.view.reset_node_custom_style(node);
|
|
1566
1587
|
}
|
|
1567
|
-
}else{
|
|
1588
|
+
} else {
|
|
1568
1589
|
logger.error('fail, this mind map is not editable');
|
|
1569
1590
|
return null;
|
|
1570
1591
|
}
|
|
1571
1592
|
},
|
|
1572
1593
|
|
|
1573
|
-
set_node_font_style:function(nodeid, size, weight, style){
|
|
1574
|
-
if(this.get_editable()){
|
|
1594
|
+
set_node_font_style: function (nodeid, size, weight, style) {
|
|
1595
|
+
if (this.get_editable()) {
|
|
1575
1596
|
var node = this.mind.get_node(nodeid);
|
|
1576
|
-
if(!!node){
|
|
1577
|
-
if(!!size){
|
|
1597
|
+
if (!!node) {
|
|
1598
|
+
if (!!size) {
|
|
1578
1599
|
node.data['font-size'] = size;
|
|
1579
1600
|
}
|
|
1580
|
-
if(!!weight){
|
|
1601
|
+
if (!!weight) {
|
|
1581
1602
|
node.data['font-weight'] = weight;
|
|
1582
1603
|
}
|
|
1583
|
-
if(!!style){
|
|
1604
|
+
if (!!style) {
|
|
1584
1605
|
node.data['font-style'] = style;
|
|
1585
1606
|
}
|
|
1586
1607
|
this.view.reset_node_custom_style(node);
|
|
@@ -1588,26 +1609,26 @@
|
|
|
1588
1609
|
this.layout.layout();
|
|
1589
1610
|
this.view.show(false);
|
|
1590
1611
|
}
|
|
1591
|
-
}else{
|
|
1612
|
+
} else {
|
|
1592
1613
|
logger.error('fail, this mind map is not editable');
|
|
1593
1614
|
return null;
|
|
1594
1615
|
}
|
|
1595
1616
|
},
|
|
1596
1617
|
|
|
1597
|
-
set_node_background_image:function(nodeid, image, width, height, rotation){
|
|
1598
|
-
if(this.get_editable()){
|
|
1618
|
+
set_node_background_image: function (nodeid, image, width, height, rotation) {
|
|
1619
|
+
if (this.get_editable()) {
|
|
1599
1620
|
var node = this.mind.get_node(nodeid);
|
|
1600
|
-
if(!!node){
|
|
1601
|
-
if(!!image){
|
|
1621
|
+
if (!!node) {
|
|
1622
|
+
if (!!image) {
|
|
1602
1623
|
node.data['background-image'] = image;
|
|
1603
1624
|
}
|
|
1604
|
-
if(!!width){
|
|
1625
|
+
if (!!width) {
|
|
1605
1626
|
node.data['width'] = width;
|
|
1606
1627
|
}
|
|
1607
|
-
if(!!height){
|
|
1628
|
+
if (!!height) {
|
|
1608
1629
|
node.data['height'] = height;
|
|
1609
1630
|
}
|
|
1610
|
-
if(!!rotation){
|
|
1631
|
+
if (!!rotation) {
|
|
1611
1632
|
node.data['background-rotation'] = rotation;
|
|
1612
1633
|
}
|
|
1613
1634
|
this.view.reset_node_custom_style(node);
|
|
@@ -1615,17 +1636,17 @@
|
|
|
1615
1636
|
this.layout.layout();
|
|
1616
1637
|
this.view.show(false);
|
|
1617
1638
|
}
|
|
1618
|
-
}else{
|
|
1639
|
+
} else {
|
|
1619
1640
|
logger.error('fail, this mind map is not editable');
|
|
1620
1641
|
return null;
|
|
1621
1642
|
}
|
|
1622
1643
|
},
|
|
1623
1644
|
|
|
1624
|
-
set_node_background_rotation:function(nodeid, rotation){
|
|
1625
|
-
if(this.get_editable()){
|
|
1645
|
+
set_node_background_rotation: function (nodeid, rotation) {
|
|
1646
|
+
if (this.get_editable()) {
|
|
1626
1647
|
var node = this.mind.get_node(nodeid);
|
|
1627
|
-
if(!!node){
|
|
1628
|
-
if(!node.data['background-image']) {
|
|
1648
|
+
if (!!node) {
|
|
1649
|
+
if (!node.data['background-image']) {
|
|
1629
1650
|
logger.error('fail, only can change rotation angle of node with background image');
|
|
1630
1651
|
return null;
|
|
1631
1652
|
}
|
|
@@ -1635,89 +1656,93 @@
|
|
|
1635
1656
|
this.layout.layout();
|
|
1636
1657
|
this.view.show(false);
|
|
1637
1658
|
}
|
|
1638
|
-
}else{
|
|
1659
|
+
} else {
|
|
1639
1660
|
logger.error('fail, this mind map is not editable');
|
|
1640
1661
|
return null;
|
|
1641
1662
|
}
|
|
1642
1663
|
},
|
|
1643
1664
|
|
|
1644
|
-
resize:function(){
|
|
1665
|
+
resize: function () {
|
|
1645
1666
|
this.view.resize();
|
|
1646
1667
|
},
|
|
1647
1668
|
|
|
1648
1669
|
// callback(type ,data)
|
|
1649
|
-
add_event_listener:function(callback){
|
|
1650
|
-
if(typeof callback === 'function'){
|
|
1670
|
+
add_event_listener: function (callback) {
|
|
1671
|
+
if (typeof callback === 'function') {
|
|
1651
1672
|
this.event_handles.push(callback);
|
|
1652
1673
|
}
|
|
1653
1674
|
},
|
|
1654
1675
|
|
|
1655
|
-
|
|
1676
|
+
clear_event_listener: function () {
|
|
1677
|
+
this.event_handles = [];
|
|
1678
|
+
},
|
|
1679
|
+
|
|
1680
|
+
invoke_event_handle: function (type, data) {
|
|
1656
1681
|
var j = this;
|
|
1657
|
-
$w.setTimeout(function(){
|
|
1658
|
-
j._invoke_event_handle(type,data);
|
|
1659
|
-
},0);
|
|
1682
|
+
$w.setTimeout(function () {
|
|
1683
|
+
j._invoke_event_handle(type, data);
|
|
1684
|
+
}, 0);
|
|
1660
1685
|
},
|
|
1661
1686
|
|
|
1662
|
-
_invoke_event_handle:function(type,data){
|
|
1687
|
+
_invoke_event_handle: function (type, data) {
|
|
1663
1688
|
var l = this.event_handles.length;
|
|
1664
|
-
for(var i=0;i<l;i++){
|
|
1665
|
-
this.event_handles[i](type,data);
|
|
1689
|
+
for (var i = 0; i < l; i++) {
|
|
1690
|
+
this.event_handles[i](type, data);
|
|
1666
1691
|
}
|
|
1667
|
-
}
|
|
1692
|
+
},
|
|
1668
1693
|
|
|
1669
1694
|
};
|
|
1670
1695
|
|
|
1671
|
-
// ============= data provider =============================================
|
|
1696
|
+
// ============= data provider =============================================
|
|
1672
1697
|
|
|
1673
|
-
jm.data_provider = function(jm){
|
|
1698
|
+
jm.data_provider = function (jm) {
|
|
1674
1699
|
this.jm = jm;
|
|
1675
1700
|
};
|
|
1676
1701
|
|
|
1677
|
-
jm.data_provider.prototype={
|
|
1678
|
-
init:function(){
|
|
1702
|
+
jm.data_provider.prototype = {
|
|
1703
|
+
init: function () {
|
|
1679
1704
|
logger.debug('data.init');
|
|
1680
1705
|
},
|
|
1681
1706
|
|
|
1682
|
-
reset:function(){
|
|
1707
|
+
reset: function () {
|
|
1683
1708
|
logger.debug('data.reset');
|
|
1684
1709
|
},
|
|
1685
1710
|
|
|
1686
|
-
load:function(mind_data){
|
|
1711
|
+
load: function (mind_data) {
|
|
1687
1712
|
var df = null;
|
|
1688
1713
|
var mind = null;
|
|
1689
|
-
if(typeof mind_data === 'object'){
|
|
1690
|
-
if(!!mind_data.format){
|
|
1714
|
+
if (typeof mind_data === 'object') {
|
|
1715
|
+
if (!!mind_data.format) {
|
|
1691
1716
|
df = mind_data.format;
|
|
1692
|
-
}else{
|
|
1717
|
+
} else {
|
|
1693
1718
|
df = 'node_tree';
|
|
1694
1719
|
}
|
|
1695
|
-
}else{
|
|
1720
|
+
} else {
|
|
1696
1721
|
df = 'freemind';
|
|
1697
1722
|
}
|
|
1698
1723
|
|
|
1699
|
-
if(df == 'node_array'){
|
|
1724
|
+
if (df == 'node_array') {
|
|
1700
1725
|
mind = jm.format.node_array.get_mind(mind_data);
|
|
1701
|
-
}else if(df == 'node_tree'){
|
|
1726
|
+
} else if (df == 'node_tree') {
|
|
1702
1727
|
mind = jm.format.node_tree.get_mind(mind_data);
|
|
1703
|
-
}else if(df == 'freemind'){
|
|
1728
|
+
} else if (df == 'freemind') {
|
|
1704
1729
|
mind = jm.format.freemind.get_mind(mind_data);
|
|
1705
|
-
}else{
|
|
1730
|
+
} else {
|
|
1706
1731
|
logger.warn('unsupported format');
|
|
1707
1732
|
}
|
|
1708
1733
|
return mind;
|
|
1709
1734
|
},
|
|
1710
1735
|
|
|
1711
|
-
get_data:function(data_format){
|
|
1736
|
+
get_data: function (data_format) {
|
|
1712
1737
|
var data = null;
|
|
1713
|
-
if(data_format == 'node_array'){
|
|
1738
|
+
if (data_format == 'node_array') {
|
|
1714
1739
|
data = jm.format.node_array.get_data(this.jm.mind);
|
|
1715
|
-
}else if(data_format == 'node_tree'){
|
|
1740
|
+
} else if (data_format == 'node_tree') {
|
|
1716
1741
|
data = jm.format.node_tree.get_data(this.jm.mind);
|
|
1717
|
-
}else if(data_format == 'freemind'){
|
|
1742
|
+
} else if (data_format == 'freemind') {
|
|
1718
1743
|
data = jm.format.freemind.get_data(this.jm.mind);
|
|
1719
|
-
}else{
|
|
1720
|
-
logger.error('unsupported '+data_format+' format');
|
|
1744
|
+
} else {
|
|
1745
|
+
logger.error('unsupported ' + data_format + ' format');
|
|
1721
1746
|
}
|
|
1722
1747
|
return data;
|
|
1723
1748
|
},
|
|
@@ -1725,7 +1750,7 @@
|
|
|
1725
1750
|
|
|
1726
1751
|
// ============= layout provider ===========================================
|
|
1727
1752
|
|
|
1728
|
-
jm.layout_provider = function(jm, options){
|
|
1753
|
+
jm.layout_provider = function (jm, options) {
|
|
1729
1754
|
this.opts = options;
|
|
1730
1755
|
this.jm = jm;
|
|
1731
1756
|
this.isside = (this.opts.mode == 'side');
|
|
@@ -1734,31 +1759,31 @@
|
|
|
1734
1759
|
this.cache_valid = false;
|
|
1735
1760
|
};
|
|
1736
1761
|
|
|
1737
|
-
jm.layout_provider.prototype={
|
|
1738
|
-
init:function(){
|
|
1762
|
+
jm.layout_provider.prototype = {
|
|
1763
|
+
init: function () {
|
|
1739
1764
|
logger.debug('layout.init');
|
|
1740
1765
|
},
|
|
1741
|
-
reset:function(){
|
|
1766
|
+
reset: function () {
|
|
1742
1767
|
logger.debug('layout.reset');
|
|
1743
|
-
this.bounds = {n:0,s:0,w:0,e:0};
|
|
1768
|
+
this.bounds = { n: 0, s: 0, w: 0, e: 0 };
|
|
1744
1769
|
},
|
|
1745
|
-
layout:function(){
|
|
1770
|
+
layout: function () {
|
|
1746
1771
|
logger.debug('layout.layout');
|
|
1747
1772
|
this.layout_direction();
|
|
1748
1773
|
this.layout_offset();
|
|
1749
1774
|
},
|
|
1750
1775
|
|
|
1751
|
-
layout_direction:function(){
|
|
1776
|
+
layout_direction: function () {
|
|
1752
1777
|
this._layout_direction_root();
|
|
1753
1778
|
},
|
|
1754
1779
|
|
|
1755
|
-
_layout_direction_root:function(){
|
|
1780
|
+
_layout_direction_root: function () {
|
|
1756
1781
|
var node = this.jm.mind.root;
|
|
1757
1782
|
// logger.debug(node);
|
|
1758
1783
|
var layout_data = null;
|
|
1759
|
-
if('layout' in node._data){
|
|
1784
|
+
if ('layout' in node._data) {
|
|
1760
1785
|
layout_data = node._data.layout;
|
|
1761
|
-
}else{
|
|
1786
|
+
} else {
|
|
1762
1787
|
layout_data = {};
|
|
1763
1788
|
node._data.layout = layout_data;
|
|
1764
1789
|
}
|
|
@@ -1766,20 +1791,20 @@
|
|
|
1766
1791
|
var children_count = children.length;
|
|
1767
1792
|
layout_data.direction = jm.direction.center;
|
|
1768
1793
|
layout_data.side_index = 0;
|
|
1769
|
-
if(this.isside){
|
|
1794
|
+
if (this.isside) {
|
|
1770
1795
|
var i = children_count;
|
|
1771
|
-
while(i--){
|
|
1796
|
+
while (i--) {
|
|
1772
1797
|
this._layout_direction_side(children[i], jm.direction.right, i);
|
|
1773
1798
|
}
|
|
1774
|
-
}else{
|
|
1799
|
+
} else {
|
|
1775
1800
|
var i = children_count;
|
|
1776
1801
|
var subnode = null;
|
|
1777
|
-
while(i--){
|
|
1802
|
+
while (i--) {
|
|
1778
1803
|
subnode = children[i];
|
|
1779
|
-
if(subnode.direction == jm.direction.left){
|
|
1780
|
-
this._layout_direction_side(subnode,jm.direction.left, i);
|
|
1781
|
-
}else{
|
|
1782
|
-
this._layout_direction_side(subnode,jm.direction.right, i);
|
|
1804
|
+
if (subnode.direction == jm.direction.left) {
|
|
1805
|
+
this._layout_direction_side(subnode, jm.direction.left, i);
|
|
1806
|
+
} else {
|
|
1807
|
+
this._layout_direction_side(subnode, jm.direction.right, i);
|
|
1783
1808
|
}
|
|
1784
1809
|
}
|
|
1785
1810
|
/*
|
|
@@ -1796,11 +1821,11 @@
|
|
|
1796
1821
|
}
|
|
1797
1822
|
},
|
|
1798
1823
|
|
|
1799
|
-
_layout_direction_side:function(node, direction, side_index){
|
|
1824
|
+
_layout_direction_side: function (node, direction, side_index) {
|
|
1800
1825
|
var layout_data = null;
|
|
1801
|
-
if('layout' in node._data){
|
|
1826
|
+
if ('layout' in node._data) {
|
|
1802
1827
|
layout_data = node._data.layout;
|
|
1803
|
-
}else{
|
|
1828
|
+
} else {
|
|
1804
1829
|
layout_data = {};
|
|
1805
1830
|
node._data.layout = layout_data;
|
|
1806
1831
|
}
|
|
@@ -1810,12 +1835,12 @@
|
|
|
1810
1835
|
layout_data.direction = direction;
|
|
1811
1836
|
layout_data.side_index = side_index;
|
|
1812
1837
|
var i = children_count;
|
|
1813
|
-
while(i--){
|
|
1838
|
+
while (i--) {
|
|
1814
1839
|
this._layout_direction_side(children[i], direction, i);
|
|
1815
1840
|
}
|
|
1816
1841
|
},
|
|
1817
1842
|
|
|
1818
|
-
layout_offset:function(){
|
|
1843
|
+
layout_offset: function () {
|
|
1819
1844
|
var node = this.jm.mind.root;
|
|
1820
1845
|
var layout_data = node._data.layout;
|
|
1821
1846
|
layout_data.offset_x = 0;
|
|
@@ -1826,11 +1851,11 @@
|
|
|
1826
1851
|
var left_nodes = [];
|
|
1827
1852
|
var right_nodes = [];
|
|
1828
1853
|
var subnode = null;
|
|
1829
|
-
while(i--){
|
|
1854
|
+
while (i--) {
|
|
1830
1855
|
subnode = children[i];
|
|
1831
|
-
if(subnode._data.layout.direction == jm.direction.right){
|
|
1856
|
+
if (subnode._data.layout.direction == jm.direction.right) {
|
|
1832
1857
|
right_nodes.unshift(subnode);
|
|
1833
|
-
}else{
|
|
1858
|
+
} else {
|
|
1834
1859
|
left_nodes.unshift(subnode);
|
|
1835
1860
|
}
|
|
1836
1861
|
}
|
|
@@ -1838,15 +1863,15 @@
|
|
|
1838
1863
|
layout_data.right_nodes = right_nodes;
|
|
1839
1864
|
layout_data.outer_height_left = this._layout_offset_subnodes(left_nodes);
|
|
1840
1865
|
layout_data.outer_height_right = this._layout_offset_subnodes(right_nodes);
|
|
1841
|
-
this.bounds.e=node._data.view.width/2;
|
|
1842
|
-
this.bounds.w=0-this.bounds.e;
|
|
1866
|
+
this.bounds.e = node._data.view.width / 2;
|
|
1867
|
+
this.bounds.w = 0 - this.bounds.e;
|
|
1843
1868
|
//logger.debug(this.bounds.w);
|
|
1844
|
-
this.bounds.n=0;
|
|
1845
|
-
this.bounds.s = Math.max(layout_data.outer_height_left,layout_data.outer_height_right);
|
|
1869
|
+
this.bounds.n = 0;
|
|
1870
|
+
this.bounds.s = Math.max(layout_data.outer_height_left, layout_data.outer_height_right);
|
|
1846
1871
|
},
|
|
1847
1872
|
|
|
1848
1873
|
// layout both the x and y axis
|
|
1849
|
-
_layout_offset_subnodes:function(nodes){
|
|
1874
|
+
_layout_offset_subnodes: function (nodes) {
|
|
1850
1875
|
var total_height = 0;
|
|
1851
1876
|
var nodes_count = nodes.length;
|
|
1852
1877
|
var i = nodes_count;
|
|
@@ -1855,36 +1880,36 @@
|
|
|
1855
1880
|
var layout_data = null;
|
|
1856
1881
|
var base_y = 0;
|
|
1857
1882
|
var pd = null; // parent._data
|
|
1858
|
-
while(i--){
|
|
1883
|
+
while (i--) {
|
|
1859
1884
|
node = nodes[i];
|
|
1860
1885
|
layout_data = node._data.layout;
|
|
1861
|
-
if(pd == null){
|
|
1886
|
+
if (pd == null) {
|
|
1862
1887
|
pd = node.parent._data;
|
|
1863
1888
|
}
|
|
1864
1889
|
|
|
1865
1890
|
node_outer_height = this._layout_offset_subnodes(node.children);
|
|
1866
|
-
if(!node.expanded){
|
|
1867
|
-
node_outer_height=0;
|
|
1868
|
-
this.set_visible(node.children,false);
|
|
1891
|
+
if (!node.expanded) {
|
|
1892
|
+
node_outer_height = 0;
|
|
1893
|
+
this.set_visible(node.children, false);
|
|
1869
1894
|
}
|
|
1870
|
-
node_outer_height = Math.max(node._data.view.height,node_outer_height);
|
|
1895
|
+
node_outer_height = Math.max(node._data.view.height, node_outer_height);
|
|
1871
1896
|
|
|
1872
1897
|
layout_data.outer_height = node_outer_height;
|
|
1873
|
-
layout_data.offset_y = base_y - node_outer_height/2;
|
|
1874
|
-
layout_data.offset_x = this.opts.hspace * layout_data.direction + pd.view.width * (pd.layout.direction + layout_data.direction)/2;
|
|
1875
|
-
if(!node.parent.isroot){
|
|
1898
|
+
layout_data.offset_y = base_y - node_outer_height / 2;
|
|
1899
|
+
layout_data.offset_x = this.opts.hspace * layout_data.direction + pd.view.width * (pd.layout.direction + layout_data.direction) / 2;
|
|
1900
|
+
if (!node.parent.isroot) {
|
|
1876
1901
|
layout_data.offset_x += this.opts.pspace * layout_data.direction;
|
|
1877
1902
|
}
|
|
1878
1903
|
|
|
1879
1904
|
base_y = base_y - node_outer_height - this.opts.vspace;
|
|
1880
1905
|
total_height += node_outer_height;
|
|
1881
1906
|
}
|
|
1882
|
-
if(nodes_count>1){
|
|
1883
|
-
total_height += this.opts.vspace * (nodes_count-1);
|
|
1907
|
+
if (nodes_count > 1) {
|
|
1908
|
+
total_height += this.opts.vspace * (nodes_count - 1);
|
|
1884
1909
|
}
|
|
1885
1910
|
i = nodes_count;
|
|
1886
|
-
var middle_height = total_height/2;
|
|
1887
|
-
while(i--){
|
|
1911
|
+
var middle_height = total_height / 2;
|
|
1912
|
+
while (i--) {
|
|
1888
1913
|
node = nodes[i];
|
|
1889
1914
|
node._data.layout.offset_y += middle_height;
|
|
1890
1915
|
}
|
|
@@ -1892,7 +1917,7 @@
|
|
|
1892
1917
|
},
|
|
1893
1918
|
|
|
1894
1919
|
// layout the y axis only, for collapse/expand a node
|
|
1895
|
-
_layout_offset_subnodes_height:function(nodes){
|
|
1920
|
+
_layout_offset_subnodes_height: function (nodes) {
|
|
1896
1921
|
var total_height = 0;
|
|
1897
1922
|
var nodes_count = nodes.length;
|
|
1898
1923
|
var i = nodes_count;
|
|
@@ -1901,30 +1926,30 @@
|
|
|
1901
1926
|
var layout_data = null;
|
|
1902
1927
|
var base_y = 0;
|
|
1903
1928
|
var pd = null; // parent._data
|
|
1904
|
-
while(i--){
|
|
1929
|
+
while (i--) {
|
|
1905
1930
|
node = nodes[i];
|
|
1906
1931
|
layout_data = node._data.layout;
|
|
1907
|
-
if(pd == null){
|
|
1932
|
+
if (pd == null) {
|
|
1908
1933
|
pd = node.parent._data;
|
|
1909
1934
|
}
|
|
1910
1935
|
|
|
1911
1936
|
node_outer_height = this._layout_offset_subnodes_height(node.children);
|
|
1912
|
-
if(!node.expanded){
|
|
1913
|
-
node_outer_height=0;
|
|
1937
|
+
if (!node.expanded) {
|
|
1938
|
+
node_outer_height = 0;
|
|
1914
1939
|
}
|
|
1915
|
-
node_outer_height = Math.max(node._data.view.height,node_outer_height);
|
|
1940
|
+
node_outer_height = Math.max(node._data.view.height, node_outer_height);
|
|
1916
1941
|
|
|
1917
1942
|
layout_data.outer_height = node_outer_height;
|
|
1918
|
-
layout_data.offset_y = base_y - node_outer_height/2;
|
|
1943
|
+
layout_data.offset_y = base_y - node_outer_height / 2;
|
|
1919
1944
|
base_y = base_y - node_outer_height - this.opts.vspace;
|
|
1920
1945
|
total_height += node_outer_height;
|
|
1921
1946
|
}
|
|
1922
|
-
if(nodes_count>1){
|
|
1923
|
-
total_height += this.opts.vspace * (nodes_count-1);
|
|
1947
|
+
if (nodes_count > 1) {
|
|
1948
|
+
total_height += this.opts.vspace * (nodes_count - 1);
|
|
1924
1949
|
}
|
|
1925
1950
|
i = nodes_count;
|
|
1926
|
-
var middle_height = total_height/2;
|
|
1927
|
-
while(i--){
|
|
1951
|
+
var middle_height = total_height / 2;
|
|
1952
|
+
while (i--) {
|
|
1928
1953
|
node = nodes[i];
|
|
1929
1954
|
node._data.layout.offset_y += middle_height;
|
|
1930
1955
|
//logger.debug(node.topic);
|
|
@@ -1933,19 +1958,19 @@
|
|
|
1933
1958
|
return total_height;
|
|
1934
1959
|
},
|
|
1935
1960
|
|
|
1936
|
-
get_node_offset:function(node){
|
|
1961
|
+
get_node_offset: function (node) {
|
|
1937
1962
|
var layout_data = node._data.layout;
|
|
1938
1963
|
var offset_cache = null;
|
|
1939
|
-
if(('_offset_' in layout_data) && this.cache_valid){
|
|
1964
|
+
if (('_offset_' in layout_data) && this.cache_valid) {
|
|
1940
1965
|
offset_cache = layout_data._offset_;
|
|
1941
|
-
}else{
|
|
1942
|
-
offset_cache = {x
|
|
1966
|
+
} else {
|
|
1967
|
+
offset_cache = { x: -1, y: -1 };
|
|
1943
1968
|
layout_data._offset_ = offset_cache;
|
|
1944
1969
|
}
|
|
1945
|
-
if(offset_cache.x == -1 || offset_cache.y == -1){
|
|
1970
|
+
if (offset_cache.x == -1 || offset_cache.y == -1) {
|
|
1946
1971
|
var x = layout_data.offset_x;
|
|
1947
1972
|
var y = layout_data.offset_y;
|
|
1948
|
-
if(!node.isroot){
|
|
1973
|
+
if (!node.isroot) {
|
|
1949
1974
|
var offset_p = this.get_node_offset(node.parent);
|
|
1950
1975
|
x += offset_p.x;
|
|
1951
1976
|
y += offset_p.y;
|
|
@@ -1956,39 +1981,39 @@
|
|
|
1956
1981
|
return offset_cache;
|
|
1957
1982
|
},
|
|
1958
1983
|
|
|
1959
|
-
get_node_point:function(node){
|
|
1984
|
+
get_node_point: function (node) {
|
|
1960
1985
|
var view_data = node._data.view;
|
|
1961
1986
|
var offset_p = this.get_node_offset(node);
|
|
1962
1987
|
//logger.debug(offset_p);
|
|
1963
1988
|
var p = {};
|
|
1964
|
-
p.x = offset_p.x + view_data.width*(node._data.layout.direction-1)/2;
|
|
1965
|
-
p.y = offset_p.y-view_data.height/2;
|
|
1989
|
+
p.x = offset_p.x + view_data.width * (node._data.layout.direction - 1) / 2;
|
|
1990
|
+
p.y = offset_p.y - view_data.height / 2;
|
|
1966
1991
|
//logger.debug(p);
|
|
1967
1992
|
return p;
|
|
1968
1993
|
},
|
|
1969
1994
|
|
|
1970
|
-
get_node_point_in:function(node){
|
|
1995
|
+
get_node_point_in: function (node) {
|
|
1971
1996
|
var p = this.get_node_offset(node);
|
|
1972
1997
|
return p;
|
|
1973
1998
|
},
|
|
1974
1999
|
|
|
1975
|
-
get_node_point_out:function(node){
|
|
2000
|
+
get_node_point_out: function (node) {
|
|
1976
2001
|
var layout_data = node._data.layout;
|
|
1977
2002
|
var pout_cache = null;
|
|
1978
|
-
if(('_pout_' in layout_data) && this.cache_valid){
|
|
2003
|
+
if (('_pout_' in layout_data) && this.cache_valid) {
|
|
1979
2004
|
pout_cache = layout_data._pout_;
|
|
1980
|
-
}else{
|
|
1981
|
-
pout_cache = {x
|
|
2005
|
+
} else {
|
|
2006
|
+
pout_cache = { x: -1, y: -1 };
|
|
1982
2007
|
layout_data._pout_ = pout_cache;
|
|
1983
2008
|
}
|
|
1984
|
-
if(pout_cache.x == -1 || pout_cache.y == -1){
|
|
1985
|
-
if(node.isroot){
|
|
2009
|
+
if (pout_cache.x == -1 || pout_cache.y == -1) {
|
|
2010
|
+
if (node.isroot) {
|
|
1986
2011
|
pout_cache.x = 0;
|
|
1987
2012
|
pout_cache.y = 0;
|
|
1988
|
-
}else{
|
|
2013
|
+
} else {
|
|
1989
2014
|
var view_data = node._data.view;
|
|
1990
2015
|
var offset_p = this.get_node_offset(node);
|
|
1991
|
-
pout_cache.x = offset_p.x + (view_data.width+this.opts.pspace)*node._data.layout.direction;
|
|
2016
|
+
pout_cache.x = offset_p.x + (view_data.width + this.opts.pspace) * node._data.layout.direction;
|
|
1992
2017
|
pout_cache.y = offset_p.y;
|
|
1993
2018
|
//logger.debug('pout');
|
|
1994
2019
|
//logger.debug(pout_cache);
|
|
@@ -1997,203 +2022,324 @@
|
|
|
1997
2022
|
return pout_cache;
|
|
1998
2023
|
},
|
|
1999
2024
|
|
|
2000
|
-
get_expander_point:function(node){
|
|
2025
|
+
get_expander_point: function (node) {
|
|
2001
2026
|
var p = this.get_node_point_out(node);
|
|
2002
2027
|
var ex_p = {};
|
|
2003
|
-
if(node._data.layout.direction == jm.direction.right){
|
|
2028
|
+
if (node._data.layout.direction == jm.direction.right) {
|
|
2004
2029
|
ex_p.x = p.x - this.opts.pspace;
|
|
2005
|
-
}else{
|
|
2030
|
+
} else {
|
|
2006
2031
|
ex_p.x = p.x;
|
|
2007
2032
|
}
|
|
2008
|
-
ex_p.y = p.y - Math.ceil(this.opts.pspace/2);
|
|
2033
|
+
ex_p.y = p.y - Math.ceil(this.opts.pspace / 2);
|
|
2009
2034
|
return ex_p;
|
|
2010
2035
|
},
|
|
2011
2036
|
|
|
2012
|
-
get_min_size:function(){
|
|
2037
|
+
get_min_size: function () {
|
|
2013
2038
|
var nodes = this.jm.mind.nodes;
|
|
2014
2039
|
var node = null;
|
|
2015
2040
|
var pout = null;
|
|
2016
|
-
for(var nodeid in nodes){
|
|
2041
|
+
for (var nodeid in nodes) {
|
|
2017
2042
|
node = nodes[nodeid];
|
|
2018
2043
|
pout = this.get_node_point_out(node);
|
|
2019
|
-
|
|
2020
|
-
if(pout.x
|
|
2021
|
-
if(pout.x < this.bounds.w){this.bounds.w = pout.x;}
|
|
2044
|
+
if (pout.x > this.bounds.e) { this.bounds.e = pout.x; }
|
|
2045
|
+
if (pout.x < this.bounds.w) { this.bounds.w = pout.x; }
|
|
2022
2046
|
}
|
|
2023
2047
|
return {
|
|
2024
|
-
w:this.bounds.e - this.bounds.w,
|
|
2025
|
-
h:this.bounds.s - this.bounds.n
|
|
2048
|
+
w: this.bounds.e - this.bounds.w,
|
|
2049
|
+
h: this.bounds.s - this.bounds.n
|
|
2026
2050
|
}
|
|
2027
2051
|
},
|
|
2028
2052
|
|
|
2029
|
-
toggle_node:function(node){
|
|
2030
|
-
if(node.isroot){
|
|
2053
|
+
toggle_node: function (node) {
|
|
2054
|
+
if (node.isroot) {
|
|
2031
2055
|
return;
|
|
2032
2056
|
}
|
|
2033
|
-
if(node.expanded){
|
|
2057
|
+
if (node.expanded) {
|
|
2034
2058
|
this.collapse_node(node);
|
|
2035
|
-
}else{
|
|
2059
|
+
} else {
|
|
2036
2060
|
this.expand_node(node);
|
|
2037
2061
|
}
|
|
2038
2062
|
},
|
|
2039
2063
|
|
|
2040
|
-
expand_node:function(node){
|
|
2064
|
+
expand_node: function (node) {
|
|
2041
2065
|
node.expanded = true;
|
|
2042
2066
|
this.part_layout(node);
|
|
2043
|
-
this.set_visible(node.children,true);
|
|
2067
|
+
this.set_visible(node.children, true);
|
|
2068
|
+
this.jm.invoke_event_handle(jm.event_type.show, { evt: 'expand_node', data: [], node: node.id });
|
|
2044
2069
|
},
|
|
2045
2070
|
|
|
2046
|
-
collapse_node:function(node){
|
|
2071
|
+
collapse_node: function (node) {
|
|
2047
2072
|
node.expanded = false;
|
|
2048
2073
|
this.part_layout(node);
|
|
2049
|
-
this.set_visible(node.children,false);
|
|
2074
|
+
this.set_visible(node.children, false);
|
|
2075
|
+
this.jm.invoke_event_handle(jm.event_type.show, { evt: 'collapse_node', data: [], node: node.id });
|
|
2050
2076
|
},
|
|
2051
2077
|
|
|
2052
|
-
expand_all:function(){
|
|
2078
|
+
expand_all: function () {
|
|
2053
2079
|
var nodes = this.jm.mind.nodes;
|
|
2054
2080
|
var c = 0;
|
|
2055
2081
|
var node;
|
|
2056
|
-
for(var nodeid in nodes){
|
|
2082
|
+
for (var nodeid in nodes) {
|
|
2057
2083
|
node = nodes[nodeid];
|
|
2058
|
-
if(!node.expanded){
|
|
2084
|
+
if (!node.expanded) {
|
|
2059
2085
|
node.expanded = true;
|
|
2060
2086
|
c++;
|
|
2061
2087
|
}
|
|
2062
2088
|
}
|
|
2063
|
-
if(c>0){
|
|
2089
|
+
if (c > 0) {
|
|
2064
2090
|
var root = this.jm.mind.root;
|
|
2065
2091
|
this.part_layout(root);
|
|
2066
|
-
this.set_visible(root.children,true);
|
|
2092
|
+
this.set_visible(root.children, true);
|
|
2067
2093
|
}
|
|
2068
2094
|
},
|
|
2069
2095
|
|
|
2070
|
-
collapse_all:function(){
|
|
2096
|
+
collapse_all: function () {
|
|
2071
2097
|
var nodes = this.jm.mind.nodes;
|
|
2072
2098
|
var c = 0;
|
|
2073
2099
|
var node;
|
|
2074
|
-
for(var nodeid in nodes){
|
|
2100
|
+
for (var nodeid in nodes) {
|
|
2075
2101
|
node = nodes[nodeid];
|
|
2076
|
-
if(node.expanded && !node.isroot){
|
|
2077
|
-
node.expanded = false
|
|
2102
|
+
if (node.expanded && !node.isroot) {
|
|
2103
|
+
node.expanded = false;
|
|
2078
2104
|
c++;
|
|
2079
2105
|
}
|
|
2080
2106
|
}
|
|
2081
|
-
if(c>0){
|
|
2107
|
+
if (c > 0) {
|
|
2082
2108
|
var root = this.jm.mind.root;
|
|
2083
2109
|
this.part_layout(root);
|
|
2084
|
-
this.set_visible(root.children,true);
|
|
2110
|
+
this.set_visible(root.children, true);
|
|
2085
2111
|
}
|
|
2086
2112
|
},
|
|
2087
2113
|
|
|
2088
|
-
expand_to_depth:function(target_depth,curr_nodes,curr_depth){
|
|
2089
|
-
if(target_depth < 1){return;}
|
|
2114
|
+
expand_to_depth: function (target_depth, curr_nodes, curr_depth) {
|
|
2115
|
+
if (target_depth < 1) { return; }
|
|
2090
2116
|
var nodes = curr_nodes || this.jm.mind.root.children;
|
|
2091
2117
|
var depth = curr_depth || 1;
|
|
2092
2118
|
var i = nodes.length;
|
|
2093
2119
|
var node = null;
|
|
2094
|
-
while(i--){
|
|
2120
|
+
while (i--) {
|
|
2095
2121
|
node = nodes[i];
|
|
2096
|
-
if(depth < target_depth){
|
|
2097
|
-
if(!node.expanded){
|
|
2122
|
+
if (depth < target_depth) {
|
|
2123
|
+
if (!node.expanded) {
|
|
2098
2124
|
this.expand_node(node);
|
|
2099
2125
|
}
|
|
2100
|
-
this.expand_to_depth(target_depth, node.children, depth+1);
|
|
2126
|
+
this.expand_to_depth(target_depth, node.children, depth + 1);
|
|
2101
2127
|
}
|
|
2102
|
-
if(depth == target_depth){
|
|
2103
|
-
if(node.expanded){
|
|
2128
|
+
if (depth == target_depth) {
|
|
2129
|
+
if (node.expanded) {
|
|
2104
2130
|
this.collapse_node(node);
|
|
2105
2131
|
}
|
|
2106
2132
|
}
|
|
2107
2133
|
}
|
|
2108
2134
|
},
|
|
2109
2135
|
|
|
2110
|
-
part_layout:function(node){
|
|
2136
|
+
part_layout: function (node) {
|
|
2111
2137
|
var root = this.jm.mind.root;
|
|
2112
|
-
if(!!root){
|
|
2138
|
+
if (!!root) {
|
|
2113
2139
|
var root_layout_data = root._data.layout;
|
|
2114
|
-
if(node.isroot){
|
|
2115
|
-
root_layout_data.outer_height_right=this._layout_offset_subnodes_height(root_layout_data.right_nodes);
|
|
2116
|
-
root_layout_data.outer_height_left=this._layout_offset_subnodes_height(root_layout_data.left_nodes);
|
|
2117
|
-
}else{
|
|
2118
|
-
if(node._data.layout.direction == jm.direction.right){
|
|
2119
|
-
root_layout_data.outer_height_right=this._layout_offset_subnodes_height(root_layout_data.right_nodes);
|
|
2120
|
-
}else{
|
|
2121
|
-
root_layout_data.outer_height_left=this._layout_offset_subnodes_height(root_layout_data.left_nodes);
|
|
2140
|
+
if (node.isroot) {
|
|
2141
|
+
root_layout_data.outer_height_right = this._layout_offset_subnodes_height(root_layout_data.right_nodes);
|
|
2142
|
+
root_layout_data.outer_height_left = this._layout_offset_subnodes_height(root_layout_data.left_nodes);
|
|
2143
|
+
} else {
|
|
2144
|
+
if (node._data.layout.direction == jm.direction.right) {
|
|
2145
|
+
root_layout_data.outer_height_right = this._layout_offset_subnodes_height(root_layout_data.right_nodes);
|
|
2146
|
+
} else {
|
|
2147
|
+
root_layout_data.outer_height_left = this._layout_offset_subnodes_height(root_layout_data.left_nodes);
|
|
2122
2148
|
}
|
|
2123
2149
|
}
|
|
2124
|
-
this.bounds.s = Math.max(root_layout_data.outer_height_left,root_layout_data.outer_height_right);
|
|
2150
|
+
this.bounds.s = Math.max(root_layout_data.outer_height_left, root_layout_data.outer_height_right);
|
|
2125
2151
|
this.cache_valid = false;
|
|
2126
|
-
}else{
|
|
2152
|
+
} else {
|
|
2127
2153
|
logger.warn('can not found root node');
|
|
2128
2154
|
}
|
|
2129
2155
|
},
|
|
2130
2156
|
|
|
2131
|
-
set_visible:function(nodes,visible){
|
|
2157
|
+
set_visible: function (nodes, visible) {
|
|
2132
2158
|
var i = nodes.length;
|
|
2133
2159
|
var node = null;
|
|
2134
2160
|
var layout_data = null;
|
|
2135
|
-
while(i--){
|
|
2161
|
+
while (i--) {
|
|
2136
2162
|
node = nodes[i];
|
|
2137
2163
|
layout_data = node._data.layout;
|
|
2138
|
-
if(node.expanded){
|
|
2139
|
-
this.set_visible(node.children,visible);
|
|
2140
|
-
}else{
|
|
2141
|
-
this.set_visible(node.children,false);
|
|
2164
|
+
if (node.expanded) {
|
|
2165
|
+
this.set_visible(node.children, visible);
|
|
2166
|
+
} else {
|
|
2167
|
+
this.set_visible(node.children, false);
|
|
2142
2168
|
}
|
|
2143
|
-
if(!node.isroot){
|
|
2169
|
+
if (!node.isroot) {
|
|
2144
2170
|
node._data.layout.visible = visible;
|
|
2145
2171
|
}
|
|
2146
2172
|
}
|
|
2147
2173
|
},
|
|
2148
2174
|
|
|
2149
|
-
is_expand:function(node){
|
|
2175
|
+
is_expand: function (node) {
|
|
2150
2176
|
return node.expanded;
|
|
2151
2177
|
},
|
|
2152
|
-
|
|
2153
|
-
is_visible:function(node){
|
|
2178
|
+
|
|
2179
|
+
is_visible: function (node) {
|
|
2154
2180
|
var layout_data = node._data.layout;
|
|
2155
|
-
if(('visible' in layout_data) && !layout_data.visible){
|
|
2181
|
+
if (('visible' in layout_data) && !layout_data.visible) {
|
|
2156
2182
|
return false;
|
|
2157
|
-
}else{
|
|
2183
|
+
} else {
|
|
2158
2184
|
return true;
|
|
2159
2185
|
}
|
|
2186
|
+
}
|
|
2187
|
+
};
|
|
2188
|
+
|
|
2189
|
+
jm.graph_canvas = function (view) {
|
|
2190
|
+
this.opts = view.opts;
|
|
2191
|
+
this.e_canvas = $c('canvas');
|
|
2192
|
+
this.e_canvas.className = 'jsmind';
|
|
2193
|
+
this.canvas_ctx = this.e_canvas.getContext('2d');
|
|
2194
|
+
this.size = { w: 0, h: 0 };
|
|
2195
|
+
};
|
|
2196
|
+
|
|
2197
|
+
jm.graph_canvas.prototype = {
|
|
2198
|
+
element: function () {
|
|
2199
|
+
return this.e_canvas;
|
|
2200
|
+
},
|
|
2201
|
+
|
|
2202
|
+
set_size: function (w, h) {
|
|
2203
|
+
this.size.w = w;
|
|
2204
|
+
this.size.h = h;
|
|
2205
|
+
this.e_canvas.width = w;
|
|
2206
|
+
this.e_canvas.height = h;
|
|
2207
|
+
},
|
|
2208
|
+
|
|
2209
|
+
clear: function () {
|
|
2210
|
+
this.canvas_ctx.clearRect(0, 0, this.size.w, this.size.h);
|
|
2211
|
+
},
|
|
2212
|
+
|
|
2213
|
+
draw_line: function (pout, pin, offset) {
|
|
2214
|
+
var ctx = this.canvas_ctx;
|
|
2215
|
+
ctx.strokeStyle = this.opts.line_color;
|
|
2216
|
+
ctx.lineWidth = this.opts.line_width;
|
|
2217
|
+
ctx.lineCap = 'round';
|
|
2218
|
+
|
|
2219
|
+
this._bezier_to(ctx,
|
|
2220
|
+
pin.x + offset.x,
|
|
2221
|
+
pin.y + offset.y,
|
|
2222
|
+
pout.x + offset.x,
|
|
2223
|
+
pout.y + offset.y);
|
|
2224
|
+
},
|
|
2225
|
+
|
|
2226
|
+
copy_to: function (dest_canvas_ctx, callback) {
|
|
2227
|
+
dest_canvas_ctx.drawImage(this.e_canvas, 0, 0);
|
|
2228
|
+
!!callback && callback();
|
|
2229
|
+
},
|
|
2230
|
+
|
|
2231
|
+
_bezier_to: function (ctx, x1, y1, x2, y2) {
|
|
2232
|
+
ctx.beginPath();
|
|
2233
|
+
ctx.moveTo(x1, y1);
|
|
2234
|
+
ctx.bezierCurveTo(x1 + (x2 - x1) * 2 / 3, y1, x1, y2, x2, y2);
|
|
2235
|
+
ctx.stroke();
|
|
2236
|
+
},
|
|
2237
|
+
|
|
2238
|
+
_line_to: function (ctx, x1, y1, x2, y2) {
|
|
2239
|
+
ctx.beginPath();
|
|
2240
|
+
ctx.moveTo(x1, y1);
|
|
2241
|
+
ctx.lineTo(x2, y2);
|
|
2242
|
+
ctx.stroke();
|
|
2243
|
+
}
|
|
2244
|
+
};
|
|
2245
|
+
|
|
2246
|
+
jm.graph_svg = function (view) {
|
|
2247
|
+
this.view = view;
|
|
2248
|
+
this.opts = view.opts;
|
|
2249
|
+
this.e_svg = jm.graph_svg.c('svg');
|
|
2250
|
+
this.e_svg.setAttribute('class', 'jsmind');
|
|
2251
|
+
this.size = { w: 0, h: 0 };
|
|
2252
|
+
this.lines = [];
|
|
2253
|
+
};
|
|
2254
|
+
|
|
2255
|
+
jm.graph_svg.c = function (tag) {
|
|
2256
|
+
return $d.createElementNS('http://www.w3.org/2000/svg', tag);
|
|
2257
|
+
};
|
|
2258
|
+
|
|
2259
|
+
jm.graph_svg.prototype = {
|
|
2260
|
+
element: function () {
|
|
2261
|
+
return this.e_svg;
|
|
2262
|
+
},
|
|
2263
|
+
|
|
2264
|
+
set_size: function (w, h) {
|
|
2265
|
+
this.size.w = w;
|
|
2266
|
+
this.size.h = h;
|
|
2267
|
+
this.e_svg.setAttribute('width', w);
|
|
2268
|
+
this.e_svg.setAttribute('height', h);
|
|
2269
|
+
},
|
|
2270
|
+
|
|
2271
|
+
clear: function () {
|
|
2272
|
+
var len = this.lines.length;
|
|
2273
|
+
while (len--) {
|
|
2274
|
+
this.e_svg.removeChild(this.lines[len]);
|
|
2275
|
+
}
|
|
2276
|
+
this.lines.length = 0;
|
|
2277
|
+
},
|
|
2278
|
+
|
|
2279
|
+
draw_line: function (pout, pin, offset) {
|
|
2280
|
+
var line = jm.graph_svg.c('path');
|
|
2281
|
+
line.setAttribute('stroke', this.opts.line_color);
|
|
2282
|
+
line.setAttribute('stroke-width', this.opts.line_width);
|
|
2283
|
+
line.setAttribute('fill', 'transparent');
|
|
2284
|
+
this.lines.push(line);
|
|
2285
|
+
this.e_svg.appendChild(line);
|
|
2286
|
+
this._bezier_to(line, pin.x + offset.x, pin.y + offset.y, pout.x + offset.x, pout.y + offset.y);
|
|
2287
|
+
},
|
|
2288
|
+
|
|
2289
|
+
copy_to: function (dest_canvas_ctx, callback) {
|
|
2290
|
+
var img = new Image();
|
|
2291
|
+
img.onload = function () {
|
|
2292
|
+
dest_canvas_ctx.drawImage(img, 0, 0);
|
|
2293
|
+
!!callback && callback();
|
|
2294
|
+
}
|
|
2295
|
+
img.src = 'data:image/svg+xml;base64,' + btoa(new XMLSerializer().serializeToString(this.e_svg));
|
|
2160
2296
|
},
|
|
2297
|
+
|
|
2298
|
+
_bezier_to: function (path, x1, y1, x2, y2) {
|
|
2299
|
+
path.setAttribute('d', 'M' + x1 + ' ' + y1 + ' C ' + (x1 + (x2 - x1) * 2 / 3) + ' ' + y1 + ', ' + x1 + ' ' + y2 + ', ' + x2 + ' ' + y2);
|
|
2300
|
+
},
|
|
2301
|
+
|
|
2302
|
+
_line_to: function (path, x1, y1, x2, y2) {
|
|
2303
|
+
path.setAttribute('d', 'M ' + x1 + ' ' + y1 + ' L ' + x2 + ' ' + y2);
|
|
2304
|
+
}
|
|
2161
2305
|
};
|
|
2162
2306
|
|
|
2163
2307
|
// view provider
|
|
2164
|
-
jm.view_provider= function(jm, options){
|
|
2308
|
+
jm.view_provider = function (jm, options) {
|
|
2165
2309
|
this.opts = options;
|
|
2166
2310
|
this.jm = jm;
|
|
2167
2311
|
this.layout = jm.layout;
|
|
2168
2312
|
|
|
2169
2313
|
this.container = null;
|
|
2170
2314
|
this.e_panel = null;
|
|
2171
|
-
this.e_nodes= null;
|
|
2172
|
-
this.e_canvas = null;
|
|
2315
|
+
this.e_nodes = null;
|
|
2173
2316
|
|
|
2174
|
-
this.
|
|
2175
|
-
this.size = {w:0,h:0};
|
|
2317
|
+
this.size = { w: 0, h: 0 };
|
|
2176
2318
|
|
|
2177
2319
|
this.selected_node = null;
|
|
2178
2320
|
this.editing_node = null;
|
|
2321
|
+
|
|
2322
|
+
this.graph = null;
|
|
2179
2323
|
};
|
|
2180
2324
|
|
|
2181
|
-
jm.view_provider.prototype={
|
|
2182
|
-
init:function(){
|
|
2325
|
+
jm.view_provider.prototype = {
|
|
2326
|
+
init: function () {
|
|
2183
2327
|
logger.debug('view.init');
|
|
2184
2328
|
|
|
2185
2329
|
this.container = $i(this.opts.container) ? this.opts.container : $g(this.opts.container);
|
|
2186
|
-
if(!this.container){
|
|
2330
|
+
if (!this.container) {
|
|
2187
2331
|
logger.error('the options.view.container was not be found in dom');
|
|
2188
2332
|
return;
|
|
2189
2333
|
}
|
|
2190
2334
|
this.e_panel = $c('div');
|
|
2191
|
-
this.e_canvas = $c('canvas');
|
|
2192
2335
|
this.e_nodes = $c('jmnodes');
|
|
2193
2336
|
this.e_editor = $c('input');
|
|
2194
2337
|
|
|
2338
|
+
this.graph = this.opts.engine.toLowerCase() === 'svg' ? new jm.graph_svg(this) : new jm.graph_canvas(this);
|
|
2339
|
+
|
|
2195
2340
|
this.e_panel.className = 'jsmind-inner';
|
|
2196
|
-
this.e_panel.
|
|
2341
|
+
this.e_panel.tabIndex = 1;
|
|
2342
|
+
this.e_panel.appendChild(this.graph.element());
|
|
2197
2343
|
this.e_panel.appendChild(this.e_nodes);
|
|
2198
2344
|
|
|
2199
2345
|
this.e_editor.className = 'jsmind-editor';
|
|
@@ -2205,46 +2351,46 @@
|
|
|
2205
2351
|
this.maxZoom = 2;
|
|
2206
2352
|
|
|
2207
2353
|
var v = this;
|
|
2208
|
-
jm.util.dom.add_event(this.e_editor,'keydown',function(e){
|
|
2354
|
+
jm.util.dom.add_event(this.e_editor, 'keydown', function (e) {
|
|
2209
2355
|
var evt = e || event;
|
|
2210
|
-
if(evt.keyCode == 13){v.edit_node_end();evt.stopPropagation();}
|
|
2356
|
+
if (evt.keyCode == 13) { v.edit_node_end(); evt.stopPropagation(); }
|
|
2211
2357
|
});
|
|
2212
|
-
jm.util.dom.add_event(this.e_editor,'blur',function(e){
|
|
2358
|
+
jm.util.dom.add_event(this.e_editor, 'blur', function (e) {
|
|
2213
2359
|
v.edit_node_end();
|
|
2214
2360
|
});
|
|
2215
2361
|
|
|
2216
2362
|
this.container.appendChild(this.e_panel);
|
|
2217
2363
|
|
|
2218
|
-
this.
|
|
2364
|
+
this.enable_draggable_canvas()
|
|
2219
2365
|
},
|
|
2220
2366
|
|
|
2221
|
-
add_event:function(obj,event_name,event_handle){
|
|
2222
|
-
jm.util.dom.add_event(this.e_nodes,event_name,function(e){
|
|
2367
|
+
add_event: function (obj, event_name, event_handle) {
|
|
2368
|
+
jm.util.dom.add_event(this.e_nodes, event_name, function (e) {
|
|
2223
2369
|
var evt = e || event;
|
|
2224
|
-
event_handle.call(obj,evt);
|
|
2370
|
+
event_handle.call(obj, evt);
|
|
2225
2371
|
});
|
|
2226
2372
|
},
|
|
2227
2373
|
|
|
2228
|
-
get_binded_nodeid:function(element){
|
|
2229
|
-
if(element == null){
|
|
2374
|
+
get_binded_nodeid: function (element) {
|
|
2375
|
+
if (element == null) {
|
|
2230
2376
|
return null;
|
|
2231
2377
|
}
|
|
2232
2378
|
var tagName = element.tagName.toLowerCase();
|
|
2233
|
-
if(tagName == 'jmnodes' || tagName == 'body' || tagName == 'html'){
|
|
2379
|
+
if (tagName == 'jmnodes' || tagName == 'body' || tagName == 'html') {
|
|
2234
2380
|
return null;
|
|
2235
2381
|
}
|
|
2236
|
-
if(tagName == 'jmnode' || tagName == 'jmexpander'){
|
|
2382
|
+
if (tagName == 'jmnode' || tagName == 'jmexpander') {
|
|
2237
2383
|
return element.getAttribute('nodeid');
|
|
2238
|
-
}else{
|
|
2384
|
+
} else {
|
|
2239
2385
|
return this.get_binded_nodeid(element.parentElement);
|
|
2240
2386
|
}
|
|
2241
2387
|
},
|
|
2242
2388
|
|
|
2243
|
-
is_expander:function(element){
|
|
2389
|
+
is_expander: function (element) {
|
|
2244
2390
|
return (element.tagName.toLowerCase() == 'jmexpander');
|
|
2245
2391
|
},
|
|
2246
2392
|
|
|
2247
|
-
reset:function(){
|
|
2393
|
+
reset: function () {
|
|
2248
2394
|
logger.debug('view.reset');
|
|
2249
2395
|
this.selected_node = null;
|
|
2250
2396
|
this.clear_lines();
|
|
@@ -2252,116 +2398,111 @@
|
|
|
2252
2398
|
this.reset_theme();
|
|
2253
2399
|
},
|
|
2254
2400
|
|
|
2255
|
-
reset_theme:function(){
|
|
2401
|
+
reset_theme: function () {
|
|
2256
2402
|
var theme_name = this.jm.options.theme;
|
|
2257
|
-
if(!!theme_name){
|
|
2403
|
+
if (!!theme_name) {
|
|
2258
2404
|
this.e_nodes.className = 'theme-' + theme_name;
|
|
2259
|
-
}else{
|
|
2405
|
+
} else {
|
|
2260
2406
|
this.e_nodes.className = '';
|
|
2261
2407
|
}
|
|
2262
2408
|
},
|
|
2263
2409
|
|
|
2264
|
-
reset_custom_style:function(){
|
|
2410
|
+
reset_custom_style: function () {
|
|
2265
2411
|
var nodes = this.jm.mind.nodes;
|
|
2266
|
-
for(var nodeid in nodes){
|
|
2412
|
+
for (var nodeid in nodes) {
|
|
2267
2413
|
this.reset_node_custom_style(nodes[nodeid]);
|
|
2268
2414
|
}
|
|
2269
2415
|
},
|
|
2270
2416
|
|
|
2271
|
-
load:function(){
|
|
2417
|
+
load: function () {
|
|
2272
2418
|
logger.debug('view.load');
|
|
2273
2419
|
this.init_nodes();
|
|
2274
2420
|
},
|
|
2275
2421
|
|
|
2276
|
-
expand_size:function(){
|
|
2422
|
+
expand_size: function () {
|
|
2277
2423
|
var min_size = this.layout.get_min_size();
|
|
2278
|
-
var min_width = min_size.w + this.opts.hmargin*2;
|
|
2279
|
-
var min_height = min_size.h + this.opts.vmargin*2;
|
|
2424
|
+
var min_width = min_size.w + this.opts.hmargin * 2;
|
|
2425
|
+
var min_height = min_size.h + this.opts.vmargin * 2;
|
|
2280
2426
|
var client_w = this.e_panel.clientWidth;
|
|
2281
2427
|
var client_h = this.e_panel.clientHeight;
|
|
2282
|
-
if(client_w < min_width){client_w = min_width;}
|
|
2283
|
-
if(client_h < min_height){client_h = min_height;}
|
|
2428
|
+
if (client_w < min_width) { client_w = min_width; }
|
|
2429
|
+
if (client_h < min_height) { client_h = min_height; }
|
|
2284
2430
|
this.size.w = client_w;
|
|
2285
2431
|
this.size.h = client_h;
|
|
2286
2432
|
},
|
|
2287
2433
|
|
|
2288
|
-
|
|
2289
|
-
var ctx = this.e_canvas.getContext('2d');
|
|
2290
|
-
this.canvas_ctx = ctx;
|
|
2291
|
-
},
|
|
2292
|
-
|
|
2293
|
-
init_nodes_size:function(node){
|
|
2434
|
+
init_nodes_size: function (node) {
|
|
2294
2435
|
var view_data = node._data.view;
|
|
2295
2436
|
view_data.width = view_data.element.clientWidth;
|
|
2296
2437
|
view_data.height = view_data.element.clientHeight;
|
|
2297
2438
|
},
|
|
2298
2439
|
|
|
2299
|
-
init_nodes:function(){
|
|
2440
|
+
init_nodes: function () {
|
|
2300
2441
|
var nodes = this.jm.mind.nodes;
|
|
2301
2442
|
var doc_frag = $d.createDocumentFragment();
|
|
2302
|
-
for(var nodeid in nodes){
|
|
2303
|
-
this.create_node_element(nodes[nodeid],doc_frag);
|
|
2443
|
+
for (var nodeid in nodes) {
|
|
2444
|
+
this.create_node_element(nodes[nodeid], doc_frag);
|
|
2304
2445
|
}
|
|
2305
2446
|
this.e_nodes.appendChild(doc_frag);
|
|
2306
|
-
for(var nodeid in nodes){
|
|
2447
|
+
for (var nodeid in nodes) {
|
|
2307
2448
|
this.init_nodes_size(nodes[nodeid]);
|
|
2308
2449
|
}
|
|
2309
2450
|
},
|
|
2310
2451
|
|
|
2311
|
-
add_node:function(node){
|
|
2312
|
-
this.create_node_element(node,this.e_nodes);
|
|
2452
|
+
add_node: function (node) {
|
|
2453
|
+
this.create_node_element(node, this.e_nodes);
|
|
2313
2454
|
this.init_nodes_size(node);
|
|
2314
2455
|
},
|
|
2315
2456
|
|
|
2316
|
-
create_node_element:function(node,parent_node){
|
|
2457
|
+
create_node_element: function (node, parent_node) {
|
|
2317
2458
|
var view_data = null;
|
|
2318
|
-
if('view' in node._data){
|
|
2459
|
+
if ('view' in node._data) {
|
|
2319
2460
|
view_data = node._data.view;
|
|
2320
|
-
}else{
|
|
2461
|
+
} else {
|
|
2321
2462
|
view_data = {};
|
|
2322
2463
|
node._data.view = view_data;
|
|
2323
2464
|
}
|
|
2324
2465
|
|
|
2325
2466
|
var d = $c('jmnode');
|
|
2326
|
-
if(node.isroot){
|
|
2467
|
+
if (node.isroot) {
|
|
2327
2468
|
d.className = 'root';
|
|
2328
|
-
}else{
|
|
2469
|
+
} else {
|
|
2329
2470
|
var d_e = $c('jmexpander');
|
|
2330
|
-
$t(d_e,'-');
|
|
2331
|
-
d_e.setAttribute('nodeid',node.id);
|
|
2471
|
+
$t(d_e, '-');
|
|
2472
|
+
d_e.setAttribute('nodeid', node.id);
|
|
2332
2473
|
d_e.style.visibility = 'hidden';
|
|
2333
2474
|
parent_node.appendChild(d_e);
|
|
2334
2475
|
view_data.expander = d_e;
|
|
2335
2476
|
}
|
|
2336
2477
|
if (!!node.topic) {
|
|
2337
|
-
if(this.opts.support_html){
|
|
2338
|
-
$h(d,node.topic);
|
|
2339
|
-
}else{
|
|
2340
|
-
$t(d,node.topic);
|
|
2478
|
+
if (this.opts.support_html) {
|
|
2479
|
+
$h(d, node.topic);
|
|
2480
|
+
} else {
|
|
2481
|
+
$t(d, node.topic);
|
|
2341
2482
|
}
|
|
2342
2483
|
}
|
|
2343
|
-
d.setAttribute('nodeid',node.id);
|
|
2344
|
-
d.style.visibility='hidden';
|
|
2484
|
+
d.setAttribute('nodeid', node.id);
|
|
2485
|
+
d.style.visibility = 'hidden';
|
|
2345
2486
|
this._reset_node_custom_style(d, node.data);
|
|
2346
2487
|
|
|
2347
2488
|
parent_node.appendChild(d);
|
|
2348
2489
|
view_data.element = d;
|
|
2349
2490
|
},
|
|
2350
2491
|
|
|
2351
|
-
remove_node:function(node){
|
|
2352
|
-
if(this.selected_node != null && this.selected_node.id == node.id){
|
|
2492
|
+
remove_node: function (node) {
|
|
2493
|
+
if (this.selected_node != null && this.selected_node.id == node.id) {
|
|
2353
2494
|
this.selected_node = null;
|
|
2354
2495
|
}
|
|
2355
|
-
if(this.editing_node != null && this.editing_node.id == node.id){
|
|
2496
|
+
if (this.editing_node != null && this.editing_node.id == node.id) {
|
|
2356
2497
|
node._data.view.element.removeChild(this.e_editor);
|
|
2357
2498
|
this.editing_node = null;
|
|
2358
2499
|
}
|
|
2359
2500
|
var children = node.children;
|
|
2360
2501
|
var i = children.length;
|
|
2361
|
-
while(i--){
|
|
2502
|
+
while (i--) {
|
|
2362
2503
|
this.remove_node(children[i]);
|
|
2363
2504
|
}
|
|
2364
|
-
if(node._data.view){
|
|
2505
|
+
if (node._data.view) {
|
|
2365
2506
|
var element = node._data.view.element;
|
|
2366
2507
|
var expander = node._data.view.expander;
|
|
2367
2508
|
this.e_nodes.removeChild(element);
|
|
@@ -2371,51 +2512,51 @@
|
|
|
2371
2512
|
}
|
|
2372
2513
|
},
|
|
2373
2514
|
|
|
2374
|
-
update_node:function(node){
|
|
2515
|
+
update_node: function (node) {
|
|
2375
2516
|
var view_data = node._data.view;
|
|
2376
2517
|
var element = view_data.element;
|
|
2377
2518
|
if (!!node.topic) {
|
|
2378
|
-
if(this.opts.support_html){
|
|
2379
|
-
$h(element,node.topic);
|
|
2380
|
-
}else{
|
|
2381
|
-
$t(element,node.topic);
|
|
2519
|
+
if (this.opts.support_html) {
|
|
2520
|
+
$h(element, node.topic);
|
|
2521
|
+
} else {
|
|
2522
|
+
$t(element, node.topic);
|
|
2382
2523
|
}
|
|
2383
2524
|
}
|
|
2384
2525
|
view_data.width = element.clientWidth;
|
|
2385
2526
|
view_data.height = element.clientHeight;
|
|
2386
2527
|
},
|
|
2387
2528
|
|
|
2388
|
-
select_node:function(node){
|
|
2389
|
-
if(!!this.selected_node){
|
|
2529
|
+
select_node: function (node) {
|
|
2530
|
+
if (!!this.selected_node) {
|
|
2390
2531
|
this.selected_node._data.view.element.className =
|
|
2391
|
-
|
|
2532
|
+
this.selected_node._data.view.element.className.replace(/\s*selected\b/i, '');
|
|
2392
2533
|
this.reset_node_custom_style(this.selected_node);
|
|
2393
2534
|
}
|
|
2394
|
-
if(!!node){
|
|
2535
|
+
if (!!node) {
|
|
2395
2536
|
this.selected_node = node;
|
|
2396
2537
|
node._data.view.element.className += ' selected';
|
|
2397
2538
|
this.clear_node_custom_style(node);
|
|
2398
2539
|
}
|
|
2399
2540
|
},
|
|
2400
2541
|
|
|
2401
|
-
select_clear:function(){
|
|
2542
|
+
select_clear: function () {
|
|
2402
2543
|
this.select_node(null);
|
|
2403
2544
|
},
|
|
2404
2545
|
|
|
2405
|
-
get_editing_node:function(){
|
|
2546
|
+
get_editing_node: function () {
|
|
2406
2547
|
return this.editing_node;
|
|
2407
2548
|
},
|
|
2408
2549
|
|
|
2409
|
-
is_editing:function(){
|
|
2550
|
+
is_editing: function () {
|
|
2410
2551
|
return (!!this.editing_node);
|
|
2411
2552
|
},
|
|
2412
2553
|
|
|
2413
|
-
edit_node_begin:function(node){
|
|
2414
|
-
if(!node.topic) {
|
|
2554
|
+
edit_node_begin: function (node) {
|
|
2555
|
+
if (!node.topic) {
|
|
2415
2556
|
logger.warn("don't edit image nodes");
|
|
2416
2557
|
return;
|
|
2417
2558
|
}
|
|
2418
|
-
if(this.editing_node != null){
|
|
2559
|
+
if (this.editing_node != null) {
|
|
2419
2560
|
this.edit_node_end();
|
|
2420
2561
|
}
|
|
2421
2562
|
this.editing_node = node;
|
|
@@ -2424,7 +2565,7 @@
|
|
|
2424
2565
|
var topic = node.topic;
|
|
2425
2566
|
var ncs = getComputedStyle(element);
|
|
2426
2567
|
this.e_editor.value = topic;
|
|
2427
|
-
this.e_editor.style.width = (element.clientWidth-parseInt(ncs.getPropertyValue('padding-left'))-parseInt(ncs.getPropertyValue('padding-right')))+'px';
|
|
2568
|
+
this.e_editor.style.width = (element.clientWidth - parseInt(ncs.getPropertyValue('padding-left')) - parseInt(ncs.getPropertyValue('padding-right'))) + 'px';
|
|
2428
2569
|
element.innerHTML = '';
|
|
2429
2570
|
element.appendChild(this.e_editor);
|
|
2430
2571
|
element.style.zIndex = 5;
|
|
@@ -2432,8 +2573,8 @@
|
|
|
2432
2573
|
this.e_editor.select();
|
|
2433
2574
|
},
|
|
2434
2575
|
|
|
2435
|
-
edit_node_end:function(){
|
|
2436
|
-
if(this.editing_node != null){
|
|
2576
|
+
edit_node_end: function () {
|
|
2577
|
+
if (this.editing_node != null) {
|
|
2437
2578
|
var node = this.editing_node;
|
|
2438
2579
|
this.editing_node = null;
|
|
2439
2580
|
var view_data = node._data.view;
|
|
@@ -2441,28 +2582,28 @@
|
|
|
2441
2582
|
var topic = this.e_editor.value;
|
|
2442
2583
|
element.style.zIndex = 'auto';
|
|
2443
2584
|
element.removeChild(this.e_editor);
|
|
2444
|
-
if(jm.util.text.is_empty(topic) || node.topic === topic){
|
|
2445
|
-
if(this.opts.support_html){
|
|
2446
|
-
$h(element,node.topic);
|
|
2447
|
-
}else{
|
|
2448
|
-
$t(element,node.topic);
|
|
2585
|
+
if (jm.util.text.is_empty(topic) || node.topic === topic) {
|
|
2586
|
+
if (this.opts.support_html) {
|
|
2587
|
+
$h(element, node.topic);
|
|
2588
|
+
} else {
|
|
2589
|
+
$t(element, node.topic);
|
|
2449
2590
|
}
|
|
2450
|
-
}else{
|
|
2451
|
-
this.jm.update_node(node.id,topic);
|
|
2591
|
+
} else {
|
|
2592
|
+
this.jm.update_node(node.id, topic);
|
|
2452
2593
|
}
|
|
2453
2594
|
}
|
|
2595
|
+
this.e_panel.focus();
|
|
2454
2596
|
},
|
|
2455
2597
|
|
|
2456
|
-
get_view_offset:function(){
|
|
2598
|
+
get_view_offset: function () {
|
|
2457
2599
|
var bounds = this.layout.bounds;
|
|
2458
|
-
var _x = (this.size.w - bounds.e - bounds.w)/2;
|
|
2600
|
+
var _x = (this.size.w - bounds.e - bounds.w) / 2;
|
|
2459
2601
|
var _y = this.size.h / 2;
|
|
2460
|
-
return{x:_x, y:_y};
|
|
2602
|
+
return { x: _x, y: _y };
|
|
2461
2603
|
},
|
|
2462
2604
|
|
|
2463
|
-
resize:function(){
|
|
2464
|
-
this.
|
|
2465
|
-
this.e_canvas.height = 1;
|
|
2605
|
+
resize: function () {
|
|
2606
|
+
this.graph.set_size(1, 1);
|
|
2466
2607
|
this.e_nodes.style.width = '1px';
|
|
2467
2608
|
this.e_nodes.style.height = '1px';
|
|
2468
2609
|
|
|
@@ -2470,31 +2611,30 @@
|
|
|
2470
2611
|
this._show();
|
|
2471
2612
|
},
|
|
2472
2613
|
|
|
2473
|
-
_show:function(){
|
|
2474
|
-
this.
|
|
2475
|
-
this.
|
|
2476
|
-
this.e_nodes.style.
|
|
2477
|
-
this.e_nodes.style.height = this.size.h+'px';
|
|
2614
|
+
_show: function () {
|
|
2615
|
+
this.graph.set_size(this.size.w, this.size.h);
|
|
2616
|
+
this.e_nodes.style.width = this.size.w + 'px';
|
|
2617
|
+
this.e_nodes.style.height = this.size.h + 'px';
|
|
2478
2618
|
this.show_nodes();
|
|
2479
2619
|
this.show_lines();
|
|
2480
2620
|
//this.layout.cache_valid = true;
|
|
2481
|
-
this.jm.invoke_event_handle(jm.event_type.resize,{data:[]});
|
|
2621
|
+
this.jm.invoke_event_handle(jm.event_type.resize, { data: [] });
|
|
2482
2622
|
},
|
|
2483
2623
|
|
|
2484
|
-
zoomIn: function() {
|
|
2624
|
+
zoomIn: function () {
|
|
2485
2625
|
return this.setZoom(this.actualZoom + this.zoomStep);
|
|
2486
2626
|
},
|
|
2487
2627
|
|
|
2488
|
-
zoomOut: function() {
|
|
2628
|
+
zoomOut: function () {
|
|
2489
2629
|
return this.setZoom(this.actualZoom - this.zoomStep);
|
|
2490
2630
|
},
|
|
2491
2631
|
|
|
2492
|
-
setZoom: function(zoom) {
|
|
2632
|
+
setZoom: function (zoom) {
|
|
2493
2633
|
if ((zoom < this.minZoom) || (zoom > this.maxZoom)) {
|
|
2494
2634
|
return false;
|
|
2495
2635
|
}
|
|
2496
2636
|
this.actualZoom = zoom;
|
|
2497
|
-
for (var i=0; i < this.e_panel.children.length; i++) {
|
|
2637
|
+
for (var i = 0; i < this.e_panel.children.length; i++) {
|
|
2498
2638
|
this.e_panel.children[i].style.transform = 'scale(' + zoom + ')';
|
|
2499
2639
|
};
|
|
2500
2640
|
this.show(true);
|
|
@@ -2502,55 +2642,55 @@
|
|
|
2502
2642
|
|
|
2503
2643
|
},
|
|
2504
2644
|
|
|
2505
|
-
_center_root:function(){
|
|
2645
|
+
_center_root: function () {
|
|
2506
2646
|
// center root node
|
|
2507
2647
|
var outer_w = this.e_panel.clientWidth;
|
|
2508
2648
|
var outer_h = this.e_panel.clientHeight;
|
|
2509
|
-
if(this.size.w > outer_w){
|
|
2649
|
+
if (this.size.w > outer_w) {
|
|
2510
2650
|
var _offset = this.get_view_offset();
|
|
2511
|
-
this.e_panel.scrollLeft = _offset.x - outer_w/2;
|
|
2651
|
+
this.e_panel.scrollLeft = _offset.x - outer_w / 2;
|
|
2512
2652
|
}
|
|
2513
|
-
if(this.size.h > outer_h){
|
|
2514
|
-
this.e_panel.scrollTop = (this.size.h - outer_h)/2;
|
|
2653
|
+
if (this.size.h > outer_h) {
|
|
2654
|
+
this.e_panel.scrollTop = (this.size.h - outer_h) / 2;
|
|
2515
2655
|
}
|
|
2516
2656
|
},
|
|
2517
2657
|
|
|
2518
|
-
show:function(keep_center){
|
|
2658
|
+
show: function (keep_center) {
|
|
2519
2659
|
logger.debug('view.show');
|
|
2520
2660
|
this.expand_size();
|
|
2521
2661
|
this._show();
|
|
2522
|
-
if(!!keep_center){
|
|
2662
|
+
if (!!keep_center) {
|
|
2523
2663
|
this._center_root();
|
|
2524
2664
|
}
|
|
2525
2665
|
},
|
|
2526
2666
|
|
|
2527
|
-
relayout:function(){
|
|
2667
|
+
relayout: function () {
|
|
2528
2668
|
this.expand_size();
|
|
2529
2669
|
this._show();
|
|
2530
2670
|
},
|
|
2531
2671
|
|
|
2532
|
-
save_location:function(node){
|
|
2672
|
+
save_location: function (node) {
|
|
2533
2673
|
var vd = node._data.view;
|
|
2534
|
-
vd._saved_location={
|
|
2535
|
-
x:parseInt(vd.element.style.left)-this.e_panel.scrollLeft,
|
|
2536
|
-
y:parseInt(vd.element.style.top)-this.e_panel.scrollTop,
|
|
2674
|
+
vd._saved_location = {
|
|
2675
|
+
x: parseInt(vd.element.style.left) - this.e_panel.scrollLeft,
|
|
2676
|
+
y: parseInt(vd.element.style.top) - this.e_panel.scrollTop,
|
|
2537
2677
|
};
|
|
2538
2678
|
},
|
|
2539
|
-
|
|
2540
|
-
restore_location:function(node){
|
|
2679
|
+
|
|
2680
|
+
restore_location: function (node) {
|
|
2541
2681
|
var vd = node._data.view;
|
|
2542
|
-
this.e_panel.scrollLeft = parseInt(vd.element.style.left)-vd._saved_location.x;
|
|
2543
|
-
this.e_panel.scrollTop = parseInt(vd.element.style.top)-vd._saved_location.y;
|
|
2682
|
+
this.e_panel.scrollLeft = parseInt(vd.element.style.left) - vd._saved_location.x;
|
|
2683
|
+
this.e_panel.scrollTop = parseInt(vd.element.style.top) - vd._saved_location.y;
|
|
2544
2684
|
},
|
|
2545
2685
|
|
|
2546
|
-
clear_nodes:function(){
|
|
2686
|
+
clear_nodes: function () {
|
|
2547
2687
|
var mind = this.jm.mind;
|
|
2548
|
-
if(mind == null){
|
|
2688
|
+
if (mind == null) {
|
|
2549
2689
|
return;
|
|
2550
2690
|
}
|
|
2551
2691
|
var nodes = mind.nodes;
|
|
2552
2692
|
var node = null;
|
|
2553
|
-
for(var nodeid in nodes){
|
|
2693
|
+
for (var nodeid in nodes) {
|
|
2554
2694
|
node = nodes[nodeid];
|
|
2555
2695
|
node._data.view.element = null;
|
|
2556
2696
|
node._data.view.expander = null;
|
|
@@ -2558,22 +2698,22 @@
|
|
|
2558
2698
|
this.e_nodes.innerHTML = '';
|
|
2559
2699
|
},
|
|
2560
2700
|
|
|
2561
|
-
show_nodes:function(){
|
|
2701
|
+
show_nodes: function () {
|
|
2562
2702
|
var nodes = this.jm.mind.nodes;
|
|
2563
2703
|
var node = null;
|
|
2564
2704
|
var node_element = null;
|
|
2565
2705
|
var expander = null;
|
|
2566
2706
|
var p = null;
|
|
2567
|
-
var p_expander= null;
|
|
2707
|
+
var p_expander = null;
|
|
2568
2708
|
var expander_text = '-';
|
|
2569
2709
|
var view_data = null;
|
|
2570
2710
|
var _offset = this.get_view_offset();
|
|
2571
|
-
for(var nodeid in nodes){
|
|
2711
|
+
for (var nodeid in nodes) {
|
|
2572
2712
|
node = nodes[nodeid];
|
|
2573
2713
|
view_data = node._data.view;
|
|
2574
2714
|
node_element = view_data.element;
|
|
2575
2715
|
expander = view_data.expander;
|
|
2576
|
-
if(!this.layout.is_visible(node)){
|
|
2716
|
+
if (!this.layout.is_visible(node)) {
|
|
2577
2717
|
node_element.style.display = 'none';
|
|
2578
2718
|
expander.style.display = 'none';
|
|
2579
2719
|
continue;
|
|
@@ -2582,139 +2722,159 @@
|
|
|
2582
2722
|
p = this.layout.get_node_point(node);
|
|
2583
2723
|
view_data.abs_x = _offset.x + p.x;
|
|
2584
2724
|
view_data.abs_y = _offset.y + p.y;
|
|
2585
|
-
node_element.style.left = (_offset.x+p.x) + 'px';
|
|
2586
|
-
node_element.style.top = (_offset.y+p.y) + 'px';
|
|
2725
|
+
node_element.style.left = (_offset.x + p.x) + 'px';
|
|
2726
|
+
node_element.style.top = (_offset.y + p.y) + 'px';
|
|
2587
2727
|
node_element.style.display = '';
|
|
2588
2728
|
node_element.style.visibility = 'visible';
|
|
2589
|
-
if(!node.isroot && node.children.length>0){
|
|
2590
|
-
expander_text = node.expanded?'-':'+';
|
|
2591
|
-
p_expander= this.layout.get_expander_point(node);
|
|
2729
|
+
if (!node.isroot && node.children.length > 0) {
|
|
2730
|
+
expander_text = node.expanded ? '-' : '+';
|
|
2731
|
+
p_expander = this.layout.get_expander_point(node);
|
|
2592
2732
|
expander.style.left = (_offset.x + p_expander.x) + 'px';
|
|
2593
2733
|
expander.style.top = (_offset.y + p_expander.y) + 'px';
|
|
2594
2734
|
expander.style.display = '';
|
|
2595
2735
|
expander.style.visibility = 'visible';
|
|
2596
|
-
$t(expander,expander_text);
|
|
2736
|
+
$t(expander, expander_text);
|
|
2597
2737
|
}
|
|
2598
2738
|
// hide expander while all children have been removed
|
|
2599
|
-
if(!node.isroot && node.children.length==0){
|
|
2739
|
+
if (!node.isroot && node.children.length == 0) {
|
|
2600
2740
|
expander.style.display = 'none';
|
|
2601
2741
|
expander.style.visibility = 'hidden';
|
|
2602
2742
|
}
|
|
2603
2743
|
}
|
|
2604
2744
|
},
|
|
2605
2745
|
|
|
2606
|
-
reset_node_custom_style:function(node){
|
|
2746
|
+
reset_node_custom_style: function (node) {
|
|
2607
2747
|
this._reset_node_custom_style(node._data.view.element, node.data);
|
|
2608
2748
|
},
|
|
2609
2749
|
|
|
2610
|
-
_reset_node_custom_style:function(node_element, node_data){
|
|
2611
|
-
if('background-color' in node_data){
|
|
2750
|
+
_reset_node_custom_style: function (node_element, node_data) {
|
|
2751
|
+
if ('background-color' in node_data) {
|
|
2612
2752
|
node_element.style.backgroundColor = node_data['background-color'];
|
|
2613
2753
|
}
|
|
2614
|
-
if('foreground-color' in node_data){
|
|
2754
|
+
if ('foreground-color' in node_data) {
|
|
2615
2755
|
node_element.style.color = node_data['foreground-color'];
|
|
2616
2756
|
}
|
|
2617
|
-
if('width' in node_data){
|
|
2618
|
-
node_element.style.width = node_data['width']+'px';
|
|
2757
|
+
if ('width' in node_data) {
|
|
2758
|
+
node_element.style.width = node_data['width'] + 'px';
|
|
2619
2759
|
}
|
|
2620
|
-
if('height' in node_data){
|
|
2621
|
-
node_element.style.height = node_data['height']+'px';
|
|
2760
|
+
if ('height' in node_data) {
|
|
2761
|
+
node_element.style.height = node_data['height'] + 'px';
|
|
2622
2762
|
}
|
|
2623
|
-
if('font-size' in node_data){
|
|
2624
|
-
node_element.style.fontSize = node_data['font-size']+'px';
|
|
2763
|
+
if ('font-size' in node_data) {
|
|
2764
|
+
node_element.style.fontSize = node_data['font-size'] + 'px';
|
|
2625
2765
|
}
|
|
2626
|
-
if('font-weight' in node_data){
|
|
2766
|
+
if ('font-weight' in node_data) {
|
|
2627
2767
|
node_element.style.fontWeight = node_data['font-weight'];
|
|
2628
2768
|
}
|
|
2629
|
-
if('font-style' in node_data){
|
|
2769
|
+
if ('font-style' in node_data) {
|
|
2630
2770
|
node_element.style.fontStyle = node_data['font-style'];
|
|
2631
2771
|
}
|
|
2632
|
-
if('background-image' in node_data) {
|
|
2772
|
+
if ('background-image' in node_data) {
|
|
2633
2773
|
var backgroundImage = node_data['background-image'];
|
|
2634
2774
|
if (backgroundImage.startsWith('data') && node_data['width'] && node_data['height']) {
|
|
2635
2775
|
var img = new Image();
|
|
2636
2776
|
|
|
2637
|
-
img.onload = function() {
|
|
2777
|
+
img.onload = function () {
|
|
2638
2778
|
var c = $c('canvas');
|
|
2639
2779
|
c.width = node_element.clientWidth;
|
|
2640
2780
|
c.height = node_element.clientHeight;
|
|
2641
2781
|
var img = this;
|
|
2642
|
-
if(c.getContext) {
|
|
2782
|
+
if (c.getContext) {
|
|
2643
2783
|
var ctx = c.getContext('2d');
|
|
2644
2784
|
ctx.drawImage(img, 2, 2, node_element.clientWidth, node_element.clientHeight);
|
|
2645
2785
|
var scaledImageData = c.toDataURL();
|
|
2646
|
-
node_element.style.backgroundImage='url('+scaledImageData+')';
|
|
2786
|
+
node_element.style.backgroundImage = 'url(' + scaledImageData + ')';
|
|
2647
2787
|
}
|
|
2648
2788
|
};
|
|
2649
2789
|
img.src = backgroundImage;
|
|
2650
2790
|
|
|
2651
2791
|
} else {
|
|
2652
|
-
node_element.style.backgroundImage='url('+backgroundImage+')';
|
|
2792
|
+
node_element.style.backgroundImage = 'url(' + backgroundImage + ')';
|
|
2653
2793
|
}
|
|
2654
|
-
node_element.style.backgroundSize='99%';
|
|
2794
|
+
node_element.style.backgroundSize = '99%';
|
|
2655
2795
|
|
|
2656
|
-
if('background-rotation' in node_data){
|
|
2796
|
+
if ('background-rotation' in node_data) {
|
|
2657
2797
|
node_element.style.transform = 'rotate(' + node_data['background-rotation'] + 'deg)';
|
|
2658
2798
|
}
|
|
2659
|
-
|
|
2660
2799
|
}
|
|
2661
2800
|
},
|
|
2662
2801
|
|
|
2663
|
-
clear_node_custom_style:function(node){
|
|
2802
|
+
clear_node_custom_style: function (node) {
|
|
2664
2803
|
var node_element = node._data.view.element;
|
|
2665
2804
|
node_element.style.backgroundColor = "";
|
|
2666
2805
|
node_element.style.color = "";
|
|
2667
2806
|
},
|
|
2668
2807
|
|
|
2669
|
-
clear_lines:function(
|
|
2670
|
-
|
|
2671
|
-
jm.util.canvas.clear(ctx,0,0,this.size.w,this.size.h);
|
|
2808
|
+
clear_lines: function () {
|
|
2809
|
+
this.graph.clear();
|
|
2672
2810
|
},
|
|
2673
2811
|
|
|
2674
|
-
show_lines:function(
|
|
2675
|
-
this.clear_lines(
|
|
2812
|
+
show_lines: function () {
|
|
2813
|
+
this.clear_lines();
|
|
2676
2814
|
var nodes = this.jm.mind.nodes;
|
|
2677
2815
|
var node = null;
|
|
2678
2816
|
var pin = null;
|
|
2679
2817
|
var pout = null;
|
|
2680
2818
|
var _offset = this.get_view_offset();
|
|
2681
|
-
for(var nodeid in nodes){
|
|
2819
|
+
for (var nodeid in nodes) {
|
|
2682
2820
|
node = nodes[nodeid];
|
|
2683
|
-
if(!!node.isroot){continue;}
|
|
2684
|
-
if(('visible' in node._data.layout) && !node._data.layout.visible){continue;}
|
|
2821
|
+
if (!!node.isroot) { continue; }
|
|
2822
|
+
if (('visible' in node._data.layout) && !node._data.layout.visible) { continue; }
|
|
2685
2823
|
pin = this.layout.get_node_point_in(node);
|
|
2686
2824
|
pout = this.layout.get_node_point_out(node.parent);
|
|
2687
|
-
this.draw_line(pout,pin,_offset
|
|
2825
|
+
this.graph.draw_line(pout, pin, _offset);
|
|
2826
|
+
}
|
|
2827
|
+
},
|
|
2828
|
+
|
|
2829
|
+
// Drag the whole mind map with your mouse, when it's larger that the container
|
|
2830
|
+
enable_draggable_canvas: function () {
|
|
2831
|
+
// If draggable option is true.
|
|
2832
|
+
if (this.opts.draggable) {
|
|
2833
|
+
// Dragging disabled by default.
|
|
2834
|
+
let dragging = false
|
|
2835
|
+
let x, y
|
|
2836
|
+
if (this.opts.hide_scrollbars_when_draggable) {
|
|
2837
|
+
// Avoid scrollbars when mind map is larger than the container (e_panel = id jsmind-inner)
|
|
2838
|
+
this.e_panel.style = 'overflow: hidden'
|
|
2839
|
+
}
|
|
2840
|
+
// Move the whole mind map with mouse moves, while button is down.
|
|
2841
|
+
jm.util.dom.add_event(this.container, 'mousedown', (eventDown) => {
|
|
2842
|
+
dragging = true
|
|
2843
|
+
// Record current mouse position.
|
|
2844
|
+
x = eventDown.clientX
|
|
2845
|
+
y = eventDown.clientY
|
|
2846
|
+
})
|
|
2847
|
+
// Stop moving mind map once mouse button is released.
|
|
2848
|
+
jm.util.dom.add_event(this.container, 'mouseup', () => {
|
|
2849
|
+
dragging = false
|
|
2850
|
+
})
|
|
2851
|
+
// Follow current mouse position and move mind map accordingly.
|
|
2852
|
+
jm.util.dom.add_event(this.container, 'mousemove', (eventMove) => {
|
|
2853
|
+
if (dragging) {
|
|
2854
|
+
this.e_panel.scrollBy(x - eventMove.clientX, y - eventMove.clientY)
|
|
2855
|
+
// Record new current position.
|
|
2856
|
+
x = eventMove.clientX
|
|
2857
|
+
y = eventMove.clientY
|
|
2858
|
+
}
|
|
2859
|
+
})
|
|
2688
2860
|
}
|
|
2689
2861
|
},
|
|
2690
2862
|
|
|
2691
|
-
draw_line:function(pin,pout,offset,canvas_ctx){
|
|
2692
|
-
var ctx = canvas_ctx || this.canvas_ctx;
|
|
2693
|
-
ctx.strokeStyle = this.opts.line_color;
|
|
2694
|
-
ctx.lineWidth = this.opts.line_width;
|
|
2695
|
-
ctx.lineCap = 'round';
|
|
2696
|
-
|
|
2697
|
-
jm.util.canvas.bezierto(
|
|
2698
|
-
ctx,
|
|
2699
|
-
pin.x + offset.x,
|
|
2700
|
-
pin.y + offset.y,
|
|
2701
|
-
pout.x + offset.x,
|
|
2702
|
-
pout.y + offset.y);
|
|
2703
|
-
},
|
|
2704
2863
|
};
|
|
2705
2864
|
|
|
2706
2865
|
// shortcut provider
|
|
2707
|
-
jm.shortcut_provider= function(jm, options){
|
|
2866
|
+
jm.shortcut_provider = function (jm, options) {
|
|
2708
2867
|
this.jm = jm;
|
|
2709
2868
|
this.opts = options;
|
|
2710
2869
|
this.mapping = options.mapping;
|
|
2711
2870
|
this.handles = options.handles;
|
|
2871
|
+
this._newid = null;
|
|
2712
2872
|
this._mapping = {};
|
|
2713
2873
|
};
|
|
2714
2874
|
|
|
2715
2875
|
jm.shortcut_provider.prototype = {
|
|
2716
|
-
init
|
|
2717
|
-
jm.util.dom.add_event(
|
|
2876
|
+
init: function () {
|
|
2877
|
+
jm.util.dom.add_event(this.jm.view.e_panel, 'keydown', this.handler.bind(this));
|
|
2718
2878
|
|
|
2719
2879
|
this.handles['addchild'] = this.handle_addchild;
|
|
2720
2880
|
this.handles['addbrother'] = this.handle_addbrother;
|
|
@@ -2726,87 +2886,94 @@
|
|
|
2726
2886
|
this.handles['left'] = this.handle_left;
|
|
2727
2887
|
this.handles['right'] = this.handle_right;
|
|
2728
2888
|
|
|
2729
|
-
for(var handle in this.mapping){
|
|
2730
|
-
if(!!this.mapping[handle] && (handle in this.handles)){
|
|
2889
|
+
for (var handle in this.mapping) {
|
|
2890
|
+
if (!!this.mapping[handle] && (handle in this.handles)) {
|
|
2731
2891
|
this._mapping[this.mapping[handle]] = this.handles[handle];
|
|
2732
2892
|
}
|
|
2733
2893
|
}
|
|
2894
|
+
|
|
2895
|
+
if (typeof this.opts.id_generator === 'function') {
|
|
2896
|
+
this._newid = this.opts.id_generator;
|
|
2897
|
+
} else {
|
|
2898
|
+
this._newid = jm.util.uuid.newid;
|
|
2899
|
+
}
|
|
2734
2900
|
},
|
|
2735
2901
|
|
|
2736
|
-
enable_shortcut
|
|
2902
|
+
enable_shortcut: function () {
|
|
2737
2903
|
this.opts.enable = true;
|
|
2738
2904
|
},
|
|
2739
2905
|
|
|
2740
|
-
disable_shortcut
|
|
2906
|
+
disable_shortcut: function () {
|
|
2741
2907
|
this.opts.enable = false;
|
|
2742
2908
|
},
|
|
2743
2909
|
|
|
2744
|
-
handler
|
|
2745
|
-
if(
|
|
2910
|
+
handler: function (e) {
|
|
2911
|
+
if (e.which == 9) { e.preventDefault(); } //prevent tab to change focus in browser
|
|
2912
|
+
if (this.jm.view.is_editing()) { return; }
|
|
2746
2913
|
var evt = e || event;
|
|
2747
|
-
if(!this.opts.enable){return true;}
|
|
2748
|
-
var kc = evt.keyCode;
|
|
2749
|
-
if(kc in this._mapping){
|
|
2750
|
-
this._mapping[kc].call(this,this.jm,e);
|
|
2914
|
+
if (!this.opts.enable) { return true; }
|
|
2915
|
+
var kc = evt.keyCode + (evt.metaKey << 13) + (evt.ctrlKey << 12) + (evt.altKey << 11) + (evt.shiftKey << 10);
|
|
2916
|
+
if (kc in this._mapping) {
|
|
2917
|
+
this._mapping[kc].call(this, this.jm, e);
|
|
2751
2918
|
}
|
|
2752
2919
|
},
|
|
2753
2920
|
|
|
2754
|
-
handle_addchild: function(_jm,e){
|
|
2921
|
+
handle_addchild: function (_jm, e) {
|
|
2755
2922
|
var selected_node = _jm.get_selected_node();
|
|
2756
|
-
if(!!selected_node){
|
|
2757
|
-
var nodeid =
|
|
2923
|
+
if (!!selected_node) {
|
|
2924
|
+
var nodeid = this._newid();
|
|
2758
2925
|
var node = _jm.add_node(selected_node, nodeid, 'New Node');
|
|
2759
|
-
if(!!node){
|
|
2926
|
+
if (!!node) {
|
|
2760
2927
|
_jm.select_node(nodeid);
|
|
2761
2928
|
_jm.begin_edit(nodeid);
|
|
2762
2929
|
}
|
|
2763
2930
|
}
|
|
2764
2931
|
},
|
|
2765
|
-
handle_addbrother:function(_jm,e){
|
|
2932
|
+
handle_addbrother: function (_jm, e) {
|
|
2766
2933
|
var selected_node = _jm.get_selected_node();
|
|
2767
|
-
if(!!selected_node && !selected_node.isroot){
|
|
2768
|
-
var nodeid =
|
|
2934
|
+
if (!!selected_node && !selected_node.isroot) {
|
|
2935
|
+
var nodeid = this._newid();
|
|
2769
2936
|
var node = _jm.insert_node_after(selected_node, nodeid, 'New Node');
|
|
2770
|
-
if(!!node){
|
|
2937
|
+
if (!!node) {
|
|
2771
2938
|
_jm.select_node(nodeid);
|
|
2772
2939
|
_jm.begin_edit(nodeid);
|
|
2773
2940
|
}
|
|
2774
2941
|
}
|
|
2775
2942
|
},
|
|
2776
|
-
handle_editnode:function(_jm,e){
|
|
2943
|
+
handle_editnode: function (_jm, e) {
|
|
2777
2944
|
var selected_node = _jm.get_selected_node();
|
|
2778
|
-
if(!!selected_node){
|
|
2945
|
+
if (!!selected_node) {
|
|
2779
2946
|
_jm.begin_edit(selected_node);
|
|
2780
2947
|
}
|
|
2781
2948
|
},
|
|
2782
|
-
handle_delnode:function(_jm,e){
|
|
2949
|
+
handle_delnode: function (_jm, e) {
|
|
2783
2950
|
var selected_node = _jm.get_selected_node();
|
|
2784
|
-
if(!!selected_node && !selected_node.isroot){
|
|
2951
|
+
if (!!selected_node && !selected_node.isroot) {
|
|
2785
2952
|
_jm.select_node(selected_node.parent);
|
|
2786
2953
|
_jm.remove_node(selected_node);
|
|
2787
2954
|
}
|
|
2788
2955
|
},
|
|
2789
|
-
handle_toggle:function(_jm,e){
|
|
2956
|
+
handle_toggle: function (_jm, e) {
|
|
2790
2957
|
var evt = e || event;
|
|
2791
2958
|
var selected_node = _jm.get_selected_node();
|
|
2792
|
-
if(!!selected_node){
|
|
2959
|
+
if (!!selected_node) {
|
|
2793
2960
|
_jm.toggle_node(selected_node.id);
|
|
2794
2961
|
evt.stopPropagation();
|
|
2795
2962
|
evt.preventDefault();
|
|
2796
2963
|
}
|
|
2797
2964
|
},
|
|
2798
|
-
handle_up:function(_jm,e){
|
|
2965
|
+
handle_up: function (_jm, e) {
|
|
2799
2966
|
var evt = e || event;
|
|
2800
2967
|
var selected_node = _jm.get_selected_node();
|
|
2801
|
-
if(!!selected_node){
|
|
2968
|
+
if (!!selected_node) {
|
|
2802
2969
|
var up_node = _jm.find_node_before(selected_node);
|
|
2803
|
-
if(!up_node){
|
|
2970
|
+
if (!up_node) {
|
|
2804
2971
|
var np = _jm.find_node_before(selected_node.parent);
|
|
2805
|
-
if(!!np && np.children.length > 0){
|
|
2806
|
-
up_node = np.children[np.children.length-1];
|
|
2972
|
+
if (!!np && np.children.length > 0) {
|
|
2973
|
+
up_node = np.children[np.children.length - 1];
|
|
2807
2974
|
}
|
|
2808
2975
|
}
|
|
2809
|
-
if(!!up_node){
|
|
2976
|
+
if (!!up_node) {
|
|
2810
2977
|
_jm.select_node(up_node);
|
|
2811
2978
|
}
|
|
2812
2979
|
evt.stopPropagation();
|
|
@@ -2814,18 +2981,18 @@
|
|
|
2814
2981
|
}
|
|
2815
2982
|
},
|
|
2816
2983
|
|
|
2817
|
-
handle_down:function(_jm,e){
|
|
2984
|
+
handle_down: function (_jm, e) {
|
|
2818
2985
|
var evt = e || event;
|
|
2819
2986
|
var selected_node = _jm.get_selected_node();
|
|
2820
|
-
if(!!selected_node){
|
|
2987
|
+
if (!!selected_node) {
|
|
2821
2988
|
var down_node = _jm.find_node_after(selected_node);
|
|
2822
|
-
if(!down_node){
|
|
2989
|
+
if (!down_node) {
|
|
2823
2990
|
var np = _jm.find_node_after(selected_node.parent);
|
|
2824
|
-
if(!!np && np.children.length > 0){
|
|
2991
|
+
if (!!np && np.children.length > 0) {
|
|
2825
2992
|
down_node = np.children[0];
|
|
2826
2993
|
}
|
|
2827
2994
|
}
|
|
2828
|
-
if(!!down_node){
|
|
2995
|
+
if (!!down_node) {
|
|
2829
2996
|
_jm.select_node(down_node);
|
|
2830
2997
|
}
|
|
2831
2998
|
evt.stopPropagation();
|
|
@@ -2833,37 +3000,37 @@
|
|
|
2833
3000
|
}
|
|
2834
3001
|
},
|
|
2835
3002
|
|
|
2836
|
-
handle_left:function(_jm,e){
|
|
2837
|
-
this._handle_direction(_jm,e,jm.direction.left);
|
|
3003
|
+
handle_left: function (_jm, e) {
|
|
3004
|
+
this._handle_direction(_jm, e, jm.direction.left);
|
|
2838
3005
|
},
|
|
2839
|
-
handle_right:function(_jm,e){
|
|
2840
|
-
this._handle_direction(_jm,e,jm.direction.right);
|
|
3006
|
+
handle_right: function (_jm, e) {
|
|
3007
|
+
this._handle_direction(_jm, e, jm.direction.right);
|
|
2841
3008
|
},
|
|
2842
|
-
_handle_direction:function(_jm,e,d){
|
|
3009
|
+
_handle_direction: function (_jm, e, d) {
|
|
2843
3010
|
var evt = e || event;
|
|
2844
3011
|
var selected_node = _jm.get_selected_node();
|
|
2845
3012
|
var node = null;
|
|
2846
|
-
if(!!selected_node){
|
|
2847
|
-
if(selected_node.isroot){
|
|
3013
|
+
if (!!selected_node) {
|
|
3014
|
+
if (selected_node.isroot) {
|
|
2848
3015
|
var c = selected_node.children;
|
|
2849
3016
|
var children = [];
|
|
2850
|
-
for(var i=0;i<c.length;i++){
|
|
2851
|
-
if(c[i].direction === d){
|
|
2852
|
-
children.push(i)
|
|
3017
|
+
for (var i = 0; i < c.length; i++) {
|
|
3018
|
+
if (c[i].direction === d) {
|
|
3019
|
+
children.push(i);
|
|
2853
3020
|
}
|
|
2854
3021
|
}
|
|
2855
|
-
node = c[children[Math.floor((children.length-1)/2)]];
|
|
3022
|
+
node = c[children[Math.floor((children.length - 1) / 2)]];
|
|
2856
3023
|
}
|
|
2857
|
-
else if(selected_node.direction === d){
|
|
3024
|
+
else if (selected_node.direction === d) {
|
|
2858
3025
|
var children = selected_node.children;
|
|
2859
3026
|
var childrencount = children.length;
|
|
2860
|
-
if(childrencount > 0){
|
|
2861
|
-
node = children[Math.floor((childrencount-1)/2)]
|
|
3027
|
+
if (childrencount > 0) {
|
|
3028
|
+
node = children[Math.floor((childrencount - 1) / 2)];
|
|
2862
3029
|
}
|
|
2863
|
-
}else{
|
|
3030
|
+
} else {
|
|
2864
3031
|
node = selected_node.parent;
|
|
2865
3032
|
}
|
|
2866
|
-
if(!!node){
|
|
3033
|
+
if (!!node) {
|
|
2867
3034
|
_jm.select_node(node);
|
|
2868
3035
|
}
|
|
2869
3036
|
evt.stopPropagation();
|
|
@@ -2874,48 +3041,49 @@
|
|
|
2874
3041
|
|
|
2875
3042
|
|
|
2876
3043
|
// plugin
|
|
2877
|
-
jm.plugin = function(name,init){
|
|
3044
|
+
jm.plugin = function (name, init) {
|
|
2878
3045
|
this.name = name;
|
|
2879
3046
|
this.init = init;
|
|
2880
3047
|
};
|
|
2881
3048
|
|
|
2882
3049
|
jm.plugins = [];
|
|
2883
3050
|
|
|
2884
|
-
jm.register_plugin = function(plugin){
|
|
2885
|
-
if(plugin instanceof jm.plugin){
|
|
3051
|
+
jm.register_plugin = function (plugin) {
|
|
3052
|
+
if (plugin instanceof jm.plugin) {
|
|
2886
3053
|
jm.plugins.push(plugin);
|
|
2887
3054
|
}
|
|
2888
3055
|
};
|
|
2889
3056
|
|
|
2890
|
-
jm.init_plugins = function(sender){
|
|
2891
|
-
$w.setTimeout(function(){
|
|
3057
|
+
jm.init_plugins = function (sender) {
|
|
3058
|
+
$w.setTimeout(function () {
|
|
2892
3059
|
jm._init_plugins(sender);
|
|
2893
|
-
},0);
|
|
3060
|
+
}, 0);
|
|
2894
3061
|
};
|
|
2895
3062
|
|
|
2896
|
-
jm._init_plugins = function(sender){
|
|
3063
|
+
jm._init_plugins = function (sender) {
|
|
2897
3064
|
var l = jm.plugins.length;
|
|
2898
3065
|
var fn_init = null;
|
|
2899
|
-
for(var i=0;i<l;i++){
|
|
3066
|
+
for (var i = 0; i < l; i++) {
|
|
2900
3067
|
fn_init = jm.plugins[i].init;
|
|
2901
|
-
if(typeof fn_init === 'function'){
|
|
3068
|
+
if (typeof fn_init === 'function') {
|
|
2902
3069
|
fn_init(sender);
|
|
2903
3070
|
}
|
|
2904
3071
|
}
|
|
2905
3072
|
};
|
|
2906
3073
|
|
|
2907
3074
|
// quick way
|
|
2908
|
-
jm.show = function(options,mind){
|
|
3075
|
+
jm.show = function (options, mind) {
|
|
2909
3076
|
var _jm = new jm(options);
|
|
2910
3077
|
_jm.show(mind);
|
|
2911
3078
|
return _jm;
|
|
2912
3079
|
};
|
|
2913
3080
|
|
|
2914
3081
|
// export jsmind
|
|
2915
|
-
if(typeof module !== 'undefined' &&
|
|
3082
|
+
if (typeof module !== 'undefined' && typeof exports === 'object') {
|
|
2916
3083
|
module.exports = jm;
|
|
2917
|
-
}else{
|
|
3084
|
+
} else if (typeof define === 'function' && (define.amd || define.cmd)) {
|
|
3085
|
+
define(function () { return jm; });
|
|
3086
|
+
} else {
|
|
2918
3087
|
$w[__name__] = jm;
|
|
2919
3088
|
}
|
|
2920
|
-
|
|
2921
|
-
})(window);
|
|
3089
|
+
})(typeof window !== 'undefined' ? window : global);
|