Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
3ea5ea8c
Commit
3ea5ea8c
authored
Jan 03, 2014
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge
parent
79fc4a40
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
131 additions
and
5 deletions
+131
-5
dev.html
demo/dev.html
+1
-1
event.js
src/core/event.js
+3
-0
minder.command.js
src/core/minder.command.js
+4
-2
minder.select.js
src/core/minder.select.js
+4
-0
history.js
src/module/history.js
+1
-1
keyboard.js
src/module/keyboard.js
+118
-1
No files found.
demo/dev.html
View file @
3ea5ea8c
...
...
@@ -10,7 +10,7 @@
</body>
<script>
minder
=
new
KM
.
createMinder
(
document
.
body
,
{
modules
:
[
"
ExampleModule"
,
"RenderModule"
,
"
KeyboardModule"
]
modules
:
[
"KeyboardModule"
]
});
minder
.
importData
({
...
...
src/core/event.js
View file @
3ea5ea8c
...
...
@@ -3,7 +3,10 @@ var MinderEvent = kity.createClass( 'MindEvent', {
params
=
params
||
{};
if
(
params
.
getType
&&
params
.
getType
()
==
'ShapeEvent'
)
{
this
.
kityEvent
=
params
;
this
.
originEvent
=
params
.
originEvent
;
this
.
getPosition
=
params
.
getPosition
.
bind
(
params
);
}
else
if
(
params
.
target
&&
params
.
preventDefault
)
{
this
.
originEvent
=
params
;
}
else
{
kity
.
Utils
.
extend
(
this
,
params
);
}
...
...
src/core/minder.command.js
View file @
3ea5ea8c
...
...
@@ -19,7 +19,7 @@ kity.extendClass( Minder, {
}
},
execCommand
:
function
(
name
)
{
var
TargetCommand
,
command
,
cmdArgs
,
eventParams
,
stoped
,
isTopCommand
;
var
TargetCommand
,
command
,
cmdArgs
,
eventParams
,
stoped
,
isTopCommand
,
result
;
TargetCommand
=
this
.
_getCommand
(
name
);
if
(
!
TargetCommand
)
{
...
...
@@ -48,7 +48,7 @@ kity.extendClass( Minder, {
if
(
!
stoped
)
{
this
.
_fire
(
new
MinderEvent
(
"precommand"
,
eventParams
,
false
)
);
command
.
execute
.
apply
(
command
,
[
this
].
concat
(
cmdArgs
)
);
result
=
command
.
execute
.
apply
(
command
,
[
this
].
concat
(
cmdArgs
)
);
this
.
_fire
(
new
MinderEvent
(
"command"
,
eventParams
,
false
)
);
// 顶级命令才触发事件
...
...
@@ -67,6 +67,8 @@ kity.extendClass( Minder, {
if
(
isTopCommand
)
{
this
.
_executingCommand
=
null
;
}
return
result
||
null
;
},
queryCommandState
:
function
(
name
)
{
...
...
src/core/minder.select.js
View file @
3ea5ea8c
...
...
@@ -15,6 +15,10 @@ kity.extendClass( Minder, {
return
this
;
},
isNodeSelected
:
function
(
node
)
{
return
!!~
this
.
getSelectedNodes
().
indexOf
(
node
);
},
selectSingle
:
function
(
node
)
{
return
this
.
clearSelect
().
select
(
node
);
},
...
...
src/module/history.js
View file @
3ea5ea8c
...
...
@@ -24,7 +24,7 @@ KityMinder.registerModule( "HistoryModule", function () {
this
.
length
=
0
;
},
splice
:
function
()
{
//
just
to make stack array-like
// to make stack array-like
}
}
);
...
...
src/module/keyboard.js
View file @
3ea5ea8c
KityMinder
.
registerModule
(
"KeyboardModule"
,
function
()
{
function
buildPositionNetwork
(
root
)
{
var
pointIndexes
=
[],
x
,
y
;
root
.
traverse
(
function
(
node
)
{
pointIndexes
.
push
(
{
x
:
node
.
getData
(
'x'
),
y
:
node
.
getData
(
'y'
),
node
:
node
}
);
}
);
for
(
var
i
=
0
;
i
<
pointIndexes
.
length
;
i
++
)
{
findClosestPointsFor
(
pointIndexes
,
i
);
}
}
function
calcQuad
(
p
)
{
return
p
.
x
>
0
?
(
p
.
y
>
0
?
1
:
2
)
:
(
p
.
y
<
0
?
3
:
4
);
}
function
findClosestPointsFor
(
pointIndexes
,
iFind
)
{
var
find
=
pointIndexes
[
iFind
];
var
matrix
=
new
kity
.
Matrix
().
translate
(
-
find
.
x
,
-
find
.
y
).
rotate
(
-
45
);
var
most
=
{},
quad
;
var
current
;
for
(
var
i
=
0
;
i
<
pointIndexes
.
length
;
i
++
)
{
if
(
i
==
iFind
)
continue
;
current
=
matrix
.
transformPoint
(
pointIndexes
[
i
].
x
,
pointIndexes
[
i
].
y
);
quad
=
calcQuad
(
current
);
if
(
!
most
[
quad
]
||
current
.
length
()
<
most
[
quad
].
point
.
length
)
{
most
[
quad
]
=
{
point
:
current
,
node
:
pointIndexes
[
i
].
node
};
}
}
find
.
node
.
setData
(
'nearestNodes'
,
{
right
:
most
[
1
]
||
null
,
top
:
most
[
2
]
||
null
,
left
:
most
[
3
]
||
null
,
down
:
most
[
4
]
||
null
}
);
}
var
KBCreateAndEditCommand
=
kity
.
createClass
(
{
base
:
Command
,
execute
:
function
(
km
,
type
,
referNode
)
{
var
node
=
km
.
execCommand
(
'create'
+
type
+
'node'
,
referNode
);
km
.
execCommand
(
'edittext'
,
node
);
this
.
setContentChanged
(
true
);
}
}
);
var
KBNavigateCommand
=
kity
.
createClass
(
{
base
:
Command
,
execute
:
function
(
km
,
direction
,
referNode
)
{
var
nextNode
=
referNode
.
getData
(
'nearestNodes'
)[
direction
];
if
(
nextNode
)
{
km
.
toggleSelect
(
[
referNode
,
nextNode
]
);
this
.
execCommand
(
'rendernode'
,
[
referNode
,
nextNode
]
);
}
}
}
);
return
{
// private usage
"commands"
:
{
'kbCreateAndEdit'
:
KBCreateAndEditCommand
,
'kbNavigate'
:
KBNavigateCommand
},
"events"
:
{
contentchange
:
function
()
{
buildPositionNetwork
(
this
.
getRoot
()
);
},
keydown
:
function
(
e
)
{
console
.
log
(
e
);
var
sNodes
=
this
.
getSelectedNodes
(),
isSingleSelected
=
sNodes
.
length
===
1
,
isRootSelected
=
this
.
isNodeSelected
(
this
.
getRoot
()
);
console
.
log
(
e
.
originEvent
.
keyCode
);
e
.
originEvent
.
preventDefault
();
switch
(
e
.
keyCode
)
{
case
13
:
// Enter
if
(
isSingleSelected
)
{
if
(
isRootSelected
)
{
this
.
execCommand
(
'kbCreateAndEdit'
,
'child'
,
sNodes
[
0
]
);
}
else
{
this
.
execCommand
(
'kbCreateAndEdit'
,
'sibling'
,
sNodes
[
0
]
);
}
}
break
;
case
9
:
// Tab
if
(
isSingleSelected
)
{
this
.
execCommand
(
'kbCreateAndEdit'
,
'child'
,
sNodes
[
0
]
);
}
break
;
case
8
:
case
46
:
// Backspace or Delete
case
37
:
case
38
:
case
39
:
case
40
:
if
(
isSingleSelected
)
{
this
.
execCommand
(
'kbNavigate'
,
{
37
:
'left'
,
38
:
'top'
,
39
:
'right'
,
40
:
'down'
}[
e
.
keyCode
],
sNodes
[
0
]
);
}
break
;
}
}
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment