Commit 378f9bf1 authored by techird's avatar techird

UI整理

parent 044ec7b0
$( function () { $( function () {
var $panel = $( '#social' ); var $panel = $( '#social' );
var $login_btn, $save_btn, $share_btn, $user_btn; var $login_btn, $save_btn, $share_btn, $user_btn, $user_menu;
var baseUrl = ( function () { var baseUrl = ( function () {
var scripts = document.getElementsByTagName( 'script' ); var scripts = document.getElementsByTagName( 'script' );
...@@ -12,15 +12,11 @@ $( function () { ...@@ -12,15 +12,11 @@ $( function () {
} }
} )(); } )();
$login_btn = $.kmuibutton( { $login_btn = $( '<button>登录</button>' ).addClass('login').click( login );
text: '登录'
} ).click( function () { $user_btn = $( '<button></button>' ).addClass('user-file');
if ( !currentUser ) {
login();
}
} ).appendTo( $panel );
var $menu = $.kmuidropmenu( { $user_menu = $.kmuidropmenu( {
data: [ { data: [ {
label: '新建脑图', label: '新建脑图',
value: 'action_newminder' value: 'action_newminder'
...@@ -30,22 +26,9 @@ $( function () { ...@@ -30,22 +26,9 @@ $( function () {
label: '最近脑图', label: '最近脑图',
value: 'action_recent' value: 'action_recent'
} ] } ]
} ).appendTo( 'body' ).kmui().attachTo( $login_btn ); } ).appendTo( 'body' ).kmui().attachTo( $user_btn );
var thisMapFilename; $save_btn = $( '<button>保存</button>' ).click( saveThisFile ).addClass( 'baidu-cloud' );
$save_btn = $( '<button>保存</button>' ).click( function () {
var data = window.km.exportData( 'json' );
save( data, 'apps/kityminder/mymind.km', function ( success, info ) {
if ( success ) {
$save_btn.text( '保存成功!' );
setTimeout( function () {
$save_btn.removeAttr( 'disabled' ).text( '保存' );
}, 3000 );
}
console.log( info );
} );
$save_btn.attr( 'disabled', 'disabled' ).text( '正在保存...' );
} ).addClass( 'baidu-cloud' );
$share_btn = $( '<button>分享</button>' ).click( function () { $share_btn = $( '<button>分享</button>' ).click( function () {
if ( $share_btn.attr( 'disabled' ) ) { if ( $share_btn.attr( 'disabled' ) ) {
...@@ -90,19 +73,23 @@ $( function () { ...@@ -90,19 +73,23 @@ $( function () {
} ).addClass( 'share' ); } ).addClass( 'share' );
baidu.frontia.init( 'wiE55BGOG8BkGnpPs6UNtPbb' ); var AK, thisMapFilename, currentUser;
var currentUser = baidu.frontia.getCurrentAccount();
if ( currentUser ) {
setLogined( currentUser );
}
AK = 'wiE55BGOG8BkGnpPs6UNtPbb';
baidu.frontia.init( AK );
baidu.frontia.social.setLoginCallback( { baidu.frontia.social.setLoginCallback( {
success: setLogined, success: setCurrentUser,
error: function ( error ) { error: function ( error ) {
console.log( error ); console.log( error );
} }
} ); } );
currentUser = baidu.frontia.getCurrentAccount();
if ( currentUser ) {
setCurrentUser( currentUser );
}
function login() { function login() {
var options = { var options = {
response_type: 'token', response_type: 'token',
...@@ -113,11 +100,13 @@ $( function () { ...@@ -113,11 +100,13 @@ $( function () {
baidu.frontia.social.login( options ); baidu.frontia.social.login( options );
} }
function setLogined( user ) { function setCurrentUser( user ) {
currentUser = user; currentUser = user;
$login_btn.text( user.getName() + ' 的文件' ); $user_btn.text( user.getName() + ' 的脑图' );
$user_btn.appendTo( $panel );
$save_btn.appendTo( $panel ); $save_btn.appendTo( $panel );
$share_btn.appendTo( $panel ); $share_btn.appendTo( $panel );
$login_btn.detach();
loadRecent(); loadRecent();
loadAvator(); loadAvator();
window.location.hash = ''; window.location.hash = '';
...@@ -131,7 +120,7 @@ $( function () { ...@@ -131,7 +120,7 @@ $( function () {
'width': 16, 'width': 16,
'height': 16 'height': 16
} ); } );
$img.prependTo( $login_btn ); $img.prependTo( $user_btn );
} }
} ); } );
} }
...@@ -165,6 +154,20 @@ $( function () { ...@@ -165,6 +154,20 @@ $( function () {
} ); } );
} }
function saveThisFile() {
var data = window.km.exportData( 'json' );
save( data, thisMapFilename, function ( success, info ) {
if ( success ) {
$save_btn.text( '保存成功!' );
setTimeout( function () {
$save_btn.removeAttr( 'disabled' ).text( '保存' );
}, 3000 );
}
console.log( info );
} );
$save_btn.attr( 'disabled', 'disabled' ).text( '正在保存...' );
}
function save( file, filename, callback ) { function save( file, filename, callback ) {
var sto = baidu.frontia.personalStorage; var sto = baidu.frontia.personalStorage;
var options = { var options = {
...@@ -208,9 +211,12 @@ $( function () { ...@@ -208,9 +211,12 @@ $( function () {
var shareId = match[ 1 ]; var shareId = match[ 1 ];
var query = new baidu.frontia.storage.Query(); var query = new baidu.frontia.storage.Query();
query.on( 'shareMinder.id' ).equal( shareId ); query.on( 'shareMinder.id' ).equal( shareId );
$share_btn.attr('disabled', 'disabled').text('正在加载分享内容...');
baidu.frontia.storage.findData( query, { baidu.frontia.storage.findData( query, {
success: function ( ret ) { success: function ( ret ) {
window.km.importData( ret.result[ 0 ].obj.shareMinder.data, 'json' ); window.km.importData( ret.result[ 0 ].obj.shareMinder.data, 'json' );
$share_btn.removeAttr('disabled').text('分享');
}, },
error: function ( e ) { error: function ( e ) {
console.log( e ); console.log( e );
......
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