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 @@
"MinderEvent",
"Command",
"KITYMINDER_CONFIG",
"keymap",
"Utils",
"utils"
]
......
window.KITYMINDER_CONFIG = {
//定义工具栏
toolbars:[
'undo redo | bold italic | forecolor | layoutstyle | fontfamily fontsize'
'undo redo | bold italic | forecolor | layoutstyle | fontfamily fontsize | saveto'
]
//设置主题
......
......@@ -3,7 +3,7 @@
<html>
<head>
<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="../dist/dev.php"></script>
<script src="../lang/zh-cn/zh-cn.js" charset="utf-8"></script>
......
......@@ -48,9 +48,11 @@ $dependency = Array(
,'src/ui/tab.js'
,'src/ui/separator.js'
,'src/ui/scale.js'
,'src/adapter/utils.js'
,'src/adapter/adapter.js'
,'src/adapter/button.js'
,'src/adapter/combobox.js'
,'src/adapter/saveto.js'
,'src/protocal/plain.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'] = {
'undo':'撤销', 'redo':'重做',
'bold':'加粗', 'italic':'斜体',
'forecolor':'字体颜色', 'fontfamily':'字体', 'fontsize':'字号',
'layoutstyle':'选择主题'
'layoutstyle':'选择主题',
'saveto':'另存为...'
},
'popupcolor':{
......@@ -11,4 +12,5 @@ KityMinder.LANG['zh-cn'] = {
'standardColor':'标准颜色',
'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
......@@ -62,41 +62,7 @@ KM.registerUI('layoutstyle fontfamily fontsize', function( name ) {
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 ) {
......@@ -106,7 +72,7 @@ KM.registerUI('layoutstyle fontfamily fontsize', function( name ) {
utils.each(options.items,function(k,v){
options.value.push(k);
tempItems.push(k);
options.autowidthitem.push( wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
options.autowidthitem.push($.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
});
options.items = tempItems;
......@@ -127,7 +93,7 @@ KM.registerUI('layoutstyle fontfamily fontsize', function( name ) {
tempItems.push( temp.split(/\s*,\s*/)[0] );
options.itemStyles.push('font-family: ' + 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, {
},
getSupportedProtocals: function () {
return Utils.keys( KityMinder._protocals );
},
getAllRegisteredProtocals:function(){
return KityMinder._protocals
}
} );
......
......@@ -253,8 +253,8 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
}
for ( var i = 0, ci;
( ci = this.children[ i++ ] ); ) {
if ( ci.equals( node ) === false ) {
( ci = this.children[ i ] );i++ ) {
if ( ci.equals( node.children[i] ) === false ) {
return false;
}
}
......
......@@ -114,6 +114,7 @@ Minder.Receiver = kity.createClass('Receiver',{
},
updateCursor : function(){
this.cursor.setShowHold();
this.km.getRenderContainer().bringFront(this.cursor);
if(this.index == this.textData.length){
this.cursor.setPosition({
......
......@@ -101,7 +101,7 @@ KityMinder.registerModule( "HistoryModule", function () {
},
queryState: function ( km ) {
km.historyManager.hasUndo ? 0 : -1;
return km.historyManager.hasUndo ? 0 : -1;
},
isNeedUndo: function () {
......
......@@ -47,7 +47,7 @@ KityMinder.registerModule( "KeyboardModule", function () {
}
function KBNavigate( km, direction ) {
function navigateTo( km, direction ) {
var nextNode = km.getSelectedNode()._nearestNodes[ direction ];
if ( nextNode ) {
km.select( nextNode );
......@@ -60,33 +60,36 @@ KityMinder.registerModule( "KeyboardModule", function () {
buildPositionNetwork( this.getRoot() );
},
keydown: function ( e ) {
var keys = KityMinder.keymap;
switch ( e.originEvent.keyCode ) {
case keymap.Enter:
case keys.Enter:
this.execCommand( 'appendSiblingNode', new MinderNode( 'Topic' ) );
e.preventDefault();
break;
case keymap.Tab:
case keys.Tab:
this.execCommand( 'appendChildNode', new MinderNode( 'Topic' ) );
e.preventDefault();
break;
case keymap.Backspace:
case keymap.Del:
case keys.Backspace:
case keys.Del:
this.execCommand( 'removenode' );
e.preventDefault();
break;
case keymap.Left:
case keymap.up:
case keymap.Right:
case keymap.Down:
if ( this.isSingleSelect() ) {
KBNavigate( this, {
37: 'left',
38: 'top',
39: 'right',
40: 'down'
}[ e.originEvent.keyCode ] );
}
case keys.Left:
navigateTo( this, 'left' );
e.preventDefault();
break;
case keys.Up:
navigateTo( this, 'top' );
e.preventDefault();
break;
case keys.Right:
navigateTo( this, 'right' );
e.preventDefault();
break;
case keys.Down:
navigateTo( this, 'down' );
e.preventDefault();
break;
}
......
......@@ -25,7 +25,6 @@ KityMinder.registerModule( "LayoutModule", function () {
},
initStyle: function () {
var curStyle = this.getCurrentStyle();
//this.getRenderContainer().clear();
this._rc.remove();
this._rc = new kity.Group();
this._paper.addShape( this._rc );
......
......@@ -77,6 +77,10 @@
this.initItemActive();
},
setLabelWithDefaultValue : function(){
var $btn = this.data('button');
$btn.kmui().label($btn.data('original-title'))
},
/**
* 初始化选择项
*/
......@@ -97,7 +101,7 @@
}).select( index );
me.hide();
me.trigger('aftercomboboxselect');
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