Commit 4cf00f52 authored by Akikonata's avatar Akikonata

added layoutstyle init

parent 7bb40a8f
......@@ -11,15 +11,17 @@
</style>
</head>
<body style="background:#262626; margin:0; padding:0">
<div id="kityminder" style="height:1000px;width:100%"></div>
<div id="kityminder" style="height:1000px;width:100%">
</div>
</body>
<script>
minder = KM.createMinder(kityminder);
minder.execCommand("switchlayout","default");
minder.execCommand("appendchildnode",new MinderNode());
minder.execCommand("appendsiblingnode",new MinderNode());
minder.execCommand("appendchildnode",new MinderNode());
minder.execCommand("appendsiblingnode",new MinderNode());
minder.execCommand("appendsiblingnode",new MinderNode());
// minder.execCommand("appendchildnode",new MinderNode('dsf'));
// minder.execCommand("appendsiblingnode",new MinderNode('sdf'));
// minder.execCommand("appendchildnode",new MinderNode('sdf'));
// minder.execCommand("appendsiblingnode",new MinderNode('df'));
// minder.execCommand("appendsiblingnode",new MinderNode('sdfsdf'));
</script>
</html>
\ No newline at end of file
......@@ -9,7 +9,9 @@
* @description KityMinder 使用类
*/
var MinderDefaultOptions = {};
var MinderDefaultOptions = {
"layoutstyle": "default"
};
var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
constructor: function ( options ) {
......@@ -20,8 +22,11 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._initMinder();
this._initSelection();
this._initModules();
this.fire( 'ready' );
},
getOptions: function ( key ) {
return this._options[ key ];
},
_initMinder: function () {
this._rc = new kity.Group();
......
......@@ -391,12 +391,15 @@ KityMinder.registerModule( "LayoutDefault", function () {
leftList.push( children[ i ] );
children[ i ].setData( "appendside", "left" );
}
children[ i ].getRenderContainer().clear();
children.setData( "shape", null );
drawNode( children[ i ] );
updateArrangement( children[ i ] );
}
}
},
appendChildNode: function ( parent, node, index ) {
var minder = this;
var appendside = parent.getData( "appendside" );
if ( parent === root ) {
var leftList = parent.getData( "leftList" );
......@@ -417,7 +420,10 @@ KityMinder.registerModule( "LayoutDefault", function () {
} else {
node.setData( "align", "left" );
}
if ( parent.getChildren().indexOf( node ) === -1 ) parent.appendChild( node, index );
if ( parent.getChildren().indexOf( node ) === -1 ) {
parent.appendChild( node, index );
minder.handelNodeInsert( node );
}
drawNode( node );
updateArrangement( node, "append" );
},
......
KityMinder.registerModule( "LayoutModule", function () {
var switchLayout = function ( km, style ) {
var _style = km.getLayoutStyle( style );
if ( !_style ) return false;
km.renderNode = _style.renderNode;
km.initStyle = _style.initStyle;
km.appendChildNode = _style.appendChildNode;
km.appendSiblingNode = _style.appendSiblingNode;
km.removeNode = _style.removeNode;
//清空节点上附加的数据
var _root = km.getRoot();
_root.preTraverse( function ( node ) {
node.clearData();
node.getRenderContainer().clear();
} );
km.initStyle();
return style;
};
var SwitchLayoutCommand = kity.createClass( "SwitchLayoutCommand", ( function () {
return {
base: Command,
execute: function ( km, style ) {
var _style = km.getLayoutStyle( style );
if ( !_style ) return false;
km.renderNode = _style.renderNode;
km.initStyle = _style.initStyle;
km.appendChildNode = _style.appendChildNode;
km.appendSiblingNode = _style.appendSiblingNode;
km.removeNode = _style.removeNode;
//清空节点上附加的数据
var _root = km.getRoot();
_root.preTraverse( function ( node ) {
node.clearData();
node.getRenderContainer().clear();
} );
km.initStyle();
return style;
}
execute: switchLayout
};
} )() );
var AppendChildNodeCommand = kity.createClass( "AppendChildNodeCommand", ( function () {
......@@ -59,6 +61,12 @@ KityMinder.registerModule( "LayoutModule", function () {
"appendsiblingnode": AppendSiblingNodeCommand,
"removenode": RemoveNodeCommand,
"switchlayout": SwitchLayoutCommand
},
"events": {
"ready": function () {
alert( "ready" );
switchLayout( this, this.getOptions( 'layoutstyle' ) );
}
}
};
} );
\ No newline at end of file
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