Skip to content

Commit b830350

Browse files
committed
primefaces#3178 for sidebar
1 parent 1c35c42 commit b830350

File tree

3 files changed

+41
-71
lines changed

3 files changed

+41
-71
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ if (!PrimeFaces.utils) {
3737
addDynamicOverlayModal: function(element, id) {
3838
var modalId = id + '_modal';
3939

40-
$(document.body).append('<div id="' + modalId + '" class="ui-widget-overlay ui-dialog-mask"></div>');
41-
$(document.body).children(PrimeFaces.escapeClientId(modalId)).css('z-index' , element.css('z-index') - 1);
40+
var modalOverlay = $(document.body).append('<div id="' + modalId + '" class="ui-widget-overlay ui-dialog-mask"></div>');
41+
modalOverlay.css('z-index' , element.css('z-index') - 1);
42+
43+
return modalOverlay;
4244
},
4345

4446
removeDynamicOverlayModal: function(id) {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ if (!PrimeFaces.widget) {
151151
}
152152
PrimeFaces.utils.removeDynamicOverlayModal(this.id);
153153

154+
this.appendTo = null;
155+
this.modalOverlay = null;
154156
},
155157

156158
//@Override
@@ -161,14 +163,18 @@ if (!PrimeFaces.widget) {
161163
PrimeFaces.utils.removeDynamicOverlay(this, this.jq, this.id, this.appendTo);
162164
}
163165
PrimeFaces.utils.removeDynamicOverlayModal(this.id);
166+
167+
this.appendTo = null;
168+
this.modalOverlay = null;
164169
},
165170

166171
enableModality: function() {
167-
PrimeFaces.utils.addDynamicOverlayModal(this.jq, this.id);
172+
this.modalOverlay = PrimeFaces.utils.addDynamicOverlayModal(this.jq, this.id);
168173
},
169174

170175
disableModality: function(){
171176
PrimeFaces.utils.removeDynamicOverlayModal(this.id);
177+
this.modalOverlay = null;
172178
}
173179
});
174180

Lines changed: 30 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,24 @@
11
/**
22
* PrimeFaces Sidebar Widget
33
*/
4-
PrimeFaces.widget.Sidebar = PrimeFaces.widget.BaseWidget.extend({
5-
4+
PrimeFaces.widget.Sidebar = PrimeFaces.widget.DynamicOverlayWidget.extend({
5+
66
init: function(cfg) {
77
this._super(cfg);
8-
8+
99
this.closeIcon = this.jq.children('.ui-sidebar-close');
1010
this.cfg.baseZIndex = this.cfg.baseZIndex||0;
11-
12-
if(this.cfg.appendTo) {
13-
this.parent = this.jq.parent();
14-
this.targetParent = PrimeFaces.expressions.SearchExpressionFacade.resolveComponentsAsSelector(this.cfg.appendTo);
15-
16-
if (!this.parent.is(this.targetParent)) {
17-
this.jq.appendTo(this.targetParent);
18-
}
19-
}
20-
21-
//remove related modality if there is one
22-
var modal = $(this.jqId + '_modal');
23-
if(modal.length > 0) {
24-
modal.remove();
25-
}
26-
11+
2712
//aria
2813
this.applyARIA();
2914

3015
if(this.cfg.visible){
3116
this.show();
3217
}
33-
18+
3419
this.bindEvents();
3520
},
36-
37-
//override
38-
refresh: function(cfg) {
39-
this.mask = false;
40-
41-
if(cfg.appendTo) {
42-
var jqs = $('[id=' + cfg.id.replace(/:/g,"\\:") + ']');
43-
if(jqs.length > 1) {
44-
PrimeFaces.expressions.SearchExpressionFacade.resolveComponentsAsSelector(cfg.appendTo).children(this.jqId).remove();
45-
}
46-
}
4721

48-
this.init(cfg);
49-
},
50-
5122
bindEvents: function() {
5223
var $this = this;
5324

@@ -64,19 +35,19 @@ PrimeFaces.widget.Sidebar = PrimeFaces.widget.BaseWidget.extend({
6435
e.preventDefault();
6536
});
6637
},
67-
38+
6839
show: function() {
6940
if(this.isVisible()) {
7041
return;
7142
}
7243

7344
this.jq.addClass('ui-sidebar-active');
7445
this.jq.css('z-index', this.cfg.baseZIndex + (++PrimeFaces.zindex));
75-
46+
7647
this.postShow();
7748
this.enableModality();
7849
},
79-
50+
8051
postShow: function() {
8152
PrimeFaces.invokeDeferredRenders(this.id);
8253

@@ -90,7 +61,7 @@ PrimeFaces.widget.Sidebar = PrimeFaces.widget.BaseWidget.extend({
9061
,'aria-live': 'polite'
9162
});
9263
},
93-
64+
9465
hide: function() {
9566
if(!this.isVisible()) {
9667
return;
@@ -100,11 +71,11 @@ PrimeFaces.widget.Sidebar = PrimeFaces.widget.BaseWidget.extend({
10071
this.onHide();
10172
this.disableModality();
10273
},
103-
74+
10475
isVisible: function() {
10576
return this.jq.hasClass('ui-sidebar-active');
10677
},
107-
78+
10879
onHide: function(event, ui) {
10980
this.jq.attr({
11081
'aria-hidden': true
@@ -122,39 +93,30 @@ PrimeFaces.widget.Sidebar = PrimeFaces.widget.BaseWidget.extend({
12293
else
12394
this.show();
12495
},
125-
96+
97+
//@override
12698
enableModality: function() {
127-
if(!this.mask) {
128-
var $this = this,
129-
docBody = $(document.body);
130-
131-
this.mask = $('<div id="' + this.id + '_modal" class="ui-widget-overlay ui-sidebar-mask"></div>');
132-
this.mask.css('z-index' , this.jq.css('z-index') - 1);
133-
docBody.append(this.mask);
134-
135-
this.mask.on('click.sidebar-mask', function() {
136-
$this.hide();
137-
});
138-
139-
if(this.cfg.blockScroll) {
140-
docBody.addClass('ui-overflow-hidden');
141-
}
99+
this._super();
100+
101+
var $this = this;
102+
this.modalOverlay.on('click', function() {
103+
$this.hide();
104+
});
105+
106+
if (this.cfg.blockScroll) {
107+
$(document.body).addClass('ui-overflow-hidden');
142108
}
143109
},
144-
110+
111+
//@override
145112
disableModality: function() {
146-
if(this.mask) {
147-
var docBody = $(document.body);
148-
this.mask.off('click.sidebar-mask');
149-
this.mask.remove();
150-
151-
if(this.cfg.blockScroll) {
152-
docBody.removeClass('ui-overflow-hidden');
153-
}
154-
this.mask = null;
113+
this._super();
114+
115+
if (this.cfg.blockScroll) {
116+
$(document.body).removeClass('ui-overflow-hidden');
155117
}
156118
},
157-
119+
158120
applyARIA: function() {
159121
this.jq.attr({
160122
'role': 'dialog'
@@ -163,5 +125,5 @@ PrimeFaces.widget.Sidebar = PrimeFaces.widget.BaseWidget.extend({
163125

164126
this.closeIcon.attr('role', 'button');
165127
}
166-
128+
167129
});

0 commit comments

Comments
 (0)