@@ -272,6 +272,7 @@ export class NgGrid {
272272 ngItem . setGridPosition ( newPos . col , newPos . row ) ;
273273 this . _items . push ( ngItem ) ;
274274 this . _addToGrid ( ngItem ) ;
275+ ngItem . recalculateSelf ( ) ;
275276 }
276277
277278 public removeItem ( ngItem : NgGridItem ) : void {
@@ -281,6 +282,8 @@ export class NgGrid {
281282 this . _items . splice ( x , 1 ) ;
282283
283284 // Update position of all items
285+ this . _updateSize ( ) ;
286+ this . _cascadeGrid ( ) ;
284287 this . _items . forEach ( ( item ) => item . recalculateSelf ( ) ) ;
285288 }
286289
@@ -321,12 +324,14 @@ export class NgGrid {
321324 if ( item != null ) {
322325 if ( this . resizeEnable && item . canResize ( e ) != null ) {
323326 this . _resizeStart ( e ) ;
327+ return false ;
324328 } else if ( this . dragEnable && item . canDrag ( e ) ) {
325329 this . _dragStart ( e ) ;
330+ return false ;
326331 }
327332 }
328333
329- return false ;
334+ return true ;
330335 }
331336
332337 private _resizeStart ( e : any ) : void {
@@ -365,7 +370,7 @@ export class NgGrid {
365370 }
366371 }
367372
368- private _onMouseMove ( e : any ) : boolean {
373+ private _onMouseMove ( e : any ) : void {
369374 if ( e . buttons == 0 && this . isDragging ) {
370375 this . _dragStop ( e ) ;
371376 } else if ( e . buttons == 0 && this . isResizing ) {
@@ -382,8 +387,6 @@ export class NgGrid {
382387 item . onMouseMove ( e ) ;
383388 }
384389 }
385-
386- return false ;
387390 }
388391
389392 private _drag ( e : any ) : void {
@@ -468,11 +471,13 @@ export class NgGrid {
468471 private _onMouseUp ( e : any ) : boolean {
469472 if ( this . isDragging ) {
470473 this . _dragStop ( e ) ;
474+ return false ;
471475 } else if ( this . isResizing ) {
472476 this . _resizeStop ( e ) ;
477+ return false ;
473478 }
474479
475- return false ;
480+ return true ;
476481 }
477482
478483 private _dragStop ( e : any ) : void {
@@ -864,9 +869,8 @@ export class NgGrid {
864869
865870 private _createPlaceholder ( pos : { col : number , row :number } , dims : { x : number , y : number } ) {
866871 var me = this ;
867- console . log ( pos , dims ) ;
872+
868873 this . _loader . loadNextToLocation ( ( < Type > NgGridPlaceholder ) , this . _items [ 0 ] . getElement ( ) ) . then ( componentRef => {
869- console . log ( componentRef ) ;
870874 me . _placeholderRef = componentRef ;
871875 var placeholder = componentRef . instance ;
872876 // me._placeholder.setGrid(me);
@@ -929,66 +933,40 @@ export class NgGridItem {
929933 this . setConfig ( v ) ;
930934
931935 if ( ! this . _added ) {
932- this . _ngGrid . addItem ( this ) ;
933936 this . _added = true ;
937+ this . _ngGrid . addItem ( this ) ;
934938 }
935939
936940 this . _recalculateDimensions ( ) ;
937941 this . _recalculatePosition ( ) ;
938942 }
939943
940944 // Constructor
941- constructor ( private _ngEl : ElementRef , private _renderer : Renderer , private _ngGrid :NgGrid ) { //@Host ()
945+ constructor ( private _ngEl : ElementRef , private _renderer : Renderer , private _ngGrid :NgGrid ) { }
946+
947+ // Public methods
948+ public onInit ( ) {
942949 this . _renderer . setElementClass ( this . _ngEl , 'grid-item' , true ) ;
943950 if ( this . _ngGrid . autoStyle ) this . _renderer . setElementStyle ( this . _ngEl , 'position' , 'absolute' ) ;
944951 this . _recalculateDimensions ( ) ;
945952 this . _recalculatePosition ( ) ;
946953 }
947954
948- // Public methods
949955 public canDrag ( e : any ) : boolean {
950956 if ( this . _dragHandle ) {
951- var foundHandle : boolean ;
952957 var parent = e . target . parentElement ;
953958
954- var last : any = e . target ;
955-
956- while ( parent ) {
957- if ( parent . querySelector ( this . _dragHandle ) == last ) {
958- foundHandle = true ;
959- break ;
960- }
961-
962- last = parent ;
963- parent = parent . parentElement ;
964- }
965-
966- return foundHandle ;
959+ return parent . querySelector ( this . _dragHandle ) == e . target ;
967960 }
968961
969962 return true ;
970963 }
971964
972965 public canResize ( e : any ) : string {
973966 if ( this . _resizeHandle ) {
974- var foundHandle : boolean ;
975- var paths : Array < any > = e . path ;
976- paths . pop ( ) ; // Get rid of #document
977-
978- var last : any = null ;
979-
980- for ( var x in paths ) {
981- if ( last !== null ) {
982- if ( paths [ x ] . querySelector ( this . _resizeHandle ) == last ) {
983- foundHandle = true ;
984- break ;
985- }
986- }
987-
988- last = paths [ x ] ;
989- }
990-
991- return foundHandle ? 'both' : null ;
967+ var parent = e . target . parentElement ;
968+
969+ return parent . querySelector ( this . _resizeHandle ) == e . target ? 'both' : null ;
992970 } else {
993971 var mousePos = this . _getMousePosition ( e ) ;
994972
@@ -1187,8 +1165,8 @@ class NgGridPlaceholder {
11871165 private _col : number ;
11881166 private _row : number ;
11891167
1190- constructor ( private _renderer : Renderer , private _ngEl : ElementRef , @ Host ( ) private _ngGrid : NgGrid ) {
1191- this . _renderer . setElementClass ( this . _ngEl , 'placeholder' , true ) ;
1168+ constructor ( private _renderer : Renderer , private _ngEl : ElementRef , private _ngGrid : NgGrid ) {
1169+ this . _renderer . setElementClass ( this . _ngEl , 'grid- placeholder' , true ) ;
11921170 if ( this . _ngGrid . autoStyle ) this . _renderer . setElementStyle ( this . _ngEl , 'position' , 'absolute' ) ;
11931171 }
11941172
0 commit comments