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 14 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
2 changes: 2 additions & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const CLASS_IS_SELECTABLE = 'bp-is-selectable';
export const CLASS_IS_BUFFERING = 'bp-is-buffering';
export const CLASS_DARK = 'bp-dark';
export const CLASS_CRAWLER = 'bp-crawler';
export const CLASS_ANNOTATIONS_DISCOVERABLE = 'bp-annotations-discoverable';
export const CLASS_ANNOTATIONS_CREATE_REGION = 'bp-annotations-create--region';
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved

export const SELECTOR_BOX_PREVIEW_CONTAINER = `.${CLASS_BOX_PREVIEW_CONTAINER}`;
export const SELECTOR_BOX_PREVIEW = `.${CLASS_BOX_PREVIEW}`;
Expand Down
18 changes: 18 additions & 0 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
} from '../util';
import {
ANNOTATOR_EVENT,
CLASS_ANNOTATIONS_CREATE_REGION,
CLASS_ANNOTATIONS_DISCOVERABLE,
CLASS_BOX_PREVIEW_MOBILE,
CLASS_HIDDEN,
FILE_OPTION_START,
Expand Down Expand Up @@ -214,6 +216,10 @@ class BaseViewer extends EventEmitter {
});
}

if (this.options.enableAnnotationsDiscoverability) {
this.containerEl.classList.add(CLASS_ANNOTATIONS_DISCOVERABLE);
}

this.isSetup = true;
}

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

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

if (this.options.enableAnnotationsDiscoverability) {
switch (nextMode) {
case AnnotationMode.REGION:
this.containerEl.classList.add(CLASS_ANNOTATIONS_CREATE_REGION);
break;
default:
this.containerEl.classList.remove(CLASS_ANNOTATIONS_CREATE_REGION);
break;
}
}
}

/**
Expand Down
48 changes: 34 additions & 14 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let base;
let containerEl;
let stubs = {};
const sandbox = sinon.sandbox.create();
const { ANNOTATOR_EVENT } = constants;
const { ANNOTATOR_EVENT, CLASS_ANNOTATIONS_CREATE_REGION, CLASS_ANNOTATIONS_DISCOVERABLE } = constants;

describe('lib/viewers/BaseViewer', () => {
before(() => {
Expand Down 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(CLASS_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(CLASS_ANNOTATIONS_DISCOVERABLE);
expect(base.destroyed).to.be.true;
expect(base.emit).to.be.calledWith('destroy');
});
Expand Down Expand Up @@ -654,6 +659,9 @@ describe('lib/viewers/BaseViewer', () => {
base.containerEl = {
addEventListener: sandbox.stub(),
removeEventListener: sandbox.stub(),
classList: {
remove: sandbox.stub(),
},
};

base.destroy();
Expand Down Expand Up @@ -1858,24 +1866,20 @@ describe('lib/viewers/BaseViewer', () => {
destroy: sandbox.stub(),
setMode: sandbox.stub(),
};
});

it('should call toggleAnnotationMode and setMode', () => {
base.containerEl = document.createElement('div');
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 +1888,21 @@ 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).to.have.class(CLASS_ANNOTATIONS_CREATE_REGION);
});

[AnnotationMode.NONE, AnnotationMode.HIGHLIGHT].forEach(mode => {
it(`should remove create region class if discoverability is enabled and mode is ${mode}`, () => {
base.options.enableAnnotationsDiscoverability = true;
base.handleAnnotationControlsClick({ mode });

expect(base.containerEl).to.not.have.class(CLASS_ANNOTATIONS_CREATE_REGION);
});
});
});
});
32 changes: 29 additions & 3 deletions src/lib/viewers/doc/_docBase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,33 @@ $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;
}
}

.annotationLayer {
section {
pointer-events: none;
}
}
ChenCodes marked this conversation as resolved.
Show resolved Hide resolved
}
}

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