Commit 324bfbc2 authored by techird's avatar techird

[Issue #39] 修复草稿箱和社会化文件名不同步的问题

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