| 57 | */ |
| 58 | @Service() |
| 59 | export class MatRippleLoader implements OnDestroy { |
| 60 | private _document = inject(DOCUMENT); |
| 61 | private _animationsDisabled = _animationsDisabled(); |
| 62 | private _globalRippleOptions = inject(MAT_RIPPLE_GLOBAL_OPTIONS, {optional: true}); |
| 63 | private _platform = inject(Platform); |
| 64 | private _ngZone = inject(NgZone); |
| 65 | private _injector = inject(Injector); |
| 66 | private _eventCleanups: (() => void)[]; |
| 67 | private _hosts = new Map< |
| 68 | HTMLElement, |
| 69 | {renderer: RippleRenderer; target: RippleTarget; hasSetUpEvents: boolean} |
| 70 | >(); |
| 71 | |
| 72 | constructor() { |
| 73 | const renderer = inject(RendererFactory2).createRenderer(null, null); |
| 74 | |
| 75 | this._eventCleanups = this._ngZone.runOutsideAngular(() => |
| 76 | rippleInteractionEvents.map(name => |
| 77 | renderer.listen(this._document, name, this._onInteraction, eventListenerOptions), |
| 78 | ), |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | ngOnDestroy(): void { |
| 83 | const hosts = this._hosts.keys(); |
| 84 | |
| 85 | for (const host of hosts) { |
| 86 | this.destroyRipple(host); |
| 87 | } |
| 88 | |
| 89 | this._eventCleanups.forEach(cleanup => cleanup()); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Configures the ripple that will be rendered by the ripple loader. |
| 94 | * |
| 95 | * Stores the given information about how the ripple should be configured on the host |
| 96 | * element so that it can later be retrived & used when the ripple is actually created. |
| 97 | */ |
| 98 | configureRipple( |
| 99 | host: HTMLElement, |
| 100 | config: { |
| 101 | className?: string; |
| 102 | centered?: boolean; |
| 103 | disabled?: boolean; |
| 104 | }, |
| 105 | ): void { |
| 106 | // Indicates that the ripple has not yet been rendered for this component. |
| 107 | host.setAttribute(matRippleUninitialized, this._globalRippleOptions?.namespace ?? ''); |
| 108 | |
| 109 | // Store the additional class name(s) that should be added to the ripple element. |
| 110 | if (config.className || !host.hasAttribute(matRippleClassName)) { |
| 111 | host.setAttribute(matRippleClassName, config.className || ''); |
| 112 | } |
| 113 | |
| 114 | // Store whether the ripple should be centered. |
| 115 | if (config.centered) { |
| 116 | host.setAttribute(matRippleCentered, ''); |
nothing calls this directly
no test coverage detected
searching dependent graphs…