Commit 4cf00f52 authored by Akikonata's avatar Akikonata

added layoutstyle init

parent 7bb40a8f
...@@ -11,15 +11,17 @@ ...@@ -11,15 +11,17 @@
</style> </style>
</head> </head>
<body style="background:#262626; margin:0; padding:0"> <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> </body>
<script> <script>
minder = KM.createMinder(kityminder); minder = KM.createMinder(kityminder);
minder.execCommand("switchlayout","default");
minder.execCommand("appendchildnode",new MinderNode()); // minder.execCommand("appendchildnode",new MinderNode('dsf'));
minder.execCommand("appendsiblingnode",new MinderNode()); // minder.execCommand("appendsiblingnode",new MinderNode('sdf'));
minder.execCommand("appendchildnode",new MinderNode()); // minder.execCommand("appendchildnode",new MinderNode('sdf'));
minder.execCommand("appendsiblingnode",new MinderNode()); // minder.execCommand("appendsiblingnode",new MinderNode('df'));
minder.execCommand("appendsiblingnode",new MinderNode()); // minder.execCommand("appendsiblingnode",new MinderNode('sdfsdf'));
</script> </script>
</html> </html>
\ No newline at end of file
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
* @description KityMinder 使用类 * @description KityMinder 使用类
*/ */
var MinderDefaultOptions = {}; var MinderDefaultOptions = {
"layoutstyle": "default"
};
var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
constructor: function ( options ) { constructor: function ( options ) {
...@@ -20,8 +22,11 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -20,8 +22,11 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._initMinder(); this._initMinder();
this._initSelection(); this._initSelection();
this._initModules(); this._initModules();
this.fire( 'ready' );
},
getOptions: function ( key ) {
return this._options[ key ];
}, },
_initMinder: function () { _initMinder: function () {
this._rc = new kity.Group(); this._rc = new kity.Group();
......
...@@ -391,12 +391,15 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -391,12 +391,15 @@ KityMinder.registerModule( "LayoutDefault", function () {
leftList.push( children[ i ] ); leftList.push( children[ i ] );
children[ i ].setData( "appendside", "left" ); children[ i ].setData( "appendside", "left" );
} }
children[ i ].getRenderContainer().clear();
children.setData( "shape", null );
drawNode( children[ i ] ); drawNode( children[ i ] );
updateArrangement( children[ i ] ); updateArrangement( children[ i ] );
} }
} }
}, },
appendChildNode: function ( parent, node, index ) { appendChildNode: function ( parent, node, index ) {
var minder = this;
var appendside = parent.getData( "appendside" ); var appendside = parent.getData( "appendside" );
if ( parent === root ) { if ( parent === root ) {
var leftList = parent.getData( "leftList" ); var leftList = parent.getData( "leftList" );
...@@ -417,7 +420,10 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -417,7 +420,10 @@ KityMinder.registerModule( "LayoutDefault", function () {
} else { } else {
node.setData( "align", "left" ); 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 ); drawNode( node );
updateArrangement( node, "append" ); updateArrangement( node, "append" );
}, },
......
KityMinder.registerModule( "LayoutModule", function () { 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 () { var SwitchLayoutCommand = kity.createClass( "SwitchLayoutCommand", ( function () {
return { return {
base: Command, base: Command,
execute: function ( km, style ) { execute: switchLayout
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 AppendChildNodeCommand = kity.createClass( "AppendChildNodeCommand", ( function () { var AppendChildNodeCommand = kity.createClass( "AppendChildNodeCommand", ( function () {
...@@ -59,6 +61,12 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -59,6 +61,12 @@ KityMinder.registerModule( "LayoutModule", function () {
"appendsiblingnode": AppendSiblingNodeCommand, "appendsiblingnode": AppendSiblingNodeCommand,
"removenode": RemoveNodeCommand, "removenode": RemoveNodeCommand,
"switchlayout": SwitchLayoutCommand "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