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
43d3fe8a
Commit
43d3fe8a
authored
Mar 10, 2014
by
Jinqn
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
da12396d
4ed6de80
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
262 additions
and
541 deletions
+262
-541
kityminder.all.js
dist/kityminder.all.js
+121
-265
kityminder.all.min.js
dist/kityminder.all.min.js
+4
-4
kity
kity
+1
-1
publish
publish
+8
-0
saveto.js
src/adapter/saveto.js
+17
-78
minder.data.js
src/core/minder.data.js
+1
-1
hand.js
src/module/hand.js
+25
-10
png.js
src/protocal/png.js
+79
-85
svg.js
src/protocal/svg.js
+3
-95
kityminder.css
themes/default/css/kityminder.css
+3
-2
No files found.
dist/kityminder.all.js
View file @
43d3fe8a
...
@@ -1015,7 +1015,7 @@ kity.extendClass( Minder, {
...
@@ -1015,7 +1015,7 @@ kity.extendClass( Minder, {
json
=
exportNode
(
this
.
getRoot
()
);
json
=
exportNode
(
this
.
getRoot
()
);
protocal
=
KityMinder
.
findProtocal
(
protocalName
);
protocal
=
KityMinder
.
findProtocal
(
protocalName
);
if
(
protocal
)
{
if
(
protocal
)
{
return
protocal
.
encode
(
json
);
return
protocal
.
encode
(
json
,
this
);
}
else
{
}
else
{
return
json
;
return
json
;
}
}
...
@@ -3477,9 +3477,9 @@ var ViewDragger = kity.createClass( "ViewDragger", {
...
@@ -3477,9 +3477,9 @@ var ViewDragger = kity.createClass( "ViewDragger", {
dragger
.
setEnabled
(
true
);
dragger
.
setEnabled
(
true
);
isRootDrag
=
true
;
isRootDrag
=
true
;
var
me
=
this
;
var
me
=
this
;
setTimeout
(
function
()
{
setTimeout
(
function
()
{
me
.
setStatus
(
'hand'
);
me
.
setStatus
(
'hand'
);
},
1
);
},
1
);
}
}
}
);
}
);
...
@@ -3553,21 +3553,36 @@ KityMinder.registerModule( 'Hand', function () {
...
@@ -3553,21 +3553,36 @@ KityMinder.registerModule( 'Hand', function () {
}
}
},
},
mousewheel
:
function
(
e
)
{
mousewheel
:
function
(
e
)
{
var
dx
=
e
.
originEvent
.
wheelDeltaX
||
0
,
var
dx
,
dy
;
dy
=
e
.
originEvent
.
wheelDeltaY
||
e
.
originEvent
.
wheelDelta
;
e
=
e
.
originEvent
;
if
(
'wheelDeltaX'
in
e
)
{
dx
=
e
.
wheelDeltaX
||
0
;
dy
=
e
.
wheelDeltaY
||
0
;
}
else
{
dx
=
0
;
dy
=
e
.
wheelDelta
;
}
this
.
_viewDragger
.
move
(
{
this
.
_viewDragger
.
move
(
{
x
:
dx
/
2.5
,
x
:
dx
/
2.5
,
y
:
dy
/
2.5
y
:
dy
/
2.5
}
);
}
);
e
.
originEvent
.
preventDefault
();
e
.
preventDefault
();
},
},
dblclick
:
function
()
{
dblclick
:
function
(
e
)
{
if
(
e
.
getTargetNode
()
)
return
;
var
viewport
=
this
.
getPaper
().
getViewPort
();
var
viewport
=
this
.
getPaper
().
getViewPort
();
var
offset
=
this
.
getRoot
().
getRenderContainer
(
this
.
getRenderContainer
()
).
getTransform
().
getTranslate
(
);
var
offset
=
this
.
getRoot
().
getRenderContainer
(
).
getRenderBox
(
this
.
getRenderContainer
()
);
var
dx
=
viewport
.
center
.
x
-
offset
.
x
,
var
dx
=
viewport
.
center
.
x
-
offset
.
x
-
offset
.
width
/
2
,
dy
=
viewport
.
center
.
y
-
offset
.
y
;
dy
=
viewport
.
center
.
y
-
offset
.
y
;
//this.getRenderContainer().fxTranslate(dx, dy, 300
);
this
.
getRenderContainer
().
fxTranslate
(
dx
,
dy
,
1000
,
"easeOutQuint"
);
}
}
}
}
};
};
...
@@ -7082,8 +7097,6 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
...
@@ -7082,8 +7097,6 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
$combox
=
null
,
$combox
=
null
,
comboboxWidget
=
null
;
comboboxWidget
=
null
;
var
downloadLink
=
document
.
createElement
(
'a'
);
utils
.
each
(
KityMinder
.
getAllRegisteredProtocals
(),
function
(
k
)
{
utils
.
each
(
KityMinder
.
getAllRegisteredProtocals
(),
function
(
k
)
{
var
p
=
KityMinder
.
findProtocal
(
k
);
var
p
=
KityMinder
.
findProtocal
(
k
);
var
text
=
p
.
fileDescription
+
'('
+
p
.
fileExtension
+
')'
;
var
text
=
p
.
fileDescription
+
'('
+
p
.
fileExtension
+
')'
;
...
@@ -7097,85 +7110,26 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
...
@@ -7097,85 +7110,26 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
$combox
=
$
.
kmuibuttoncombobox
(
options
).
css
(
'zIndex'
,
me
.
getOptions
(
'zIndex'
)
+
1
);
$combox
=
$
.
kmuibuttoncombobox
(
options
).
css
(
'zIndex'
,
me
.
getOptions
(
'zIndex'
)
+
1
);
comboboxWidget
=
$combox
.
kmui
();
comboboxWidget
=
$combox
.
kmui
();
comboboxWidget
.
on
(
'comboboxselect'
,
function
(
evt
,
res
)
{
function
doDownload
(
url
,
filename
)
{
if
(
res
.
value
===
"png"
)
{
var
a
=
document
.
createElement
(
'a'
);
var
svghtml
=
$
(
"#kityminder .kmui-editor-body"
).
html
();
a
.
setAttribute
(
'download'
,
filename
);
var
bgImg
=
$
(
"#kityminder .kmui-editor-body"
).
css
(
"backgroundImage"
).
replace
(
/"/g
,
""
).
replace
(
/url
\(
|
\)
$/ig
,
""
);
a
.
setAttribute
(
'href'
,
url
);
var
renderBox
=
me
.
getRenderContainer
().
getRenderBox
(
"top"
);
a
.
dispatchEvent
(
new
MouseEvent
(
'click'
)
);
var
renderContainer
=
me
.
getRenderContainer
();
}
var
transform
=
renderContainer
.
getTransform
();
renderContainer
.
clearTransform
();
var
loop
=
0
;
var
svg
=
$
(
svghtml
).
attr
(
{
width
:
renderBox
.
width
,
height
:
renderBox
.
height
,
viewBox
:
null
}
);
var
div
=
$
(
"<div></div>"
).
append
(
svg
);
svghtml
=
div
.
html
();
var
canvas
=
$
(
'<canvas width="'
+
(
parseInt
(
renderBox
.
width
)
+
40
)
+
'" height="'
+
(
parseInt
(
renderBox
.
height
)
+
40
)
+
'"></canvas>'
);
var
ctx
=
canvas
[
0
].
getContext
(
"2d"
);
var
DOMURL
=
self
.
URL
||
self
.
webkitURL
||
self
;
var
img
=
new
Image
();
var
svg
=
new
Blob
(
[
svghtml
],
{
type
:
"image/svg+xml;charset=utf-8"
}
);
var
url
=
DOMURL
.
createObjectURL
(
svg
);
img
.
onload
=
function
()
{
var
bgTexture
=
document
.
createElement
(
'img'
);
bgTexture
.
src
=
bgImg
;
bgTexture
.
onload
=
function
()
{
var
bgfill
=
ctx
.
createPattern
(
bgTexture
,
"repeat"
);
ctx
.
fillStyle
=
bgfill
;
ctx
.
fillRect
(
0
,
0
,
renderBox
.
width
+
40
,
renderBox
.
height
+
40
);
ctx
.
drawImage
(
img
,
-
renderBox
.
x
+
20
,
-
renderBox
.
y
+
20
);
DOMURL
.
revokeObjectURL
(
url
);
var
type
=
'png'
;
var
imgData
=
canvas
[
0
].
toDataURL
(
type
);
var
_fixType
=
function
(
type
)
{
type
=
type
.
toLowerCase
().
replace
(
/jpg/i
,
'jpeg'
);
var
r
=
type
.
match
(
/png|jpeg|bmp|gif/
)[
0
];
return
'image/'
+
r
;
};
imgData
=
imgData
.
replace
(
_fixType
(
type
),
'image/octet-stream'
);
var
saveFile
=
function
(
data
,
filename
)
{
var
save_link
=
document
.
createElementNS
(
'http://www.w3.org/1999/xhtml'
,
'a'
);
save_link
.
href
=
data
;
save_link
.
download
=
filename
;
var
event
=
document
.
createEvent
(
'MouseEvents'
);
event
.
initMouseEvent
(
'click'
,
true
,
false
,
window
,
0
,
0
,
0
,
0
,
0
,
false
,
false
,
false
,
false
,
0
,
null
);
save_link
.
dispatchEvent
(
event
);
};
// 下载后的文件名
comboboxWidget
.
on
(
'comboboxselect'
,
function
(
evt
,
res
)
{
var
filename
=
'kityminder_'
+
(
new
Date
()
).
getTime
()
+
'.'
+
type
;
// download
saveFile
(
imgData
,
filename
);
renderContainer
.
setTransform
(
transform
);
};
};
img
.
src
=
url
;
return
"png"
;
}
else
if
(
res
.
value
===
"svg"
)
{
var
svghtml
=
$
(
"#kityminder .kmui-editor-body"
).
html
();
var
saveFile
=
function
(
data
,
filename
)
{
var
save_link
=
document
.
createElementNS
(
'http://www.w3.org/1999/xhtml'
,
'a'
);
save_link
.
href
=
'data:image/svg+xml; utf-8,'
+
encodeURI
(
svghtml
);
save_link
.
download
=
filename
;
var
event
=
document
.
createEvent
(
'MouseEvents'
);
event
.
initMouseEvent
(
'click'
,
true
,
false
,
window
,
0
,
0
,
0
,
0
,
0
,
false
,
false
,
false
,
false
,
0
,
null
);
save_link
.
dispatchEvent
(
event
);
};
var
filename
=
'kityminder_'
+
(
new
Date
()
).
getTime
()
+
'.svg'
;
saveFile
(
svg
,
filename
);
return
"svg"
;
}
var
data
=
me
.
exportData
(
res
.
value
);
var
data
=
me
.
exportData
(
res
.
value
);
var
p
=
KityMinder
.
findProtocal
(
res
.
value
);
var
p
=
KityMinder
.
findProtocal
(
res
.
value
);
var
a
=
downloadLink
;
var
filename
=
me
.
getMinderTitle
()
+
p
.
fileExtension
;
a
.
setAttribute
(
'download'
,
'MyMind'
+
p
.
fileExtension
);
a
.
setAttribute
(
'href'
,
'data:text/plain; utf-8,'
+
encodeURI
(
data
)
);
if
(
typeof
(
data
)
==
'string'
)
{
a
.
dispatchEvent
(
new
MouseEvent
(
'click'
)
);
var
url
=
'data:text/plain; utf-8,'
+
encodeURI
(
data
);
doDownload
(
url
,
filename
);
}
else
if
(
data
&&
data
.
then
)
{
data
.
then
(
function
(
url
)
{
doDownload
(
url
,
filename
);
}
);
}
}
).
on
(
"beforeshow"
,
function
()
{
}
).
on
(
"beforeshow"
,
function
()
{
if
(
$combox
.
parent
().
length
===
0
)
{
if
(
$combox
.
parent
().
length
===
0
)
{
$combox
.
appendTo
(
me
.
$container
.
find
(
'.kmui-dialog-container'
)
);
$combox
.
appendTo
(
me
.
$container
.
find
(
'.kmui-dialog-container'
)
);
...
@@ -7609,207 +7563,109 @@ KityMinder.registerProtocal( 'json', function () {
...
@@ -7609,207 +7563,109 @@ KityMinder.registerProtocal( 'json', function () {
}
);
}
);
KityMinder
.
registerProtocal
(
"png"
,
function
()
{
KityMinder
.
registerProtocal
(
"png"
,
function
()
{
var
LINE_ENDING
=
'
\
n'
,
function
loadImage
(
url
,
callback
)
{
TAB_CHAR
=
'
\
t'
;
var
image
=
new
Image
();
image
.
onload
=
callback
;
function
repeat
(
s
,
n
)
{
image
.
src
=
url
;
var
result
=
""
;
while
(
n
--
)
result
+=
s
;
return
result
;
}
}
function
encode
(
json
,
level
)
{
return
{
var
local
=
""
;
fileDescription
:
'PNG 图片'
,
level
=
level
||
0
;
fileExtension
:
'.png'
,
local
+=
repeat
(
TAB_CHAR
,
level
);
encode
:
function
(
json
,
km
)
{
local
+=
json
.
data
.
text
+
LINE_ENDING
;
var
domContainer
=
km
.
getPaper
().
container
,
if
(
json
.
children
)
{
svgXml
,
json
.
children
.
forEach
(
function
(
child
)
{
$svg
,
local
+=
encode
(
child
,
level
+
1
);
}
);
}
return
local
;
}
function
isEmpty
(
line
)
{
return
!
/
\S
/
.
test
(
line
);
}
function
getLevel
(
line
)
{
var
level
=
0
;
while
(
line
.
charAt
(
level
)
===
TAB_CHAR
)
level
++
;
return
level
;
}
function
getNode
(
line
)
{
bgDeclare
=
getComputedStyle
(
domContainer
).
backgroundImage
,
return
{
bgUrl
=
/url
\((
.+
)\)
$/
.
exec
(
bgDeclare
)[
1
],
data
:
{
text
:
line
.
replace
(
new
RegExp
(
'^'
+
TAB_CHAR
+
'*'
),
''
)
}
};
}
function
decode
(
local
)
{
renderContainer
=
km
.
getRenderContainer
(),
var
json
,
renderBox
=
renderContainer
.
getRenderBox
(),
parentMap
=
{},
transform
=
renderContainer
.
getTransform
(),
lines
=
local
.
split
(
LINE_ENDING
),
width
=
renderBox
.
width
,
line
,
level
,
node
;
height
=
renderBox
.
height
,
padding
=
20
,
function
addChild
(
parent
,
child
)
{
canvas
=
document
.
createElement
(
'canvas'
),
var
children
=
parent
.
children
||
(
parent
.
children
=
[]
);
ctx
=
canvas
.
getContext
(
'2d'
),
children
.
push
(
child
);
blob
,
DomURL
,
url
,
img
,
finishCallback
;
}
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
line
=
lines
[
i
];
if
(
isEmpty
(
line
)
)
continue
;
level
=
getLevel
(
line
);
renderContainer
.
translate
(
-
renderBox
.
x
,
-
renderBox
.
y
);
node
=
getNode
(
line
);
if
(
level
===
0
)
{
svgXml
=
km
.
getPaper
().
container
.
innerHTML
;
if
(
json
)
{
throw
new
Error
(
'Invalid local format'
);
}
json
=
node
;
}
else
{
if
(
!
parentMap
[
level
-
1
]
)
{
throw
new
Error
(
'Invalid local format'
);
}
addChild
(
parentMap
[
level
-
1
],
node
);
}
parentMap
[
level
]
=
node
;
}
return
json
;
}
var
lastTry
,
lastResult
;
function
recognize
(
local
)
{
if
(
!
Utils
.
isString
(
local
)
)
return
false
;
lastTry
=
local
;
try
{
lastResult
=
decode
(
local
);
}
catch
(
e
)
{
lastResult
=
null
;
}
return
!!
lastResult
;
}
return
{
fileDescription
:
'png'
,
fileExtension
:
'.png'
,
encode
:
function
(
json
)
{
return
encode
(
json
,
0
);
},
decode
:
function
(
local
)
{
if
(
lastTry
==
local
&&
lastResult
)
{
return
lastResult
;
}
return
decode
(
local
);
},
recognize
:
recognize
,
recognizePriority
:
-
1
};
}
);
KityMinder
.
registerProtocal
(
"svg"
,
function
()
{
renderContainer
.
translate
(
renderBox
.
x
,
renderBox
.
y
);
var
LINE_ENDING
=
'
\
n'
,
TAB_CHAR
=
'
\
t'
;
$svg
=
$
(
svgXml
);
$svg
.
attr
(
{
width
:
renderBox
.
width
,
height
:
renderBox
.
height
,
style
:
'font-family: Arial, "Heiti SC", "Microsoft Yahei";'
}
);
function
repeat
(
s
,
n
)
{
// need a xml with width and height
var
result
=
""
;
svgXml
=
$
(
'<div></div'
).
append
(
$svg
).
html
();
while
(
n
--
)
result
+=
s
;
return
result
;
}
function
encode
(
json
,
level
)
{
blob
=
new
Blob
(
[
svgXml
],
{
var
local
=
""
;
type
:
"image/svg+xml;charset=utf-8"
level
=
level
||
0
;
local
+=
repeat
(
TAB_CHAR
,
level
);
local
+=
json
.
data
.
text
+
LINE_ENDING
;
if
(
json
.
children
)
{
json
.
children
.
forEach
(
function
(
child
)
{
local
+=
encode
(
child
,
level
+
1
);
}
);
}
);
}
return
local
;
}
function
isEmpty
(
line
)
{
DomURL
=
window
.
URL
||
window
.
webkitURL
||
window
;
return
!
/
\S
/
.
test
(
line
);
}
function
getLevel
(
line
)
{
url
=
DomURL
.
createObjectURL
(
blob
);
var
level
=
0
;
while
(
line
.
charAt
(
level
)
===
TAB_CHAR
)
level
++
;
return
level
;
}
function
getNode
(
line
)
{
canvas
.
width
=
width
+
padding
*
2
;
return
{
canvas
.
height
=
height
+
padding
*
2
;
data
:
{
text
:
line
.
replace
(
new
RegExp
(
'^'
+
TAB_CHAR
+
'*'
),
''
)
}
};
}
function
decode
(
local
)
{
function
fillBackground
(
ctx
,
image
,
width
,
height
)
{
var
json
,
ctx
.
save
();
parentMap
=
{},
ctx
.
fillStyle
=
ctx
.
createPattern
(
image
,
"repeat"
);
lines
=
local
.
split
(
LINE_ENDING
),
ctx
.
fillRect
(
0
,
0
,
width
,
height
);
line
,
level
,
node
;
ctx
.
restore
();
}
function
addChild
(
parent
,
child
)
{
function
drawImage
(
ctx
,
image
,
x
,
y
)
{
var
children
=
parent
.
children
||
(
parent
.
children
=
[]
);
ctx
.
drawImage
(
image
,
x
,
y
);
children
.
push
(
child
);
}
}
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
function
generateDataUrl
(
canvas
)
{
line
=
lines
[
i
];
var
url
=
canvas
.
toDataURL
(
'png'
);
if
(
isEmpty
(
line
)
)
continue
;
return
url
.
replace
(
'image/png'
,
'image/octet-stream'
);
}
level
=
getLevel
(
line
);
loadImage
(
url
,
function
()
{
node
=
getNode
(
line
);
var
svgImage
=
this
;
loadImage
(
bgUrl
,
function
()
{
var
downloadUrl
;
fillBackground
(
ctx
,
this
,
canvas
.
width
,
canvas
.
height
);
drawImage
(
ctx
,
svgImage
,
padding
,
padding
);
DomURL
.
revokeObjectURL
(
url
);
downloadUrl
=
generateDataUrl
(
canvas
);
if
(
finishCallback
)
{
finishCallback
(
downloadUrl
);
}
}
);
}
);
if
(
level
===
0
)
{
return
{
if
(
json
)
{
then
:
function
(
callback
)
{
throw
new
Error
(
'Invalid local format'
);
finishCallback
=
callback
;
}
json
=
node
;
}
else
{
if
(
!
parentMap
[
level
-
1
]
)
{
throw
new
Error
(
'Invalid local format'
);
}
}
addChild
(
parentMap
[
level
-
1
],
node
);
};
}
},
parentMap
[
level
]
=
node
;
recognizePriority
:
-
1
}
};
return
json
;
}
);
}
var
lastTry
,
lastResult
;
function
recognize
(
local
)
{
KityMinder
.
registerProtocal
(
"svg"
,
function
()
{
if
(
!
Utils
.
isString
(
local
)
)
return
false
;
lastTry
=
local
;
try
{
lastResult
=
decode
(
local
);
}
catch
(
e
)
{
lastResult
=
null
;
}
return
!!
lastResult
;
}
return
{
return
{
fileDescription
:
'
svg
'
,
fileDescription
:
'
SVG 矢量图
'
,
fileExtension
:
'.svg'
,
fileExtension
:
'.svg'
,
encode
:
function
(
json
)
{
encode
:
function
(
json
,
km
)
{
return
encode
(
json
,
0
)
;
return
km
.
getPaper
().
container
.
innerHTML
;
},
},
decode
:
function
(
local
)
{
if
(
lastTry
==
local
&&
lastResult
)
{
return
lastResult
;
}
return
decode
(
local
);
},
recognize
:
recognize
,
recognizePriority
:
-
1
recognizePriority
:
-
1
};
};
}
);
}
);
...
...
dist/kityminder.all.min.js
View file @
43d3fe8a
This source diff could not be displayed because it is too large. You can
view the blob
instead.
kity
@
e144ccd9
Subproject commit
26f9836718affd92c95196be698b14b1c6da4a95
Subproject commit
e144ccd9270712497804915d13ec92f6593299b0
publish
0 → 100755
View file @
43d3fe8a
git stash
git checkout gh-pages
git merge dev -m "merge from dev"
grunt
git commit -am "publish"
git push origin gh-pages
git checkout dev
git stash pop
src/adapter/saveto.js
View file @
43d3fe8a
...
@@ -15,8 +15,6 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
...
@@ -15,8 +15,6 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
$combox
=
null
,
$combox
=
null
,
comboboxWidget
=
null
;
comboboxWidget
=
null
;
var
downloadLink
=
document
.
createElement
(
'a'
);
utils
.
each
(
KityMinder
.
getAllRegisteredProtocals
(),
function
(
k
)
{
utils
.
each
(
KityMinder
.
getAllRegisteredProtocals
(),
function
(
k
)
{
var
p
=
KityMinder
.
findProtocal
(
k
);
var
p
=
KityMinder
.
findProtocal
(
k
);
var
text
=
p
.
fileDescription
+
'('
+
p
.
fileExtension
+
')'
;
var
text
=
p
.
fileDescription
+
'('
+
p
.
fileExtension
+
')'
;
...
@@ -30,85 +28,26 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
...
@@ -30,85 +28,26 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
$combox
=
$
.
kmuibuttoncombobox
(
options
).
css
(
'zIndex'
,
me
.
getOptions
(
'zIndex'
)
+
1
);
$combox
=
$
.
kmuibuttoncombobox
(
options
).
css
(
'zIndex'
,
me
.
getOptions
(
'zIndex'
)
+
1
);
comboboxWidget
=
$combox
.
kmui
();
comboboxWidget
=
$combox
.
kmui
();
comboboxWidget
.
on
(
'comboboxselect'
,
function
(
evt
,
res
)
{
function
doDownload
(
url
,
filename
)
{
if
(
res
.
value
===
"png"
)
{
var
a
=
document
.
createElement
(
'a'
);
var
svghtml
=
$
(
"#kityminder .kmui-editor-body"
).
html
();
a
.
setAttribute
(
'download'
,
filename
);
var
bgImg
=
$
(
"#kityminder .kmui-editor-body"
).
css
(
"backgroundImage"
).
replace
(
/"/g
,
""
).
replace
(
/url
\(
|
\)
$/ig
,
""
);
a
.
setAttribute
(
'href'
,
url
);
var
renderBox
=
me
.
getRenderContainer
().
getRenderBox
(
"top"
);
a
.
dispatchEvent
(
new
MouseEvent
(
'click'
)
);
var
renderContainer
=
me
.
getRenderContainer
();
}
var
transform
=
renderContainer
.
getTransform
();
renderContainer
.
clearTransform
();
var
loop
=
0
;
var
svg
=
$
(
svghtml
).
attr
(
{
width
:
renderBox
.
width
,
height
:
renderBox
.
height
,
viewBox
:
null
}
);
var
div
=
$
(
"<div></div>"
).
append
(
svg
);
svghtml
=
div
.
html
();
var
canvas
=
$
(
'<canvas width="'
+
(
parseInt
(
renderBox
.
width
)
+
40
)
+
'" height="'
+
(
parseInt
(
renderBox
.
height
)
+
40
)
+
'"></canvas>'
);
var
ctx
=
canvas
[
0
].
getContext
(
"2d"
);
var
DOMURL
=
self
.
URL
||
self
.
webkitURL
||
self
;
var
img
=
new
Image
();
var
svg
=
new
Blob
(
[
svghtml
],
{
type
:
"image/svg+xml;charset=utf-8"
}
);
var
url
=
DOMURL
.
createObjectURL
(
svg
);
img
.
onload
=
function
()
{
var
bgTexture
=
document
.
createElement
(
'img'
);
bgTexture
.
src
=
bgImg
;
bgTexture
.
onload
=
function
()
{
var
bgfill
=
ctx
.
createPattern
(
bgTexture
,
"repeat"
);
ctx
.
fillStyle
=
bgfill
;
ctx
.
fillRect
(
0
,
0
,
renderBox
.
width
+
40
,
renderBox
.
height
+
40
);
ctx
.
drawImage
(
img
,
-
renderBox
.
x
+
20
,
-
renderBox
.
y
+
20
);
DOMURL
.
revokeObjectURL
(
url
);
var
type
=
'png'
;
var
imgData
=
canvas
[
0
].
toDataURL
(
type
);
var
_fixType
=
function
(
type
)
{
type
=
type
.
toLowerCase
().
replace
(
/jpg/i
,
'jpeg'
);
var
r
=
type
.
match
(
/png|jpeg|bmp|gif/
)[
0
];
return
'image/'
+
r
;
};
imgData
=
imgData
.
replace
(
_fixType
(
type
),
'image/octet-stream'
);
var
saveFile
=
function
(
data
,
filename
)
{
var
save_link
=
document
.
createElementNS
(
'http://www.w3.org/1999/xhtml'
,
'a'
);
save_link
.
href
=
data
;
save_link
.
download
=
filename
;
var
event
=
document
.
createEvent
(
'MouseEvents'
);
event
.
initMouseEvent
(
'click'
,
true
,
false
,
window
,
0
,
0
,
0
,
0
,
0
,
false
,
false
,
false
,
false
,
0
,
null
);
save_link
.
dispatchEvent
(
event
);
};
// 下载后的文件名
comboboxWidget
.
on
(
'comboboxselect'
,
function
(
evt
,
res
)
{
var
filename
=
'kityminder_'
+
(
new
Date
()
).
getTime
()
+
'.'
+
type
;
// download
saveFile
(
imgData
,
filename
);
renderContainer
.
setTransform
(
transform
);
};
};
img
.
src
=
url
;
return
"png"
;
}
else
if
(
res
.
value
===
"svg"
)
{
var
svghtml
=
$
(
"#kityminder .kmui-editor-body"
).
html
();
var
saveFile
=
function
(
data
,
filename
)
{
var
save_link
=
document
.
createElementNS
(
'http://www.w3.org/1999/xhtml'
,
'a'
);
save_link
.
href
=
'data:image/svg+xml; utf-8,'
+
encodeURI
(
svghtml
);
save_link
.
download
=
filename
;
var
event
=
document
.
createEvent
(
'MouseEvents'
);
event
.
initMouseEvent
(
'click'
,
true
,
false
,
window
,
0
,
0
,
0
,
0
,
0
,
false
,
false
,
false
,
false
,
0
,
null
);
save_link
.
dispatchEvent
(
event
);
};
var
filename
=
'kityminder_'
+
(
new
Date
()
).
getTime
()
+
'.svg'
;
saveFile
(
svg
,
filename
);
return
"svg"
;
}
var
data
=
me
.
exportData
(
res
.
value
);
var
data
=
me
.
exportData
(
res
.
value
);
var
p
=
KityMinder
.
findProtocal
(
res
.
value
);
var
p
=
KityMinder
.
findProtocal
(
res
.
value
);
var
a
=
downloadLink
;
var
filename
=
me
.
getMinderTitle
()
+
p
.
fileExtension
;
a
.
setAttribute
(
'download'
,
'MyMind'
+
p
.
fileExtension
);
a
.
setAttribute
(
'href'
,
'data:text/plain; utf-8,'
+
encodeURI
(
data
)
);
if
(
typeof
(
data
)
==
'string'
)
{
a
.
dispatchEvent
(
new
MouseEvent
(
'click'
)
);
var
url
=
'data:text/plain; utf-8,'
+
encodeURI
(
data
);
doDownload
(
url
,
filename
);
}
else
if
(
data
&&
data
.
then
)
{
data
.
then
(
function
(
url
)
{
doDownload
(
url
,
filename
);
}
);
}
}
).
on
(
"beforeshow"
,
function
()
{
}
).
on
(
"beforeshow"
,
function
()
{
if
(
$combox
.
parent
().
length
===
0
)
{
if
(
$combox
.
parent
().
length
===
0
)
{
$combox
.
appendTo
(
me
.
$container
.
find
(
'.kmui-dialog-container'
)
);
$combox
.
appendTo
(
me
.
$container
.
find
(
'.kmui-dialog-container'
)
);
...
...
src/core/minder.data.js
View file @
43d3fe8a
...
@@ -55,7 +55,7 @@ kity.extendClass( Minder, {
...
@@ -55,7 +55,7 @@ kity.extendClass( Minder, {
json
=
exportNode
(
this
.
getRoot
()
);
json
=
exportNode
(
this
.
getRoot
()
);
protocal
=
KityMinder
.
findProtocal
(
protocalName
);
protocal
=
KityMinder
.
findProtocal
(
protocalName
);
if
(
protocal
)
{
if
(
protocal
)
{
return
protocal
.
encode
(
json
);
return
protocal
.
encode
(
json
,
this
);
}
else
{
}
else
{
return
json
;
return
json
;
}
}
...
...
src/module/hand.js
View file @
43d3fe8a
...
@@ -35,9 +35,9 @@ var ViewDragger = kity.createClass( "ViewDragger", {
...
@@ -35,9 +35,9 @@ var ViewDragger = kity.createClass( "ViewDragger", {
dragger
.
setEnabled
(
true
);
dragger
.
setEnabled
(
true
);
isRootDrag
=
true
;
isRootDrag
=
true
;
var
me
=
this
;
var
me
=
this
;
setTimeout
(
function
()
{
setTimeout
(
function
()
{
me
.
setStatus
(
'hand'
);
me
.
setStatus
(
'hand'
);
},
1
);
},
1
);
}
}
}
);
}
);
...
@@ -111,21 +111,36 @@ KityMinder.registerModule( 'Hand', function () {
...
@@ -111,21 +111,36 @@ KityMinder.registerModule( 'Hand', function () {
}
}
},
},
mousewheel
:
function
(
e
)
{
mousewheel
:
function
(
e
)
{
var
dx
=
e
.
originEvent
.
wheelDeltaX
||
0
,
var
dx
,
dy
;
dy
=
e
.
originEvent
.
wheelDeltaY
||
e
.
originEvent
.
wheelDelta
;
e
=
e
.
originEvent
;
if
(
'wheelDeltaX'
in
e
)
{
dx
=
e
.
wheelDeltaX
||
0
;
dy
=
e
.
wheelDeltaY
||
0
;
}
else
{
dx
=
0
;
dy
=
e
.
wheelDelta
;
}
this
.
_viewDragger
.
move
(
{
this
.
_viewDragger
.
move
(
{
x
:
dx
/
2.5
,
x
:
dx
/
2.5
,
y
:
dy
/
2.5
y
:
dy
/
2.5
}
);
}
);
e
.
originEvent
.
preventDefault
();
e
.
preventDefault
();
},
},
dblclick
:
function
()
{
dblclick
:
function
(
e
)
{
if
(
e
.
getTargetNode
()
)
return
;
var
viewport
=
this
.
getPaper
().
getViewPort
();
var
viewport
=
this
.
getPaper
().
getViewPort
();
var
offset
=
this
.
getRoot
().
getRenderContainer
(
this
.
getRenderContainer
()
).
getTransform
().
getTranslate
(
);
var
offset
=
this
.
getRoot
().
getRenderContainer
(
).
getRenderBox
(
this
.
getRenderContainer
()
);
var
dx
=
viewport
.
center
.
x
-
offset
.
x
,
var
dx
=
viewport
.
center
.
x
-
offset
.
x
-
offset
.
width
/
2
,
dy
=
viewport
.
center
.
y
-
offset
.
y
;
dy
=
viewport
.
center
.
y
-
offset
.
y
;
//this.getRenderContainer().fxTranslate(dx, dy, 300
);
this
.
getRenderContainer
().
fxTranslate
(
dx
,
dy
,
1000
,
"easeOutQuint"
);
}
}
}
}
};
};
...
...
src/protocal/png.js
View file @
43d3fe8a
KityMinder
.
registerProtocal
(
"png"
,
function
()
{
KityMinder
.
registerProtocal
(
"png"
,
function
()
{
var
LINE_ENDING
=
'
\
n'
,
function
loadImage
(
url
,
callback
)
{
TAB_CHAR
=
'
\
t'
;
var
image
=
new
Image
();
image
.
onload
=
callback
;
function
repeat
(
s
,
n
)
{
image
.
src
=
url
;
var
result
=
""
;
while
(
n
--
)
result
+=
s
;
return
result
;
}
}
function
encode
(
json
,
level
)
{
return
{
var
local
=
""
;
fileDescription
:
'PNG 图片'
,
level
=
level
||
0
;
fileExtension
:
'.png'
,
local
+=
repeat
(
TAB_CHAR
,
level
);
encode
:
function
(
json
,
km
)
{
local
+=
json
.
data
.
text
+
LINE_ENDING
;
var
domContainer
=
km
.
getPaper
().
container
,
if
(
json
.
children
)
{
svgXml
,
json
.
children
.
forEach
(
function
(
child
)
{
$svg
,
local
+=
encode
(
child
,
level
+
1
);
}
);
}
return
local
;
}
function
isEmpty
(
line
)
{
bgDeclare
=
getComputedStyle
(
domContainer
).
backgroundImage
,
return
!
/
\S
/
.
test
(
line
);
bgUrl
=
/url
\((
.+
)\)
$/
.
exec
(
bgDeclare
)[
1
],
}
function
getLevel
(
line
)
{
renderContainer
=
km
.
getRenderContainer
(),
var
level
=
0
;
renderBox
=
renderContainer
.
getRenderBox
(),
while
(
line
.
charAt
(
level
)
===
TAB_CHAR
)
level
++
;
transform
=
renderContainer
.
getTransform
(),
return
level
;
width
=
renderBox
.
width
,
}
height
=
renderBox
.
height
,
padding
=
20
,
function
getNode
(
line
)
{
canvas
=
document
.
createElement
(
'canvas'
),
return
{
ctx
=
canvas
.
getContext
(
'2d'
),
data
:
{
blob
,
DomURL
,
url
,
img
,
finishCallback
;
text
:
line
.
replace
(
new
RegExp
(
'^'
+
TAB_CHAR
+
'*'
),
''
)
}
};
}
function
decode
(
local
)
{
var
json
,
parentMap
=
{},
lines
=
local
.
split
(
LINE_ENDING
),
line
,
level
,
node
;
function
addChild
(
parent
,
child
)
{
renderContainer
.
translate
(
-
renderBox
.
x
,
-
renderBox
.
y
);
var
children
=
parent
.
children
||
(
parent
.
children
=
[]
);
children
.
push
(
child
);
}
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
svgXml
=
km
.
getPaper
().
container
.
innerHTML
;
line
=
lines
[
i
];
if
(
isEmpty
(
line
)
)
continue
;
level
=
getLevel
(
line
);
renderContainer
.
translate
(
renderBox
.
x
,
renderBox
.
y
);
node
=
getNode
(
line
);
$svg
=
$
(
svgXml
);
$svg
.
attr
(
{
width
:
renderBox
.
width
,
height
:
renderBox
.
height
,
style
:
'font-family: Arial, "Heiti SC", "Microsoft Yahei";'
}
);
if
(
level
===
0
)
{
// need a xml with width and height
if
(
json
)
{
svgXml
=
$
(
'<div></div'
).
append
(
$svg
).
html
();
throw
new
Error
(
'Invalid local format'
);
}
blob
=
new
Blob
(
[
svgXml
],
{
json
=
node
;
type
:
"image/svg+xml;charset=utf-8"
}
else
{
}
);
if
(
!
parentMap
[
level
-
1
]
)
{
throw
new
Error
(
'Invalid local format'
);
DomURL
=
window
.
URL
||
window
.
webkitURL
||
window
;
}
addChild
(
parentMap
[
level
-
1
],
node
);
url
=
DomURL
.
createObjectURL
(
blob
);
canvas
.
width
=
width
+
padding
*
2
;
canvas
.
height
=
height
+
padding
*
2
;
function
fillBackground
(
ctx
,
image
,
width
,
height
)
{
ctx
.
save
();
ctx
.
fillStyle
=
ctx
.
createPattern
(
image
,
"repeat"
);
ctx
.
fillRect
(
0
,
0
,
width
,
height
);
ctx
.
restore
();
}
}
parentMap
[
level
]
=
node
;
}
function
drawImage
(
ctx
,
image
,
x
,
y
)
{
return
json
;
ctx
.
drawImage
(
image
,
x
,
y
);
}
}
var
lastTry
,
lastResult
;
function
generateDataUrl
(
canvas
)
{
function
recognize
(
local
)
{
var
url
=
canvas
.
toDataURL
(
'png'
);
if
(
!
Utils
.
isString
(
local
)
)
return
false
;
return
url
.
replace
(
'image/png'
,
'image/octet-stream'
);
lastTry
=
local
;
try
{
lastResult
=
decode
(
local
);
}
catch
(
e
)
{
lastResult
=
null
;
}
return
!!
lastResult
;
}
return
{
fileDescription
:
'png'
,
fileExtension
:
'.png'
,
encode
:
function
(
json
)
{
return
encode
(
json
,
0
);
},
decode
:
function
(
local
)
{
if
(
lastTry
==
local
&&
lastResult
)
{
return
lastResult
;
}
}
return
decode
(
local
);
loadImage
(
url
,
function
()
{
var
svgImage
=
this
;
loadImage
(
bgUrl
,
function
()
{
var
downloadUrl
;
fillBackground
(
ctx
,
this
,
canvas
.
width
,
canvas
.
height
);
drawImage
(
ctx
,
svgImage
,
padding
,
padding
);
DomURL
.
revokeObjectURL
(
url
);
downloadUrl
=
generateDataUrl
(
canvas
);
if
(
finishCallback
)
{
finishCallback
(
downloadUrl
);
}
}
);
}
);
return
{
then
:
function
(
callback
)
{
finishCallback
=
callback
;
}
};
},
},
recognize
:
recognize
,
recognizePriority
:
-
1
recognizePriority
:
-
1
};
};
}
);
}
);
\ No newline at end of file
src/protocal/svg.js
View file @
43d3fe8a
KityMinder
.
registerProtocal
(
"svg"
,
function
()
{
KityMinder
.
registerProtocal
(
"svg"
,
function
()
{
var
LINE_ENDING
=
'
\
n'
,
TAB_CHAR
=
'
\
t'
;
function
repeat
(
s
,
n
)
{
var
result
=
""
;
while
(
n
--
)
result
+=
s
;
return
result
;
}
function
encode
(
json
,
level
)
{
var
local
=
""
;
level
=
level
||
0
;
local
+=
repeat
(
TAB_CHAR
,
level
);
local
+=
json
.
data
.
text
+
LINE_ENDING
;
if
(
json
.
children
)
{
json
.
children
.
forEach
(
function
(
child
)
{
local
+=
encode
(
child
,
level
+
1
);
}
);
}
return
local
;
}
function
isEmpty
(
line
)
{
return
!
/
\S
/
.
test
(
line
);
}
function
getLevel
(
line
)
{
var
level
=
0
;
while
(
line
.
charAt
(
level
)
===
TAB_CHAR
)
level
++
;
return
level
;
}
function
getNode
(
line
)
{
return
{
data
:
{
text
:
line
.
replace
(
new
RegExp
(
'^'
+
TAB_CHAR
+
'*'
),
''
)
}
};
}
function
decode
(
local
)
{
var
json
,
parentMap
=
{},
lines
=
local
.
split
(
LINE_ENDING
),
line
,
level
,
node
;
function
addChild
(
parent
,
child
)
{
var
children
=
parent
.
children
||
(
parent
.
children
=
[]
);
children
.
push
(
child
);
}
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
line
=
lines
[
i
];
if
(
isEmpty
(
line
)
)
continue
;
level
=
getLevel
(
line
);
node
=
getNode
(
line
);
if
(
level
===
0
)
{
if
(
json
)
{
throw
new
Error
(
'Invalid local format'
);
}
json
=
node
;
}
else
{
if
(
!
parentMap
[
level
-
1
]
)
{
throw
new
Error
(
'Invalid local format'
);
}
addChild
(
parentMap
[
level
-
1
],
node
);
}
parentMap
[
level
]
=
node
;
}
return
json
;
}
var
lastTry
,
lastResult
;
function
recognize
(
local
)
{
if
(
!
Utils
.
isString
(
local
)
)
return
false
;
lastTry
=
local
;
try
{
lastResult
=
decode
(
local
);
}
catch
(
e
)
{
lastResult
=
null
;
}
return
!!
lastResult
;
}
return
{
return
{
fileDescription
:
'
svg
'
,
fileDescription
:
'
SVG 矢量图
'
,
fileExtension
:
'.svg'
,
fileExtension
:
'.svg'
,
encode
:
function
(
json
)
{
encode
:
function
(
json
,
km
)
{
return
encode
(
json
,
0
)
;
return
km
.
getPaper
().
container
.
innerHTML
;
},
},
decode
:
function
(
local
)
{
if
(
lastTry
==
local
&&
lastResult
)
{
return
lastResult
;
}
return
decode
(
local
);
},
recognize
:
recognize
,
recognizePriority
:
-
1
recognizePriority
:
-
1
};
};
}
);
}
);
\ No newline at end of file
themes/default/css/kityminder.css
View file @
43d3fe8a
...
@@ -4,8 +4,9 @@ html, body, div {
...
@@ -4,8 +4,9 @@ html, body, div {
padding
:
0
;
padding
:
0
;
}
}
html
,
body
,
#kity-minder
,
div
.kmui-editor-body
{
html
,
body
,
#kity-minder
,
div
.kmui-editor-body
{
height
:
100%
;
height
:
100%
;
width
:
100%
width
:
100%
overflow
:
hidden
;
-moz-user-select
:
none
;
-moz-user-select
:
none
;
}
}
.km_receiver
{
.km_receiver
{
...
...
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