Commit 31c1dcc5 authored by Ronny's avatar Ronny

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

parents 9a8960b7 f1207cb1
/*! /*!
* ==================================================== * ====================================================
* kityminder - v1.0.0 - 2014-03-28 * kityminder - v1.0.0 - 2014-04-08
* https://github.com/fex-team/kityminder * https://github.com/fex-team/kityminder
* GitHub: https://github.com/fex-team/kityminder.git * GitHub: https://github.com/fex-team/kityminder.git
* Copyright (c) 2014 f-cube @ FEX; Licensed MIT * Copyright (c) 2014 f-cube @ FEX; Licensed MIT
...@@ -1947,13 +1947,13 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1947,13 +1947,13 @@ KityMinder.registerModule( "LayoutModule", function () {
} ); } );
this.getLayoutStyle( curStyle ).initStyle.call( this ); this.getLayoutStyle( curStyle ).initStyle.call( this );
}, },
appendChildNode: function ( parent, node, index ) { appendChildNode: function ( parent, node, focus, index ) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).appendChildNode.call( this, parent, node, index ); this.getLayoutStyle( curStyle ).appendChildNode.call( this, parent, node, focus, index );
}, },
appendSiblingNode: function ( sibling, node ) { appendSiblingNode: function ( sibling, node, focus ) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).appendSiblingNode.call( this, sibling, node ); this.getLayoutStyle( curStyle ).appendSiblingNode.call( this, sibling, node, focus );
}, },
removeNode: function ( nodes ) { removeNode: function ( nodes ) {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
...@@ -2011,12 +2011,18 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -2011,12 +2011,18 @@ KityMinder.registerModule( "LayoutModule", function () {
var AppendChildNodeCommand = kity.createClass( "AppendChildNodeCommand", ( function () { var AppendChildNodeCommand = kity.createClass( "AppendChildNodeCommand", ( function () {
return { return {
base: Command, base: Command,
execute: function ( km, node ) { execute: function ( km, node, focus, silbling ) {
var parent = km.getSelectedNode(); var parent = km.getSelectedNode();
if( !parent ){
return null;
}
if ( parent.getType() !== "root" && parent.getChildren().length !== 0 && parent.getData( "expand" ) === false ) { if ( parent.getType() !== "root" && parent.getChildren().length !== 0 && parent.getData( "expand" ) === false ) {
km.expandNode( parent ); km.expandNode( parent );
} }
km.appendChildNode( parent, node );
km.appendChildNode( parent, node, focus, silbling );
km.select( node, true ); km.select( node, true );
return node; return node;
}, },
...@@ -2033,13 +2039,17 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -2033,13 +2039,17 @@ KityMinder.registerModule( "LayoutModule", function () {
var AppendSiblingNodeCommand = kity.createClass( "AppendSiblingNodeCommand", ( function () { var AppendSiblingNodeCommand = kity.createClass( "AppendSiblingNodeCommand", ( function () {
return { return {
base: Command, base: Command,
execute: function ( km, node ) { execute: function ( km, node, focus ) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
if( !selectedNode ){
return null;
}
if ( selectedNode.isRoot() ) { if ( selectedNode.isRoot() ) {
node.setType( "main" ); node.setType( "main" );
km.appendChildNode( selectedNode, node ); km.appendChildNode( selectedNode, node, focus );
} else { } else {
km.appendSiblingNode( selectedNode, node ); km.appendSiblingNode( selectedNode, node, focus );
} }
km.select( node, true ); km.select( node, true );
return node; return node;
...@@ -2059,6 +2069,11 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -2059,6 +2069,11 @@ KityMinder.registerModule( "LayoutModule", function () {
return { return {
base: Command, base: Command,
execute: function ( km ) { execute: function ( km ) {
if( km.getRoot().children.length == 0 ){
return;
}
var selectedNodes = km.getSelectedNodes(); var selectedNodes = km.getSelectedNodes();
var _root = km.getRoot(); var _root = km.getRoot();
var _buffer = []; var _buffer = [];
...@@ -2538,6 +2553,21 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -2538,6 +2553,21 @@ KityMinder.registerModule( "LayoutDefault", function () {
Layout.shicon.update(); Layout.shicon.update();
} }
}; };
var showNodeInView = function( node ){
var padding = 5;
var viewport = minder.getPaper().getViewPort();
var offset = node.getRenderContainer().getRenderBox( minder.getRenderContainer() );
var tmpX = viewport.center.x * 2 - (offset.x + offset.width);
var tmpY = viewport.center.y * 2 - (offset.y + offset.height);
var dx = offset.x < 0 ? -offset.x : Math.min(tmpX, 0);
var dy = offset.y < 0 ? -offset.y : Math.min(tmpY, 0);
km.getRenderContainer().fxTranslate( dx, dy, 100, "easeOutQuint" );
};
var _style = { var _style = {
highlightNode: function ( node ) { highlightNode: function ( node ) {
var highlight = node.isHighlight(); var highlight = node.isHighlight();
...@@ -2630,7 +2660,7 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -2630,7 +2660,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
} }
_root.setPoint( _root.getLayout().x, _root.getLayout().y ); _root.setPoint( _root.getLayout().x, _root.getLayout().y );
}, },
appendChildNode: function ( parent, node, sibling ) { appendChildNode: function ( parent, node, focus, sibling ) {
minder.handelNodeInsert( node ); minder.handelNodeInsert( node );
node.clearLayout(); node.clearLayout();
var Layout = node.getLayout(); var Layout = node.getLayout();
...@@ -2714,10 +2744,14 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -2714,10 +2744,14 @@ KityMinder.registerModule( "LayoutDefault", function () {
translateNode( set[ i ] ); translateNode( set[ i ] );
updateConnectAndshIcon( set[ i ] ); updateConnectAndshIcon( set[ i ] );
} }
if( focus ){
showNodeInView( node );
}
}, },
appendSiblingNode: function ( sibling, node ) { appendSiblingNode: function ( sibling, node, focus ) {
var parent = sibling.getParent(); var parent = sibling.getParent();
this.appendChildNode( parent, node, sibling ); this.appendChildNode( parent, node, focus, sibling );
}, },
removeNode: function ( nodes ) { removeNode: function ( nodes ) {
while ( nodes.length !== 0 ) { while ( nodes.length !== 0 ) {
...@@ -3372,13 +3406,17 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -3372,13 +3406,17 @@ KityMinder.registerModule( "LayoutBottom", function () {
// 选区管理 // 选区管理
kity.extendClass( Minder, function () { kity.extendClass( Minder, function () {
function highlightNode( km, node ) { function highlightNode( km, node ) {
node.setTmpData( "highlight", true ); if( node ){
km.highlightNode( node ); node.setTmpData( "highlight", true );
km.highlightNode( node );
}
} }
function unhighlightNode( km, node ) { function unhighlightNode( km, node ) {
node.setTmpData( "highlight", false ); if( node ){
km.highlightNode( node ); node.setTmpData( "highlight", false );
km.highlightNode( node );
}
} }
return { return {
_initSelection: function () { _initSelection: function () {
...@@ -4031,32 +4069,16 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -4031,32 +4069,16 @@ KityMinder.registerModule( "KeyboardModule", function () {
}; };
} }
function coefForX( a, b ) {
return 0.1 * min( abs( a.top - b.top ), abs( a.bottom - b.bottom ) ) + 1;
}
function coefForY( a, b ) {
return 0.1 * min( abs( a.left - b.left ), abs( a.right - b.right ) ) + 1;
}
function findClosestPointsFor( pointIndexes, iFind ) { function findClosestPointsFor( pointIndexes, iFind ) {
var find = pointIndexes[ iFind ]; var find = pointIndexes[ iFind ];
var most = {}, quad; var most = {}, quad;
var current, dist; var current, dist;
var table = [];
console.log( 'table for ' + find.text );
for ( var i = 0; i < pointIndexes.length; i++ ) { for ( var i = 0; i < pointIndexes.length; i++ ) {
if ( i == iFind ) continue; if ( i == iFind ) continue;
current = pointIndexes[ i ]; current = pointIndexes[ i ];
dist = getCoefedDistance( current, find ); dist = getCoefedDistance( current, find );
table.push( {
text: current.text,
dist: dist.cx
} );
// left check // left check
if ( current.right < find.left ) { if ( current.right < find.left ) {
if ( !most.left || dist.cx < most.left.dist ) { if ( !most.left || dist.cx < most.left.dist ) {
...@@ -4097,7 +4119,6 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -4097,7 +4119,6 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
} }
} }
console.table( table );
find.node._nearestNodes = { find.node._nearestNodes = {
right: most.right && most.right.node || null, right: most.right && most.right.node || null,
top: most.top && most.top.node || null, top: most.top && most.top.node || null,
...@@ -4133,11 +4154,11 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -4133,11 +4154,11 @@ KityMinder.registerModule( "KeyboardModule", function () {
this.receiver.keydownNode = node; this.receiver.keydownNode = node;
switch ( e.originEvent.keyCode ) { switch ( e.originEvent.keyCode ) {
case keys.Enter: case keys.Enter:
this.execCommand( 'appendSiblingNode', new MinderNode( this.getLang().topic ) ); this.execCommand( 'appendSiblingNode', new MinderNode( this.getLang().topic ), true );
e.preventDefault(); e.preventDefault();
break; break;
case keys.Tab: case keys.Tab:
this.execCommand( 'appendChildNode', new MinderNode( this.getLang().topic ) ); this.execCommand( 'appendChildNode', new MinderNode( this.getLang().topic ), true );
e.preventDefault(); e.preventDefault();
break; break;
case keys.Backspace: case keys.Backspace:
...@@ -4456,6 +4477,9 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4456,6 +4477,9 @@ KityMinder.registerModule( "TextEditModule", function () {
if(cmds[e.commandName]){ if(cmds[e.commandName]){
var node = km.getSelectedNode(); var node = km.getSelectedNode();
if( !node ){
return;
}
var textShape = node.getTextShape(); var textShape = node.getTextShape();
...@@ -5069,7 +5093,7 @@ KityMinder.registerModule( "basestylemodule", function () { ...@@ -5069,7 +5093,7 @@ KityMinder.registerModule( "basestylemodule", function () {
return -1; return -1;
} }
utils.each(nodes,function(i,n){ utils.each(nodes,function(i,n){
if(n.getData('bold')){ if( n && n.getData('bold') ){
result = 1; result = 1;
return false; return false;
} }
...@@ -5104,7 +5128,7 @@ KityMinder.registerModule( "basestylemodule", function () { ...@@ -5104,7 +5128,7 @@ KityMinder.registerModule( "basestylemodule", function () {
return -1; return -1;
} }
utils.each(nodes,function(i,n){ utils.each(nodes,function(i,n){
if(n.getData('italic')){ if( n && n.getData('italic') ){
result = 1; result = 1;
return false; return false;
} }
...@@ -7507,7 +7531,7 @@ KM.registerToolbarUI( 'node', function ( name ) { ...@@ -7507,7 +7531,7 @@ KM.registerToolbarUI( 'node', function ( name ) {
comboboxWidget = $combox.kmui(); comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) { comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( res.value, new MinderNode( me.getLang().topic ) ); me.execCommand( res.value, new MinderNode( me.getLang().topic ), true );
} ).on( "beforeshow", function () { } ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) { if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) ); $combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
...@@ -8130,6 +8154,8 @@ KityMinder.registerProtocal( "png", function () { ...@@ -8130,6 +8154,8 @@ KityMinder.registerProtocal( "png", function () {
renderContainer.translate( -renderBox.x, -renderBox.y ); renderContainer.translate( -renderBox.x, -renderBox.y );
svgXml = km.getPaper().container.innerHTML; svgXml = km.getPaper().container.innerHTML;
// svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
svgXml = svgXml.replace(/&nbsp;/g, ' ').replace(/\s+/g, ' ');
renderContainer.translate( renderBox.x, renderBox.y ); renderContainer.translate( renderBox.x, renderBox.y );
...@@ -8199,7 +8225,8 @@ KityMinder.registerProtocal( "svg", function () { ...@@ -8199,7 +8225,8 @@ KityMinder.registerProtocal( "svg", function () {
fileDescription: 'SVG 矢量图', fileDescription: 'SVG 矢量图',
fileExtension: '.svg', fileExtension: '.svg',
encode: function ( json, km ) { encode: function ( json, km ) {
return km.getPaper().container.innerHTML; // svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
return km.getPaper().container.innerHTML.replace( /&nbsp;/g, '&#xa0;' );
}, },
recognizePriority: -1 recognizePriority: -1
}; };
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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