Commit 326e819f authored by techird's avatar techird

merge from dev

parents b810bb61 fa229ae7
......@@ -77,7 +77,7 @@ $( function () {
// 脑图实例
minder = window.km,
// 草稿箱
draftManager = window.draftManager || new window.DraftManager( minder ),
draftManager = window.draftManager || ( window.draftManager = new window.DraftManager( minder ) ),
// 当前是否要检测文档内容是否变化的开关
watchingChanges = true,
......@@ -681,4 +681,10 @@ $( function () {
return "很久之前";
}
window.social = {
setRemotePath: setRemotePath,
watchChanges: function ( value ) {
watchingChanges = value;
}
};
} );
\ No newline at end of file
KityMinder.registerModule( "DropFile", function () {
var social,
draftManager,
importing = false;
function init() {
var container = this.getPaper().getContainer();
container.addEventListener( 'dragover', onDragOver );
......@@ -20,51 +24,58 @@ KityMinder.registerModule( "DropFile", function () {
var files = e.dataTransfer.files;
if ( files ) {
var file = files[0];
var ext = file.type || (/(.)\w+$/).exec(file.name)[0];
var file = files[ 0 ];
var ext = file.type || ( /(.)\w+$/ ).exec( file.name )[ 0 ];
if( (/xmind/g).test(ext) ){ //xmind zip
if ( ( /xmind/g ).test( ext ) ) { //xmind zip
importSync( minder, file, 'xmind' );
}else if( (/mmap/g).test(ext) ){ // mindmanager zip
} else if ( ( /mmap/g ).test( ext ) ) { // mindmanager zip
importSync( minder, file, 'mindmanager' );
}else if( (/mm/g).test(ext) ){ //freemind xml
} else if ( ( /mm/g ).test( ext ) ) { //freemind xml
importAsync( minder, file, 'freemind' );
}else{// txt json
} else { // txt json
importAsync( minder, file );
}
}
}
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 ){
minder.importData( file, protocal );//zip文件的import是同步的
manageDraft( minder );
minder.execCommand( 'camera', minder.getRoot() );
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 ){
function importAsync( minder, file, protocal ) {
var reader = new FileReader();
reader.onload = function ( e ) {
minder.importData( e.target.result, protocal );//纯文本文件的import是同步的
manageDraft( minder );
minder.execCommand( 'camera', minder.getRoot() );
importSync( minder, e.target.result, protocal );
};
reader.readAsText( file );
}
function manageDraft( minder ){
if( !window.draftManager ){
window.draftManager = new window.DraftManager( minder );
}
window.draftManager.create();
function createDraft( minder ) {
draftManager = window.draftManager;
draftManager.create();
}
return {
events: {
ready: init
'ready': init,
'import': afterImport
}
};
} );
\ 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