[59329aa] | 1 | import * as i0 from '@angular/core';
|
---|
| 2 | import { Directive, Optional, NgModule } from '@angular/core';
|
---|
| 3 | import { CommonModule } from '@angular/common';
|
---|
| 4 | import { DomHandler } from 'primeng/dom';
|
---|
| 5 | import * as i1 from 'primeng/api';
|
---|
| 6 |
|
---|
| 7 | class Ripple {
|
---|
| 8 | constructor(el, zone, config) {
|
---|
| 9 | this.el = el;
|
---|
| 10 | this.zone = zone;
|
---|
| 11 | this.config = config;
|
---|
| 12 | }
|
---|
| 13 | ngAfterViewInit() {
|
---|
| 14 | if (this.config && this.config.ripple) {
|
---|
| 15 | this.zone.runOutsideAngular(() => {
|
---|
| 16 | this.create();
|
---|
| 17 | this.mouseDownListener = this.onMouseDown.bind(this);
|
---|
| 18 | this.el.nativeElement.addEventListener('mousedown', this.mouseDownListener);
|
---|
| 19 | });
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
| 22 | onMouseDown(event) {
|
---|
| 23 | let ink = this.getInk();
|
---|
| 24 | if (!ink || getComputedStyle(ink, null).display === 'none') {
|
---|
| 25 | return;
|
---|
| 26 | }
|
---|
| 27 | DomHandler.removeClass(ink, 'p-ink-active');
|
---|
| 28 | if (!DomHandler.getHeight(ink) && !DomHandler.getWidth(ink)) {
|
---|
| 29 | let d = Math.max(DomHandler.getOuterWidth(this.el.nativeElement), DomHandler.getOuterHeight(this.el.nativeElement));
|
---|
| 30 | ink.style.height = d + 'px';
|
---|
| 31 | ink.style.width = d + 'px';
|
---|
| 32 | }
|
---|
| 33 | let offset = DomHandler.getOffset(this.el.nativeElement);
|
---|
| 34 | let x = event.pageX - offset.left + document.body.scrollTop - DomHandler.getWidth(ink) / 2;
|
---|
| 35 | let y = event.pageY - offset.top + document.body.scrollLeft - DomHandler.getHeight(ink) / 2;
|
---|
| 36 | ink.style.top = y + 'px';
|
---|
| 37 | ink.style.left = x + 'px';
|
---|
| 38 | DomHandler.addClass(ink, 'p-ink-active');
|
---|
| 39 | }
|
---|
| 40 | getInk() {
|
---|
| 41 | for (let i = 0; i < this.el.nativeElement.children.length; i++) {
|
---|
| 42 | if (this.el.nativeElement.children[i].className.indexOf('p-ink') !== -1) {
|
---|
| 43 | return this.el.nativeElement.children[i];
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | return null;
|
---|
| 47 | }
|
---|
| 48 | resetInk() {
|
---|
| 49 | let ink = this.getInk();
|
---|
| 50 | if (ink) {
|
---|
| 51 | DomHandler.removeClass(ink, 'p-ink-active');
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | onAnimationEnd(event) {
|
---|
| 55 | DomHandler.removeClass(event.currentTarget, 'p-ink-active');
|
---|
| 56 | }
|
---|
| 57 | create() {
|
---|
| 58 | let ink = document.createElement('span');
|
---|
| 59 | ink.className = 'p-ink';
|
---|
| 60 | this.el.nativeElement.appendChild(ink);
|
---|
| 61 | this.animationListener = this.onAnimationEnd.bind(this);
|
---|
| 62 | ink.addEventListener('animationend', this.animationListener);
|
---|
| 63 | }
|
---|
| 64 | remove() {
|
---|
| 65 | let ink = this.getInk();
|
---|
| 66 | if (ink) {
|
---|
| 67 | this.el.nativeElement.removeEventListener('mousedown', this.mouseDownListener);
|
---|
| 68 | ink.removeEventListener('animationend', this.animationListener);
|
---|
| 69 | DomHandler.removeElement(ink);
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | ngOnDestroy() {
|
---|
| 73 | if (this.config && this.config.ripple) {
|
---|
| 74 | this.remove();
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | Ripple.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Ripple, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }, { token: i1.PrimeNGConfig, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
|
---|
| 79 | Ripple.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.0.0", type: Ripple, selector: "[pRipple]", host: { classAttribute: "p-ripple p-element" }, ngImport: i0 });
|
---|
| 80 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Ripple, decorators: [{
|
---|
| 81 | type: Directive,
|
---|
| 82 | args: [{
|
---|
| 83 | selector: '[pRipple]',
|
---|
| 84 | host: {
|
---|
| 85 | 'class': 'p-ripple p-element'
|
---|
| 86 | }
|
---|
| 87 | }]
|
---|
| 88 | }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: i1.PrimeNGConfig, decorators: [{
|
---|
| 89 | type: Optional
|
---|
| 90 | }] }]; } });
|
---|
| 91 | class RippleModule {
|
---|
| 92 | }
|
---|
| 93 | RippleModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RippleModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
| 94 | RippleModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RippleModule, declarations: [Ripple], imports: [CommonModule], exports: [Ripple] });
|
---|
| 95 | RippleModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RippleModule, imports: [[CommonModule]] });
|
---|
| 96 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: RippleModule, decorators: [{
|
---|
| 97 | type: NgModule,
|
---|
| 98 | args: [{
|
---|
| 99 | imports: [CommonModule],
|
---|
| 100 | exports: [Ripple],
|
---|
| 101 | declarations: [Ripple]
|
---|
| 102 | }]
|
---|
| 103 | }] });
|
---|
| 104 |
|
---|
| 105 | /**
|
---|
| 106 | * Generated bundle index. Do not edit.
|
---|
| 107 | */
|
---|
| 108 |
|
---|
| 109 | export { Ripple, RippleModule };
|
---|