Commit edb81a8e authored by Akikonata's avatar Akikonata

Merge branch 'dev' of https://github.com/kitygraph/kityminder into dev

parents a9af083d 68fb69e2
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
"MinderEvent", "MinderEvent",
"Command", "Command",
"KITYMINDER_CONFIG", "KITYMINDER_CONFIG",
"keymap",
"Utils", "Utils",
"utils" "utils"
] ]
......
window.KITYMINDER_CONFIG = { window.KITYMINDER_CONFIG = {
//定义工具栏 //定义工具栏
toolbars:[ toolbars:[
'undo redo | bold italic | forecolor | layoutstyle | fontfamily fontsize' 'undo redo | bold italic | forecolor | layoutstyle | fontfamily fontsize | saveto'
] ]
//设置主题 //设置主题
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<html> <html>
<head> <head>
<script src="jquery-2.1.0.min.js"></script> <script src="jquery-2.1.0.min.js"></script>
<script src="kity.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.php"></script> <script src="../dist/dev.php"></script>
<script src="../lang/zh-cn/zh-cn.js" charset="utf-8"></script> <script src="../lang/zh-cn/zh-cn.js" charset="utf-8"></script>
......
...@@ -48,9 +48,11 @@ $dependency = Array( ...@@ -48,9 +48,11 @@ $dependency = Array(
,'src/ui/tab.js' ,'src/ui/tab.js'
,'src/ui/separator.js' ,'src/ui/separator.js'
,'src/ui/scale.js' ,'src/ui/scale.js'
,'src/adapter/utils.js'
,'src/adapter/adapter.js' ,'src/adapter/adapter.js'
,'src/adapter/button.js' ,'src/adapter/button.js'
,'src/adapter/combobox.js' ,'src/adapter/combobox.js'
,'src/adapter/saveto.js'
,'src/protocal/plain.js' ,'src/protocal/plain.js'
,'src/protocal/json.js' ,'src/protocal/json.js'
); );
......
<!DOCTYPE html>
<html>
<head>
<script src="../kity/dist/kitygraph.all.js"></script>
<script src="../dist/dev.php"></script>
</head>
<body style="background:#262626; margin:0; padding:0">
</body>
<script>
minder = new KM.createMinder( document.body );
minder.importData({
data: {
x: 50,
y: 50,
text: 'center',
},
children: [{
data: {
x: 200,
y: 50,
text: 'child1'
}
},{
data: {
x: 200,
y: 100,
text: 'child2'
},
children: [{
data: {
x: 350,
y: 100,
text: 'leaf'
}
}]
}]
});
var minderWidth = document.body.clientWidth;
var minderHeight = document.body.clientHeight;
var _node = minder.getRoot();
_node.data = {
centerX:minderWidth/2,
centerY:minderHeight/2,
style:{
radius:10,
fill:"orange",
stroke:"orange",
color:"black",
padding:[10,10,10,10],
fontSize:20
},
text:"I am the root",
};
minder.select(_node);
// var _childnode = new MinderNode();
// _node.insertChild(_childnode);
// _childnode.data = {
// centerX:minderWidth/2+150,
// centerY:minderHeight/2+100,
// style:{
// radius:10,
// fill:"yellow",
// stroke:"orange",
// strokeWidth:2,
// color:"black",
// padding:[10,10,10,10],
// fontSize:12
// },
// text:"childnode1",
// };
// var _childnode2 = new MinderNode();
// _node.insertChild(_childnode2);
// _childnode2.data = {
// centerX:minderWidth/2+250,
// centerY:minderHeight/2+10,
// style:{
// radius:10,
// fill:"yellow",
// stroke:"orange",
// color:"black",
// padding:[10,10,10,10],
// fontSize:12
// },
// text:"childnode2",
// };
minder.execCommand("rendernode",_node);
// minder.execCommand("rendernode",_childnode);
// minder.execCommand("rendernode",_childnode2);
</script>
</html>
\ No newline at end of file
Subproject commit 1bfcdd712725d25d54bfe88d0ee0fac6ee33830a Subproject commit 1c5434e295dae9cad0f39248c9071ed99227cb33
...@@ -3,7 +3,8 @@ KityMinder.LANG['zh-cn'] = { ...@@ -3,7 +3,8 @@ KityMinder.LANG['zh-cn'] = {
'undo':'撤销', 'redo':'重做', 'undo':'撤销', 'redo':'重做',
'bold':'加粗', 'italic':'斜体', 'bold':'加粗', 'italic':'斜体',
'forecolor':'字体颜色', 'fontfamily':'字体', 'fontsize':'字号', 'forecolor':'字体颜色', 'fontfamily':'字体', 'fontsize':'字号',
'layoutstyle':'选择主题' 'layoutstyle':'选择主题',
'saveto':'另存为...'
}, },
'popupcolor':{ 'popupcolor':{
...@@ -11,4 +12,5 @@ KityMinder.LANG['zh-cn'] = { ...@@ -11,4 +12,5 @@ KityMinder.LANG['zh-cn'] = {
'standardColor':'标准颜色', 'standardColor':'标准颜色',
'themeColor':'主题颜色' 'themeColor':'主题颜色'
} }
}; };
\ No newline at end of file
{
"undef" : true,
"unused" : false,
"strict" : false,
"curly" : false,
"newcap" : true,
"trailing" : true,
"white": false,
"quotmark": false,
"predef" : [
"require",
"console",
"kity",
"KityMinder",
"KM",
"Minder",
"MinderNode",
"MinderEvent",
"Command",
"KITYMINDER_CONFIG",
"Utils",
"utils",
"describe",
"it",
"beforeEach",
"expect"
]
}
\ No newline at end of file
describe( "protocal/plain", function () {
var json, local, protocal;
beforeEach( function () {
protocal = KM.findProtocal( 'plain' );
} );
it( '协议存在', function () {
expect( protocal ).toBeDefined();
} );
it( '正确 encode', function () {
json = {
data: {
text: 'root',
anyway: 'omg'
},
children: [ {
data: {
text: 'l1c1'
}
}, {
data: {
text: 'l1c2'
},
children: [ {
data: {
text: 'l2c1'
}
}, {
data: {
text: 'l2c2'
}
} ]
}, {
data: {
text: 'l1c3'
}
} ]
};
local = protocal.encode( json );
expect( local ).toBe(
'root\n' +
'\tl1c1\n' +
'\tl1c2\n' +
'\t\tl2c1\n' +
'\t\tl2c2\n' +
'\tl1c3\n'
);
} );
} );
\ No newline at end of file
...@@ -116,4 +116,4 @@ utils.extend( KityMinder, function () { ...@@ -116,4 +116,4 @@ utils.extend( KityMinder, function () {
_activeWidget = $widget; _activeWidget = $widget;
} }
} }
}() ); }() );
\ No newline at end of file
...@@ -62,41 +62,7 @@ KM.registerUI('layoutstyle fontfamily fontsize', function( name ) { ...@@ -62,41 +62,7 @@ KM.registerUI('layoutstyle fontfamily fontsize', function( name ) {
return comboboxWidget.button().addClass('kmui-combobox'); return comboboxWidget.button().addClass('kmui-combobox');
/**
* 宽度自适应工具函数
* @param word 单词内容
* @param hasSuffix 是否含有后缀
*/
function wordCountAdaptive ( word, hasSuffix ) {
var $tmpNode = $('<span>' ).html( word ).css( {
display: 'inline',
position: 'absolute',
top: -10000000,
left: -100000
} ).appendTo( document.body),
width = $tmpNode.width();
$tmpNode.remove();
$tmpNode = null;
if( width < 50 ) {
return word;
} else {
word = word.slice( 0, hasSuffix ? -4 : -1 );
if( !word.length ) {
return '...';
}
return wordCountAdaptive( word + '...', true );
}
}
function transForLayoutstyle ( options ) { function transForLayoutstyle ( options ) {
...@@ -106,7 +72,7 @@ KM.registerUI('layoutstyle fontfamily fontsize', function( name ) { ...@@ -106,7 +72,7 @@ KM.registerUI('layoutstyle fontfamily fontsize', function( name ) {
utils.each(options.items,function(k,v){ utils.each(options.items,function(k,v){
options.value.push(k); options.value.push(k);
tempItems.push(k); tempItems.push(k);
options.autowidthitem.push( wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) ); options.autowidthitem.push($.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
}); });
options.items = tempItems; options.items = tempItems;
...@@ -127,7 +93,7 @@ KM.registerUI('layoutstyle fontfamily fontsize', function( name ) { ...@@ -127,7 +93,7 @@ KM.registerUI('layoutstyle fontfamily fontsize', function( name ) {
tempItems.push( temp.split(/\s*,\s*/)[0] ); tempItems.push( temp.split(/\s*,\s*/)[0] );
options.itemStyles.push('font-family: ' + temp); options.itemStyles.push('font-family: ' + temp);
options.value.push( temp ); options.value.push( temp );
options.autowidthitem.push( wordCountAdaptive( tempItems[ i ] ) ); options.autowidthitem.push( $.wordCountAdaptive( tempItems[ i ] ) );
} }
......
KM.registerUI('saveto', function( name ) {
var me = this,
label = me.getLang('tooltips.' + name),
options = {
label: label,
title: label,
comboboxName: name,
items: [],
itemStyles: [],
value: [],
autowidthitem: []
},
$combox = null,
comboboxWidget = null;
utils.each(KityMinder.getAllRegisteredProtocals(),function(k){
options.value.push(k);
options.items.push(k);
options.autowidthitem.push($.wordCountAdaptive( k ) );
});
//实例化
$combox = $.kmuibuttoncombobox(options).css('zIndex',me.getOptions('zIndex') + 1);
comboboxWidget = $combox.kmui();
comboboxWidget.on('comboboxselect', function( evt, res ){
alert(me.exportData(res.value));
}).on("beforeshow", function(){
if( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find('.kmui-dialog-container') );
}
}).on('aftercomboboxselect',function(){
this.setLabelWithDefaultValue()
});
return comboboxWidget.button().addClass('kmui-combobox');
});
/**
* 宽度自适应工具函数
* @param word 单词内容
* @param hasSuffix 是否含有后缀
*/
$.wordCountAdaptive = function( word, hasSuffix ) {
var $tmpNode = $('<span>' ).html( word ).css( {
display: 'inline',
position: 'absolute',
top: -10000000,
left: -100000
} ).appendTo( document.body),
width = $tmpNode.width();
$tmpNode.remove();
$tmpNode = null;
if( width < 50 ) {
return word;
} else {
word = word.slice( 0, hasSuffix ? -4 : -1 );
if( !word.length ) {
return '...';
}
return $.wordCountAdaptive( word + '...', true );
}
};
\ No newline at end of file
...@@ -8,6 +8,9 @@ Utils.extend( KityMinder, { ...@@ -8,6 +8,9 @@ Utils.extend( KityMinder, {
}, },
getSupportedProtocals: function () { getSupportedProtocals: function () {
return Utils.keys( KityMinder._protocals ); return Utils.keys( KityMinder._protocals );
},
getAllRegisteredProtocals:function(){
return KityMinder._protocals
} }
} ); } );
......
...@@ -253,8 +253,8 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { ...@@ -253,8 +253,8 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
} }
for ( var i = 0, ci; for ( var i = 0, ci;
( ci = this.children[ i++ ] ); ) { ( ci = this.children[ i ] );i++ ) {
if ( ci.equals( node ) === false ) { if ( ci.equals( node.children[i] ) === false ) {
return false; return false;
} }
} }
......
...@@ -114,6 +114,7 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -114,6 +114,7 @@ Minder.Receiver = kity.createClass('Receiver',{
}, },
updateCursor : function(){ updateCursor : function(){
this.cursor.setShowHold(); this.cursor.setShowHold();
this.km.getRenderContainer().bringFront(this.cursor);
if(this.index == this.textData.length){ if(this.index == this.textData.length){
this.cursor.setPosition({ this.cursor.setPosition({
......
...@@ -101,7 +101,7 @@ KityMinder.registerModule( "HistoryModule", function () { ...@@ -101,7 +101,7 @@ KityMinder.registerModule( "HistoryModule", function () {
}, },
queryState: function ( km ) { queryState: function ( km ) {
km.historyManager.hasUndo ? 0 : -1; return km.historyManager.hasUndo ? 0 : -1;
}, },
isNeedUndo: function () { isNeedUndo: function () {
......
...@@ -47,7 +47,7 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -47,7 +47,7 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
function KBNavigate( km, direction ) { function navigateTo( km, direction ) {
var nextNode = km.getSelectedNode()._nearestNodes[ direction ]; var nextNode = km.getSelectedNode()._nearestNodes[ direction ];
if ( nextNode ) { if ( nextNode ) {
km.select( nextNode ); km.select( nextNode );
...@@ -60,33 +60,36 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -60,33 +60,36 @@ KityMinder.registerModule( "KeyboardModule", function () {
buildPositionNetwork( this.getRoot() ); buildPositionNetwork( this.getRoot() );
}, },
keydown: function ( e ) { keydown: function ( e ) {
var keys = KityMinder.keymap;
switch ( e.originEvent.keyCode ) { switch ( e.originEvent.keyCode ) {
case keymap.Enter: case keys.Enter:
this.execCommand( 'appendSiblingNode', new MinderNode( 'Topic' ) ); this.execCommand( 'appendSiblingNode', new MinderNode( 'Topic' ) );
e.preventDefault(); e.preventDefault();
break; break;
case keymap.Tab: case keys.Tab:
this.execCommand( 'appendChildNode', new MinderNode( 'Topic' ) ); this.execCommand( 'appendChildNode', new MinderNode( 'Topic' ) );
e.preventDefault(); e.preventDefault();
break; break;
case keymap.Backspace: case keys.Backspace:
case keymap.Del: case keys.Del:
this.execCommand( 'removenode' ); this.execCommand( 'removenode' );
e.preventDefault(); e.preventDefault();
break; break;
case keymap.Left: case keys.Left:
case keymap.up: navigateTo( this, 'left' );
case keymap.Right: e.preventDefault();
case keymap.Down: break;
if ( this.isSingleSelect() ) { case keys.Up:
KBNavigate( this, { navigateTo( this, 'top' );
37: 'left', e.preventDefault();
38: 'top', break;
39: 'right', case keys.Right:
40: 'down' navigateTo( this, 'right' );
}[ e.originEvent.keyCode ] ); e.preventDefault();
} break;
case keys.Down:
navigateTo( this, 'down' );
e.preventDefault(); e.preventDefault();
break; break;
} }
......
...@@ -25,7 +25,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -25,7 +25,6 @@ KityMinder.registerModule( "LayoutModule", function () {
}, },
initStyle: function () { initStyle: function () {
var curStyle = this.getCurrentStyle(); var curStyle = this.getCurrentStyle();
//this.getRenderContainer().clear();
this._rc.remove(); this._rc.remove();
this._rc = new kity.Group(); this._rc = new kity.Group();
this._paper.addShape( this._rc ); this._paper.addShape( this._rc );
......
...@@ -77,6 +77,10 @@ ...@@ -77,6 +77,10 @@
this.initItemActive(); this.initItemActive();
}, },
setLabelWithDefaultValue : function(){
var $btn = this.data('button');
$btn.kmui().label($btn.data('original-title'))
},
/** /**
* 初始化选择项 * 初始化选择项
*/ */
...@@ -97,7 +101,7 @@ ...@@ -97,7 +101,7 @@
}).select( index ); }).select( index );
me.hide(); me.hide();
me.trigger('aftercomboboxselect');
return false; return false;
}); });
......
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