1- /// <reference path="typings/angular2/angular2.d.ts" />
2-
31import { Component , View , Directive , ElementRef , Renderer , EventEmitter , DynamicComponentLoader , Host , ViewEncapsulation , Type , ComponentRef , LifecycleEvent , KeyValueDiffer , KeyValueDiffers } from 'angular2/angular2' ;
42
53@Directive ( {
@@ -46,7 +44,7 @@ export class NgGrid {
4644 private _draggingItem : NgGridItem = null ;
4745 private _resizingItem : NgGridItem = null ;
4846 private _resizeDirection : string = null ;
49- private _itemGrid = { 1 : { 1 : null } } ;
47+ private _itemGrid : Map < number , Map < number , NgGridItem > > = { 1 : { 1 : null } } ;
5048 private _containerWidth : number ;
5149 private _containerHeight : number ;
5250 private _maxCols :number = 0 ;
@@ -81,7 +79,7 @@ export class NgGrid {
8179 private _config = NgGrid . CONST_DEFAULT_CONFIG ;
8280
8381 // [ng-grid] attribute handler
84- set config ( v ) {
82+ set config ( v : any ) {
8583 this . _config = v ;
8684
8785 if ( this . _differ == null && v != null ) {
@@ -99,7 +97,7 @@ export class NgGrid {
9997 }
10098
10199 // Public methods
102- public setConfig ( config ) : void {
100+ public setConfig ( config : any ) : void {
103101 var maxColRowChanged = false ;
104102 for ( var x in config ) {
105103 var val = config [ x ] ;
@@ -171,13 +169,13 @@ export class NgGrid {
171169 }
172170 }
173171
174- for ( var r = 1 ; r <= this . _getMaxRow ( ) ; r ++ ) {
172+ for ( var r : number = 1 ; r <= this . _getMaxRow ( ) ; r ++ ) {
175173 if ( this . _itemGrid [ r ] != null ) {
176- for ( var c = 1 ; c <= this . _getMaxCol ( ) ; c ++ ) {
174+ for ( var c : number = 1 ; c <= this . _getMaxCol ( ) ; c ++ ) {
177175 if ( this . _itemGrid [ r ] != null && this . _itemGrid [ r ] [ c ] != null ) {
178- var item = this . _itemGrid [ r ] [ c ] ;
179- var pos = item . getGridPosition ( ) ;
180- var dims = item . getSize ( ) ;
176+ var item : NgGridItem = this . _itemGrid [ r ] [ c ] ;
177+ var pos : { 'col' : number , 'row' : number } = item . getGridPosition ( ) ;
178+ var dims : { 'x' : number , 'y' : number } = item . getSize ( ) ;
181179
182180 if ( ( this . _maxCols > 0 && ( pos . col + dims . x - 1 ) > this . _maxCols ) || ( this . _maxRows > 0 && ( pos . row + dims . y - 1 ) > this . _maxRows ) ) {
183181 this . _removeFromGrid ( item ) ;
@@ -209,15 +207,15 @@ export class NgGrid {
209207 }
210208
211209 if ( this . _autoResize && this . _maxCols > 0 ) {
212- var maxWidth = this . _ngEl . nativeElement . parentElement . getBoundingClientRect ( ) . width ;
210+ var maxWidth : number = this . _ngEl . nativeElement . parentElement . getBoundingClientRect ( ) . width ;
213211
214- var colWidth = Math . floor ( maxWidth / this . _maxCols ) ;
212+ var colWidth : number = Math . floor ( maxWidth / this . _maxCols ) ;
215213 colWidth -= ( this . marginLeft + this . marginRight ) ;
216214 this . colWidth = colWidth ;
217215 } else if ( this . _autoResize && this . _maxRows > 0 ) {
218- var maxHeight = window . innerHeight ;
216+ var maxHeight : number = window . innerHeight ;
219217
220- var rowHeight = Math . floor ( maxHeight / this . _maxRows ) ;
218+ var rowHeight : number = Math . floor ( maxHeight / this . _maxRows ) ;
221219 rowHeight -= ( this . marginTop + this . marginBottom ) ;
222220 this . rowHeight = rowHeight ;
223221 }
@@ -246,7 +244,7 @@ export class NgGrid {
246244 }
247245 }
248246
249- public setMargins ( margins ) : void {
247+ public setMargins ( margins : Array < string > ) : void {
250248 this . marginTop = parseInt ( margins [ 0 ] ) ;
251249 this . marginRight = margins . length >= 2 ? parseInt ( margins [ 1 ] ) : this . marginTop ;
252250 this . marginBottom = margins . length >= 3 ? parseInt ( margins [ 2 ] ) : this . marginTop ;
@@ -283,7 +281,7 @@ export class NgGrid {
283281 }
284282
285283 // Private methods
286- private _onResize ( e ) {
284+ private _onResize ( e : any ) : void {
287285 if ( this . _autoResize && this . _maxCols > 0 ) {
288286 var maxWidth = this . _ngEl . nativeElement . parentElement . getBoundingClientRect ( ) . width ;
289287
@@ -306,9 +304,9 @@ export class NgGrid {
306304 }
307305
308306 private _applyChanges ( changes : any ) : void {
309- changes . forEachAddedItem ( ( record ) => { this . _config [ record . key ] = record . currentValue ; } ) ;
310- changes . forEachChangedItem ( ( record ) => { this . _config [ record . key ] = record . currentValue ; } ) ;
311- changes . forEachRemovedItem ( ( record ) => { delete this . _config [ record . key ] ; } ) ;
307+ changes . forEachAddedItem ( ( record : any ) => { this . _config [ record . key ] = record . currentValue ; } ) ;
308+ changes . forEachChangedItem ( ( record : any ) => { this . _config [ record . key ] = record . currentValue ; } ) ;
309+ changes . forEachRemovedItem ( ( record : any ) => { delete this . _config [ record . key ] ; } ) ;
312310 this . setConfig ( this . _config ) ;
313311 }
314312
@@ -481,7 +479,7 @@ export class NgGrid {
481479
482480 this . _draggingItem . setGridPosition ( itemPos . col , itemPos . row ) ;
483481 this . _addToGrid ( this . _draggingItem ) ;
484- console . log ( "STOP" , itemPos ) ;
482+
485483 this . _cascadeGrid ( ) ;
486484
487485 this . _draggingItem . stopMoving ( ) ;
@@ -519,7 +517,7 @@ export class NgGrid {
519517 return { 'x' : sizex , 'y' : sizey } ;
520518 }
521519
522- private _calculateGridSize ( width , height ) : { x : number , y : number } {
520+ private _calculateGridSize ( width : number , height : number ) : { x : number , y : number } {
523521 width += this . marginLeft + this . marginRight ;
524522 height += this . marginTop + this . marginBottom ;
525523
@@ -670,7 +668,6 @@ export class NgGrid {
670668 for ( var c :number = 1 ; c <= this . _getMaxCol ( ) ; c ++ ) {
671669 if ( this . _itemGrid [ r ] == undefined ) break ;
672670 if ( c < lowCol [ r ] ) continue ;
673- console . log ( r , c , lowCol ) ;
674671
675672 if ( this . _itemGrid [ r ] [ c ] != null ) {
676673 var item = this . _itemGrid [ r ] [ c ] ;
@@ -891,7 +888,7 @@ export class NgGridItem {
891888 public resizeStop : EventEmitter = new EventEmitter ( ) ;
892889
893890 // Default config
894- private static CONST_DEFAULT_CONFIG = {
891+ private static CONST_DEFAULT_CONFIG : { 'col' : number , 'row' : number , 'sizex' : number , 'sizey' : number , 'dragHandle' : string , 'resizeHandle' : string } = {
895892 'col' : 1 ,
896893 'row' : 1 ,
897894 'sizex' : 1 ,
@@ -918,7 +915,7 @@ export class NgGridItem {
918915 private _added : boolean = false ;
919916
920917 // [ng-grid-item] handler
921- set config ( v ) {
918+ set config ( v : any ) {
922919 var defaults = NgGridItem . CONST_DEFAULT_CONFIG ;
923920
924921 for ( var x in defaults )
@@ -947,11 +944,11 @@ export class NgGridItem {
947944 // Public methods
948945 public canDrag ( e : any ) : boolean {
949946 if ( this . _dragHandle ) {
950- var foundHandle ;
951- var paths = e . path ;
947+ var foundHandle : boolean ;
948+ var paths : Array < any > = e . path ;
952949 paths . pop ( ) ; // Get rid of #document
953950
954- var last = null ;
951+ var last : any = null ;
955952
956953 for ( var x in paths ) {
957954 if ( last !== null ) {
@@ -972,11 +969,11 @@ export class NgGridItem {
972969
973970 public canResize ( e : any ) : string {
974971 if ( this . _resizeHandle ) {
975- var foundHandle ;
976- var paths = e . path ;
972+ var foundHandle : boolean ;
973+ var paths : Array < any > = e . path ;
977974 paths . pop ( ) ; // Get rid of #document
978975
979- var last = null ;
976+ var last : any = null ;
980977
981978 for ( var x in paths ) {
982979 if ( last !== null ) {
@@ -1032,7 +1029,7 @@ export class NgGridItem {
10321029 }
10331030 }
10341031
1035- public onDestroy ( ) {
1032+ public onDestroy ( ) : void {
10361033 if ( this . _added ) this . _ngGrid . removeItem ( this ) ;
10371034 }
10381035
@@ -1066,7 +1063,7 @@ export class NgGridItem {
10661063 }
10671064
10681065 // Setters
1069- public setConfig ( config ) : void {
1066+ public setConfig ( config : any ) : void {
10701067 this . _col = config . col ;
10711068 this . _row = config . row ;
10721069 this . _sizex = config . sizex ;
@@ -1091,7 +1088,7 @@ export class NgGridItem {
10911088 this . _col = col ;
10921089 this . _row = row ;
10931090 this . gridPosition = { 'col' : this . _col , 'row' : this . _row } ;
1094- console . log ( this . gridPosition ) ;
1091+
10951092 this . _recalculatePosition ( ) ;
10961093
10971094 this . itemChange . next ( { 'col' : this . _col , 'row' : this . _row , 'sizex' : this . _sizex , 'sizey' : this . _sizey } ) ;
0 commit comments