Commit bb44a06f authored by techird's avatar techird

spec

parent 484331d1
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
"MinderEvent", "MinderEvent",
"Command", "Command",
"KITYMINDER_CONFIG", "KITYMINDER_CONFIG",
"keymap",
"Utils", "Utils",
"utils" "utils"
] ]
......
{
"undef" : true,
"unused" : false,
"strict" : false,
"curly" : false,
"newcap" : true,
"trailing" : true,
"white": false,
"quotmark": false,
"predef" : [
"require",
"console",
"kity",
"KityMinder",
"KM",
"Minder",
"MinderNode",
"MinderEvent",
"Command",
"KITYMINDER_CONFIG",
"Utils",
"utils",
"describe",
"it",
"beforeEach",
"expect"
]
}
\ No newline at end of file
describe( "protocal/plain", function () {
var json, local, protocal;
beforeEach( function () {
protocal = KM.findProtocal( 'plain' );
} );
it( '协议存在', function () {
expect( protocal ).toBeDefined();
} );
it( '正确 encode', function () {
json = {
data: {
text: 'root',
anyway: 'omg'
},
children: [ {
data: {
text: 'l1c1'
}
}, {
data: {
text: 'l1c2'
},
children: [ {
data: {
text: 'l2c1'
}
}, {
data: {
text: 'l2c2'
}
} ]
}, {
data: {
text: 'l1c3'
}
} ]
};
local = protocal.encode( json );
expect( local ).toBe(
'root\n' +
'\tl1c1\n' +
'\tl1c2\n' +
'\t\tl2c1\n' +
'\t\tl2c2\n' +
'\tl1c3\n'
);
} );
} );
\ No newline at end of file
...@@ -47,7 +47,7 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -47,7 +47,7 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
function KBNavigate( km, direction ) { function navigateTo( km, direction ) {
var nextNode = km.getSelectedNode()._nearestNodes[ direction ]; var nextNode = km.getSelectedNode()._nearestNodes[ direction ];
if ( nextNode ) { if ( nextNode ) {
km.select( nextNode ); km.select( nextNode );
...@@ -60,33 +60,36 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -60,33 +60,36 @@ KityMinder.registerModule( "KeyboardModule", function () {
buildPositionNetwork( this.getRoot() ); buildPositionNetwork( this.getRoot() );
}, },
keydown: function ( e ) { keydown: function ( e ) {
var keys = KityMinder.keymap;
switch ( e.originEvent.keyCode ) { switch ( e.originEvent.keyCode ) {
case keymap.Enter: case keys.Enter:
this.execCommand( 'appendSiblingNode', new MinderNode( 'Topic' ) ); this.execCommand( 'appendSiblingNode', new MinderNode( 'Topic' ) );
e.preventDefault(); e.preventDefault();
break; break;
case keymap.Tab: case keys.Tab:
this.execCommand( 'appendChildNode', new MinderNode( 'Topic' ) ); this.execCommand( 'appendChildNode', new MinderNode( 'Topic' ) );
e.preventDefault(); e.preventDefault();
break; break;
case keymap.Backspace: case keys.Backspace:
case keymap.Del: case keys.Del:
this.execCommand( 'removenode' ); this.execCommand( 'removenode' );
e.preventDefault(); e.preventDefault();
break; break;
case keymap.Left: case keys.Left:
case keymap.up: navigateTo( this, 'left' );
case keymap.Right: e.preventDefault();
case keymap.Down: break;
if ( this.isSingleSelect() ) { case keys.Up:
KBNavigate( this, { navigateTo( this, 'top' );
37: 'left', e.preventDefault();
38: 'top', break;
39: 'right', case keys.Right:
40: 'down' navigateTo( this, 'right' );
}[ e.originEvent.keyCode ] ); e.preventDefault();
} break;
case keys.Down:
navigateTo( this, 'down' );
e.preventDefault(); e.preventDefault();
break; break;
} }
......
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