@@ -11,19 +11,12 @@ import {
11
11
SimpleChanges ,
12
12
OnChanges ,
13
13
SimpleChange ,
14
- Renderer2 ,
15
- Inject ,
16
- PLATFORM_ID ,
17
14
} from '@angular/core' ;
18
15
19
16
import { buildLayoutCSS } from '../../utils/layout-validator' ;
20
17
import {
21
18
StyleDefinition ,
22
- lookupStyle ,
23
- lookupInlineStyle ,
24
- applyStyleToElement ,
25
- applyStyleToElements ,
26
- lookupAttributeValue ,
19
+ StyleUtils ,
27
20
} from '../../utils/style-utils' ;
28
21
29
22
import { ResponsiveActivation , KeyOptions } from '../core/responsive-activation' ;
@@ -70,8 +63,7 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
70
63
*/
71
64
constructor ( protected _mediaMonitor : MediaMonitor ,
72
65
protected _elementRef : ElementRef ,
73
- protected _renderer : Renderer2 ,
74
- @Inject ( PLATFORM_ID ) protected _platformId : Object ) {
66
+ protected _styleUtils : StyleUtils ) {
75
67
}
76
68
77
69
// *********************************************
@@ -137,19 +129,20 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
137
129
138
130
/**
139
131
* Quick accessor to the current HTMLElement's `display` style
140
- * Note: this allows use to preserve the original style
132
+ * Note: this allows us to preserve the original style
141
133
* and optional restore it when the mediaQueries deactivate
142
134
*/
143
135
protected _getDisplayStyle ( source : HTMLElement = this . nativeElement ) : string {
144
- return lookupStyle ( this . _platformId , source || this . nativeElement , 'display' ) ;
136
+ const query = 'display' ;
137
+ return this . _styleUtils . lookupStyle ( source , query ) ;
145
138
}
146
139
147
140
/**
148
141
* Quick accessor to raw attribute value on the target DOM element
149
142
*/
150
143
protected _getAttributeValue ( attribute : string ,
151
144
source : HTMLElement = this . nativeElement ) : string {
152
- return lookupAttributeValue ( source || this . nativeElement , attribute ) ;
145
+ return this . _styleUtils . lookupAttributeValue ( source , attribute ) ;
153
146
}
154
147
155
148
/**
@@ -158,15 +151,20 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
158
151
* Check inline style first then check computed (stylesheet) style.
159
152
* And optionally add the flow value to element's inline style.
160
153
*/
161
- protected _getFlowDirection ( target : any , addIfMissing = false ) : string {
154
+ protected _getFlowDirection ( target : HTMLElement , addIfMissing = false ) : string {
162
155
let value = 'row' ;
156
+ let hasInlineValue = '' ;
157
+ const query = 'flex-direction' ;
163
158
164
159
if ( target ) {
165
- value = lookupStyle ( this . _platformId , target , 'flex-direction' ) || 'row' ;
166
- let hasInlineValue = lookupInlineStyle ( target , 'flex-direction' ) ;
160
+
161
+ value = this . _styleUtils . lookupStyle ( target , query ) || 'row' ;
162
+ hasInlineValue = this . _styleUtils . lookupInlineStyle ( target , query ) ;
167
163
168
164
if ( ! hasInlineValue && addIfMissing ) {
169
- applyStyleToElements ( this . _renderer , buildLayoutCSS ( value ) , [ target ] ) ;
165
+ const style = buildLayoutCSS ( value ) ;
166
+ const elements = [ target ] ;
167
+ this . _styleUtils . applyStyleToElements ( style , elements ) ;
170
168
}
171
169
}
172
170
@@ -178,16 +176,15 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
178
176
*/
179
177
protected _applyStyleToElement ( style : StyleDefinition ,
180
178
value ?: string | number ,
181
- nativeElement : any = this . nativeElement ) {
182
- let element = nativeElement || this . nativeElement ;
183
- applyStyleToElement ( this . _renderer , element , style , value ) ;
179
+ element : HTMLElement = this . nativeElement ) {
180
+ this . _styleUtils . applyStyleToElement ( element , style , value ) ;
184
181
}
185
182
186
183
/**
187
184
* Applies styles given via string pair or object map to the directive's element.
188
185
*/
189
- protected _applyStyleToElements ( style : StyleDefinition , elements : HTMLElement [ ] ) {
190
- applyStyleToElements ( this . _renderer , style , elements || [ ] ) ;
186
+ protected _applyStyleToElements ( style : StyleDefinition , elements : HTMLElement [ ] ) {
187
+ this . _styleUtils . applyStyleToElements ( style , elements ) ;
191
188
}
192
189
193
190
/**
0 commit comments