Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix viewer scrollable container #237

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/incito-browser/__tests__/incito.test-jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Incito', () => {

// @ts-expect-error can't treat the json import as const 🤷‍♀️
const incito: IIncito = data;
const incitoViewer = new Incito(main, {incito});
const incitoViewer = new Incito(main, {incito}, '');

expect(() => incitoViewer.start()).not.toThrow();

Expand Down
13 changes: 10 additions & 3 deletions lib/incito-browser/incito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ export default class Incito extends MicroEvent<{
sectionHidden: [{sectionId: string; sectionPosition: number}];
}> {
containerEl: HTMLElement;
scrollableContainer: string;
incito: IIncito;
el: HTMLDivElement;
ids: Record<string, unknown>;
Expand All @@ -707,11 +708,13 @@ export default class Incito extends MicroEvent<{
sectionVisibility: Map<HTMLElement, boolean>;
constructor(
containerEl: HTMLElement,
{incito, canLazyload}: {incito: IIncito; canLazyload?: boolean}
{incito, canLazyload}: {incito: IIncito; canLazyload?: boolean},
scrollableContainer: string
) {
super();

this.containerEl = containerEl;
this.scrollableContainer = scrollableContainer;
this.incito = incito;
this.el = document.createElement('div');
this.ids = {};
Expand Down Expand Up @@ -920,6 +923,10 @@ export default class Incito extends MicroEvent<{
window.addEventListener('pagehide', this.handlePageHide);
window.addEventListener('beforeunload', this.handleBeforeUnload);

const scrollableContainerEl = this.scrollableContainer
? document.querySelector(this.scrollableContainer)
: null;

this.sectionObserver = new IntersectionObserver(
(entries) =>
entries.forEach(({target, isIntersecting: newVisibility}) => {
Expand All @@ -932,7 +939,7 @@ export default class Incito extends MicroEvent<{
this.sectionVisibility.set(target, newVisibility);
this.triggerSectionVisibility(target, newVisibility);
}),
{rootMargin: '5px 0px'}
{rootMargin: '5px 0px', root: scrollableContainerEl}
);
this.lazyObserver = new IntersectionObserver(
(entries) => {
Expand All @@ -943,7 +950,7 @@ export default class Incito extends MicroEvent<{
}
});
},
{rootMargin: '500px 0px'}
{rootMargin: '500px 0px', root: scrollableContainerEl}
);
this.videoObserver = new IntersectionObserver(
(entries) => {
Expand Down
3 changes: 3 additions & 0 deletions lib/kits/core-ui/incito-publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ const IncitoPublication = (
// @ts-expect-error
bootstrapper = new Bootstrapper(options);
bootstrapper.enableLazyLoading = scriptEls.enableLazyload;
bootstrapper.scrollableContainer = scriptEls.enableSidebar
? '.incito'
: '.sgn__incito';

const data = await bootstrapper.fetch();

Expand Down
15 changes: 10 additions & 5 deletions lib/kits/incito-publication/bootstrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class Bootstrapper {
featureLabels = this.getFeatureLabels();
versionsSupported = ['1.0.0'];
enableLazyLoading = false;
scrollableContainer: string;
options: BootstrapperInit;
maxWidth: number;
// @ts-expect-error
Expand Down Expand Up @@ -182,11 +183,15 @@ export default class Bootstrapper {
);
}

const viewer = new Viewer(this.options.el, {
details,
incito,
eventTracker: this.options.eventTracker
});
const viewer = new Viewer(
this.options.el,
{
details,
incito,
eventTracker: this.options.eventTracker
},
this.scrollableContainer
);
const controls = new Controls(viewer);

viewer.incito.bind('destroyed', controls.destroy);
Expand Down
17 changes: 12 additions & 5 deletions lib/kits/incito-publication/viewer.test-jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ describe('SGN.IncitoPublicationKit.Viewer', () => {

const mountPoint = document.createElement('div');

const viewer = new Viewer(mountPoint, {
details: {id: 'incito-id', types: ['paged', 'incito']} as V2Catalog,
incito: dummyIncito,
eventTracker: fakeEventTracker as any
});
const viewer = new Viewer(
mountPoint,
{
details: {
id: 'incito-id',
types: ['paged', 'incito']
} as V2Catalog,
incito: dummyIncito,
eventTracker: fakeEventTracker as any
},
''
);

viewer.start();

Expand Down
18 changes: 14 additions & 4 deletions lib/kits/incito-publication/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ class Viewer extends MicroEvent {
options: ViewerInit;
incito: Incito;
_eventTracking: EventTracking;
constructor(el: HTMLElement, options: ViewerInit) {
scrollableContainer: string;
constructor(
el: HTMLElement,
options: ViewerInit,
scrollableContainer: string
) {
super();

this.el = el;
this.options = options;
this.incito = new Incito(this.el, {
incito: this.options.incito
});
this.scrollableContainer = scrollableContainer;
this.incito = new Incito(
this.el,
{
incito: this.options.incito
},
this.scrollableContainer
);
this._eventTracking = new EventTracking(
this.options.eventTracker,
this.options.details
Expand Down
Loading