@@ -18,6 +18,9 @@ <h1>Swap collision demo</h1>
1818 < a class ="btn btn-primary " onclick ="toggleFloat() " id ="float " href ="# "> </ a >
1919 < a class ="btn btn-primary " onclick ="toggleMax() " id ="max " href ="# "> </ a >
2020 < a class ="btn btn-primary " onclick ="toggleBigger() " id ="big " href ="# "> </ a >
21+ with layouts:
22+ < a class ="btn btn-primary " onclick ="load(0) " href ="# "> load 0</ a >
23+ < a class ="btn btn-primary " onclick ="load(1) " href ="# "> load 1</ a >
2124 </ div >
2225 < br > < br >
2326 < div class ="grid-stack "> </ div >
@@ -28,31 +31,45 @@ <h1>Swap collision demo</h1>
2831 let maxButton = document . getElementById ( 'max' ) ;
2932 let bigButton = document . getElementById ( 'big' ) ;
3033 let size = 1 ;
34+ let layout = 0 ;
3135
3236 let grid = GridStack . init ( { float : false , cellHeight : 70 , maxRow : 0 } ) ;
3337 addEvents ( grid ) ;
3438
35- let count = 0 ;
36- let items = [
39+ let items = [ [
3740 { x :0 , y :0 } , { x :0 , y :1 } , { x :0 , y :2 } , { x :1 , y :0 } , { x :1 , y :1 } , { x :1 , y :2 , h :2 , w :2 } ,
3841 { x :5 , y :0 } , { x :4 , y :1 , w :3 , locked : false , _content : 'locked' } , { x :5 , y :2 } ,
3942 { x :7 , y :0 } , { x :8 , y :0 } , { x :9 , y :0 } , { x :7 , y :1 , w :3 } , { x :8 , y :2 } ,
4043 { x :11 , y :0 } , { x :11 , y :1 , h :2 } ,
41- ] ;
42- items . forEach ( n => { n . id = count ; n . content = n . content || String ( count ) ; count ++ } )
43- grid . load ( items ) ;
44+ ] , [
45+ { x : 1 , y : 0 } ,
46+ { x : 1 , y : 1 } ,
47+ { x : 1 , y : 2 , w : 2 } ,
48+ { x : 0 , y : 3 , w : 3 } ,
49+ { x : 1 , y : 4 , h : 2 } ,
50+ ] ] ;
51+ items . forEach ( layout => {
52+ let count = 0 ;
53+ layout . forEach ( n => { n . id = count ; n . content = n . content || String ( count ) ; count ++ } )
54+ } ) ;
55+ grid . load ( items [ layout ] ) ;
4456
4557 addNewWidget = function ( ) {
4658 let n = {
4759 x : Math . round ( 12 * Math . random ( ) ) ,
4860 y : Math . round ( 5 * Math . random ( ) ) ,
4961 w : Math . round ( 1 + 3 * Math . random ( ) ) ,
5062 h : Math . round ( 1 + 3 * Math . random ( ) ) ,
51- content : String ( count ++ )
63+ content : String ( grid . engine . nodes . length + 1 )
5264 } ;
5365 grid . addWidget ( n ) ;
5466 } ;
5567
68+ load = function ( i ) {
69+ grid . removeAll ( ) ;
70+ grid . load ( items [ i ] ) ;
71+ }
72+
5673 toggleFloat = function ( ) {
5774 grid . float ( ! grid . getFloat ( ) ) ;
5875 floatButton . innerHTML = 'float: ' + grid . getFloat ( ) ;
0 commit comments