Skip to content

Commit

Permalink
Fix #11700: Widgets with trigger/target bind for removal
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Mar 29, 2024
1 parent 21eccd1 commit 5192735
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,8 @@ if (!PrimeFaces.widget) {
//remove script tag
this.removeScriptElement(this.id);

if (this.widgetVar) {
var $this = this;
this.jq.on("remove", function() {
PrimeFaces.detachedWidgets.push($this.widgetVar);
});
}
// clean up the widget if its DOM element is removed from the DOM
this.bindDomRemovalEvent(this.jq);
},

/**
Expand Down Expand Up @@ -585,6 +581,23 @@ if (!PrimeFaces.widget) {
}

return this.cfg.formId;
},

/**
* Registers a DOM element such that its removal from the DOM results in the widget becoming "detached,"
* subsequently leading to its removal upon completion of the AJAX call.
*
* @param {JQuery | HTMLElement} watchElement The HTML element that if removed from the DOM will detach this widget.
* @since 14.0.0
*/
bindDomRemovalEvent: function(watchElement) {
if (this.widgetVar) {
var $this = this;
var jq = $(watchElement);
jq.off("remove.widget").on("remove.widget", function() {
PrimeFaces.detachedWidgets.push($this.widgetVar);
});
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ PrimeFaces.widget.Menu = PrimeFaces.widget.BaseWidget.extend({
var $this = this;

this.trigger = PrimeFaces.expressions.SearchExpressionFacade.resolveComponentsAsSelector(this.jq, this.cfg.trigger);

// if the trigger is removed from the DOM we should destroy this menu widget
this.bindDomRemovalEvent(this.trigger);

//mark trigger and descendants of trigger as a trigger for a primefaces overlay
this.trigger.data('primefaces-overlay-target', true).find('*').data('primefaces-overlay-target', true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ PrimeFaces.widget.Sticky = PrimeFaces.widget.BaseWidget.extend({
height: this.target.height()
};

// if the target is removed from the DOM we should destroy this widget
this.bindDomRemovalEvent(this.target);
this.bindEvents();
},

Expand Down

0 comments on commit 5192735

Please sign in to comment.