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
434b240c
Commit
434b240c
authored
Jun 18, 2014
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化拖动性能
parent
85d41ead
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
112 deletions
+123
-112
layout.js
src/core/layout.js
+6
-5
minder.event.js
src/core/minder.event.js
+1
-1
dragtree.js
src/module/dragtree.js
+1
-2
dropfile.js
src/module/dropfile.js
+76
-73
image.js
src/module/image.js
+39
-31
No files found.
src/core/layout.js
View file @
434b240c
...
...
@@ -159,11 +159,13 @@ kity.extendClass(Minder, {
layoutNode
(
this
.
getRoot
());
return
this
.
applyLayoutResult
(
duration
);
this
.
applyLayoutResult
(
this
.
getRoot
(),
duration
);
return
this
.
fire
(
'layout'
);
},
applyLayoutResult
:
function
(
duration
)
{
var
root
=
this
.
getRoot
();
applyLayoutResult
:
function
(
root
,
duration
)
{
root
=
root
||
this
.
getRoot
();
var
me
=
this
;
function
apply
(
node
,
pMatrix
)
{
...
...
@@ -217,8 +219,7 @@ kity.extendClass(Minder, {
}
}
apply
(
root
,
new
kity
.
Matrix
());
this
.
fire
(
'layout'
);
apply
(
root
,
root
.
parent
?
root
.
parent
.
getGlobalLayoutTransform
()
:
new
kity
.
Matrix
());
return
this
;
},
});
...
...
src/core/minder.event.js
View file @
434b240c
...
...
@@ -13,7 +13,7 @@ kity.extendClass( Minder, {
},
// TODO: mousemove lazy bind
_bindPaperEvents
:
function
()
{
this
.
_paper
.
on
(
'click dblclick mousedown contextmenu mouseup mousemove mousewheel DOMMouseScroll touchstart touchmove touchend'
,
this
.
_firePharse
.
bind
(
this
)
);
this
.
_paper
.
on
(
'click dblclick mousedown contextmenu mouseup mousemove mousewheel DOMMouseScroll touchstart touchmove touchend
dragenter dragleave drop
'
,
this
.
_firePharse
.
bind
(
this
)
);
if
(
window
)
{
window
.
addEventListener
(
'resize'
,
this
.
_firePharse
.
bind
(
this
)
);
window
.
addEventListener
(
'blur'
,
this
.
_firePharse
.
bind
(
this
)
);
...
...
src/module/dragtree.js
View file @
434b240c
...
...
@@ -106,10 +106,9 @@ var TreeDragger = kity.createClass('TreeDragger', {
for
(
var
i
=
0
;
i
<
this
.
_dragSources
.
length
;
i
++
)
{
this
.
_dragSources
[
i
].
setLayoutOffset
(
this
.
_dragSourceOffsets
[
i
].
offset
(
movement
));
minder
.
applyLayoutResult
(
this
.
_dragSources
[
i
]);
}
minder
.
layout
();
if
(
!
this
.
_dropTest
())
{
this
.
_orderTest
();
}
else
{
...
...
src/module/dropfile.js
View file @
434b240c
KityMinder
.
registerModule
(
"DropFile"
,
function
()
{
KityMinder
.
registerModule
(
'DropFile'
,
function
()
{
var
social
,
draftManager
,
importing
=
false
;
var
social
,
draftManager
,
importing
=
false
;
function
init
()
{
var
container
=
this
.
getPaper
().
getContainer
();
container
.
addEventListener
(
'dragover'
,
onDragOver
);
container
.
addEventListener
(
'drop'
,
onDrop
.
bind
(
this
)
);
}
function
init
()
{
var
container
=
this
.
getPaper
().
getContainer
();
container
.
addEventListener
(
'dragover'
,
onDragOver
);
container
.
addEventListener
(
'drop'
,
onDrop
.
bind
(
this
)
);
}
function
onDragOver
(
e
)
{
e
.
preventDefault
();
e
.
stopPropagation
();
e
.
dataTransfer
.
dropEffect
=
'copy'
;
}
function
onDragOver
(
e
)
{
e
.
preventDefault
();
e
.
stopPropagation
();
e
.
dataTransfer
.
dropEffect
=
'copy'
;
}
function
onDrop
(
e
)
{
e
.
preventDefault
();
e
.
stopPropagation
();
var
minder
=
this
;
function
onDrop
(
e
)
{
e
.
preventDefault
();
e
.
stopPropagation
();
var
minder
=
this
;
if
(
kity
.
Browser
.
ie
&&
Number
(
kity
.
Browser
.
version
)
<
10
)
{
alert
(
'文件导入对IE浏览器仅支持10以上版本'
);
return
;
}
if
(
kity
.
Browser
.
ie
&&
Number
(
kity
.
Browser
.
version
)
<
10
)
{
alert
(
'文件导入对IE浏览器仅支持10以上版本'
);
return
;
}
var
files
=
e
.
dataTransfer
.
files
;
var
files
=
e
.
dataTransfer
.
files
;
if
(
files
)
{
var
file
=
files
[
0
];
var
ext
=
file
.
type
||
(
/
(
.
)\w
+$/
).
exec
(
file
.
name
)[
0
];
if
(
files
)
{
var
file
=
files
[
0
];
var
ext
=
file
.
type
||
(
/
(
.
)\w
+$/
).
exec
(
file
.
name
)[
0
];
console
.
log
(
ext
);
if
(
(
/xmind/g
).
test
(
ext
)
)
{
//xmind zip
importSync
(
minder
,
file
,
'xmind'
);
}
else
if
(
(
/mmap/g
).
test
(
ext
)
)
{
// mindmanager zip
importSync
(
minder
,
file
,
'mindmanager'
);
}
else
if
(
(
/mm/g
).
test
(
ext
)
)
{
//freemind xml
importAsync
(
minder
,
file
,
'freemind'
);
}
else
{
// txt json
importAsync
(
minder
,
file
);
}
}
}
if
((
/xmind/g
).
test
(
ext
))
{
//xmind zip
importSync
(
minder
,
file
,
'xmind'
);
}
else
if
((
/mmap/g
).
test
(
ext
))
{
// mindmanager zip
importSync
(
minder
,
file
,
'mindmanager'
);
}
else
if
((
/mm/g
).
test
(
ext
))
{
//freemind xml
importAsync
(
minder
,
file
,
'freemind'
);
}
else
if
(
/km/
.
test
(
ext
))
{
// txt json
importAsync
(
minder
,
file
,
'json'
);
}
else
if
(
/txt/
.
test
(
ext
))
{
importAsync
(
minder
,
file
,
'plain'
);
}
}
}
function
afterImport
()
{
if
(
!
importing
)
return
;
createDraft
(
this
);
social
.
setRemotePath
(
null
,
false
);
this
.
execCommand
(
'camera'
,
this
.
getRoot
()
);
setTimeout
(
function
()
{
social
.
watchChanges
(
true
);
},
10
);
importing
=
false
;
}
function
afterImport
()
{
if
(
!
importing
)
return
;
createDraft
(
this
);
social
.
setRemotePath
(
null
,
false
);
this
.
execCommand
(
'camera'
,
this
.
getRoot
()
);
setTimeout
(
function
()
{
social
.
watchChanges
(
true
);
},
10
);
importing
=
false
;
}
// 同步加载文件
function
importSync
(
minder
,
file
,
protocal
)
{
social
=
social
||
window
.
social
;
social
.
watchChanges
(
false
);
importing
=
true
;
minder
.
importData
(
file
,
protocal
);
//zip文件的import是同步的
}
// 同步加载文件
function
importSync
(
minder
,
file
,
protocal
)
{
social
=
social
||
window
.
social
;
social
.
watchChanges
(
false
);
importing
=
true
;
minder
.
importData
(
file
,
protocal
);
//zip文件的import是同步的
}
// 异步加载文件
function
importAsync
(
minder
,
file
,
protocal
)
{
var
reader
=
new
FileReader
();
reader
.
onload
=
function
(
e
)
{
importSync
(
minder
,
e
.
target
.
result
,
protocal
);
};
reader
.
readAsText
(
file
);
}
// 异步加载文件
function
importAsync
(
minder
,
file
,
protocal
)
{
var
reader
=
new
FileReader
();
reader
.
onload
=
function
(
e
)
{
importSync
(
minder
,
e
.
target
.
result
,
protocal
);
};
reader
.
readAsText
(
file
);
}
function
createDraft
(
minder
)
{
draftManager
=
window
.
draftManager
||
(
window
.
draftManager
=
new
window
.
DraftManager
(
minder
)
);
draftManager
.
create
();
}
function
createDraft
(
minder
)
{
draftManager
=
window
.
draftManager
||
(
window
.
draftManager
=
new
window
.
DraftManager
(
minder
)
);
draftManager
.
create
();
}
return
{
events
:
{
'ready'
:
init
,
'import'
:
afterImport
}
};
}
);
\ No newline at end of file
return
{
events
:
{
'ready'
:
init
,
'import'
:
afterImport
}
};
});
\ No newline at end of file
src/module/image.js
View file @
434b240c
...
...
@@ -38,12 +38,15 @@ KityMinder.registerModule('image', function() {
loadImageSize
(
url
,
function
(
width
,
height
)
{
if
(
!
width
)
return
;
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
var
size
=
fitImageSize
(
width
,
height
,
km
.
getOptions
(
'maxImageWidth'
),
km
.
getOptions
(
'maxImageHeight'
));
n
.
setData
(
'image'
,
url
);
n
.
setData
(
'imageWidth'
,
width
);
n
.
setData
(
'imageHeight'
,
height
);
n
.
setData
(
'imageSize'
,
size
);
n
.
render
();
});
km
.
layout
();
km
.
layout
(
300
);
});
},
...
...
@@ -73,9 +76,9 @@ KityMinder.registerModule('image', function() {
execute
:
function
(
km
)
{
var
nodes
=
km
.
getSelectedNodes
();
utils
.
each
(
nodes
,
function
(
i
,
n
)
{
n
.
setData
(
'image'
);
km
.
updateLayout
(
n
);
n
.
setData
(
'image'
).
render
();
});
km
.
layout
(
300
);
},
queryState
:
function
(
km
)
{
var
nodes
=
km
.
getSelectedNodes
();
...
...
@@ -97,6 +100,35 @@ KityMinder.registerModule('image', function() {
}
});
var
ImageRenderer
=
kity
.
createClass
(
'ImageRenderer'
,
{
base
:
KityMinder
.
Renderer
,
create
:
function
(
node
)
{
return
new
kity
.
Image
();
},
shouldRender
:
function
(
node
)
{
return
node
.
getData
(
'image'
);
},
update
:
function
(
image
,
node
,
box
)
{
var
url
=
node
.
getData
(
'image'
);
var
size
=
node
.
getData
(
'imageSize'
);
var
spaceTop
=
node
.
getStyle
(
'space-top'
);
if
(
!
size
)
return
;
image
.
setUrl
(
url
)
.
setX
(
box
.
cx
-
size
.
width
/
2
)
.
setY
(
box
.
y
-
size
.
height
-
spaceTop
)
.
setWidth
(
size
.
width
)
.
setHeight
(
size
.
height
);
return
new
kity
.
Box
(
image
.
getX
(),
image
.
getY
(),
size
.
width
,
size
.
height
);
}
});
return
{
'defaultOptions'
:
{
'maxImageWidth'
:
200
,
...
...
@@ -106,32 +138,8 @@ KityMinder.registerModule('image', function() {
'image'
:
ImageCommand
,
'removeimage'
:
RemoveImageCommand
},
'events'
:
{
'RenderNodeTop'
:
function
(
e
)
{
var
node
=
e
.
node
,
url
=
node
.
getData
(
'image'
);
var
link
,
img
,
size
,
currentBox
;
if
(
url
)
{
size
=
fitImageSize
(
node
.
getData
(
'imageWidth'
),
node
.
getData
(
'imageHeight'
),
this
.
getOptions
(
'maxImageWidth'
),
this
.
getOptions
(
'maxImageHeight'
));
img
=
new
kity
.
Image
(
url
,
size
.
width
,
size
.
height
);
link
=
new
kity
.
HyperLink
(
url
);
link
.
addShape
(
img
);
link
.
setTarget
(
'_blank'
);
link
.
setStyle
(
'cursor'
,
'pointer'
);
currentBox
=
node
.
getContRc
().
getBoundaryBox
();
node
.
getContRc
().
addShape
(
link
.
setTranslate
(
0
,
currentBox
.
y
-
size
.
height
));
}
}
'renderers'
:
{
'top'
:
ImageRenderer
}
};
});
\ No newline at end of file
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