@@ -22,7 +22,6 @@ import {ContentType as GroupContentType} from "./panel/group/content-type";
22
22
* @api
23
23
*/
24
24
export default class Panel implements PanelInterface {
25
- public stageReady : KnockoutObservable < boolean > = ko . observable ( false ) ;
26
25
public groups : KnockoutObservableArray < any > = ko . observableArray ( [ ] ) ;
27
26
public searchResults : KnockoutObservableArray < any > = ko . observableArray ( [ ] ) ;
28
27
public isCollapsed : KnockoutObservable < boolean > = ko . observable ( false ) ;
@@ -53,13 +52,6 @@ export default class Panel implements PanelInterface {
53
52
*/
54
53
public afterRender ( element : Element ) : void {
55
54
this . element = element ;
56
- this . stageReady . subscribe (
57
- ( data : boolean ) => {
58
- if ( data ) {
59
- this . onScroll ( ) ;
60
- }
61
- } ,
62
- ) ;
63
55
}
64
56
65
57
/**
@@ -68,7 +60,7 @@ export default class Panel implements PanelInterface {
68
60
public initListeners ( ) : void {
69
61
events . on ( "stage:" + this . id + ":readyAfter" , ( ) => {
70
62
this . populateContentTypes ( ) ;
71
- this . stageReady ( true ) ;
63
+ this . onScroll ( ) ;
72
64
this . isVisible ( true ) ;
73
65
} ) ;
74
66
}
@@ -148,34 +140,36 @@ export default class Panel implements PanelInterface {
148
140
const panel = $ ( this . element ) ;
149
141
const stage = panel . siblings ( ".pagebuilder-stage" ) ;
150
142
$ ( window ) . scroll ( function ( ) {
151
- const panelOffsetTop = panel . offset ( ) . top ;
152
- const stageOffsetTop = stage . offset ( ) . top ;
153
- const panelHeight = panel . outerHeight ( ) ;
154
- const stageHeight = stage . outerHeight ( ) ;
155
- const currentPanelBottom = Math . round ( panelOffsetTop + panel . outerHeight ( true ) - $ ( this ) . scrollTop ( ) ) ;
156
- const currentStageBottom = Math . round ( stageOffsetTop + stage . outerHeight ( true ) - $ ( this ) . scrollTop ( ) ) ;
157
- const currentPanelTop = Math . round ( panelOffsetTop - $ ( this ) . scrollTop ( ) ) ;
158
- const currentStageTop = Math . round ( stageOffsetTop - $ ( this ) . scrollTop ( ) ) ;
159
- // When panel height is less than stage, begin stickiness
160
- if ( panelHeight <= stageHeight && pageActions . hasClass ( "_fixed" ) ) {
161
- const pageActionsHeight = pageActions . outerHeight ( ) + 15 ;
162
- // When scroll reaches top of stage, stick panel to top
163
- if ( currentStageTop <= pageActionsHeight ) {
164
- // When panel reaches bottom of stage, stick panel to bottom of stage
165
- if ( currentPanelBottom >= currentStageBottom && currentPanelTop <= pageActionsHeight ) {
166
- self . isStickyBottom ( true ) ;
167
- self . isStickyTop ( false ) ;
143
+ if ( panel && panel . offset ( ) ) {
144
+ const panelOffsetTop = panel . offset ( ) . top ;
145
+ const stageOffsetTop = stage . offset ( ) . top ;
146
+ const panelHeight = panel . outerHeight ( ) ;
147
+ const stageHeight = stage . outerHeight ( ) ;
148
+ const currentPanelBottom = Math . round ( panelOffsetTop + panel . outerHeight ( true ) - $ ( this ) . scrollTop ( ) ) ;
149
+ const currentStageBottom = Math . round ( stageOffsetTop + stage . outerHeight ( true ) - $ ( this ) . scrollTop ( ) ) ;
150
+ const currentPanelTop = Math . round ( panelOffsetTop - $ ( this ) . scrollTop ( ) ) ;
151
+ const currentStageTop = Math . round ( stageOffsetTop - $ ( this ) . scrollTop ( ) ) ;
152
+ // When panel height is less than stage, begin stickiness
153
+ if ( panelHeight <= stageHeight && pageActions . hasClass ( "_fixed" ) ) {
154
+ const pageActionsHeight = pageActions . outerHeight ( ) + 15 ;
155
+ // When scroll reaches top of stage, stick panel to top
156
+ if ( currentStageTop <= pageActionsHeight ) {
157
+ // When panel reaches bottom of stage, stick panel to bottom of stage
158
+ if ( currentPanelBottom >= currentStageBottom && currentPanelTop <= pageActionsHeight ) {
159
+ self . isStickyBottom ( true ) ;
160
+ self . isStickyTop ( false ) ;
161
+ } else {
162
+ self . isStickyBottom ( false ) ;
163
+ self . isStickyTop ( true ) ;
164
+ }
168
165
} else {
169
166
self . isStickyBottom ( false ) ;
170
- self . isStickyTop ( true ) ;
167
+ self . isStickyTop ( false ) ;
171
168
}
172
169
} else {
173
170
self . isStickyBottom ( false ) ;
174
171
self . isStickyTop ( false ) ;
175
172
}
176
- } else {
177
- self . isStickyBottom ( false ) ;
178
- self . isStickyTop ( false ) ;
179
173
}
180
174
} ) ;
181
175
}
0 commit comments