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
ec5ae11b
Commit
ec5ae11b
authored
Dec 26, 2014
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
整理按键支持
parent
4ba6d7a3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
133 additions
and
75 deletions
+133
-75
command.js
src/core/command.js
+2
-0
event.js
src/core/event.js
+11
-70
focus.js
src/core/focus.js
+41
-0
keyreceiver.js
src/core/keyreceiver.js
+66
-0
option.js
src/core/option.js
+1
-1
select.js
src/core/select.js
+1
-1
shortcut.js
src/core/shortcut.js
+0
-0
kityminder.js
src/kityminder.js
+3
-1
node.js
src/module/node.js
+8
-2
No files found.
src/core/command.js
View file @
ec5ae11b
...
@@ -116,6 +116,8 @@ define(function(require, exports, module) {
...
@@ -116,6 +116,8 @@ define(function(require, exports, module) {
* @param {argument} args 要传递给命令的其它参数
* @param {argument} args 要传递给命令的其它参数
*/
*/
execCommand
:
function
(
name
)
{
execCommand
:
function
(
name
)
{
if
(
!
name
)
return
null
;
name
=
name
.
toLowerCase
();
name
=
name
.
toLowerCase
();
var
cmdArgs
=
[].
slice
.
call
(
arguments
,
1
),
var
cmdArgs
=
[].
slice
.
call
(
arguments
,
1
),
...
...
src/core/event.js
View file @
ec5ae11b
...
@@ -3,14 +3,6 @@ define(function(require, exports, module) {
...
@@ -3,14 +3,6 @@ define(function(require, exports, module) {
var
utils
=
require
(
'./utils'
);
var
utils
=
require
(
'./utils'
);
var
Minder
=
require
(
'./minder'
);
var
Minder
=
require
(
'./minder'
);
function
listen
(
element
,
type
,
handler
)
{
var
types
=
utils
.
isArray
(
type
)
?
type
:
utils
.
trim
(
type
).
split
(
' '
),
k
=
types
.
length
;
types
.
forEach
(
function
(
name
)
{
element
.
addEventListener
(
name
,
handler
,
false
);
});
}
/**
/**
* @class MinderEvent
* @class MinderEvent
* @description 表示一个脑图中发生的事件
* @description 表示一个脑图中发生的事件
...
@@ -134,7 +126,7 @@ define(function(require, exports, module) {
...
@@ -134,7 +126,7 @@ define(function(require, exports, module) {
}
}
});
});
Minder
.
registerInitHook
(
function
()
{
Minder
.
registerInitHook
(
function
(
option
)
{
this
.
_initEvents
();
this
.
_initEvents
();
});
});
...
@@ -144,17 +136,12 @@ define(function(require, exports, module) {
...
@@ -144,17 +136,12 @@ define(function(require, exports, module) {
this
.
_eventCallbacks
=
{};
this
.
_eventCallbacks
=
{};
},
},
_bindEvents
:
function
()
{
this
.
_bindPaperEvents
();
this
.
_bindKeyboardEvents
();
},
_resetEvents
:
function
()
{
_resetEvents
:
function
()
{
this
.
_initEvents
();
this
.
_initEvents
();
this
.
_bindEvents
();
this
.
_bindEvents
();
},
},
_bind
Paper
Events
:
function
()
{
_bindEvents
:
function
()
{
/* jscs:disable maximumLineLength */
/* jscs:disable maximumLineLength */
this
.
_paper
.
on
(
'click dblclick mousedown contextmenu mouseup mousemove mouseover mousewheel DOMMouseScroll touchstart touchmove touchend dragenter dragleave drop'
,
this
.
_firePharse
.
bind
(
this
));
this
.
_paper
.
on
(
'click dblclick mousedown contextmenu mouseup mousemove mouseover mousewheel DOMMouseScroll touchstart touchmove touchend dragenter dragleave drop'
,
this
.
_firePharse
.
bind
(
this
));
if
(
window
)
{
if
(
window
)
{
...
@@ -162,61 +149,15 @@ define(function(require, exports, module) {
...
@@ -162,61 +149,15 @@ define(function(require, exports, module) {
}
}
},
},
_bindKeyboardEvents
:
function
()
{
/**
if
(
this
.
_keyboardReceiver
)
return
;
* @method dispatchKeyEvent
* @description 派发键盘(相关)事件到脑图实例上,让实例的模块处理
var
receiver
=
this
.
_keyboardReceiver
=
document
.
createElement
(
'input'
);
* @grammar dispatchKeyEvent(e) => {this}
receiver
.
classList
.
add
(
'km-receiver'
);
* @param {Event} e 原生的 Dom 事件对象
*/
var
renderTarget
=
this
.
_renderTarget
;
dispatchKeyEvent
:
function
(
e
)
{
renderTarget
.
appendChild
(
receiver
);
this
.
_firePharse
(
e
);
e
.
preventDefault
();
var
minder
=
this
;
listen
(
receiver
,
'keydown keyup keypress copy paste blur focus input'
,
function
(
e
)
{
switch
(
e
.
type
)
{
case
'blur'
:
minder
.
blur
();
break
;
case
'focus'
:
minder
.
focus
();
break
;
case
'input'
:
receiver
.
value
=
null
;
break
;
}
minder
.
_firePharse
(
e
);
e
.
preventDefault
();
});
this
.
on
(
'beforemousedown'
,
function
(
e
)
{
this
.
focus
();
e
.
preventDefault
();
});
this
.
focus
=
function
()
{
if
(
!
this
.
isFocused
())
{
renderTarget
.
classList
.
add
(
'focus'
);
receiver
.
select
();
receiver
.
focus
();
this
.
renderNodeBatch
(
this
.
getSelectedNodes
());
}
return
this
;
};
this
.
blur
=
function
()
{
if
(
this
.
isFocused
())
{
renderTarget
.
classList
.
remove
(
'focus'
);
receiver
.
blur
();
this
.
renderNodeBatch
(
this
.
getSelectedNodes
());
}
return
this
;
};
this
.
focus
();
},
isFocused
:
function
()
{
var
renderTarget
=
this
.
_renderTarget
;
return
renderTarget
&&
renderTarget
.
classList
.
contains
(
'focus'
);
},
},
_firePharse
:
function
(
e
)
{
_firePharse
:
function
(
e
)
{
...
...
src/core/focus.js
0 → 100644
View file @
ec5ae11b
define
(
function
(
require
,
exports
,
module
)
{
var
kity
=
require
(
'./kity'
);
var
Minder
=
require
(
'./minder'
);
Minder
.
registerInitHook
(
function
()
{
this
.
on
(
'beforemousedown'
,
function
(
e
)
{
this
.
focus
();
e
.
preventDefault
();
});
this
.
on
(
'paperrender'
,
function
()
{
this
.
focus
();
});
});
kity
.
extendClass
(
Minder
,
{
focus
:
function
()
{
if
(
!
this
.
isFocused
())
{
var
renderTarget
=
this
.
_renderTarget
;
renderTarget
.
classList
.
add
(
'focus'
);
this
.
renderNodeBatch
(
this
.
getSelectedNodes
());
}
this
.
fire
(
'focus'
);
return
this
;
},
blur
:
function
()
{
if
(
this
.
isFocused
())
{
var
renderTarget
=
this
.
_renderTarget
;
renderTarget
.
classList
.
remove
(
'focus'
);
this
.
renderNodeBatch
(
this
.
getSelectedNodes
());
}
this
.
fire
(
'blur'
);
return
this
;
},
isFocused
:
function
()
{
var
renderTarget
=
this
.
_renderTarget
;
return
renderTarget
&&
renderTarget
.
classList
.
contains
(
'focus'
);
}
});
});
\ No newline at end of file
src/core/keyreceiver.js
0 → 100644
View file @
ec5ae11b
define
(
function
(
require
,
exports
,
module
)
{
var
kity
=
require
(
'./kity'
);
var
utils
=
require
(
'./utils'
);
var
Minder
=
require
(
'./minder'
);
function
listen
(
element
,
type
,
handler
)
{
type
.
split
(
' '
).
forEach
(
function
(
name
)
{
element
.
addEventListener
(
name
,
handler
,
false
);
});
}
Minder
.
registerInitHook
(
function
(
option
)
{
this
.
addDefaultOption
({
enableKeyReceiver
:
true
});
if
(
this
.
getOption
(
'enableKeyReceiver'
))
{
this
.
on
(
'paperrender'
,
function
()
{
this
.
_initKeyReceiver
();
});
}
});
kity
.
extendClass
(
Minder
,
{
_initKeyReceiver
:
function
()
{
if
(
this
.
_keyReceiver
)
return
;
var
receiver
=
this
.
_keyReceiver
=
document
.
createElement
(
'input'
);
receiver
.
classList
.
add
(
'km-receiver'
);
var
renderTarget
=
this
.
_renderTarget
;
renderTarget
.
appendChild
(
receiver
);
var
minder
=
this
;
listen
(
receiver
,
'keydown keyup keypress copy paste blur focus input'
,
function
(
e
)
{
switch
(
e
.
type
)
{
case
'blur'
:
minder
.
blur
();
break
;
case
'focus'
:
minder
.
focus
();
break
;
case
'input'
:
receiver
.
value
=
null
;
break
;
}
minder
.
_firePharse
(
e
);
e
.
preventDefault
();
});
this
.
on
(
'focus'
,
function
()
{
receiver
.
select
();
receiver
.
focus
();
});
this
.
on
(
'blur'
,
function
()
{
receiver
.
blur
();
});
if
(
this
.
isFocused
())
{
receiver
.
select
();
receiver
.
focus
();
}
}
});
});
\ No newline at end of file
src/core/option.js
View file @
ec5ae11b
...
@@ -22,7 +22,7 @@ define(function(require, exports, module) {
...
@@ -22,7 +22,7 @@ define(function(require, exports, module) {
},
},
getOption
:
function
(
key
)
{
getOption
:
function
(
key
)
{
if
(
key
)
{
if
(
key
)
{
return
this
.
_options
[
key
]
||
this
.
_defaultOptions
[
key
];
return
key
in
this
.
_options
?
this
.
_options
[
key
]
:
this
.
_defaultOptions
[
key
];
}
else
{
}
else
{
return
utils
.
extend
({},
this
.
_defaultOptions
,
this
.
_options
);
return
utils
.
extend
({},
this
.
_defaultOptions
,
this
.
_options
);
}
}
...
...
src/core/select.js
View file @
ec5ae11b
...
@@ -75,7 +75,7 @@ define(function(require, exports, module) {
...
@@ -75,7 +75,7 @@ define(function(require, exports, module) {
nodes
=
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
];
nodes
=
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
];
nodes
.
forEach
(
function
(
node
)
{
nodes
.
forEach
(
function
(
node
)
{
if
(
me
.
_selectedNodes
.
indexOf
(
node
)
!==
-
1
)
return
;
if
(
me
.
_selectedNodes
.
indexOf
(
node
)
!==
-
1
)
return
;
me
.
_selectedNodes
.
push
(
node
);
me
.
_selectedNodes
.
unshift
(
node
);
});
});
this
.
renderChangedSelection
(
lastSelect
);
this
.
renderChangedSelection
(
lastSelect
);
return
this
;
return
this
;
...
...
src/core/
key
.js
→
src/core/
shortcut
.js
View file @
ec5ae11b
File moved
src/kityminder.js
View file @
ec5ae11b
...
@@ -24,10 +24,12 @@ define(function(require, exports, module) {
...
@@ -24,10 +24,12 @@ define(function(require, exports, module) {
kityminder
.
data
=
require
(
'./core/data'
);
kityminder
.
data
=
require
(
'./core/data'
);
require
(
'./core/compatibility'
);
require
(
'./core/compatibility'
);
kityminder
.
KeyMap
=
require
(
'./core/keymap'
);
kityminder
.
KeyMap
=
require
(
'./core/keymap'
);
require
(
'./core/
key
'
);
require
(
'./core/
shortcut
'
);
require
(
'./core/status'
);
require
(
'./core/status'
);
require
(
'./core/paper'
);
require
(
'./core/paper'
);
require
(
'./core/select'
);
require
(
'./core/select'
);
require
(
'./core/focus'
);
require
(
'./core/keyreceiver'
);
kityminder
.
Module
=
require
(
'./core/module'
);
kityminder
.
Module
=
require
(
'./core/module'
);
require
(
'./core/readonly'
);
require
(
'./core/readonly'
);
kityminder
.
Render
=
require
(
'./core/render'
);
kityminder
.
Render
=
require
(
'./core/render'
);
...
...
src/module/node.js
View file @
ec5ae11b
...
@@ -52,6 +52,7 @@ define(function(require, exports, module) {
...
@@ -52,6 +52,7 @@ define(function(require, exports, module) {
return
km
.
execCommand
(
'AppendChildNode'
,
text
);
return
km
.
execCommand
(
'AppendChildNode'
,
text
);
}
}
var
node
=
km
.
createNode
(
text
,
parent
,
sibling
.
getIndex
()
+
1
);
var
node
=
km
.
createNode
(
text
,
parent
,
sibling
.
getIndex
()
+
1
);
node
.
setGlobalLayoutTransform
(
sibling
.
getGlobalLayoutTransform
());
km
.
select
(
node
,
true
);
km
.
select
(
node
,
true
);
node
.
render
();
node
.
render
();
km
.
layout
(
600
);
km
.
layout
(
600
);
...
@@ -74,12 +75,17 @@ define(function(require, exports, module) {
...
@@ -74,12 +75,17 @@ define(function(require, exports, module) {
execute
:
function
(
km
)
{
execute
:
function
(
km
)
{
var
nodes
=
km
.
getSelectedNodes
();
var
nodes
=
km
.
getSelectedNodes
();
var
ancestor
=
MinderNode
.
getCommonAncestor
.
apply
(
null
,
nodes
);
var
ancestor
=
MinderNode
.
getCommonAncestor
.
apply
(
null
,
nodes
);
var
index
=
nodes
[
0
].
getIndex
();
nodes
.
forEach
(
function
(
node
)
{
nodes
.
forEach
(
function
(
node
)
{
if
(
!
node
.
isRoot
())
km
.
removeNode
(
node
);
if
(
!
node
.
isRoot
())
km
.
removeNode
(
node
);
});
});
if
(
nodes
.
length
==
1
)
{
km
.
select
(
ancestor
||
km
.
getRoot
(),
true
);
var
selectBack
=
ancestor
.
children
[
index
-
1
]
||
ancestor
.
children
[
index
];
km
.
select
(
selectBack
||
ancestor
||
km
.
getRoot
(),
true
);
}
else
{
km
.
select
(
ancestor
||
km
.
getRoot
(),
true
);
}
km
.
layout
(
600
);
km
.
layout
(
600
);
},
},
queryState
:
function
(
km
)
{
queryState
:
function
(
km
)
{
...
...
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