Skip to content

Commit ea22411

Browse files
committed
primefaces#3178 for overlaypanel
1 parent 15d137f commit ea22411

File tree

3 files changed

+53
-53
lines changed

3 files changed

+53
-53
lines changed

src/main/resources/META-INF/resources/primefaces/core/core.utils.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,29 @@ if (!PrimeFaces.utils) {
99
},
1010

1111
/**
12-
* Removes the overlay from the overlay container (in general cfg.appendTo or document.body).
12+
* Removes the overlay from the appendTo overlay container.
1313
*/
14-
removeDynamicOverlay: function(widget, element, id) {
15-
var container = PrimeFaces.utils.resolveDynamicOverlayContainer(widget);
16-
14+
removeDynamicOverlay: function(widget, element, id, appendTo) {
1715
// if the id contains a ':'
18-
container.children(PrimeFaces.escapeClientId(id)).not(element).remove();
16+
appendTo.children(PrimeFaces.escapeClientId(id)).not(element).remove();
1917

2018
// if the id does NOT contain a ':'
21-
container.children("[id='" + id + "']").not(element).remove();
19+
appendTo.children("[id='" + id + "']").not(element).remove();
20+
},
21+
22+
appendDynamicOverlay: function(widget, element, id, appendTo) {
23+
var elementParent = element.parent();
24+
25+
// skip when the parent currently is already the same
26+
// this likely happens when the dialog is updated directly instead of a container
27+
// as our ajax update mechanism just updates by id
28+
if (!elementParent.is(appendTo)
29+
&& !appendTo.is(element)) {
30+
31+
PrimeFaces.utils.removeDynamicOverlay(widget, element, id, appendTo);
32+
33+
element.appendTo(appendTo);
34+
}
2235
},
2336

2437
addDynamicOverlayModal: function(element, id) {
@@ -36,23 +49,9 @@ if (!PrimeFaces.utils) {
3649

3750
// if the id does NOT contain a ':'
3851
$(document.body).children("[id='" + modalId + "']").remove();
39-
},
40-
41-
appendDynamicOverlay: function(widget, element, id) {
42-
var elementParent = element.parent();
43-
var container = PrimeFaces.utils.resolveDynamicOverlayContainer(widget);
44-
45-
// skip when the parent currently is already the same
46-
// this likely happens when the dialog is updated directly instead of a container
47-
// as our ajax update mechanism just updates by id
48-
if (!elementParent.is(container)
49-
&& !container.is(element)) {
52+
}
5053

51-
PrimeFaces.utils.removeDynamicOverlay(widget, element, id);
5254

53-
element.appendTo(container);
54-
}
55-
}
5655

5756

5857
};

src/main/resources/META-INF/resources/primefaces/core/core.widget.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,17 @@ if (!PrimeFaces.widget) {
137137
this._super(cfg);
138138

139139
if (this.cfg.appendTo) {
140-
PrimeFaces.utils.appendDynamicOverlay(this, this.jq, this.id);
140+
this.appendTo = PrimeFaces.utils.resolveDynamicOverlayContainer(this);
141+
PrimeFaces.utils.appendDynamicOverlay(this, this.jq, this.id, this.appendTo);
141142
}
142143
},
143144

144145
//@Override
145146
refresh: function() {
146147
this._super();
147148

148-
if (this.cfg.appendTo) {
149-
PrimeFaces.utils.removeDynamicOverlay(this, this.jq, this.id);
149+
if (this.appendTo) {
150+
PrimeFaces.utils.removeDynamicOverlay(this, this.jq, this.id, this.appendTo);
150151
}
151152
PrimeFaces.utils.removeDynamicOverlayModal(this.id);
152153

@@ -156,8 +157,8 @@ if (!PrimeFaces.widget) {
156157
destroy: function() {
157158
this._super();
158159

159-
if (this.cfg.appendTo) {
160-
PrimeFaces.utils.removeDynamicOverlay(this, this.jq, this.id);
160+
if (this.appendTo) {
161+
PrimeFaces.utils.removeDynamicOverlay(this, this.jq, this.id, this.appendTo);
161162
}
162163
PrimeFaces.utils.removeDynamicOverlayModal(this.id);
163164
},

src/main/resources/META-INF/resources/primefaces/overlaypanel/overlaypanel.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* PrimeFaces OverlayPanel Widget
33
*/
4-
PrimeFaces.widget.OverlayPanel = PrimeFaces.widget.BaseWidget.extend({
4+
PrimeFaces.widget.OverlayPanel = PrimeFaces.widget.DynamicOverlayWidget.extend({
55

66
init: function(cfg) {
77
this._super(cfg);
@@ -20,28 +20,6 @@ PrimeFaces.widget.OverlayPanel = PrimeFaces.widget.BaseWidget.extend({
2020
this.closerIcon = $('<a href="#" class="ui-overlaypanel-close ui-state-default" href="#"><span class="ui-icon ui-icon-closethick"></span></a>').appendTo(this.jq);
2121
}
2222

23-
// prevent duplicate elements
24-
// the first check is required if the id contains a ':' - See #2485
25-
if(this.jq.length > 1) {
26-
$(document.body).children(this.jqId).remove();
27-
this.jq = $(this.jqId);
28-
}
29-
else {
30-
// this is required if the id does NOT contain a ':' - See #2485
31-
$(document.body).children("[id='" + this.id + "']").not(this.jq).remove();
32-
}
33-
34-
//remove related modality if there is one
35-
var modal = $(this.jqId + '_modal');
36-
if(modal.length > 0) {
37-
modal.remove();
38-
}
39-
40-
if(this.cfg.appendToBody) {
41-
var appendTo = PrimeFaces.expressions.SearchExpressionFacade.resolveComponentsAsSelector(this.cfg.appendTo);;
42-
this.jq.appendTo(appendTo);
43-
}
44-
4523
this.bindCommonEvents();
4624

4725
if(this.cfg.target) {
@@ -53,6 +31,26 @@ PrimeFaces.widget.OverlayPanel = PrimeFaces.widget.BaseWidget.extend({
5331
}
5432
},
5533

34+
//@Override
35+
refresh: function() {
36+
this._super();
37+
38+
// see #setupDialogSupport
39+
if (!this.cfg.appendTo) {
40+
PrimeFaces.utils.removeDynamicOverlay(this, this.jq, this.id, $(document.body));
41+
}
42+
},
43+
44+
//@Override
45+
destroy: function() {
46+
this._super();
47+
48+
// see #setupDialogSupport
49+
if (!this.cfg.appendTo) {
50+
PrimeFaces.utils.removeDynamicOverlay(this, this.jq, this.id, $(document.body));
51+
}
52+
},
53+
5654
bindTargetEvents: function() {
5755
var $this = this;
5856

@@ -320,13 +318,13 @@ PrimeFaces.widget.OverlayPanel = PrimeFaces.widget.BaseWidget.extend({
320318
this.jq.find(':not(:submit):not(:button):input:visible:enabled:first').focus();
321319
},
322320

321+
//@override
323322
enableModality: function() {
323+
this._super();
324+
324325
var $this = this,
325326
doc = $(document);
326327

327-
$(document.body).append('<div id="' + this.id + '_modal" class="ui-widget-overlay ui-overlaypanel-mask"></div>')
328-
.children(this.jqId + '_modal').css('z-index' , this.jq.css('z-index') - 1);
329-
330328
this.blockEvents = 'focus.' + this.id + ' mousedown.' + this.id + ' mouseup.' + this.id;
331329
if(this.targetElement) {
332330
this.targetElement.css('z-index', this.jq.css('z-index'));
@@ -384,12 +382,14 @@ PrimeFaces.widget.OverlayPanel = PrimeFaces.widget.BaseWidget.extend({
384382
});
385383
},
386384

385+
//@override
387386
disableModality: function(){
387+
this._super();
388+
388389
if(this.targetElement) {
389390
this.targetElement.css('z-index', this.targetZindex);
390391
}
391392

392-
$(document.body).children(this.jqId + '_modal').remove();
393393
$(document).off(this.blockEvents).off('keydown.' + this.id);
394394
},
395395

0 commit comments

Comments
 (0)