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
23788395
Commit
23788395
authored
Sep 21, 2015
by
hy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加core中clipboard事件处理,修复了mac下FF不同字体显示的一点错位,增加了通过节点导入text并生成节点的protocol兼容处理
parent
31a7b2df
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
143 additions
and
46 deletions
+143
-46
data.js
src/core/data.js
+23
-18
module.js
src/core/module.js
+21
-1
shortcut.js
src/core/shortcut.js
+10
-1
clipboard.js
src/module/clipboard.js
+47
-15
text.js
src/module/text.js
+9
-7
text.js
src/protocol/text.js
+33
-4
No files found.
src/core/data.js
View file @
23788395
...
@@ -77,6 +77,28 @@ define(function(require, exports, module) {
...
@@ -77,6 +77,28 @@ define(function(require, exports, module) {
return
JSON
.
parse
(
JSON
.
stringify
(
json
));
return
JSON
.
parse
(
JSON
.
stringify
(
json
));
},
},
/**
* @method importNode()
* @description 根据纯json {data, children}数据转换成为脑图节点
* @Editor: Naixor
* @Date: 2015.9.20
*/
importNode
:
function
(
node
,
json
)
{
var
data
=
json
.
data
;
node
.
data
=
{};
for
(
var
field
in
data
)
{
node
.
setData
(
field
,
data
[
field
]);
}
var
childrenTreeData
=
json
.
children
||
[];
for
(
var
i
=
0
;
i
<
childrenTreeData
.
length
;
i
++
)
{
var
childNode
=
this
.
createNode
(
null
,
node
);
this
.
importNode
(
childNode
,
childrenTreeData
[
i
]);
}
return
node
;
},
/**
/**
* @method importJson()
* @method importJson()
* @for Minder
* @for Minder
...
@@ -87,23 +109,6 @@ define(function(require, exports, module) {
...
@@ -87,23 +109,6 @@ define(function(require, exports, module) {
* @param {plain} json 要导入的数据
* @param {plain} json 要导入的数据
*/
*/
importJson
:
function
(
json
)
{
importJson
:
function
(
json
)
{
function
importNode
(
node
,
json
,
km
)
{
var
data
=
json
.
data
;
node
.
data
=
{};
for
(
var
field
in
data
)
{
node
.
setData
(
field
,
data
[
field
]);
}
var
childrenTreeData
=
json
.
children
||
[];
for
(
var
i
=
0
;
i
<
childrenTreeData
.
length
;
i
++
)
{
var
childNode
=
km
.
createNode
(
null
,
node
);
importNode
(
childNode
,
childrenTreeData
[
i
],
km
);
}
return
node
;
}
if
(
!
json
)
return
;
if
(
!
json
)
return
;
/**
/**
...
@@ -120,7 +125,7 @@ define(function(require, exports, module) {
...
@@ -120,7 +125,7 @@ define(function(require, exports, module) {
json
=
compatibility
(
json
);
json
=
compatibility
(
json
);
importNode
(
this
.
_root
,
json
.
root
,
this
);
this
.
importNode
(
this
.
_root
,
json
.
root
);
this
.
setTemplate
(
json
.
template
||
'default'
);
this
.
setTemplate
(
json
.
template
||
'default'
);
this
.
setTheme
(
json
.
theme
||
null
);
this
.
setTheme
(
json
.
theme
||
null
);
...
...
src/core/module.js
View file @
23788395
...
@@ -54,6 +54,27 @@ define(function(require, exports, module) {
...
@@ -54,6 +54,27 @@ define(function(require, exports, module) {
moduleDeals
.
init
.
call
(
me
,
this
.
_options
);
moduleDeals
.
init
.
call
(
me
,
this
.
_options
);
}
}
/**
* @Desc: 判断是否支持原生clipboard事件,如果支持,则对pager添加其监听
* @Editor: Naixor
* @Date: 2015.9.20
*/
if
(
name
===
'ClipboardModule'
&&
this
.
supportClipboardEvent
&&
!
kity
.
Browser
.
gecko
)
{
var
on
=
function
()
{
var
clipBoardReceiver
=
this
.
clipBoardReceiver
||
document
;
if
(
document
.
addEventListener
)
{
clipBoardReceiver
.
addEventListener
.
apply
(
this
,
arguments
);
}
else
{
arguments
[
0
]
=
'on'
+
arguments
[
0
];
clipBoardReceiver
.
attachEvent
.
apply
(
this
,
arguments
);
}
}
for
(
var
command
in
moduleDeals
.
clipBoardEvents
)
{
on
(
command
,
moduleDeals
.
clipBoardEvents
[
command
]);
}
};
// command加入命令池子
// command加入命令池子
dealCommands
=
moduleDeals
.
commands
;
dealCommands
=
moduleDeals
.
commands
;
for
(
name
in
dealCommands
)
{
for
(
name
in
dealCommands
)
{
...
@@ -88,7 +109,6 @@ define(function(require, exports, module) {
...
@@ -88,7 +109,6 @@ define(function(require, exports, module) {
if
(
moduleDeals
.
commandShortcutKeys
)
{
if
(
moduleDeals
.
commandShortcutKeys
)
{
this
.
addCommandShortcutKeys
(
moduleDeals
.
commandShortcutKeys
);
this
.
addCommandShortcutKeys
(
moduleDeals
.
commandShortcutKeys
);
}
}
}
}
},
},
...
...
src/core/shortcut.js
View file @
23788395
...
@@ -135,6 +135,15 @@ define(function(require, exports, module) {
...
@@ -135,6 +135,15 @@ define(function(require, exports, module) {
getCommandShortcutKey
:
function
(
cmd
)
{
getCommandShortcutKey
:
function
(
cmd
)
{
var
binds
=
this
.
_commandShortcutKeys
;
var
binds
=
this
.
_commandShortcutKeys
;
return
binds
&&
binds
[
cmd
]
||
null
;
return
binds
&&
binds
[
cmd
]
||
null
;
}
},
/**
* @Desc: 添加一个判断是否支持原生Clipboard的变量,用于对ctrl + v和ctrl + c的处理
* @Editor: Naixor
* @Date: 2015.9.20
*/
supportClipboardEvent
:
(
function
(
window
)
{
return
!!
window
.
ClipboardEvent
;
})(
window
)
});
});
});
});
\ No newline at end of file
src/module/clipboard.js
View file @
23788395
...
@@ -7,11 +7,9 @@ define(function(require, exports, module) {
...
@@ -7,11 +7,9 @@ define(function(require, exports, module) {
Module
.
register
(
'ClipboardModule'
,
function
()
{
Module
.
register
(
'ClipboardModule'
,
function
()
{
var
km
=
this
,
var
km
=
this
,
_clipboardNodes
=
[],
_clipboardNodes
=
[],
_selectedNodes
=
[];
_selectedNodes
=
[];
function
appendChildNode
(
parent
,
child
)
{
function
appendChildNode
(
parent
,
child
)
{
_selectedNodes
.
push
(
child
);
_selectedNodes
.
push
(
child
);
km
.
appendNode
(
child
,
parent
);
km
.
appendNode
(
child
,
parent
);
...
@@ -43,7 +41,7 @@ define(function(require, exports, module) {
...
@@ -43,7 +41,7 @@ define(function(require, exports, module) {
_clipboardNodes
=
nodes
.
map
(
function
(
node
)
{
_clipboardNodes
=
nodes
.
map
(
function
(
node
)
{
return
node
.
clone
();
return
node
.
clone
();
});
});
}
}
/**
/**
* @command Copy
* @command Copy
...
@@ -123,17 +121,51 @@ define(function(require, exports, module) {
...
@@ -123,17 +121,51 @@ define(function(require, exports, module) {
}
}
});
});
return
{
/**
'commands'
:
{
* @Desc: 若支持原生clipboadr事件则基于原生扩展,否则使用km的基础事件只处理节点的粘贴复制
'copy'
:
CopyCommand
,
* @Editor: Naixor
'cut'
:
CutCommand
,
* @Date: 2015.9.20
'paste'
:
PasteCommand
*/
},
if
(
km
.
supportClipboardEvent
&&
!
kity
.
Browser
.
gecko
)
{
'commandShortcutKeys'
:
{
var
Copy
=
function
(
e
)
{
'copy'
:
'normal::ctrl+c|'
,
this
.
fire
(
'beforeCopy'
,
e
);
'cut'
:
'normal::ctrl+x'
,
'paste'
:
'normal::ctrl+v'
}
}
};
var
Cut
=
function
(
e
)
{
this
.
fire
(
'beforeCut'
,
e
);
}
var
Paste
=
function
(
e
)
{
this
.
fire
(
'beforePaste'
,
e
);
}
return
{
'commands'
:
{
'copy'
:
CopyCommand
,
'cut'
:
CutCommand
,
'paste'
:
PasteCommand
},
'clipBoardEvents'
:
{
'copy'
:
Copy
.
bind
(
km
),
'cut'
:
Cut
.
bind
(
km
),
'paste'
:
Paste
.
bind
(
km
)
},
sendToClipboard
:
sendToClipboard
};
}
else
{
return
{
'commands'
:
{
'copy'
:
CopyCommand
,
'cut'
:
CutCommand
,
'paste'
:
PasteCommand
},
'commandShortcutKeys'
:
{
'copy'
:
'normal::ctrl+c|'
,
'cut'
:
'normal::ctrl+x'
,
'paste'
:
'normal::ctrl+v'
},
sendToClipboard
:
sendToClipboard
};
}
});
});
});
});
\ No newline at end of file
src/module/text.js
View file @
23788395
...
@@ -9,6 +9,7 @@ define(function(require, exports, module) {
...
@@ -9,6 +9,7 @@ define(function(require, exports, module) {
var
Renderer
=
require
(
'../core/render'
);
var
Renderer
=
require
(
'../core/render'
);
/**
/**
* 针对不同系统、不同浏览器、不同字体做居中兼容性处理
* 针对不同系统、不同浏览器、不同字体做居中兼容性处理
* 暂时未增加Linux的处理
*/
*/
var
FONT_ADJUST
=
{
var
FONT_ADJUST
=
{
'safari'
:
{
'safari'
:
{
...
@@ -75,7 +76,7 @@ define(function(require, exports, module) {
...
@@ -75,7 +76,7 @@ define(function(require, exports, module) {
'comic sans ms'
:
-
0.2
,
'comic sans ms'
:
-
0.2
,
'impact,chicago'
:
-
0.12
,
'impact,chicago'
:
-
0.12
,
'times new roman'
:
-
0.02
,
'times new roman'
:
-
0.02
,
'default'
:
-
0.15
'default'
:
-
0.15
},
},
'Lux'
:
{
'Lux'
:
{
'andale mono'
:
-
0.05
,
'andale mono'
:
-
0.05
,
...
@@ -89,11 +90,12 @@ define(function(require, exports, module) {
...
@@ -89,11 +90,12 @@ define(function(require, exports, module) {
'firefox'
:
{
'firefox'
:
{
'Mac'
:
{
'Mac'
:
{
'微软雅黑,Microsoft YaHei'
:
-
0.2
,
'微软雅黑,Microsoft YaHei'
:
-
0.2
,
'宋体,SimSun'
:
-
0.1
5
,
'宋体,SimSun'
:
0.0
5
,
'comic sans ms'
:
-
0.2
,
'comic sans ms'
:
-
0.2
,
'impact,chicago'
:
-
0.15
,
'impact,chicago'
:
-
0.15
,
'arial black,avant garde'
:
-
0.17
,
'arial black,avant garde'
:
-
0.17
,
'default'
:
-
0.15
'times new roman'
:
-
0.1
,
'default'
:
0.05
},
},
'Win'
:
{
'Win'
:
{
'微软雅黑,Microsoft YaHei'
:
-
0.16
,
'微软雅黑,Microsoft YaHei'
:
-
0.16
,
...
@@ -104,12 +106,12 @@ define(function(require, exports, module) {
...
@@ -104,12 +106,12 @@ define(function(require, exports, module) {
'times new roman'
:
-
0.22
,
'times new roman'
:
-
0.22
,
'sans-serif'
:
-
0.22
,
'sans-serif'
:
-
0.22
,
'arial black,avant garde'
:
-
0.17
,
'arial black,avant garde'
:
-
0.17
,
'default'
:
-
0.16
'default'
:
-
0.16
},
},
'Lux'
:
{
'Lux'
:
{
'宋体,SimSun'
:
-
0.02
'宋体,SimSun'
:
-
0.02
}
}
}
}
,
};
};
var
TextRenderer
=
kity
.
createClass
(
'TextRenderer'
,
{
var
TextRenderer
=
kity
.
createClass
(
'TextRenderer'
,
{
...
@@ -187,7 +189,7 @@ define(function(require, exports, module) {
...
@@ -187,7 +189,7 @@ define(function(require, exports, module) {
}
}
for
(
i
=
0
,
text
,
textShape
;
for
(
i
=
0
,
text
,
textShape
;
(
text
=
textArr
[
i
],
textShape
=
textGroup
.
getItem
(
i
));
i
++
)
{
(
text
=
textArr
[
i
],
textShape
=
textGroup
.
getItem
(
i
));
i
++
)
{
textShape
.
setContent
(
text
);
textShape
.
setContent
(
text
);
if
(
kity
.
Browser
.
ie
||
kity
.
Browser
.
edge
)
{
if
(
kity
.
Browser
.
ie
||
kity
.
Browser
.
edge
)
{
textShape
.
fixPosition
();
textShape
.
fixPosition
();
...
...
src/protocol/text.js
View file @
23788395
define
(
function
(
require
,
exports
,
module
)
{
define
(
function
(
require
,
exports
,
module
)
{
var
data
=
require
(
'../core/data'
);
var
data
=
require
(
'../core/data'
);
var
Browser
=
require
(
'../core/kity'
).
Browser
;
/**
* @Desc: 增加对不容浏览器下节点中文本\t匹配的处理,不同浏览器下\t无法正确匹配,导致无法使用TAB来批量导入节点
* @Editor: Naixor
* @Date: 2015.9.17
*/
var
LINE_ENDING
=
'
\
r'
,
var
LINE_ENDING
=
'
\
r'
,
LINE_ENDING_SPLITER
=
/
\r\n
|
\r
|
\n
/
,
LINE_ENDING_SPLITER
=
/
\r\n
|
\r
|
\n
/
,
TAB_CHAR
=
'
\
t'
;
TAB_CHAR
=
'
\
t'
,
TAB_CHAR
=
(
function
(
Browser
)
{
if
(
Browser
.
gecko
)
{
return
{
REGEXP
:
new
RegExp
(
'^(
\
t|'
+
String
.
fromCharCode
(
160
,
160
,
32
,
160
)
+
')'
),
DELETE
:
new
RegExp
(
'^(
\
t|'
+
String
.
fromCharCode
(
160
,
160
,
32
,
160
)
+
')+'
)
}
}
else
if
(
Browser
.
ie
||
Browser
.
edge
)
{
// ie系列和edge比较特别,\t在div中会被直接转义成SPACE故只好使用SPACE来做处理
return
{
REGEXP
:
new
RegExp
(
'^('
+
String
.
fromCharCode
(
32
)
+
'|'
+
String
.
fromCharCode
(
160
)
+
')'
),
DELETE
:
new
RegExp
(
'^('
+
String
.
fromCharCode
(
32
)
+
'|'
+
String
.
fromCharCode
(
160
)
+
')+'
)
}
}
else
{
return
{
REGEXP
:
/^
(\t
|
\x
20
\x
20
\x
20
\x
20
)
/
,
DELETE
:
/^
(\t
|
\x
20
\x
20
\x
20
\x
20
)
+/
}
}
})(
Browser
);
function
repeat
(
s
,
n
)
{
function
repeat
(
s
,
n
)
{
var
result
=
''
;
var
result
=
''
;
...
@@ -14,7 +39,7 @@ define(function(require, exports, module) {
...
@@ -14,7 +39,7 @@ define(function(require, exports, module) {
function
encode
(
json
,
level
)
{
function
encode
(
json
,
level
)
{
var
local
=
''
;
var
local
=
''
;
level
=
level
||
0
;
level
=
level
||
0
;
local
+=
repeat
(
TAB_CHAR
,
level
);
local
+=
repeat
(
'
\
t'
,
level
);
local
+=
json
.
data
.
text
+
LINE_ENDING
;
local
+=
json
.
data
.
text
+
LINE_ENDING
;
if
(
json
.
children
)
{
if
(
json
.
children
)
{
json
.
children
.
forEach
(
function
(
child
)
{
json
.
children
.
forEach
(
function
(
child
)
{
...
@@ -30,14 +55,18 @@ define(function(require, exports, module) {
...
@@ -30,14 +55,18 @@ define(function(require, exports, module) {
function
getLevel
(
line
)
{
function
getLevel
(
line
)
{
var
level
=
0
;
var
level
=
0
;
while
(
line
.
charAt
(
level
)
===
TAB_CHAR
)
level
++
;
while
(
TAB_CHAR
.
REGEXP
.
test
(
line
))
{
line
=
line
.
replace
(
TAB_CHAR
.
REGEXP
,
''
);
level
++
;
}
return
level
;
return
level
;
}
}
function
getNode
(
line
)
{
function
getNode
(
line
)
{
return
{
return
{
data
:
{
data
:
{
text
:
line
.
replace
(
new
RegExp
(
'^'
+
TAB_CHAR
+
'*'
),
''
)
text
:
line
.
replace
(
TAB_CHAR
.
DELETE
,
""
)
}
}
};
};
}
}
...
...
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