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