@@ -22,18 +22,16 @@ import {SplitAreaDirective} from './split-area.directive';
22
22
}
23
23
} )
24
24
export class SplitDirective implements AfterContentInit , OnDestroy {
25
- watcher : Subscription ;
26
-
27
- @Input ( 'ngxSplit' )
28
- direction = 'row' ;
29
-
25
+ @Input ( 'ngxSplit' ) direction = 'row' ;
30
26
@ContentChild ( SplitHandleDirective ) handle : SplitHandleDirective ;
31
27
@ContentChildren ( SplitAreaDirective ) areas : QueryList < SplitAreaDirective > ;
32
28
29
+ private watcher : Subscription ;
30
+
33
31
constructor ( private elementRef : ElementRef ) { }
34
32
35
33
ngAfterContentInit ( ) : void {
36
- this . watcher = this . handle . drag . subscribe ( pos => this . onDrag ( pos ) ) ;
34
+ this . watcher = this . handle . drag . subscribe ( this . onDrag . bind ( this ) ) ;
37
35
}
38
36
39
37
ngOnDestroy ( ) {
@@ -62,24 +60,17 @@ export class SplitDirective implements AfterContentInit, OnDestroy {
62
60
* Use the pixel delta change to recalculate the area size (%)
63
61
* Note: flex value may be '', %, px, or '<grow> <shrink> <basis>'
64
62
*/
65
- calculateSize ( value : string | number , delta : number ) {
63
+ calculateSize ( value : string , delta : number ) : number {
66
64
const containerSizePx = this . elementRef . nativeElement . clientWidth ;
67
- const elementSizePx = Math . round ( this . valueToPixel ( value , containerSizePx ) ) ;
65
+ const elementSizePx = Math . round ( valueToPixel ( value , containerSizePx ) ) ;
68
66
69
67
const elementSize = ( ( elementSizePx + delta ) / containerSizePx ) * 100 ;
70
68
return Math . round ( elementSize * 100 ) / 100 ;
71
69
}
70
+ }
72
71
73
- /**
74
- * Convert the pixel or percentage value to a raw
75
- * pixel float value.
76
- */
77
- valueToPixel ( value : string | number , parentWidth : number ) : number {
78
- const isPercent = ( ) => String ( value ) . indexOf ( 'px' ) < 0 ;
79
- let size = parseFloat ( String ( value ) ) ;
80
- if ( isPercent ( ) ) {
81
- size = parentWidth * ( size / 100 ) ; // Convert percentage to actual pixel float value
82
- }
83
- return size ;
84
- }
72
+ /** Convert the pixel or percentage value to a raw pixel float value */
73
+ function valueToPixel ( value : string , parentWidth : number ) : number {
74
+ const size = parseFloat ( value ) ;
75
+ return ! value . includes ( 'px' ) ? parentWidth * ( size / 100 ) : size ;
85
76
}
0 commit comments