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

feat(discoverability): add class to bp-content if FF is enabled #1256

Merged
merged 18 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ef60ed1
feat(discoverability): add class to docEl if FF is enabled
ChenCodes Sep 15, 2020
642b282
feat(discoverability): rename class
ChenCodes Sep 15, 2020
4d99ac7
feat(discoverability): move bp-annotations-discoverable to BaseViewer
ChenCodes Sep 16, 2020
9a35183
feat(discoverability): use containerEl instead of rootEl / use nextMode
ChenCodes Sep 16, 2020
2001af7
feat(discoverability): move styles from bp to bp-content
ChenCodes Sep 16, 2020
49f953b
feat(discoverability): move styles together under bp-content
ChenCodes Sep 16, 2020
8d7a55a
feat(discoverability): remove FF check / remove NONE case
ChenCodes Sep 16, 2020
17a7fd7
feat(discoverability): update BaseViewer test
ChenCodes Sep 16, 2020
1bf6525
feat(discoverability): define const for class
ChenCodes Sep 16, 2020
726a22f
feat(discoverability): use empty div / use constant for class
ChenCodes Sep 16, 2020
bb086a4
feat(discoverability): fix test title typo
ChenCodes Sep 16, 2020
1fd882e
feat(discoverability): move classes to constants file
ChenCodes Sep 16, 2020
b2b70e7
feat(discoverability): parameterize tests
ChenCodes Sep 17, 2020
0495b98
feat(discoverability): add pointer events to annotationLayer section
ChenCodes Sep 17, 2020
9038972
feat(discoverability): remove section class from styles
ChenCodes Sep 17, 2020
71ed882
feat(discoverability): abc constants
ChenCodes Sep 17, 2020
65e0648
feat(discoverability): abc constants
ChenCodes Sep 17, 2020
b8e74c6
Merge branch 'master' into add-discoverability-ff-to-preview-sdk
Sep 17, 2020
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
16 changes: 16 additions & 0 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ class BaseViewer extends EventEmitter {
});
}

if (this.options.enableAnnotationsDiscoverability) {
this.containerEl.classList.add('bp-annotations-discoverable');
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
}

this.isSetup = true;
}

Expand Down Expand Up @@ -260,6 +264,7 @@ class BaseViewer extends EventEmitter {
if (this.containerEl) {
this.containerEl.removeEventListener('contextmenu', this.preventDefault);
this.containerEl.innerHTML = '';
this.containerEl.classList.remove('bp-annotations-discoverable');
}

// Destroy the annotator
Expand Down Expand Up @@ -1089,6 +1094,17 @@ class BaseViewer extends EventEmitter {
: nextMode,
);
this.annotationControls.setMode(nextMode);

if (this.options.enableAnnotationsDiscoverability) {
switch (nextMode) {
case AnnotationMode.REGION:
this.containerEl.classList.add('bp-annotations-create--region');
break;
default:
this.containerEl.classList.remove('bp-annotations-create--region');
break;
}
}
}

/**
Expand Down
54 changes: 41 additions & 13 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ describe('lib/viewers/BaseViewer', () => {
sandbox.stub(base, 'finishLoadingSetup');
sandbox.stub(base, 'loadBoxAnnotations').returns(Promise.resolve());
base.options.showAnnotations = true;
base.options.enableAnnotationsDiscoverability = true;

base.setup();

Expand All @@ -81,9 +82,11 @@ describe('lib/viewers/BaseViewer', () => {
},
},
showAnnotations: true,
enableAnnotationsDiscoverability: true,
});

expect(base.containerEl).to.have.class(constants.CLASS_BOX_PREVIEW_CONTENT);
expect(base.containerEl).to.have.class('bp-annotations-discoverable');
expect(base.addCommonListeners).to.be.called;
expect(getIconFromExtensionStub).to.be.called;
expect(base.loadTimeout).to.be.a('number');
Expand Down Expand Up @@ -443,7 +446,13 @@ describe('lib/viewers/BaseViewer', () => {
stubs.fullscreenAddListener = sandbox.stub(fullscreen, 'addListener');
stubs.baseAddListener = sandbox.spy(base, 'addListener');
stubs.documentAddEventListener = sandbox.stub(document.defaultView, 'addEventListener');
base.containerEl = document;
base.containerEl = {
addEventListener: sandbox.stub(),
removeEventListener: sandbox.stub(),
classList: {
remove: sandbox.stub(),
},
};
});

it('should append common event listeners', () => {
Expand All @@ -460,11 +469,6 @@ describe('lib/viewers/BaseViewer', () => {
can_download: false,
};

base.containerEl = {
addEventListener: sandbox.stub(),
removeEventListener: sandbox.stub(),
};

base.addCommonListeners();

expect(base.containerEl.addEventListener).to.be.calledWith('contextmenu', sinon.match.func);
Expand Down Expand Up @@ -627,6 +631,7 @@ describe('lib/viewers/BaseViewer', () => {

expect(base.removeAllListeners).to.be.called;
expect(base.containerEl.innerHTML).to.equal('');
expect(base.containerEl).to.not.have.class('bp-annotations-discoverable');
expect(base.destroyed).to.be.true;
expect(base.emit).to.be.calledWith('destroy');
});
Expand Down Expand Up @@ -1858,24 +1863,26 @@ describe('lib/viewers/BaseViewer', () => {
destroy: sandbox.stub(),
setMode: sandbox.stub(),
};
});

it('should call toggleAnnotationMode and setMode', () => {
base.containerEl = {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
classList: {
add: sandbox.stub(),
remove: sandbox.stub(),
},
removeEventListener: sandbox.stub(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is removeEventListener needed?

Copy link
Contributor Author

@ChenCodes ChenCodes Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it looks like it's needed as this error shows up if I remove that line:

 undefined is not a constructor (evaluating 'this.containerEl.removeEventListener('contextmenu', this.preventDefault)')

};
base.annotator = {
toggleAnnotationMode: sandbox.stub(),
};
});

it('should call toggleAnnotationMode and setMode', () => {
base.handleAnnotationControlsClick({ mode: AnnotationMode.REGION });

expect(base.annotator.toggleAnnotationMode).to.be.calledWith(AnnotationMode.REGION);
expect(base.annotationControls.setMode).to.be.calledWith(AnnotationMode.REGION);
});

it('should call toggleAnnotationMode with appropriate mode if discoverability is enabled', () => {
base.annotator = {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
toggleAnnotationMode: sandbox.stub(),
};

base.options.enableAnnotationsDiscoverability = false;
base.handleAnnotationControlsClick({ mode: AnnotationMode.NONE });
expect(base.annotator.toggleAnnotationMode).to.be.calledWith(AnnotationMode.NONE);
Expand All @@ -1884,5 +1891,26 @@ describe('lib/viewers/BaseViewer', () => {
base.handleAnnotationControlsClick({ mode: AnnotationMode.NONE });
expect(base.annotator.toggleAnnotationMode).to.be.calledWith(AnnotationMode.REGION);
});

it('should add create region class if discoverability is enabled and mode is REGION', () => {
base.options.enableAnnotationsDiscoverability = true;
base.handleAnnotationControlsClick({ mode: AnnotationMode.REGION });

expect(base.containerEl.classList.add).to.be.calledWith('bp-annotations-create--region');
});

it('should add create region class if discoverability is enabled and mode is NONE', () => {
base.options.enableAnnotationsDiscoverability = true;
base.handleAnnotationControlsClick({ mode: AnnotationMode.NONE });

expect(base.containerEl.classList.add).to.be.calledWith('bp-annotations-create--region');
});

it('should remove create region class if discoverability is enabled and mode is HIGHLIGHT', () => {
base.options.enableAnnotationsDiscoverability = true;
base.handleAnnotationControlsClick({ mode: AnnotationMode.HIGHLIGHT });

expect(base.containerEl.classList.remove).to.be.calledWith('bp-annotations-create--region');
});
});
});
26 changes: 23 additions & 3 deletions src/lib/viewers/doc/_docBase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,27 @@ $thumbnail-sidebar-width: 226px;
}
}

// Hide the toggle thumbnails button when in fullscreen
.bp-content.bp-is-fullscreen .bp-toggle-thumbnails-icon {
display: none;
.bp-content {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
&.bp-annotations-discoverable {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
.textLayer {
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
pointer-events: none;

span {
pointer-events: auto;
}
}

&.bp-annotations-create--region {
.textLayer {
span {
pointer-events: none;
}
}
}
}

// Hide the toggle thumbnails button when in fullscreen
&.bp-is-fullscreen .bp-toggle-thumbnails-icon {
display: none;
}
}