Refactor #3965 - For Directives

pull/4084/head
Tuğçe Küçükoğlu 2023-06-23 12:34:16 +03:00
parent 1398d98615
commit 7cb1814a1d
6 changed files with 7 additions and 11 deletions

View File

@ -34,9 +34,8 @@ const BadgeDirective = BaseDirective.extend('badge', {
!el.$_pbadgeUnstyled && DomHandler.addClass(el, 'p-overlay-badge'); !el.$_pbadgeUnstyled && DomHandler.addClass(el, 'p-overlay-badge');
el.setAttribute('data-p-overlay-badge', 'true'); el.setAttribute('data-p-overlay-badge', 'true');
el.appendChild(badge); el.appendChild(badge);
el.$_pDirectiveElement = badge; el.$pEl = badge;
BaseDirective.directiveElement = badge;
BaseDirective.handleCSS('badge', el, binding); BaseDirective.handleCSS('badge', el, binding);
}, },
updated(el, binding) { updated(el, binding) {

View File

@ -1,7 +1,6 @@
import { DomHandler, ObjectUtils } from 'primevue/utils'; import { DomHandler, ObjectUtils } from 'primevue/utils';
export const BaseDirective = { export const BaseDirective = {
directiveElement: null,
extend: (directiveName, hooks) => { extend: (directiveName, hooks) => {
return { return {
created: (el, binding, vnode, prevVnode) => { created: (el, binding, vnode, prevVnode) => {
@ -39,9 +38,9 @@ export const BaseDirective = {
let _directive = _config && _config.pt && _config.pt.directives && _config.pt.directives[directiveName]; let _directive = _config && _config.pt && _config.pt.directives && _config.pt.directives[directiveName];
// global pt hook // global pt hook
_directive && _directive.hooks && _directive.hooks[hookName] && _directive.hooks[hookName](BaseDirective.directiveElement, el, binding, vnode, prevVnode); _directive && _directive.hooks && _directive.hooks[hookName] && _directive.hooks[hookName](el.$pEl, el, binding, vnode, prevVnode);
// options pt hook // options pt hook
binding.value && typeof binding.value === 'object' && binding.value.pt && binding.value.pt.hooks && binding.value.pt.hooks[hookName] && binding.value.pt.hooks[hookName](BaseDirective.directiveElement, el, binding, vnode, prevVnode); binding.value && typeof binding.value === 'object' && binding.value.pt && binding.value.pt.hooks && binding.value.pt.hooks[hookName] && binding.value.pt.hooks[hookName](el.$pEl, el, binding, vnode, prevVnode);
}, },
handleCSS: (directiveName, el, binding) => { handleCSS: (directiveName, el, binding) => {
let _config = binding.instance.$primevue && binding.instance.$primevue.config; let _config = binding.instance.$primevue && binding.instance.$primevue.config;

View File

@ -121,7 +121,7 @@ const FocusTrap = BaseDirective.extend('focustrap', {
el.setAttribute('data-pc-section', 'root'); el.setAttribute('data-pc-section', 'root');
el.setAttribute('data-pc-name', 'focustrap'); el.setAttribute('data-pc-name', 'focustrap');
BaseDirective.directiveElement = el; el.$pEl = el;
BaseDirective.handleCSS('focustrap', el, binding); BaseDirective.handleCSS('focustrap', el, binding);
}, },

View File

@ -22,11 +22,10 @@ function create(el, binding) {
ink.setAttribute('data-p-ink', 'true'); ink.setAttribute('data-p-ink', 'true');
ink.setAttribute('data-p-ink-active', 'false'); ink.setAttribute('data-p-ink-active', 'false');
el.appendChild(ink); el.appendChild(ink);
el.$_pDirectiveElement = ink; el.$pEl = ink;
ink.addEventListener('animationend', onAnimationEnd); ink.addEventListener('animationend', onAnimationEnd);
BaseDirective.directiveElement = ink;
BaseDirective.handleCSS('ripple', ink, binding); BaseDirective.handleCSS('ripple', ink, binding);
} }

View File

@ -4,7 +4,7 @@ import { DomHandler } from 'primevue/utils';
function bind(el, binding) { function bind(el, binding) {
const target = resolveTarget(el, binding); const target = resolveTarget(el, binding);
BaseDirective.directiveElement = target; el.$pEl = target;
el.$_pstyleclass_clicklistener = () => { el.$_pstyleclass_clicklistener = () => {
if (binding.value.toggleClass) { if (binding.value.toggleClass) {

View File

@ -190,8 +190,7 @@ function create(el, options) {
container.style.width = 'fit-content'; container.style.width = 'fit-content';
} }
el.$_pDirectiveElement = container; el.$pEl = container;
BaseDirective.directiveElement = container;
BaseDirective.handleCSS('tooltip', container, options); BaseDirective.handleCSS('tooltip', container, options);
return container; return container;