Commit 84a209de authored by campaign's avatar campaign

Merge branch 'gh-pages' of https://github.com/kitygraph/kityminder into gh-pages

parents d21984aa d118c1a4
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<script src="jquery-2.1.0.min.js"></script> <script src="../dist/jquery-2.1.0.min.js"></script>
<script src="../kity/dist/kitygraph.all.js"></script> <script src="../kity/dist/kitygraph.all.js"></script>
<script src="../configure.js"></script> <script src="../configure.js"></script>
<script src="../dist/dev.js"></script> <script src="../dist/dev.js"></script>
......
<!DOCTYPE html>
<html>
<head>
<script src="../kity/dist/kitygraph.all.js"></script>
<script src="../dist/dev.php"></script>
</head>
<body>
</body>
<script>
KityMinder.registerModule("Test", function() {
var AppendCommand = kity.createClass({
base: Command,
execute: function( km, str ) {
km.text = km.text + str;
this.appendLength = str.length;
},
revert: function( km ) {
km.text = km.text.substr(0, km.text.length - this.appendLength);
}
});
var DeleteCommand = kity.createClass({
base: Command,
execute: function( km, count ) {
this.deleted = km.text.substr(km.text.length - count);
km.text = km.text.substr(0, km.text.length - count);
},
revert: function(km) {
km.text += this.deleted;
}
});
var BatchCommand = kity.createClass({
base: Command,
execute: function( km ) {
var combines = Array.prototype.slice.call(arguments, 1);
var cmd;
while(combines.length) {
cmd = combines.shift().split(':');
switch(cmd[0]) {
case 'a':
km.execCommand('append', cmd[1]);
break;
case 'd':
km.execCommand('delete', cmd[1]);
break;
}
}
}
});
return {
commands: {
'append': AppendCommand,
'delete': DeleteCommand,
'batch': BatchCommand
}
}
});
minder = new KityMinder.Minder(document.body);
minder.text = "";
function run(name) {
minder.execCommand.apply(minder, arguments);
console.log(name,': ', minder.text);
}
run('append', 'techird');
run('append', ' good ');
run('batch', 'a:good ', 'a:studying', 'd:3');
run('undo');
run('redo');
run('undo');
run('redo');
run('delete', 5);
run('undo');
</script>
</html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="jquery-2.1.0.min.js" charset="utf-8"></script>
<script src="baidu-frontia-js-full-1.0.0.js" charset="utf-8"></script>
<script src="social.js" charset="utf-8"></script>
<script src="../kity/dist/kitygraph.all.js" charset="utf-8"></script>
<script src="../configure.js" charset="utf-8"></script>
<script src="../dist/dev.js" charset="utf-8"></script>
<script src="../lang/zh-cn/zh-cn.js" charset="utf-8"></script>
<link href="../themes/default/css/import.css" type="text/css" rel="stylesheet">
<style>
.km_receiver{
width:0;
height:0;
}
.km-minderNode{
cursor:default;
}
.kmui-container {
height: 100%;
}
html, body, div {
margin: 0;
padding: 0;
}
#social {
position: absolute;
right: 10px;
top: 10px;
line-height: 20px;
text-align: right;
overflow: hidden;
}
#social button {
outline: none;
display: inline-block;
bottom: 20px;
right: 30px;
background: #0099f2;
padding: 0 15px;
height: 35px;
font-size: 13px;
line-height: 35px;
text-align: center;
border-radius: 5px;
color: #ffffff;
text-decoration: none;
border: none;
margin-left: 5px;
cursor: pointer;
}
#social button:hover {
background: #009fff;
}
#social button[disabled] {
background-color: #AAA;
}
</style>
</head>
<body >
<div id="kityminder" style="height:100%;width:100%" onselectstart="return false">
</div>
<div id="social"></div>
</body>
<script>
window.km = KM.getKityMinder('kityminder');
</script>
</html>
\ No newline at end of file
$( function () {
var $panel = $( '#social' );
var $login_btn, $save_btn, $share_btn;
var baseUrl = ( function () {
var scripts = document.getElementsByTagName( 'script' );
for ( var i = 0; i < scripts.length; i++ ) {
var index = scripts[ i ].src.indexOf( 'social.js' );
if ( ~index ) {
return scripts[ i ].src.substr( 0, index );
}
}
} )();
$login_btn = $( '<button>登录</button>' ).click( function () {
if ( currentUser === null ) {
login();
} else {
baidu.frontia.logOutCurrentAccount();
currentUser = null;
//$save_btn.detach();
$share_btn.detach();
$login_btn.text( '登录' );
}
} ).appendTo( $panel );
$save_btn = $( '<button>保存到云盘</button>' ).click( function () {
var data = window.km.exportData( 'json' );
save( data, 'apps/kityminder/mymind.km' );
} );
$share_btn = $( '<button>分享脑图</button>' ).click( function () {
if ( $share_btn.attr( 'disabled' ) ) {
}
var data = window.km.exportData( 'json' );
$share_btn.attr( 'disabled', 'disabled' ).text( '正在分享...' );
var share_id = uuid();
var shareUrl = baseUrl + 'index.html?share_id=' + share_id;
share( data, share_id, function ( success ) {
if ( success ) {
var $popup = $( '<div></div>' ).addClass( 'popup' ).appendTo( 'body' );
$popup.css( {
'position': 'absolute',
'right': 10,
'top': $share_btn.offset().top + $share_btn.height() + 10,
'width': 250,
'padding': 10,
'background': 'white',
'border-radius': '5px',
'box-shadow': '1px 2px 4px rgba(0, 0, 0, .3)'
} );
$popup.append( '<p style="margin: 5px 0; font-size: 12px;">分享成功,请复制URL:</p>' );
var $input = $( '<input type="text" style="width: 250px;" value="' + shareUrl + '"></input>' ).appendTo( $popup );
$input[0].select();
$popup.mousedown( function ( e ) {
e.stopPropagation();
} );
$( 'body' ).on( 'mousedown', function ( e ) {
$popup.fadeOut( 'fast', function () {
$popup.remove();
} );
$share_btn.removeAttr( 'disabled' ).text( '分享脑图' );
$( 'body' ).off( 'mousedown', arguments.callee );
} );
}
} );
} );
baidu.frontia.init( 'wiE55BGOG8BkGnpPs6UNtPbb' );
var currentUser = baidu.frontia.getCurrentAccount();
if ( currentUser ) {
setLogined( currentUser );
}
baidu.frontia.social.setLoginCallback( {
success: setLogined,
error: function ( error ) {
console.log( error );
}
} );
function login() {
var options = {
response_type: 'token',
media_type: 'baidu',
redirect_uri: baseUrl + 'index.html',
client_type: 'web'
};
baidu.frontia.social.login( options );
}
function setLogined( user ) {
currentUser = user;
$login_btn.text( '注销 ' + user.getName() );
//$save_btn.appendTo( $panel );
$share_btn.appendTo( $panel );
}
function save( file, filename ) {
var personlStorage = baidu.frontia.personalStorage;
var options = {
ondup: personlStorage.constant.ONDUP_OVERWRITE,
success: function ( result ) {
console.log( result );
},
error: function ( error ) {
console.log( error );
}
};
personlStorage.uploadTextFile( file, filename, options );
}
function uuid() {
return ( ( +new Date() * 10000 ) + ( Math.random() * 9999 ) ).toString( 36 );
}
function share( text, shareId, callback ) {
var data = new baidu.frontia.Data( {
shareMinder: {
id: shareId,
data: text
}
} );
var handles = {
success: function ( result ) {
callback( true );
},
error: function ( e ) {
callback( false );
}
};
baidu.frontia.storage.insertData( data, handles );
}
function loadShare() {
var pattern = /share_id=(\w+)([&#]|$)/;
var match = pattern.exec( window.location.href );
if ( !match ) return;
var shareId = match[ 1 ];
var query = new baidu.frontia.storage.Query();
query.on( 'shareMinder.id' ).equal( shareId );
baidu.frontia.storage.findData( query, {
success: function ( ret ) {
window.km.importData( ret.result[ 0 ].obj.shareMinder.data, 'json' );
},
error: function ( e ) {
console.log( e );
}
} );
}
loadShare();
} );
\ No newline at end of file
/* @require <kityminder.js>
* @require <module.js>
* @require <event.js>
* @require <node.js>
* @reuqire <command.js>
* @require <utils.js>
*
* @description KityMinder 使用类
*/
var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
constructor: function ( options ) { constructor: function ( options ) {
this._options = Utils.extend( window.KITYMINDER_CONFIG || {}, options ); this._options = Utils.extend( window.KITYMINDER_CONFIG || {}, options );
......
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