Commit 434b240c authored by techird's avatar techird

优化拖动性能

parent 85d41ead
......@@ -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;
},
});
......
......@@ -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 ) );
......
......@@ -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 {
......
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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment