Skip to content

Commit 19b27bc

Browse files
committed
primefaces#3178 first prototype
1 parent 286e764 commit 19b27bc

File tree

4 files changed

+114
-34
lines changed

4 files changed

+114
-34
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@
446446
<include>${project.build.directory}/classes/META-INF/resources/primefaces/core/core.env.js</include>
447447
<include>${project.build.directory}/classes/META-INF/resources/primefaces/core/core.ajax.js</include>
448448
<include>${project.build.directory}/classes/META-INF/resources/primefaces/core/core.expressions.js</include>
449+
<include>${project.build.directory}/classes/META-INF/resources/primefaces/core/core.utils.js</include>
449450
<include>${project.build.directory}/classes/META-INF/resources/primefaces/core/core.widget.js</include>
450451

451452
<include>${project.build.directory}/classes/META-INF/resources/primefaces/ajaxstatus/ajaxstatus.js</include>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
if (!PrimeFaces.utils) {
2+
3+
PrimeFaces.utils = {
4+
5+
resolveDynamicOverlayContainer: function(widget) {
6+
return widget.cfg.appendTo
7+
? PrimeFaces.expressions.SearchExpressionFacade.resolveComponentsAsSelector(widget.cfg.appendTo)
8+
: $(document.body);
9+
},
10+
11+
/**
12+
* Removes the overlay from the overlay container (in general cfg.appendTo or document.body).
13+
*/
14+
removeDynamicOverlay: function(widget, element, id) {
15+
var container = PrimeFaces.utils.resolveDynamicOverlayContainer(widget);
16+
17+
// if the id contains a ':'
18+
container.children(PrimeFaces.escapeClientId(id)).not(element).remove();
19+
20+
// if the id does NOT contain a ':'
21+
container.children("[id='" + id + "']").not(element).remove();
22+
},
23+
24+
addDynamicOverlayModal: function(element, id) {
25+
var modalId = id + '_modal';
26+
27+
$(document.body).append('<div id="' + modalId + '" class="ui-widget-overlay ui-dialog-mask"></div>');
28+
$(document.body).children(PrimeFaces.escapeClientId(modalId)).css('z-index' , element.css('z-index') - 1);
29+
},
30+
31+
removeDynamicOverlayModal: function(id) {
32+
var modalId = id + '_modal';
33+
34+
// if the id contains a ':'
35+
$(PrimeFaces.escapeClientId(modalId)).remove();
36+
37+
// if the id does NOT contain a ':'
38+
$(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)) {
50+
51+
PrimeFaces.utils.removeDynamicOverlay(widget, element, id);
52+
53+
element.appendTo(container);
54+
}
55+
}
56+
57+
58+
};
59+
60+
}

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

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// Copy the properties over onto the new prototype
2222
for (var name in prop) {
2323
// Check if we're overwriting an existing function
24-
prototype[name] = typeof prop[name] == "function" &&
24+
prototype[name] = typeof prop[name] == "function" &&
2525
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
2626
(function(name, fn){
2727
return function() {
@@ -33,7 +33,7 @@
3333

3434
// The method only need to be bound temporarily, so we
3535
// remove it when we're done executing
36-
var ret = fn.apply(this, arguments);
36+
var ret = fn.apply(this, arguments);
3737
this._super = tmp;
3838

3939
return ret;
@@ -119,23 +119,64 @@ if (!PrimeFaces.widget) {
119119
removeScriptElement: function(clientId) {
120120
$(PrimeFaces.escapeClientId(clientId) + '_s').remove();
121121
},
122-
122+
123123
hasBehavior: function(event) {
124124
if(this.cfg.behaviors) {
125125
return this.cfg.behaviors[event] != undefined;
126126
}
127127

128128
return false;
129+
}
130+
131+
});
132+
133+
PrimeFaces.widget.DynamicOverlayWidget = PrimeFaces.widget.BaseWidget.extend({
134+
135+
//@Override
136+
init: function(cfg) {
137+
this._super(cfg);
138+
139+
if (this.cfg.appendTo) {
140+
PrimeFaces.utils.appendDynamicOverlay(this, this.jq, this.id);
141+
}
142+
},
143+
144+
//@Override
145+
refresh: function() {
146+
this._super();
147+
148+
if (this.cfg.appendTo) {
149+
PrimeFaces.utils.removeDynamicOverlay(this, this.jq, this.id);
150+
}
151+
PrimeFaces.utils.removeDynamicOverlayModal(this.id);
152+
153+
},
154+
155+
//@Override
156+
destroy: function() {
157+
this._super();
158+
159+
if (this.cfg.appendTo) {
160+
PrimeFaces.utils.removeDynamicOverlay(this, this.jq, this.id);
161+
}
162+
PrimeFaces.utils.removeDynamicOverlayModal(this.id);
129163
},
130164

165+
enableModality: function() {
166+
PrimeFaces.utils.addDynamicOverlayModal(this.jq, this.id);
167+
},
168+
169+
disableModality: function(){
170+
PrimeFaces.utils.removeDynamicOverlayModal(this.id);
171+
}
131172
});
132173

133174
/**
134175
* Widgets that require to be visible to initialize properly for hidden container support
135176
*/
136177
PrimeFaces.widget.DeferredWidget = PrimeFaces.widget.BaseWidget.extend({
137178

138-
renderDeferred: function() {
179+
renderDeferred: function() {
139180
if(this.jq.is(':visible')) {
140181
this._render();
141182
this.postRender();
@@ -174,6 +215,7 @@ if (!PrimeFaces.widget) {
174215

175216
},
176217

218+
//@Override
177219
destroy: function() {
178220
this._super();
179221
PrimeFaces.removeDeferredRenders(this.id);

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

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

66
init: function(cfg) {
77
this._super(cfg);
@@ -43,29 +43,11 @@ PrimeFaces.widget.Dialog = PrimeFaces.widget.BaseWidget.extend({
4343
this.setupResizable();
4444
}
4545

46-
if(this.cfg.appendTo) {
47-
this.parent = this.jq.parent();
48-
this.targetParent = PrimeFaces.expressions.SearchExpressionFacade.resolveComponentsAsSelector(this.cfg.appendTo);
49-
50-
// skip when the parent currently is already the same
51-
// this likely happens when the dialog is updated directly instead of a container
52-
// as our ajax update mechanism just updates by id
53-
if (!this.parent.is(this.targetParent)) {
54-
this.jq.appendTo(this.targetParent);
55-
}
56-
}
57-
5846
//docking zone
5947
if($(document.body).children('.ui-dialog-docking-zone').length === 0) {
6048
$(document.body).append('<div class="ui-dialog-docking-zone"></div>');
6149
}
6250

63-
//remove related modality if there is one
64-
var modal = $(this.jqId + '_modal');
65-
if(modal.length > 0) {
66-
modal.remove();
67-
}
68-
6951
//aria
7052
this.applyARIA();
7153

@@ -85,13 +67,6 @@ PrimeFaces.widget.Dialog = PrimeFaces.widget.BaseWidget.extend({
8567

8668
$(document).off('keydown.dialog_' + cfg.id);
8769

88-
if(cfg.appendTo) {
89-
var jqs = $('[id=' + cfg.id.replace(/:/g,"\\:") + ']');
90-
if(jqs.length > 1) {
91-
PrimeFaces.expressions.SearchExpressionFacade.resolveComponentsAsSelector(cfg.appendTo).children(this.jqId).remove();
92-
}
93-
}
94-
9570
if(this.minimized) {
9671
var dockingZone = $(document.body).children('.ui-dialog-docking-zone');
9772
if(dockingZone.length && dockingZone.children(this.jqId).length) {
@@ -141,13 +116,13 @@ PrimeFaces.widget.Dialog = PrimeFaces.widget.BaseWidget.extend({
141116
this.content.css('max-height', maxHeight + 'px');
142117
},
143118

119+
//@override
144120
enableModality: function() {
121+
this._super();
122+
145123
var $this = this,
146124
doc = $(document);
147125

148-
$(document.body).append('<div id="' + this.id + '_modal" class="ui-widget-overlay ui-dialog-mask"></div>')
149-
.children(this.jqId + '_modal').css('z-index' , this.jq.css('z-index') - 1);
150-
151126
//Disable tabbing out of modal dialog and stop events from targets outside of dialog
152127
doc.on('keydown.' + this.id,
153128
function(event) {
@@ -199,8 +174,10 @@ PrimeFaces.widget.Dialog = PrimeFaces.widget.BaseWidget.extend({
199174
});
200175
},
201176

177+
//@override
202178
disableModality: function(){
203-
$(document.body).children(this.jqId + '_modal').remove();
179+
this._super();
180+
204181
$(document).off(this.blockEvents).off('keydown.' + this.id);
205182
},
206183

0 commit comments

Comments
 (0)