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
211403ac
Commit
211403ac
authored
Apr 23, 2014
by
Akikonata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolved code error
parent
02961137
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
227 additions
and
220 deletions
+227
-220
Gruntfile.js
Gruntfile.js
+11
-13
saveto.js
src/adapter/saveto.js
+1
-1
editor.receiver.js
src/module/editor.receiver.js
+175
-177
history.js
src/module/history.js
+28
-17
layout.default.js
src/module/layout.default.js
+9
-9
layout.js
src/module/layout.js
+3
-3
No files found.
Gruntfile.js
View file @
211403ac
...
@@ -61,31 +61,29 @@ module.exports = function ( grunt ) {
...
@@ -61,31 +61,29 @@ module.exports = function ( grunt ) {
options
:
{
options
:
{
banner
:
banner
banner
:
banner
},
},
files
:
(
function
()
{
files
:
(
function
()
{
var
files
=
{};
var
files
=
{};
files
[
distPath
+
'kityminder.all.js'
]
=
distPath
+
'kityminder.all.min.js'
;
files
[
distPath
+
'kityminder.all.js'
]
=
distPath
+
'kityminder.all.min.js'
;
return
files
;
return
files
;
})()
}
)()
}
}
},
},
copy
:
{
copy
:
{
dir
:
{
dir
:
{
files
:
[
files
:
[
{
{
src
:
[
'dialogs/**'
,
'lang/**'
,
'lib/**'
,
'social/**'
,
'themes/**'
],
src
:
[
'dialogs/**'
,
'lang/**'
,
'lib/**'
,
'social/**'
,
'themes/**'
],
dest
:
distPath
dest
:
distPath
}
}
]
]
}
}
},
},
replace
:
{
replace
:
{
online
:
{
online
:
{
src
:
distPath
+
'index.html'
,
src
:
distPath
+
'index.html'
,
overwrite
:
true
,
overwrite
:
true
,
replacements
:
[
{
replacements
:
[
{
from
:
/1234567890/ig
,
from
:
/1234567890/ig
,
to
:
'1234567890'
to
:
'1234567890'
}]
}
]
}
}
},
},
...
@@ -123,8 +121,8 @@ module.exports = function ( grunt ) {
...
@@ -123,8 +121,8 @@ module.exports = function ( grunt ) {
/* [Build plugin & task ] ------------------------------------*/
/* [Build plugin & task ] ------------------------------------*/
grunt
.
loadNpmTasks
(
'grunt-contrib-concat'
);
grunt
.
loadNpmTasks
(
'grunt-contrib-concat'
);
grunt
.
loadNpmTasks
(
'grunt-contrib-uglify'
);
grunt
.
loadNpmTasks
(
'grunt-contrib-uglify'
);
grunt
.
loadNpmTasks
(
'grunt-contrib-copy'
);
grunt
.
loadNpmTasks
(
'grunt-contrib-copy'
);
grunt
.
loadNpmTasks
(
'grunt-text-replace'
);
grunt
.
loadNpmTasks
(
'grunt-text-replace'
);
// Build task(s).
// Build task(s).
grunt
.
registerTask
(
'default'
,
[
'concat'
,
'uglify'
,
'copy'
,
'replace'
]
);
grunt
.
registerTask
(
'default'
,
[
'concat'
,
'uglify'
,
'copy'
,
'replace'
]
);
...
...
src/adapter/saveto.js
View file @
211403ac
...
@@ -70,7 +70,7 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
...
@@ -70,7 +70,7 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
if
(
typeof
(
data
)
==
'string'
)
{
if
(
typeof
(
data
)
==
'string'
)
{
var
url
=
'data:text/plain; utf-8,'
+
encodeURIComponent
(
data
);
var
url
=
'data:text/plain; utf-8,'
+
encodeURIComponent
(
data
);
if
(
ie_ver
()
>
0
)
{
if
(
ie_ver
()
>
0
)
{
console
.
log
(
p
.
fileExtension
);
//
console.log( p.fileExtension );
if
(
p
.
fileExtension
===
'.km'
)
{
if
(
p
.
fileExtension
===
'.km'
)
{
doSave
(
'application/x-javascript'
,
data
,
me
.
getMinderTitle
()
);
doSave
(
'application/x-javascript'
,
data
,
me
.
getMinderTitle
()
);
}
else
if
(
p
.
fileExtension
===
'.svg'
)
{
}
else
if
(
p
.
fileExtension
===
'.svg'
)
{
...
...
src/module/editor.receiver.js
View file @
211403ac
//接收者
//接收者
Minder
.
Receiver
=
kity
.
createClass
(
'Receiver'
,
{
Minder
.
Receiver
=
kity
.
createClass
(
'Receiver'
,
{
clear
:
function
()
{
clear
:
function
()
{
this
.
container
.
innerHTML
=
''
;
this
.
container
.
innerHTML
=
''
;
this
.
selection
&&
this
.
selection
.
setHide
();
this
.
selection
&&
this
.
selection
.
setHide
();
this
.
range
&&
this
.
range
.
nativeSel
.
removeAllRanges
();
this
.
range
&&
this
.
range
.
nativeSel
.
removeAllRanges
();
...
@@ -8,134 +8,135 @@ Minder.Receiver = kity.createClass('Receiver',{
...
@@ -8,134 +8,135 @@ Minder.Receiver = kity.createClass('Receiver',{
this
.
inputLength
=
0
;
this
.
inputLength
=
0
;
return
this
;
return
this
;
},
},
setTextEditStatus
:
function
(
status
)
{
setTextEditStatus
:
function
(
status
)
{
this
.
textEditStatus
=
status
||
false
;
this
.
textEditStatus
=
status
||
false
;
return
this
;
return
this
;
},
},
isTextEditStatus
:
function
()
{
isTextEditStatus
:
function
()
{
return
this
.
textEditStatus
;
return
this
.
textEditStatus
;
},
},
constructor
:
function
(
km
)
{
constructor
:
function
(
km
)
{
this
.
setKityMinder
(
km
);
this
.
setKityMinder
(
km
);
this
.
textEditStatus
=
false
;
this
.
textEditStatus
=
false
;
var
_div
=
document
.
createElement
(
'div'
);
var
_div
=
document
.
createElement
(
'div'
);
_div
.
setAttribute
(
'contenteditable'
,
true
);
_div
.
setAttribute
(
'contenteditable'
,
true
);
_div
.
className
=
'km_receiver'
;
_div
.
className
=
'km_receiver'
;
this
.
container
=
document
.
body
.
insertBefore
(
_div
,
document
.
body
.
firstChild
);
this
.
container
=
document
.
body
.
insertBefore
(
_div
,
document
.
body
.
firstChild
);
utils
.
addCssRule
(
'km_receiver_css'
,
' .km_receiver{position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}'
);
//
utils
.
addCssRule
(
'km_receiver_css'
,
' .km_receiver{position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}'
);
//
this
.
km
.
on
(
'textedit.beforekeyup textedit.keydown textedit.paste'
,
utils
.
proxy
(
this
.
keyboardEvents
,
this
)
);
this
.
km
.
on
(
'textedit.beforekeyup textedit.keydown textedit.paste'
,
utils
.
proxy
(
this
.
keyboardEvents
,
this
)
);
this
.
timer
=
null
;
this
.
timer
=
null
;
this
.
index
=
0
;
this
.
index
=
0
;
},
},
setRange
:
function
(
range
,
index
)
{
setRange
:
function
(
range
,
index
)
{
this
.
index
=
index
||
this
.
index
;
this
.
index
=
index
||
this
.
index
;
var
text
=
this
.
container
.
firstChild
;
var
text
=
this
.
container
.
firstChild
;
this
.
range
=
range
;
this
.
range
=
range
;
range
.
setStart
(
text
||
this
.
container
,
this
.
index
).
collapse
(
true
);
range
.
setStart
(
text
||
this
.
container
,
this
.
index
).
collapse
(
true
);
var
me
=
this
;
var
me
=
this
;
setTimeout
(
function
()
{
setTimeout
(
function
()
{
me
.
container
.
focus
();
me
.
container
.
focus
();
range
.
select
()
range
.
select
()
});
}
);
return
this
;
return
this
;
},
},
setTextShape
:
function
(
textShape
)
{
setTextShape
:
function
(
textShape
)
{
if
(
!
textShape
)
{
if
(
!
textShape
)
{
textShape
=
new
kity
.
Text
();
textShape
=
new
kity
.
Text
();
}
}
this
.
textShape
=
textShape
;
this
.
textShape
=
textShape
;
this
.
container
.
innerHTML
=
textShape
.
getContent
();
this
.
container
.
innerHTML
=
textShape
.
getContent
();
return
this
;
return
this
;
},
},
setTextShapeSize
:
function
(
size
)
{
setTextShapeSize
:
function
(
size
)
{
this
.
textShape
.
setSize
(
size
);
this
.
textShape
.
setSize
(
size
);
return
this
;
return
this
;
},
},
getTextShapeHeight
:
function
()
{
getTextShapeHeight
:
function
()
{
return
this
.
textShape
.
getRenderBox
().
height
;
return
this
.
textShape
.
getRenderBox
().
height
;
},
},
appendTextShapeToPaper
:
function
(
paper
)
{
appendTextShapeToPaper
:
function
(
paper
)
{
paper
.
addShape
(
this
.
textShape
);
paper
.
addShape
(
this
.
textShape
);
return
this
;
return
this
;
},
},
setKityMinder
:
function
(
km
)
{
setKityMinder
:
function
(
km
)
{
this
.
km
=
km
;
this
.
km
=
km
;
return
this
;
return
this
;
},
},
setMinderNode
:
function
(
node
)
{
setMinderNode
:
function
(
node
)
{
this
.
minderNode
=
node
;
this
.
minderNode
=
node
;
return
this
;
return
this
;
},
},
keyboardEvents
:
function
(
e
)
{
keyboardEvents
:
function
(
e
)
{
clearTimeout
(
this
.
timer
);
clearTimeout
(
this
.
timer
);
var
me
=
this
;
var
me
=
this
;
var
orgEvt
=
e
.
originEvent
;
var
orgEvt
=
e
.
originEvent
;
var
keyCode
=
orgEvt
.
keyCode
;
var
keyCode
=
orgEvt
.
keyCode
;
var
keys
=
KityMinder
.
keymap
;
var
keys
=
KityMinder
.
keymap
;
function
setTextToContainer
(){
var
text
=
me
.
container
.
textContent
.
replace
(
/
[\u
200b
\t\r\n]
/g
,
''
);
if
(
me
.
textShape
.
getOpacity
()
==
0
){
function
setTextToContainer
()
{
me
.
textShape
.
setOpacity
(
1
);
var
text
=
me
.
container
.
textContent
.
replace
(
/
[\u
200b
\t\r\n]
/g
,
''
);
if
(
me
.
textShape
.
getOpacity
()
==
0
)
{
me
.
textShape
.
setOpacity
(
1
);
}
}
//#46 修复在ff下定位到文字后方空格光标不移动问题
//#46 修复在ff下定位到文字后方空格光标不移动问题
if
(
browser
.
gecko
&&
/
\s
$/
.
test
(
text
))
{
if
(
browser
.
gecko
&&
/
\s
$/
.
test
(
text
)
)
{
text
+=
"
\
u200b"
;
text
+=
"
\
u200b"
;
}
}
me
.
textShape
.
setContent
(
text
);
me
.
textShape
.
setContent
(
text
);
me
.
setContainerStyle
();
me
.
setContainerStyle
();
me
.
minderNode
.
setText
(
text
);
me
.
minderNode
.
setText
(
text
);
if
(
text
.
length
==
0
)
{
if
(
text
.
length
==
0
)
{
me
.
textShape
.
setContent
(
'a'
);
me
.
textShape
.
setContent
(
'a'
);
me
.
textShape
.
setOpacity
(
0
);
me
.
textShape
.
setOpacity
(
0
);
}
}
me
.
km
.
updateLayout
(
me
.
minderNode
);
me
.
km
.
updateLayout
(
me
.
minderNode
);
me
.
setBaseOffset
();
me
.
setBaseOffset
();
me
.
updateTextData
();
me
.
updateTextData
();
me
.
updateIndex
();
me
.
updateIndex
();
me
.
updateSelection
();
me
.
updateSelection
();
me
.
timer
=
setTimeout
(
function
()
{
me
.
timer
=
setTimeout
(
function
()
{
me
.
selection
.
setShow
()
me
.
selection
.
setShow
()
},
500
);
},
500
);
}
}
switch
(
e
.
type
)
{
switch
(
e
.
type
)
{
case
'keydown'
:
case
'keydown'
:
switch
(
e
.
originEvent
.
keyCode
)
{
switch
(
e
.
originEvent
.
keyCode
)
{
case
keys
.
Enter
:
case
keys
.
Enter
:
case
keys
.
Tab
:
case
keys
.
Tab
:
this
.
selection
.
setHide
();
this
.
selection
.
setHide
();
this
.
clear
().
setTextEditStatus
(
false
);
this
.
clear
().
setTextEditStatus
(
false
);
this
.
km
.
fire
(
'contentchange'
);
this
.
km
.
fire
(
'contentchange'
);
this
.
km
.
setStatus
(
'normal'
);
this
.
km
.
setStatus
(
'normal'
);
e
.
preventDefault
();
e
.
preventDefault
();
break
;
break
;
}
}
if
(
e
.
originEvent
.
ctrlKey
||
e
.
originEvent
.
metaKey
)
{
if
(
e
.
originEvent
.
ctrlKey
||
e
.
originEvent
.
metaKey
)
{
//粘贴
//粘贴
if
(
keyCode
==
keymap
.
v
)
{
if
(
keyCode
==
keymap
.
v
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
me
.
range
.
updateNativeRange
().
insertNode
(
$
(
'<span>$$_kityminder_bookmark_$$</span>'
)[
0
]
);
me
.
range
.
updateNativeRange
().
insertNode
(
$
(
'<span>$$_kityminder_bookmark_$$</span>'
)[
0
]
);
me
.
container
.
innerHTML
=
me
.
container
.
textContent
.
replace
(
/
[\u
200b
\t\r\n]
/g
,
''
);
me
.
container
.
innerHTML
=
me
.
container
.
textContent
.
replace
(
/
[\u
200b
\t\r\n]
/g
,
''
);
var
index
=
me
.
container
.
textContent
.
indexOf
(
'$$_kityminder_bookmark_$$'
);
var
index
=
me
.
container
.
textContent
.
indexOf
(
'$$_kityminder_bookmark_$$'
);
me
.
container
.
textContent
=
me
.
container
.
textContent
.
replace
(
'$$_kityminder_bookmark_$$'
,
''
);
me
.
container
.
textContent
=
me
.
container
.
textContent
.
replace
(
'$$_kityminder_bookmark_$$'
,
''
);
me
.
range
.
setStart
(
me
.
container
.
firstChild
,
index
).
collapse
(
true
).
select
();
me
.
range
.
setStart
(
me
.
container
.
firstChild
,
index
).
collapse
(
true
).
select
();
setTextToContainer
()
setTextToContainer
()
},
100
);
},
100
);
}
}
//剪切
//剪切
if
(
keyCode
==
keymap
.
x
)
{
if
(
keyCode
==
keymap
.
x
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
setTextToContainer
()
setTextToContainer
()
},
100
);
},
100
);
}
}
return
;
return
;
}
}
...
@@ -143,12 +144,12 @@ Minder.Receiver = kity.createClass('Receiver',{
...
@@ -143,12 +144,12 @@ Minder.Receiver = kity.createClass('Receiver',{
case
'beforekeyup'
:
case
'beforekeyup'
:
switch
(
keyCode
)
{
switch
(
keyCode
)
{
case
keymap
.
Enter
:
case
keymap
.
Enter
:
case
keymap
.
Tab
:
case
keymap
.
Tab
:
if
(
this
.
keydownNode
===
this
.
minderNode
)
{
if
(
this
.
keydownNode
===
this
.
minderNode
)
{
this
.
rollbackStatus
();
this
.
rollbackStatus
();
this
.
setTextEditStatus
(
false
);
this
.
setTextEditStatus
(
false
);
this
.
clear
();
this
.
clear
();
}
}
e
.
preventDefault
();
e
.
preventDefault
();
...
@@ -168,183 +169,180 @@ Minder.Receiver = kity.createClass('Receiver',{
...
@@ -168,183 +169,180 @@ Minder.Receiver = kity.createClass('Receiver',{
},
},
updateIndex
:
function
()
{
updateIndex
:
function
()
{
this
.
index
=
this
.
range
.
getStart
().
startOffset
;
this
.
index
=
this
.
range
.
getStart
().
startOffset
;
},
},
updateTextData
:
function
()
{
updateTextData
:
function
()
{
this
.
textShape
.
textData
=
this
.
getTextOffsetData
();
this
.
textShape
.
textData
=
this
.
getTextOffsetData
();
},
},
setSelection
:
function
(
selection
)
{
setSelection
:
function
(
selection
)
{
this
.
selection
=
selection
;
this
.
selection
=
selection
;
return
this
;
return
this
;
},
},
updateSelection
:
function
()
{
updateSelection
:
function
()
{
this
.
selection
.
setShowHold
();
this
.
selection
.
setShowHold
();
this
.
selection
.
bringTop
();
this
.
selection
.
bringTop
();
//更新模拟选区的范围
//更新模拟选区的范围
this
.
selection
.
setStartOffset
(
this
.
index
).
collapse
(
true
);
this
.
selection
.
setStartOffset
(
this
.
index
).
collapse
(
true
);
if
(
this
.
index
==
this
.
textData
.
length
)
{
if
(
this
.
index
==
this
.
textData
.
length
)
{
if
(
this
.
index
==
0
)
{
if
(
this
.
index
==
0
)
{
this
.
selection
.
setPosition
(
this
.
getBaseOffset
()
)
this
.
selection
.
setPosition
(
this
.
getBaseOffset
()
)
}
else
{
}
else
{
this
.
selection
.
setPosition
({
this
.
selection
.
setPosition
(
{
x
:
this
.
textData
[
this
.
index
-
1
].
x
+
this
.
textData
[
this
.
index
-
1
].
width
,
x
:
this
.
textData
[
this
.
index
-
1
].
x
+
this
.
textData
[
this
.
index
-
1
].
width
,
y
:
this
.
textData
[
this
.
index
-
1
].
y
y
:
this
.
textData
[
this
.
index
-
1
].
y
})
}
)
}
}
}
else
{
}
else
{
this
.
selection
.
setPosition
(
this
.
textData
[
this
.
index
]
)
this
.
selection
.
setPosition
(
this
.
textData
[
this
.
index
]
)
}
}
return
this
;
return
this
;
},
},
getBaseOffset
:
function
()
{
getBaseOffset
:
function
()
{
return
this
.
textShape
.
getRenderBox
(
'top'
);
return
this
.
textShape
.
getRenderBox
(
'top'
);
},
},
setBaseOffset
:
function
()
{
setBaseOffset
:
function
()
{
this
.
offset
=
this
.
textShape
.
getRenderBox
(
'top'
);
this
.
offset
=
this
.
textShape
.
getRenderBox
(
'top'
);
return
this
;
return
this
;
},
},
setContainerStyle
:
function
()
{
setContainerStyle
:
function
()
{
var
textShapeBox
=
this
.
textShape
.
getRenderBox
();
var
textShapeBox
=
this
.
textShape
.
getRenderBox
();
this
.
container
.
style
.
cssText
=
";left:"
+
this
.
offset
.
x
this
.
container
.
style
.
cssText
=
";left:"
+
this
.
offset
.
x
+
'px;top:'
+
(
this
.
offset
.
y
+
textShapeBox
.
height
)
+
'px;width:'
+
textShapeBox
.
width
+
'px;height:'
+
textShapeBox
.
height
+
'px;'
;
+
'px;top:'
+
(
this
.
offset
.
y
+
textShapeBox
.
height
)
+
'px;width:'
+
textShapeBox
.
width
+
'px;height:'
+
textShapeBox
.
height
+
'px;'
;
return
this
;
return
this
;
},
},
getTextOffsetData
:
function
()
{
getTextOffsetData
:
function
()
{
var
text
=
this
.
textShape
.
getContent
();
var
text
=
this
.
textShape
.
getContent
();
this
.
textData
=
[];
this
.
textData
=
[];
for
(
var
i
=
0
,
l
=
text
.
length
;
i
<
l
;
i
++
)
{
for
(
var
i
=
0
,
l
=
text
.
length
;
i
<
l
;
i
++
)
{
try
{
try
{
var
box
=
this
.
textShape
.
getExtentOfChar
(
i
);
var
box
=
this
.
textShape
.
getExtentOfChar
(
i
);
}
catch
(
e
)
{
}
catch
(
e
)
{
debugger
debugger
}
}
this
.
textData
.
push
({
this
.
textData
.
push
(
{
x
:
box
.
x
+
this
.
offset
.
x
,
x
:
box
.
x
+
this
.
offset
.
x
,
y
:
this
.
offset
.
y
,
y
:
this
.
offset
.
y
,
width
:
box
.
width
,
width
:
box
.
width
,
height
:
box
.
height
height
:
box
.
height
})
}
)
}
}
return
this
;
return
this
;
},
},
setCurrentIndex
:
function
(
offset
)
{
setCurrentIndex
:
function
(
offset
)
{
var
me
=
this
;
var
me
=
this
;
this
.
getTextOffsetData
();
this
.
getTextOffsetData
();
var
hadChanged
=
false
;
var
hadChanged
=
false
;
utils
.
each
(
this
.
textData
,
function
(
i
,
v
)
{
utils
.
each
(
this
.
textData
,
function
(
i
,
v
)
{
//点击开始之前
//点击开始之前
if
(
i
==
0
&&
offset
.
x
<=
v
.
x
)
{
if
(
i
==
0
&&
offset
.
x
<=
v
.
x
)
{
me
.
index
=
0
;
me
.
index
=
0
;
return
false
;
return
false
;
}
}
if
(
offset
.
x
>=
v
.
x
&&
offset
.
x
<=
v
.
x
+
v
.
width
)
{
if
(
offset
.
x
>=
v
.
x
&&
offset
.
x
<=
v
.
x
+
v
.
width
)
{
if
(
offset
.
x
-
v
.
x
>
v
.
width
/
2
)
{
if
(
offset
.
x
-
v
.
x
>
v
.
width
/
2
)
{
me
.
index
=
i
+
1
;
me
.
index
=
i
+
1
;
}
else
{
}
else
{
me
.
index
=
i
me
.
index
=
i
}
}
hadChanged
=
true
;
hadChanged
=
true
;
return
false
;
return
false
;
}
}
if
(
i
==
me
.
textData
.
length
-
1
&&
offset
.
x
>=
v
.
x
)
{
if
(
i
==
me
.
textData
.
length
-
1
&&
offset
.
x
>=
v
.
x
)
{
me
.
index
=
me
.
textData
.
length
;
me
.
index
=
me
.
textData
.
length
;
return
false
;
return
false
;
}
}
});
}
);
return
this
;
return
this
;
},
},
setSelectionHeight
:
function
()
{
setSelectionHeight
:
function
()
{
this
.
selection
.
setHeight
(
this
.
getTextShapeHeight
()
);
this
.
selection
.
setHeight
(
this
.
getTextShapeHeight
()
);
return
this
;
return
this
;
},
},
updateSelectionByMousePosition
:
function
(
offset
,
dir
)
{
updateSelectionByMousePosition
:
function
(
offset
,
dir
)
{
var
me
=
this
;
var
me
=
this
;
utils
.
each
(
this
.
textData
,
function
(
i
,
v
)
{
utils
.
each
(
this
.
textData
,
function
(
i
,
v
)
{
//点击开始之前
//点击开始之前
if
(
i
==
0
&&
offset
.
x
<=
v
.
x
)
{
if
(
i
==
0
&&
offset
.
x
<=
v
.
x
)
{
me
.
selection
.
setStartOffset
(
0
);
me
.
selection
.
setStartOffset
(
0
);
return
false
;
return
false
;
}
}
if
(
i
==
me
.
textData
.
length
-
1
&&
offset
.
x
>=
v
.
x
)
{
if
(
i
==
me
.
textData
.
length
-
1
&&
offset
.
x
>=
v
.
x
)
{
me
.
selection
.
setEndOffset
(
me
.
textData
.
length
);
me
.
selection
.
setEndOffset
(
me
.
textData
.
length
);
return
false
;
return
false
;
}
}
if
(
offset
.
x
>=
v
.
x
&&
offset
.
x
<=
v
.
x
+
v
.
width
)
{
if
(
offset
.
x
>=
v
.
x
&&
offset
.
x
<=
v
.
x
+
v
.
width
)
{
if
(
me
.
index
==
i
)
{
if
(
me
.
index
==
i
)
{
if
(
i
==
0
)
{
if
(
i
==
0
)
{
me
.
selection
.
setStartOffset
(
i
)
me
.
selection
.
setStartOffset
(
i
)
}
}
if
(
offset
.
x
<=
v
.
x
+
v
.
width
/
2
)
{
if
(
offset
.
x
<=
v
.
x
+
v
.
width
/
2
)
{
me
.
selection
.
collapse
()
me
.
selection
.
collapse
()
}
else
{
}
else
{
me
.
selection
.
setEndOffset
(
i
+
(
me
.
selection
.
endOffset
>
i
||
dir
==
1
?
1
:
0
)
)
me
.
selection
.
setEndOffset
(
i
+
(
me
.
selection
.
endOffset
>
i
||
dir
==
1
?
1
:
0
)
)
}
}
}
else
if
(
i
>
me
.
index
)
{
}
else
if
(
i
>
me
.
index
)
{
me
.
selection
.
setStartOffset
(
me
.
index
);
me
.
selection
.
setStartOffset
(
me
.
index
);
me
.
selection
.
setEndOffset
(
i
+
1
)
me
.
selection
.
setEndOffset
(
i
+
1
)
}
else
{
}
else
{
if
(
dir
==
1
)
{
if
(
dir
==
1
)
{
me
.
selection
.
setStartOffset
(
i
+
(
offset
.
x
>=
v
.
x
+
v
.
width
/
2
?
1
:
0
)
);
me
.
selection
.
setStartOffset
(
i
+
(
offset
.
x
>=
v
.
x
+
v
.
width
/
2
?
1
:
0
)
);
}
else
{
}
else
{
me
.
selection
.
setStartOffset
(
i
);
me
.
selection
.
setStartOffset
(
i
);
}
}
me
.
selection
.
setEndOffset
(
me
.
index
)
me
.
selection
.
setEndOffset
(
me
.
index
)
}
}
return
false
;
return
false
;
}
}
});
}
);
return
this
;
return
this
;
},
},
updateSelectionShow
:
function
()
{
updateSelectionShow
:
function
()
{
var
startOffset
=
this
.
textData
[
this
.
selection
.
startOffset
],
var
startOffset
=
this
.
textData
[
this
.
selection
.
startOffset
],
endOffset
=
this
.
textData
[
this
.
selection
.
endOffset
],
endOffset
=
this
.
textData
[
this
.
selection
.
endOffset
],
width
=
0
;
width
=
0
;
if
(
this
.
selection
.
collapsed
)
{
if
(
this
.
selection
.
collapsed
)
{
this
.
selection
.
updateShow
(
startOffset
||
this
.
textData
[
this
.
textData
.
length
-
1
],
0
);
this
.
selection
.
updateShow
(
startOffset
||
this
.
textData
[
this
.
textData
.
length
-
1
],
0
);
return
this
;
return
this
;
}
}
if
(
!
endOffset
)
{
if
(
!
endOffset
)
{
var
lastOffset
=
this
.
textData
[
this
.
textData
.
length
-
1
];
var
lastOffset
=
this
.
textData
[
this
.
textData
.
length
-
1
];
width
=
lastOffset
.
x
-
startOffset
.
x
+
lastOffset
.
width
;
width
=
lastOffset
.
x
-
startOffset
.
x
+
lastOffset
.
width
;
}
else
{
}
else
{
width
=
endOffset
.
x
-
startOffset
.
x
;
width
=
endOffset
.
x
-
startOffset
.
x
;
}
}
this
.
selection
.
updateShow
(
startOffset
,
width
);
this
.
selection
.
updateShow
(
startOffset
,
width
);
return
this
;
return
this
;
},
},
updateRange
:
function
(
range
)
{
updateRange
:
function
(
range
)
{
var
node
=
this
.
container
.
firstChild
;
var
node
=
this
.
container
.
firstChild
;
range
.
setStart
(
node
,
this
.
selection
.
startOffset
);
range
.
setStart
(
node
,
this
.
selection
.
startOffset
);
range
.
setEnd
(
node
,
this
.
selection
.
endOffset
);
range
.
setEnd
(
node
,
this
.
selection
.
endOffset
);
range
.
select
();
range
.
select
();
return
this
;
return
this
;
},
},
setIndex
:
function
(
index
)
{
setIndex
:
function
(
index
)
{
this
.
index
=
index
;
this
.
index
=
index
;
return
this
return
this
},
},
setContainerTxt
:
function
(
txt
)
{
setContainerTxt
:
function
(
txt
)
{
this
.
container
.
textContent
=
txt
;
this
.
container
.
textContent
=
txt
;
return
this
;
return
this
;
}
}
});
}
);
\ No newline at end of file
\ No newline at end of file
src/module/history.js
View file @
211403ac
...
@@ -58,8 +58,8 @@ KityMinder.registerModule( "HistoryModule", function () {
...
@@ -58,8 +58,8 @@ KityMinder.registerModule( "HistoryModule", function () {
this
.
km
.
initStyle
();
this
.
km
.
initStyle
();
this
.
update
();
this
.
update
();
this
.
km
.
fire
(
'restoreScene'
);
this
.
km
.
fire
(
'restoreScene'
);
this
.
km
.
fire
(
'contentChange'
);
this
.
km
.
fire
(
'contentChange'
);
},
},
getScene
:
function
()
{
getScene
:
function
()
{
return
new
Scene
(
this
.
km
.
getRoot
()
)
return
new
Scene
(
this
.
km
.
getRoot
()
)
...
@@ -95,8 +95,18 @@ KityMinder.registerModule( "HistoryModule", function () {
...
@@ -95,8 +95,18 @@ KityMinder.registerModule( "HistoryModule", function () {
this
.
historyManager
=
new
HistoryManager
(
this
);
this
.
historyManager
=
new
HistoryManager
(
this
);
var
keys
=
{
var
keys
=
{
/*Shift*/
16
:
1
,
/*Ctrl*/
17
:
1
,
/*Alt*/
18
:
1
,
/*Command*/
91
:
1
,
/*Shift*/
37
:
1
,
38
:
1
,
39
:
1
,
40
:
1
16
:
1
,
/*Ctrl*/
17
:
1
,
/*Alt*/
18
:
1
,
/*Command*/
91
:
1
,
37
:
1
,
38
:
1
,
39
:
1
,
40
:
1
},
},
keycont
=
0
,
keycont
=
0
,
lastKeyCode
,
lastKeyCode
,
...
@@ -104,7 +114,7 @@ KityMinder.registerModule( "HistoryModule", function () {
...
@@ -104,7 +114,7 @@ KityMinder.registerModule( "HistoryModule", function () {
return
{
return
{
defaultOptions
:
{
defaultOptions
:
{
maxUndoCount
:
20
,
maxUndoCount
:
20
,
maxInputCount
:
20
maxInputCount
:
20
},
},
"commands"
:
{
"commands"
:
{
"undo"
:
kity
.
createClass
(
"UndoCommand"
,
{
"undo"
:
kity
.
createClass
(
"UndoCommand"
,
{
...
@@ -143,38 +153,39 @@ KityMinder.registerModule( "HistoryModule", function () {
...
@@ -143,38 +153,39 @@ KityMinder.registerModule( "HistoryModule", function () {
},
},
"events"
:
{
"events"
:
{
"saveScene"
:
function
(
e
)
{
"saveScene"
:
function
(
e
)
{
debugger
;
this
.
historyManager
.
saveScene
();
this
.
historyManager
.
saveScene
();
},
},
"renderNode"
:
function
(
e
)
{
"renderNode"
:
function
(
e
)
{
var
node
=
e
.
node
;
var
node
=
e
.
node
;
if
(
node
.
isHighlight
())
{
if
(
node
.
isHighlight
()
)
{
km
.
select
(
node
);
km
.
select
(
node
);
}
}
},
},
"keydown"
:
function
(
e
)
{
"keydown"
:
function
(
e
)
{
var
orgEvt
=
e
.
originEvent
;
var
orgEvt
=
e
.
originEvent
;
var
keyCode
=
orgEvt
.
keyCode
||
orgEvt
.
which
;
var
keyCode
=
orgEvt
.
keyCode
||
orgEvt
.
which
;
if
(
!
keys
[
keyCode
]
&&
!
orgEvt
.
ctrlKey
&&
!
orgEvt
.
metaKey
&&
!
orgEvt
.
shiftKey
&&
!
orgEvt
.
altKey
)
{
if
(
!
keys
[
keyCode
]
&&
!
orgEvt
.
ctrlKey
&&
!
orgEvt
.
metaKey
&&
!
orgEvt
.
shiftKey
&&
!
orgEvt
.
altKey
)
{
if
(
km
.
historyManager
.
list
.
length
==
0
)
{
if
(
km
.
historyManager
.
list
.
length
==
0
)
{
km
.
historyManager
.
saveScene
();
km
.
historyManager
.
saveScene
();
}
}
clearTimeout
(
saveSceneTimer
);
clearTimeout
(
saveSceneTimer
);
saveSceneTimer
=
setTimeout
(
function
()
{
saveSceneTimer
=
setTimeout
(
function
()
{
km
.
historyManager
.
saveScene
();
km
.
historyManager
.
saveScene
();
},
200
);
},
200
);
lastKeyCode
=
keyCode
;
lastKeyCode
=
keyCode
;
keycont
++
;
keycont
++
;
if
(
keycont
>=
km
.
getOptions
(
'maxInputCount'
)
)
{
if
(
keycont
>=
km
.
getOptions
(
'maxInputCount'
)
)
{
km
.
historyManager
.
saveScene
()
km
.
historyManager
.
saveScene
()
}
}
}
}
},
},
"import"
:
function
()
{
"import"
:
function
()
{
this
.
historyManager
.
reset
()
this
.
historyManager
.
reset
()
}
}
}
}
...
...
src/module/layout.default.js
View file @
211403ac
...
@@ -394,16 +394,16 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -394,16 +394,16 @@ KityMinder.registerModule( "LayoutDefault", function () {
}
}
};
};
var
showNodeInView
=
function
(
node
)
{
var
showNodeInView
=
function
(
node
)
{
var
padding
=
5
;
var
padding
=
5
;
var
viewport
=
minder
.
getPaper
().
getViewPort
();
var
viewport
=
minder
.
getPaper
().
getViewPort
();
var
offset
=
node
.
getRenderContainer
().
getRenderBox
(
minder
.
getRenderContainer
()
);
var
offset
=
node
.
getRenderContainer
().
getRenderBox
(
minder
.
getRenderContainer
()
);
var
tmpX
=
viewport
.
center
.
x
*
2
-
(
offset
.
x
+
offset
.
width
);
var
tmpX
=
viewport
.
center
.
x
*
2
-
(
offset
.
x
+
offset
.
width
);
var
tmpY
=
viewport
.
center
.
y
*
2
-
(
offset
.
y
+
offset
.
height
);
var
tmpY
=
viewport
.
center
.
y
*
2
-
(
offset
.
y
+
offset
.
height
);
var
dx
=
offset
.
x
<
0
?
-
offset
.
x
:
Math
.
min
(
tmpX
,
0
);
var
dx
=
offset
.
x
<
0
?
-
offset
.
x
:
Math
.
min
(
tmpX
,
0
);
var
dy
=
offset
.
y
<
0
?
-
offset
.
y
:
Math
.
min
(
tmpY
,
0
);
var
dy
=
offset
.
y
<
0
?
-
offset
.
y
:
Math
.
min
(
tmpY
,
0
);
km
.
getRenderContainer
().
fxTranslate
(
dx
,
dy
,
100
,
"easeOutQuint"
);
km
.
getRenderContainer
().
fxTranslate
(
dx
,
dy
,
100
,
"easeOutQuint"
);
};
};
...
@@ -585,7 +585,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
...
@@ -585,7 +585,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
updateConnectAndshIcon
(
set
[
i
]
);
updateConnectAndshIcon
(
set
[
i
]
);
}
}
if
(
focus
)
{
if
(
focus
)
{
showNodeInView
(
node
);
showNodeInView
(
node
);
}
}
},
},
...
...
src/module/layout.js
View file @
211403ac
...
@@ -107,7 +107,7 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -107,7 +107,7 @@ KityMinder.registerModule( "LayoutModule", function () {
execute
:
function
(
km
,
node
,
focus
,
silbling
)
{
execute
:
function
(
km
,
node
,
focus
,
silbling
)
{
var
parent
=
km
.
getSelectedNode
();
var
parent
=
km
.
getSelectedNode
();
if
(
!
parent
)
{
if
(
!
parent
)
{
return
null
;
return
null
;
}
}
...
@@ -134,7 +134,7 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -134,7 +134,7 @@ KityMinder.registerModule( "LayoutModule", function () {
base
:
Command
,
base
:
Command
,
execute
:
function
(
km
,
node
,
focus
)
{
execute
:
function
(
km
,
node
,
focus
)
{
var
selectedNode
=
km
.
getSelectedNode
();
var
selectedNode
=
km
.
getSelectedNode
();
if
(
!
selectedNode
)
{
if
(
!
selectedNode
)
{
return
null
;
return
null
;
}
}
...
@@ -163,7 +163,7 @@ KityMinder.registerModule( "LayoutModule", function () {
...
@@ -163,7 +163,7 @@ KityMinder.registerModule( "LayoutModule", function () {
base
:
Command
,
base
:
Command
,
execute
:
function
(
km
)
{
execute
:
function
(
km
)
{
if
(
km
.
getRoot
().
children
.
length
==
0
)
{
if
(
km
.
getRoot
().
children
.
length
==
0
)
{
return
;
return
;
}
}
...
...
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