patch to use Keyboard hotkey to browse mindmap

17 views
Skip to first unread message

wade(菠蘿麵包)

unread,
Jul 18, 2010, 9:33:36 AM7/18/10
to js-mindmap
patch the following code to below this.el.dblclick(function(){...}



$('body').keyup(function(event){
if (!obj.activeNode) return true;
// console.log(obj.activeNode.parent);
switch (event.which) {
case 33: // PgUp
case 38: // Up, move to parent
if (obj.activeNode.parent) {
obj.activeNode.el.removeClass('active');
obj.activeNode = obj.activeNode.parent;
obj.activeNode.el.addClass('active');
}
break;
case 34: // PgDn
case 40: // Down, move to first child
var idx = obj.activeNode.index;
var nodes = obj.nodes;
for (;idx<nodes.length; idx++) {
if (nodes[idx].parent == obj.activeNode) {
obj.activeNode.el.removeClass('active');
obj.activeNode = nodes[idx];
obj.activeNode.el.addClass('active');
}
}
break;

case 37: // Left, move to previous sibling
if (obj.activeNode.index > 0) {
var prevIdx = obj.activeNode.index - 1;
var prevNode = obj.nodes[prevIdx];
if (prevNode.parent == obj.activeNode.parent) {
obj.activeNode.el.removeClass('active');
obj.activeNode = prevNode;
obj.activeNode.el.addClass('active');
}
}
break;
case 39: // Right, move to next sibling
if (obj.activeNode.index < (obj.nodes.length-1)) {
var nextIdx = obj.activeNode.index + 1;
var nextNode = obj.nodes[nextIdx];
if (nextNode.parent == obj.activeNode.parent) {
obj.activeNode.el.removeClass('active');
obj.activeNode = nextNode;
obj.activeNode.el.addClass('active');
}
}
break;
case 45: // Ins, insert a child
break;

case 46: // Del, delete this node
break;
case 13: // Enter, insert a sibling
break;
case 27: // Esc, cancel insert
break;
case 83: // 'S', save
break;
}
event.stopImmediatePropagation()
event.stopPropagation();
event.preventDefault();
return false;
});

kenneth

unread,
Jul 18, 2010, 12:01:17 PM7/18/10
to js-mindmap
Neat! I'll include that in the next version.
I'd always meant to include that.

Kenneth
Reply all
Reply to author
Forward
0 new messages