Commit 0034c01d authored by techird's avatar techird

添加节点收起功能

parent 0feacf5a
......@@ -137,7 +137,9 @@ KityMinder.LANG['zh-cn'] = {
'editnode': '编辑',
'arrangeup': '上移',
'arrangedown': '下移',
'resetlayout': '整理布局'
'resetlayout': '整理布局',
'expandtoleave': '展开全部节点',
'collapsetolevel1': '收起到一级节点'
},
'back': '返回',
......
......@@ -9,9 +9,17 @@ var keymap = KityMinder.keymap = (function(origin) {
var aKeyCode = 65;
var aCharCode = 'a'.charCodeAt(0);
// letters
'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(letter) {
ret[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode);
});
// numbers
var n = 9;
do {
ret[n.toString()] = n + 48;
} while(--n);
return ret;
})({
'Backspace': 8,
......@@ -65,6 +73,7 @@ var keymap = KityMinder.keymap = (function(origin) {
'F11': 121,
'F12': 122,
'`': 192,
'=': 187,
'-': 189,
......
......@@ -151,7 +151,7 @@ KityMinder.registerModule('Expand', function() {
});
},
queryState: function(km) {
return 0;
return !km.getSelectedNode() ? 0 : -1;
}
});
var CollapseNodeCommand = kity.createClass('CollapseNodeCommand', {
......@@ -163,7 +163,7 @@ KityMinder.registerModule('Expand', function() {
});
},
queryState: function(km) {
return 0;
return !km.getSelectedNode() ? 0 : -1;
}
});
var Expander = kity.createClass('Expander', {
......@@ -241,8 +241,8 @@ KityMinder.registerModule('Expand', function() {
});
return {
commands: {
'ExpandNode': ExpandNodeCommand,
'CollapseNode': CollapseNodeCommand
'expandtoleave': ExpandNodeCommand,
'collapsetolevel1': CollapseNodeCommand
},
events: {
'layoutapply': function(e) {
......@@ -276,6 +276,17 @@ KityMinder.registerModule('Expand', function() {
},
renderers: {
outside: ExpanderRenderer
},
contextmenu: [{
command: 'expandtoleave'
}, {
command: 'collapsetolevel1'
}, {
divider: true
}],
commandShortcutKeys: {
'expandtoleave': 'Alt+`',
'collapsetolevel1': 'Alt+1'
}
};
});
\ No newline at end of file
......@@ -20,6 +20,13 @@ KityMinder.registerUI('contextmenu', function(minder) {
var downPosition;
function distance(p1, p2) {
var dx = p1[0] - p2[0];
var dy = p1[1] - p2[1];
var ds = Math.sqrt(dx * dx + dy * dy);
return ds;
}
$menu.delegate('li', 'mousedown', function(e, info) {
var item = $(e.target).closest('li').data('menu');
if (item.command) {
......@@ -34,7 +41,7 @@ KityMinder.registerUI('contextmenu', function(minder) {
$('#content-wrapper').on('mousedown', function(e) {
$menu.hide();
if (e.button == 2) {
downPosition = [e.pageX, e.pageY].join(',');
downPosition = [e.pageX, e.pageY];
} else {
downPosition = null;
}
......@@ -47,7 +54,8 @@ KityMinder.registerUI('contextmenu', function(minder) {
e = e.originEvent;
if (downPosition != [e.pageX, e.pageY].join(',')) return;
var d = distance(downPosition, [e.pageX, e.pageY]);
if (isNaN(d) || d > 5) return;
$menu.empty();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment