Commit b72d7ac9 authored by techird's avatar techird

merge

parents 6b25e103 00833f3d
...@@ -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.
<!DOCTYPE html>
<html>
<head>
<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"></script>
<script src="../configure.js"></script>
<script src="../dist/dev.php"></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
utils.extend( KityMinder, function () { utils.extend( KityMinder, function () {
var _kityminderUI = {}, var _kityminderUI = {},
_kityminderToolbarUI ={}, _kityminderToolbarUI = {},
_activeWidget = null, _activeWidget = null,
_widgetData = {}, _widgetData = {},
_widgetCallBack = {}; _widgetCallBack = {};
...@@ -15,9 +15,9 @@ utils.extend( KityMinder, function () { ...@@ -15,9 +15,9 @@ utils.extend( KityMinder, function () {
_kityminderToolbarUI[ name ] = fn; _kityminderToolbarUI[ name ] = fn;
} ) } )
}, },
loadUI:function(km){ loadUI: function ( km ) {
utils.each( _kityminderUI, function ( i, fn ) { utils.each( _kityminderUI, function ( i, fn ) {
fn.call(km) fn.call( km )
} ) } )
}, },
_createUI: function ( id ) { _createUI: function ( id ) {
...@@ -68,7 +68,7 @@ utils.extend( KityMinder, function () { ...@@ -68,7 +68,7 @@ utils.extend( KityMinder, function () {
this._createStatusbar( containers.$statusbar, km ); this._createStatusbar( containers.$statusbar, km );
km.$container = containers.$container; km.$container = containers.$container;
this.loadUI(km); this.loadUI( km );
return km.fire( 'interactchange' ); return km.fire( 'interactchange' );
}, },
registerWidget: function ( name, pro, cb ) { registerWidget: function ( name, pro, cb ) {
......
...@@ -10,7 +10,7 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -10,7 +10,7 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
itemStyles: [], itemStyles: [],
value: [], value: [],
autowidthitem: [], autowidthitem: [],
enabledRecord:false enabledRecord: false
}, },
$combox = null, $combox = null,
comboboxWidget = null; comboboxWidget = null;
...@@ -33,15 +33,17 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -33,15 +33,17 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
comboboxWidget.on( 'comboboxselect', function ( evt, res ) { comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
if ( res.value === "png" ) { if ( res.value === "png" ) {
var svghtml = $( "#kityminder .kmui-editor-body" ).html(); var svghtml = $( "#kityminder .kmui-editor-body" ).html();
var rootBox = me.getRoot().getRenderContainer().getRenderBox(); var bgImg = $( "#kityminder .kmui-editor-body" ).css( "backgroundImage" ).replace( /"/g, "" ).replace( /url\(|\)$/ig, "" );
var renderBox = me.getRenderContainer().getRenderBox( "top" );
//debugger;
var svg = $( svghtml ).attr( { var svg = $( svghtml ).attr( {
width: rootBox.x + me.getRenderContainer().getWidth() + 20, width: renderBox.x + me.getRenderContainer().getWidth(),
height: rootBox.y + me.getRenderContainer().getHeight() + 20, height: renderBox.y + me.getRenderContainer().getHeight(),
viewBox: null viewBox: null
} ); } );
var div = $( "<div></div>" ).append( svg ); var div = $( "<div></div>" ).append( svg );
svghtml = div.html(); svghtml = div.html();
var canvas = $( '<canvas style="border:2px solid black;" width="' + svg.attr( "width" ) + '" height="' + svg.attr( "height" ) + '"></canvas>' ); var canvas = $( '<canvas width="' + renderBox.width + '" height="' + renderBox.height + '"></canvas>' );
var ctx = canvas[ 0 ].getContext( "2d" ); var ctx = canvas[ 0 ].getContext( "2d" );
var DOMURL = self.URL || self.webkitURL || self; var DOMURL = self.URL || self.webkitURL || self;
var img = new Image(); var img = new Image();
...@@ -50,30 +52,37 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -50,30 +52,37 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
} ); } );
var url = DOMURL.createObjectURL( svg ); var url = DOMURL.createObjectURL( svg );
img.onload = function () { img.onload = function () {
ctx.drawImage( img, 0, 0 ); var bgTexture = document.createElement( 'img' );
DOMURL.revokeObjectURL( url ); bgTexture.src = bgImg;
var type = 'png'; bgTexture.onload = function () {
var imgData = canvas[ 0 ].toDataURL( type ); var bgfill = ctx.createPattern( bgTexture, "repeat" );
var _fixType = function ( type ) { ctx.fillStyle = bgfill;
type = type.toLowerCase().replace( /jpg/i, 'jpeg' ); ctx.fillRect( 0, 0, renderBox.width, renderBox.height );
var r = type.match( /png|jpeg|bmp|gif/ )[ 0 ]; ctx.drawImage( img, -renderBox.x, -renderBox.y );
return 'image/' + r; DOMURL.revokeObjectURL( url );
}; var type = 'png';
imgData = imgData.replace( _fixType( type ), 'image/octet-stream' ); var imgData = canvas[ 0 ].toDataURL( type );
var saveFile = function ( data, filename ) { var _fixType = function ( type ) {
var save_link = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'a' ); type = type.toLowerCase().replace( /jpg/i, 'jpeg' );
save_link.href = data; var r = type.match( /png|jpeg|bmp|gif/ )[ 0 ];
save_link.download = filename; return 'image/' + r;
};
imgData = imgData.replace( _fixType( type ), 'image/octet-stream' );
var saveFile = function ( data, filename ) {
var save_link = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'a' );
save_link.href = data;
save_link.download = filename;
var event = document.createEvent( 'MouseEvents' ); var event = document.createEvent( 'MouseEvents' );
event.initMouseEvent( 'click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null ); event.initMouseEvent( 'click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null );
save_link.dispatchEvent( event ); save_link.dispatchEvent( event );
}; };
// 下载后的问题名 // 下载后的文件名
var filename = 'kityminder_' + ( new Date() ).getTime() + '.' + type; var filename = 'kityminder_' + ( new Date() ).getTime() + '.' + type;
// download // download
saveFile( imgData, filename ); saveFile( imgData, filename );
};
}; };
img.src = url; img.src = url;
return "png"; return "png";
......
/* @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 );
......
...@@ -161,7 +161,7 @@ var DragBox = kity.createClass( "DragBox", { ...@@ -161,7 +161,7 @@ var DragBox = kity.createClass( "DragBox", {
_drawForDragMode: function () { _drawForDragMode: function () {
this._text.setContent( this._dragSources.length + ' items' ); this._text.setContent( this._dragSources.length + ' items' );
this._text.setPosition( this._startPosition.x, this._startPosition.y + 5 ); this._text.setPosition( this._startPosition.x, this._startPosition.y + 5 );
this._minder.getRenderContainer().addShape( this ); this._minder.getPaper().addShape( this );
}, },
_shrink: function () { _shrink: function () {
// 合并所有拖放源图形的矩形即可 // 合并所有拖放源图形的矩形即可
......
kity.Draggable = ( function () { var ViewDragger = kity.createClass( "ViewDragger", {
var Paper = kity.Paper; constructor: function ( minder ) {
this._minder = minder;
var touchable = window.ontouchstart !== undefined; this._enabled = false;
var DRAG_START_EVENT = touchable ? 'touchstart' : 'mousedown', this._offset = {
DRAG_MOVE_EVENT = touchable ? 'touchmove' : 'mousemove', x: 0,
DRAG_END_EVENT = touchable ? 'touchend' : 'mouseup'; y: 0
};
return kity.createClass( { this._bind();
drag: function ( opt ) { },
isEnabled: function () {
if ( this.dragEnabled ) { return this._enabled;
return; },
setEnabled: function ( value ) {
var paper = this._minder.getPaper();
paper.setStyle( 'cursor', value ? 'pointer' : 'default' );
paper.setStyle( 'cursor', value ? '-webkit-grab' : 'default' );
this._enabled = value;
},
_bind: function () {
var dragger = this,
isRootDrag = false,
lastPosition = null,
currentPosition = null;
this._minder.on( 'beforemousedown', function ( e ) {
// 已经被用户打开拖放模式
if ( dragger.isEnabled() ) {
lastPosition = e.getPosition();
e.stopPropagation();
}
// 点击未选中的根节点临时开启
else if ( e.getTargetNode() == this.getRoot() &&
(!this.getRoot().isSelected() || !this.isSingleSelect())) {
lastPosition = e.getPosition();
dragger.setEnabled( true );
isRootDrag = true;
} }
var dragStart = opt && opt.start || this.dragStart, } )
dragMove = opt && opt.move || this.dragMove,
dragEnd = opt && opt.end || this.dragEnd,
dragTarget = opt && opt.target || this.dragTarget || this,
me = this;
this.dragEnabled = true;
this.dragTarget = dragTarget;
function bindEvents( paper ) {
var startPosition, lastPosition, dragging = false;
var dragFn = function ( e ) {
if ( !dragging ) {
paper.off( DRAG_MOVE_EVENT, dragFn );
}
if ( e.originEvent.touches && e.originEvent.touches.length !== 1 ) return;
var currentPosition = e.getPosition();
var movement = {
x: currentPosition.x - startPosition.x,
y: currentPosition.y - startPosition.y
};
var delta = {
x: currentPosition.x - lastPosition.x,
y: currentPosition.y - lastPosition.y
};
var dragInfo = {
position: currentPosition,
movement: movement,
delta: delta
};
lastPosition = currentPosition;
if ( dragMove ) {
dragMove.call( me, dragInfo );
} else if ( me instanceof Paper ) {
// treate paper drag different
var view = me.getViewPort();
view.center.x -= movement.x;
view.center.y -= movement.y;
me.setViewPort( view );
} else {
me.translate( delta.x, delta.y );
}
dragTarget.trigger( 'dragmove', dragInfo );
e.stopPropagation();
e.preventDefault();
};
dragTarget.on( DRAG_START_EVENT, dragTarget._dragStartHandler = function ( e ) {
if ( e.originEvent.button ) {
return;
}
dragging = true;
var dragInfo = {
position: lastPosition = startPosition = e.getPosition()
};
if ( dragStart ) {
var cancel = dragStart.call( me, dragInfo ) === false;
if ( cancel ) {
return;
}
}
paper.on( DRAG_MOVE_EVENT, dragFn );
dragTarget.trigger( 'dragstart', dragInfo );
e.stopPropagation();
e.preventDefault();
} );
paper.on( DRAG_END_EVENT, dragTarget._dragEndHandler = function ( e ) { .on( 'beforemousemove', function ( e ) {
if ( dragging ) { if ( lastPosition ) {
dragging = false; currentPosition = e.getPosition();
if ( dragEnd ) {
dragEnd.call( me );
}
paper.off( DRAG_MOVE_EVENT, dragFn ); // 当前偏移加上历史偏移
dragTarget.trigger( 'dragend' ); var offset = kity.Vector.fromPoints( lastPosition, currentPosition );
if ( e ) { this.getRenderContainer().translate( offset.x, offset.y );
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); lastPosition = currentPosition;
}
}
} );
} }
} )
if ( me instanceof Paper ) { .on( 'mouseup', function ( e ) {
bindEvents( me ); lastPosition = null;
} else if ( me.getPaper() ) {
bindEvents( me.getPaper() );
} else {
var listener = function ( e ) {
if ( e.targetShape.getPaper() ) {
bindEvents( e.targetShape.getPaper() );
me.off( 'add', listener );
me.off( 'treeadd', listener );
}
};
me.on( 'add treeadd', listener );
}
return this;
}, // end of drag
// 临时拖动需要还原状态
undrag: function () { if ( isRootDrag ) {
var target = this.dragTarget; dragger.setEnabled( false );
target.off( DRAG_START_EVENT, target._dragStartHandler ); isRootDrag = false;
target._dragEndHandler(); }
target.getPaper().off( DRAG_END_EVENT, target._dragEndHandler ); } );
delete target._dragStartHandler; }
delete target._dragEndHandler; } );
this.dragEnabled = false;
return this;
}
} );
} )();
KityMinder.registerModule( 'Hand', function () { KityMinder.registerModule( 'Hand', function () {
var ToggleHandCommand = kity.createClass( "ToggleHandCommand", { var ToggleHandCommand = kity.createClass( "ToggleHandCommand", {
base: Command, base: Command,
execute: function ( minder ) { execute: function ( minder ) {
var drag = minder._onDragMode = !minder._onDragMode; minder._viewDragger.setEnabled( !minder._viewDragger.isEnabled() );
minder.getPaper().setStyle( 'cursor', drag ? 'pointer' : 'default' );
minder.getPaper().setStyle( 'cursor', drag ? '-webkit-grab' : 'default' );
if ( drag ) {
minder.getPaper().drag();
} else {
minder.getPaper().undrag();
}
}, },
queryState: function ( minder ) { queryState: function ( minder ) {
return minder._onDragMode ? 1 : 0; return minder._viewDragger.isEnabled() ? 1 : 0;
} }
} ); } );
return { return {
init: function () { init: function () {
this._onDragMode = false; this._viewDragger = new ViewDragger( this );
kity.extendClass( kity.Paper, kity.Draggable );
}, },
commands: { commands: {
'hand': ToggleHandCommand 'hand': ToggleHandCommand
...@@ -172,11 +89,6 @@ KityMinder.registerModule( 'Hand', function () { ...@@ -172,11 +89,6 @@ KityMinder.registerModule( 'Hand', function () {
this.execCommand( 'hand' ); this.execCommand( 'hand' );
e.preventDefault(); e.preventDefault();
} }
},
beforemousemove: function ( e ) {
if ( this._onDragMode ) {
e.stopPropagation();
}
} }
} }
}; };
......
...@@ -29,8 +29,9 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -29,8 +29,9 @@ KityMinder.registerModule( "LayoutModule", function () {
}, },
initStyle: function () { initStyle: function () {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
var lastTransform = this._rc.getTransform();
this._rc.remove(); this._rc.remove();
this._rc = new kity.Group(); this._rc = new kity.Group().setTransform( lastTransform );
this._paper.addShape( this._rc ); this._paper.addShape( this._rc );
var _root = this.getRoot(); var _root = this.getRoot();
......
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