Skip to content

Commit

Permalink
Refactor #3965 - For Directives
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Jun 23, 2023
1 parent 1398d98 commit 7cb1814
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 11 deletions.
3 changes: 1 addition & 2 deletions components/lib/badgedirective/BadgeDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ const BadgeDirective = BaseDirective.extend('badge', {
!el.$_pbadgeUnstyled && DomHandler.addClass(el, 'p-overlay-badge');
el.setAttribute('data-p-overlay-badge', 'true');
el.appendChild(badge);
el.$_pDirectiveElement = badge;
el.$pEl = badge;

BaseDirective.directiveElement = badge;
BaseDirective.handleCSS('badge', el, binding);
},
updated(el, binding) {
Expand Down
5 changes: 2 additions & 3 deletions components/lib/basedirective/BaseDirective.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DomHandler, ObjectUtils } from 'primevue/utils';

export const BaseDirective = {
directiveElement: null,
extend: (directiveName, hooks) => {
return {
created: (el, binding, vnode, prevVnode) => {
Expand Down Expand Up @@ -39,9 +38,9 @@ export const BaseDirective = {
let _directive = _config && _config.pt && _config.pt.directives && _config.pt.directives[directiveName];

// 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
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) => {
let _config = binding.instance.$primevue && binding.instance.$primevue.config;
Expand Down
2 changes: 1 addition & 1 deletion components/lib/focustrap/FocusTrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const FocusTrap = BaseDirective.extend('focustrap', {
el.setAttribute('data-pc-section', 'root');
el.setAttribute('data-pc-name', 'focustrap');

BaseDirective.directiveElement = el;
el.$pEl = el;
BaseDirective.handleCSS('focustrap', el, binding);
},

Expand Down
3 changes: 1 addition & 2 deletions components/lib/ripple/Ripple.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ function create(el, binding) {
ink.setAttribute('data-p-ink', 'true');
ink.setAttribute('data-p-ink-active', 'false');
el.appendChild(ink);
el.$_pDirectiveElement = ink;
el.$pEl = ink;

ink.addEventListener('animationend', onAnimationEnd);

BaseDirective.directiveElement = ink;
BaseDirective.handleCSS('ripple', ink, binding);
}

Expand Down
2 changes: 1 addition & 1 deletion components/lib/styleclass/StyleClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DomHandler } from 'primevue/utils';
function bind(el, binding) {
const target = resolveTarget(el, binding);

BaseDirective.directiveElement = target;
el.$pEl = target;

el.$_pstyleclass_clicklistener = () => {
if (binding.value.toggleClass) {
Expand Down
3 changes: 1 addition & 2 deletions components/lib/tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ function create(el, options) {
container.style.width = 'fit-content';
}

el.$_pDirectiveElement = container;
BaseDirective.directiveElement = container;
el.$pEl = container;
BaseDirective.handleCSS('tooltip', container, options);

return container;
Expand Down

0 comments on commit 7cb1814

Please sign in to comment.