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
24909964
Commit
24909964
authored
Dec 10, 2014
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[bug fix] 你懂得~
parent
412bd81b
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
167 additions
and
22 deletions
+167
-22
command.js
src/core/command.js
+38
-3
connect.js
src/core/connect.js
+16
-0
data.js
src/core/data.js
+32
-3
event.js
src/core/event.js
+69
-5
node.js
src/core/node.js
+1
-1
paper.js
src/core/paper.js
+1
-0
dragtree.js
src/module/dragtree.js
+4
-4
select.js
src/module/select.js
+2
-2
view.js
src/module/view.js
+4
-4
No files found.
src/core/command.js
View file @
24909964
...
...
@@ -10,8 +10,6 @@ define(function(require, exports, module) {
var
COMMAND_STATE_ACTIVED
=
1
;
/**
* @class Command
*
* 表示一个命令,包含命令的查询及执行
*/
var
Command
=
kity
.
createClass
(
'Command'
,
{
...
...
@@ -72,14 +70,51 @@ define(function(require, exports, module) {
return
0
;
},
/**
* @method queryCommandState()
* @for Minder
* @description 查询指定命令的状态
*
* @grammar queryCommandName(name) => {number}
*
* @param {string} name 要查询的命令名称
*
* @return {number}
* -1: 命令不存在或命令当前不可用
* 0: 命令可用
* 1: 命令当前可用并且已经执行过
*/
queryCommandState
:
function
(
name
)
{
return
this
.
_queryCommand
(
name
,
'State'
,
[].
slice
.
call
(
arguments
,
1
));
},
/**
* @method queryCommandValue()
* @for Minder
* @description 查询指定命令当前的执行值
*
* @grammar queryCommandValue(name) => {any}
*
* @param {string} name 要查询的命令名称
*
* @return {any}
* 如果命令不存在,返回 undefined
* 不同命令具有不同返回值,具体请查看 [Command](command) 章节
*/
queryCommandValue
:
function
(
name
)
{
return
this
.
_queryCommand
(
name
,
'Value'
,
[].
slice
.
call
(
arguments
,
1
));
},
/**
* @method execCommand()
* @for Minder
* @description 执行指定的命令。
*
* @grammar execCommand(name, args...)
*
* @param {string} name 要执行的命令名称
* @param {argument} args 要传递给命令的其它参数
*/
execCommand
:
function
(
name
)
{
name
=
name
.
toLowerCase
();
...
...
@@ -99,12 +134,12 @@ define(function(require, exports, module) {
if
(
!
this
.
_hasEnterExecCommand
&&
cmd
.
isNeedUndo
())
{
this
.
_hasEnterExecCommand
=
true
;
stoped
=
this
.
_fire
(
new
MinderEvent
(
'beforeExecCommand'
,
eventParams
,
true
));
if
(
!
stoped
)
{
//保存场景
this
.
_fire
(
new
MinderEvent
(
'saveScene'
));
this
.
_fire
(
new
MinderEvent
(
'preExecCommand'
,
eventParams
,
false
));
result
=
cmd
.
execute
.
apply
(
cmd
,
[
me
].
concat
(
cmdArgs
));
...
...
src/core/connect.js
View file @
24909964
...
...
@@ -20,6 +20,14 @@ define(function(require, exports, module) {
});
kity
.
extendClass
(
MinderNode
,
{
/**
* @private
* @method getConnect()
* @for MinderNode
* @description 获取当前节点的连线类型
*
* @grammar getConnect() => {string}
*/
getConnect
:
function
()
{
return
this
.
data
.
connect
||
'default'
;
},
...
...
@@ -28,6 +36,14 @@ define(function(require, exports, module) {
return
_connectProviders
[
this
.
getConnect
()]
||
_connectProviders
[
'default'
];
},
/**
* @private
* @method getConnection()
* @for MinderNode
* @description 获取当前节点的连线对象
*
* @grammar getConnection() => {kity.Path}
*/
getConnection
:
function
()
{
return
this
.
_connection
||
null
;
}
...
...
src/core/data.js
View file @
24909964
...
...
@@ -9,6 +9,13 @@ define(function(require, exports, module) {
// 导入导出
kity
.
extendClass
(
Minder
,
{
/**
* @method exportJson()
* @for Minder
* @description
* 导出当前脑图数据为 JSON 对象,导出的数据格式请参考 [Data](data) 章节。
* @grammar exportJson() => {plain}
*/
exportJson
:
function
()
{
/* 导出 node 上整棵树的数据为 JSON */
function
exportNode
(
node
)
{
...
...
@@ -33,7 +40,16 @@ define(function(require, exports, module) {
return
json
;
},
importJson
:
function
(
json
,
params
)
{
/**
* @method importJson()
* @for Minder
* @description 导入脑图数据,数据格式为 JSON,具体的数据字段形式请参考 [Data](data) 章节。
*
* @grammar importJson(json) => {this}
*
* @param {plain} json 要导入的数据
*/
importJson
:
function
(
json
)
{
function
importNode
(
node
,
json
,
km
)
{
var
data
=
json
.
data
;
...
...
@@ -54,7 +70,12 @@ define(function(require, exports, module) {
if
(
!
json
)
return
;
this
.
_fire
(
new
MinderEvent
(
'preimport'
,
params
,
false
));
/**
* @event preimport
* @for Minder
* @when 导入数据之前
*/
this
.
_fire
(
new
MinderEvent
(
'preimport'
,
null
,
false
));
// 删除当前所有节点
while
(
this
.
_root
.
getChildren
().
length
)
{
...
...
@@ -69,12 +90,20 @@ define(function(require, exports, module) {
this
.
setTheme
(
json
.
theme
||
null
);
this
.
refresh
();
this
.
fire
(
'import'
,
params
);
/**
* @event import,contentchange,interactchange
* @for Minder
* @when 导入数据之后
*/
this
.
fire
(
'import'
);
this
.
_firePharse
({
type
:
'contentchange'
});
this
.
_interactChange
();
return
this
;
}
});
});
\ No newline at end of file
src/core/event.js
View file @
24909964
...
...
@@ -11,22 +11,75 @@ define(function(require, exports, module) {
});
}
/**
* @class MinderEvent
* @description 表示一个脑图中发生的事件
*/
var
MinderEvent
=
kity
.
createClass
(
'MindEvent'
,
{
constructor
:
function
(
type
,
params
,
canstop
)
{
params
=
params
||
{};
if
(
params
.
getType
&&
params
.
getType
()
==
'ShapeEvent'
)
{
/**
* @property kityEvent
* @for MinderEvent
* @description 如果事件是从一个 kity 的事件派生的,会有 kityEvent 属性指向原来的 kity 事件
* @type {KityEvent}
*/
this
.
kityEvent
=
params
;
/**
* @property originEvent
* @for MinderEvent
* @description 如果事件是从原声 Dom 事件派生的(如 click、mousemove 等),会有 originEvent 指向原来的 Dom 事件
* @type {DomEvent}
*/
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
);
}
/**
* @property type
* @for MinderEvent
* @description 事件的类型,如 `click`、`contentchange` 等
* @type {string}
*/
this
.
type
=
type
;
this
.
_canstop
=
canstop
||
false
;
},
/**
* @method getPosition()
* @for MinderEvent
* @description 如果事件是从一个 kity 事件派生的,会有 `getPosition()` 获取事件发生的坐标
*
* @grammar getPosition(refer) => {kity.Point}
*
* @param {string|kity.Shape} refer
* 参照的坐标系,
* `"screen"` - 以浏览器屏幕为参照坐标系
* `"minder"` - (默认)以脑图画布为参照坐标系
* `{kity.Shape}` - 指定以某个 kity 图形为参照坐标系
*/
getPosition
:
function
(
refer
)
{
if
(
!
this
.
kityEvent
)
return
;
if
(
!
refer
||
refer
==
'minder'
)
{
return
this
.
kityEvent
.
getPosition
(
this
.
minder
.
getRenderContainer
());
}
return
this
.
kityEvent
.
getPosition
.
call
(
this
.
kityEvent
,
refer
);
},
/**
* @method getTargetNode()
* @for MinderEvent
* @description 当发生的事件是鼠标事件时,获取事件位置命中的脑图节点
*
* @grammar getTargetNode() => {MinderNode}
*/
getTargetNode
:
function
()
{
var
findShape
=
this
.
kityEvent
&&
this
.
kityEvent
.
targetShape
;
if
(
!
findShape
)
return
null
;
...
...
@@ -38,6 +91,13 @@ define(function(require, exports, module) {
return
node
||
null
;
},
/**
* @method stopPropagation()
* @for MinderEvent
* @description 当发生的事件是鼠标事件时,获取事件位置命中的脑图节点
*
* @grammar getTargetNode() => {MinderNode}
*/
stopPropagation
:
function
()
{
this
.
_stoped
=
true
;
},
...
...
@@ -111,10 +171,6 @@ define(function(require, exports, module) {
},
_firePharse
:
function
(
e
)
{
// //只读模式下强了所有的事件操作
// if(this.readOnly === true){
// return false;
// }
var
beforeEvent
,
preEvent
,
executeEvent
;
if
(
e
.
type
==
'DOMMouseScroll'
)
{
...
...
@@ -152,6 +208,14 @@ define(function(require, exports, module) {
},
_fire
:
function
(
e
)
{
/**
* @property minder
* @description 产生事件的 Minder 对象
* @for MinderShape
* @type {Minder}
*/
e
.
minder
=
this
;
var
status
=
this
.
getStatus
();
var
callbacks
=
this
.
_eventCallbacks
[
e
.
type
.
toLowerCase
()]
||
[];
...
...
src/core/node.js
View file @
24909964
...
...
@@ -118,7 +118,7 @@ define(function(require, exports, module) {
},
getData
:
function
(
key
)
{
return
this
.
data
[
key
]
;
return
key
?
this
.
data
[
key
]
:
this
.
data
;
},
setData
:
function
(
key
,
value
)
{
...
...
src/core/paper.js
View file @
24909964
...
...
@@ -20,6 +20,7 @@ define(function(require, exports, module) {
_initPaper
:
function
()
{
this
.
_paper
=
new
kity
.
Paper
();
this
.
_paper
.
_minder
=
this
;
this
.
_paper
.
getNode
().
ondragstart
=
function
(
e
)
{
e
.
preventDefault
();
};
...
...
src/module/dragtree.js
View file @
24909964
...
...
@@ -114,7 +114,7 @@ define(function(require, exports, module) {
this
.
_dragSources
[
i
].
setLayoutOffset
(
this
.
_dragSources
[
i
].
getLayoutOffset
().
offset
(
movement
));
minder
.
applyLayoutResult
(
this
.
_dragSources
[
i
]);
}
if
(
!
this
.
_dropTest
())
{
this
.
_orderTest
();
}
else
{
...
...
@@ -137,7 +137,7 @@ define(function(require, exports, module) {
this
.
_dragSources
.
forEach
(
function
(
source
)
{
source
.
setLayoutOffset
(
null
);
});
this
.
_minder
.
layout
(
-
1
);
this
.
_minder
.
execCommand
(
'movetoparent'
,
this
.
_dragSources
,
this
.
_dropSucceedTarget
);
...
...
@@ -364,11 +364,11 @@ define(function(require, exports, module) {
// 单选中根节点也不触发拖拽
if
(
e
.
originEvent
.
button
)
return
;
if
(
e
.
getTargetNode
()
&&
e
.
getTargetNode
()
!=
this
.
getRoot
())
{
dragger
.
dragStart
(
e
.
getPosition
(
this
.
getRenderContainer
()
));
dragger
.
dragStart
(
e
.
getPosition
());
}
},
'normal.mousemove dragtree.mousemove'
:
function
(
e
)
{
dragger
.
dragMove
(
e
.
getPosition
(
this
.
getRenderContainer
()
));
dragger
.
dragMove
(
e
.
getPosition
());
},
'normal.mouseup dragtree.beforemouseup'
:
function
(
e
)
{
dragger
.
dragEnd
();
...
...
src/module/select.js
View file @
24909964
...
...
@@ -147,7 +147,7 @@ define(function(require, exports, module) {
// 不能马上变为单选,因为可能是需要拖动选中的多个节点
else
if
(
!
this
.
isSingleSelect
())
{
lastDownNode
=
downNode
;
lastDownPosition
=
e
.
getPosition
(
this
.
getRenderContainer
()
);
lastDownPosition
=
e
.
getPosition
();
}
},
'mousemove'
:
marqueeActivator
.
selectMove
,
...
...
@@ -156,7 +156,7 @@ define(function(require, exports, module) {
// 如果 mouseup 发生在 lastDownNode 外,是无需理会的
if
(
upNode
&&
upNode
==
lastDownNode
)
{
var
upPosition
=
e
.
getPosition
(
this
.
getRenderContainer
()
);
var
upPosition
=
e
.
getPosition
();
var
movement
=
kity
.
Vector
.
fromPoints
(
lastDownPosition
,
upPosition
);
if
(
movement
.
length
()
<
1
)
this
.
select
(
lastDownNode
,
true
);
lastDownNode
=
null
;
...
...
src/module/view.js
View file @
24909964
...
...
@@ -114,7 +114,7 @@ define(function(require, exports, module) {
}
// 点击未选中的根节点临时开启
if
(
e
.
getTargetNode
()
==
this
.
getRoot
()
||
e
.
originEvent
.
button
==
2
||
e
.
originEvent
.
altKey
)
{
lastPosition
=
e
.
getPosition
();
lastPosition
=
e
.
getPosition
(
'view'
);
isTempDrag
=
true
;
}
})
...
...
@@ -127,7 +127,7 @@ define(function(require, exports, module) {
e
.
preventDefault
();
// 阻止浏览器的后退事件
}
if
(
!
isTempDrag
)
return
;
var
offset
=
kity
.
Vector
.
fromPoints
(
lastPosition
,
e
.
getPosition
());
var
offset
=
kity
.
Vector
.
fromPoints
(
lastPosition
,
e
.
getPosition
(
'view'
));
if
(
offset
.
length
()
>
10
)
{
this
.
setStatus
(
'hand'
,
true
);
var
paper
=
dragger
.
_minder
.
getPaper
();
...
...
@@ -138,7 +138,7 @@ define(function(require, exports, module) {
.
on
(
'hand.beforemousedown hand.beforetouchstart'
,
function
(
e
)
{
// 已经被用户打开拖放模式
if
(
dragger
.
isEnabled
())
{
lastPosition
=
e
.
getPosition
();
lastPosition
=
e
.
getPosition
(
'view'
);
e
.
stopPropagation
();
var
paper
=
dragger
.
_minder
.
getPaper
();
paper
.
setStyle
(
'cursor'
,
'-webkit-grabbing'
);
...
...
@@ -147,7 +147,7 @@ define(function(require, exports, module) {
.
on
(
'hand.beforemousemove hand.beforetouchmove'
,
function
(
e
)
{
if
(
lastPosition
)
{
currentPosition
=
e
.
getPosition
();
currentPosition
=
e
.
getPosition
(
'view'
);
// 当前偏移加上历史偏移
var
offset
=
kity
.
Vector
.
fromPoints
(
lastPosition
,
currentPosition
);
...
...
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