1 line
9.9 KiB
Plaintext
1 line
9.9 KiB
Plaintext
|
{"version":3,"file":"primeng-ripple.mjs","sources":["../../src/app/components/ripple/ripple.ts","../../src/app/components/ripple/primeng-ripple.ts"],"sourcesContent":["import { CommonModule, DOCUMENT, isPlatformBrowser } from '@angular/common';\nimport { AfterViewInit, Directive, ElementRef, Inject, NgModule, NgZone, OnDestroy, Optional, PLATFORM_ID, Renderer2 } from '@angular/core';\nimport { PrimeNGConfig } from 'primeng/api';\nimport { DomHandler } from 'primeng/dom';\nimport { VoidListener } from 'primeng/ts-helpers';\n/**\n * Ripple directive adds ripple effect to the host element.\n * @group Components\n */\n@Directive({\n selector: '[pRipple]',\n host: {\n class: 'p-ripple p-element'\n }\n})\nexport class Ripple implements AfterViewInit, OnDestroy {\n constructor(@Inject(DOCUMENT) private document: Document, @Inject(PLATFORM_ID) private platformId: any, private renderer: Renderer2, public el: ElementRef, public zone: NgZone, @Optional() public config: PrimeNGConfig) {}\n\n animationListener: VoidListener;\n\n mouseDownListener: VoidListener;\n\n timeout: any;\n\n ngAfterViewInit() {\n if (isPlatformBrowser(this.platformId)) {\n if (this.config && this.config.ripple) {\n this.zone.runOutsideAngular(() => {\n this.create();\n this.mouseDownListener = this.renderer.listen(this.el.nativeElement, 'mousedown', this.onMouseDown.bind(this));\n });\n }\n }\n }\n\n onMouseDown(event: MouseEvent) {\n let ink = this.getInk();\n if (!ink || this.document.defaultView?.getComputedStyle(ink, null).display === 'none') {\n return;\n }\n\n DomHandler.removeClass(ink, 'p-ink-active');\n if (!DomHandler.getHeight(ink) && !DomHandler.getWidth(ink)) {\n let d = Math.max(DomHandler.getOuterWidth(this.el.nativeElement), DomHandler.getOuterHeight(this.el.nativeElement));\n ink.style.height = d + 'px';\n ink.style.width = d + 'px';\n }\n\n let offset = DomHandler.getOffset(this.el.nativeElement);\n let x = event.pageX - offset.left + this.document.body.scrollTop - DomHandler.getWidth(ink) / 2;\n let y = event.pageY - offset.top + this.document.body.scrollLeft - DomHandler.getHeight(ink) / 2;\n\n this.renderer.setStyle(ink, 'top', y + 'px');\n this.renderer.setStyle(ink, 'left', x + 'px');\n DomHandler.addClass(ink, 'p-ink-active');\n\n this.timeout = setTimeout(() => {\n let ink = this.getInk();\n if (ink) {\n DomHandler.removeClass(ink, 'p-ink-active');\n }\n }, 401);\n }\n\n getInk() {\n const children = this.el.nativeElement.children;\n for (let i = 0; i < children.length; i++) {\n if (typeof children[i].className === 'string' && children[i].className.indexOf('p-ink') !== -1) {\n return children[i];\n }\n }\n return null;\n }\n\n resetInk() {\n let ink = this.getInk();\n if (ink) {\n DomHandler.removeClass(ink, 'p-ink-active');\n }\n }\n\n onAnimationEnd(event: Event) {\n if (this.timeout) {\n clearTimeout(this.timeout);\n }\n DomHandler.removeClass(event.currentTarget, 'p-ink-active');\n }\n\n create() {\n let ink = this.renderer.createElement('span');\n this.renderer.addClass(ink, 'p-ink');\n this.renderer.appendChild(this.el.nativeElement, ink);\n this.renderer.setAttribute(ink, 'aria-hidden', 'true');\n this.renderer.setAttribute(ink, 'role', 'presentation');\n\n if (!this.animationListener) {\n this.animationListener = this.renderer.listen(ink, 'animationend', this.onAnimationEnd.bind(this));\n }\n }\n\n remove() {\n let ink = this.getInk();\n if (ink) {\n this.mouseDownListener && this.mouseDownListener();\n this.animationListener && this.animationListener
|