Skip to content

Commit c4b4a40

Browse files
author
Mingze
authored
feat(header): Remove header buttons (#404)
* feat(header): Remove header buttons * feat(header): Remove selectors
1 parent c1dbb06 commit c4b4a40

11 files changed

+2
-320
lines changed

i18n/en-US.properties

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
# Accessibility message for button that toggles drawing annotation mode
2-
ba.annotationDrawToggle = Drawing annotation mode
31
# Accessibility message for button that toggles highlight annotation mode
42
ba.annotationHighlightToggle = Highlight text
5-
# Accessibility message for button that toggles point annotation mode
6-
ba.annotationPointToggle = Point annotation mode
73
# Error message when Authorizing
84
ba.annotationsAuthError = Your session has expired. Please refresh the page
9-
# Label for the Cancel button
10-
ba.annotationsCancel = Cancel
115
# Label for the close button
126
ba.annotationsClose = Close
137
# Error message when creating
148
ba.annotationsCreateError = We’re sorry, the annotation could not be created.
159
# Error message when deleting an annotation
1610
ba.annotationsDeleteError = We’re sorry, the annotation could not be deleted.
17-
# Label for the Done button
18-
ba.annotationsDone = Done
1911
# Error message when loading
2012
ba.annotationsLoadError = We’re sorry, annotations failed to load for this file
2113
# Label for the post button

src/constants.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ export const CLASS_ANNOTATION_DRAW_MODE = 'ba-draw-mode';
6565
export const SELECTOR_ANNOTATION_DRAW_MODE = `.${CLASS_ANNOTATION_DRAW_MODE}`;
6666
export const CLASS_ANNNOTATION_MODE_BACKGROUND = 'ba-annotate-mode-background';
6767
export const SELECTOR_ANNNOTATION_MODE_BACKGROUND = `.${CLASS_ANNNOTATION_MODE_BACKGROUND}`;
68-
export const CLASS_ANNOTATION_BUTTON_POINT_EXIT = 'ba-btn-annotate-point-exit';
69-
export const SELECTOR_ANNOTATION_BUTTON_POINT_EXIT = `.${CLASS_ANNOTATION_BUTTON_POINT_EXIT}`;
7068

7169
export const CLASS_ANNOTATION_MODE_HEADER = 'ba-mode-header';
7270
export const SELECTOR_ANNOTATION_MODE_HEADER = `.${CLASS_ANNOTATION_MODE_HEADER}`;
@@ -93,14 +91,6 @@ export const SELECTOR_HIGHLIGHT_QUAD_CORNER = `.${CLASS_HIGHLIGHT_QUAD_CORNER}`;
9391
// Drawing CSS constants
9492
export const CLASS_ANNOTATION_DRAW = 'ba-annotation-draw';
9593
export const SELECTOR_ANNOTATION_DRAW = `.${CLASS_ANNOTATION_DRAW}`;
96-
export const CLASS_ANNOTATION_BUTTON_DRAW_UNDO = 'ba-btn-annotate-draw-undo';
97-
export const SELECTOR_ANNOTATION_BUTTON_DRAW_UNDO = `.${CLASS_ANNOTATION_BUTTON_DRAW_UNDO}`;
98-
export const CLASS_ANNOTATION_BUTTON_DRAW_REDO = 'ba-btn-annotate-draw-redo';
99-
export const SELECTOR_ANNOTATION_BUTTON_DRAW_REDO = `.${CLASS_ANNOTATION_BUTTON_DRAW_REDO}`;
100-
export const CLASS_ANNOTATION_BUTTON_DRAW_POST = 'ba-btn-annotate-draw-post';
101-
export const SELECTOR_ANNOTATION_BUTTON_DRAW_POST = `.${CLASS_ANNOTATION_BUTTON_DRAW_POST}`;
102-
export const CLASS_ANNOTATION_BUTTON_DRAW_CANCEL = 'ba-btn-annotate-draw-cancel';
103-
export const SELECTOR_ANNOTATION_BUTTON_DRAW_CANCEL = `.${CLASS_ANNOTATION_BUTTON_DRAW_CANCEL}`;
10494

10595
// Data types
10696
export const DATA_TYPE_ANNOTATION_INDICATOR = 'annotation-indicator';

src/controllers/AnnotationModeController.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import noop from 'lodash/noop';
55

66
import { insertTemplate, replaceHeader, hasValidBoundaryCoordinates } from '../util';
77
import {
8-
CLASS_HIDDEN,
98
CLASS_ACTIVE,
109
CLASS_ANNOTATION_MODE,
1110
CLASS_ANNNOTATION_MODE_BACKGROUND,
@@ -37,12 +36,6 @@ class AnnotationModeController extends EventEmitter {
3736
/** @property {HTMLElement} - Header HTML DOM element */
3837
headerElement: HTMLElement;
3938

40-
/** @property {HTMLElement} - Annotation mode button HTML DOM element */
41-
buttonEl: HTMLElement;
42-
43-
/** @property {Object} - Annotation mode button selector and title */
44-
modeButton: Object;
45-
4639
/** @property {AnnotationType} - Mode for annotation controller */
4740
mode: AnnotationType;
4841

@@ -112,11 +105,6 @@ class AnnotationModeController extends EventEmitter {
112105
permissions: this.permissions,
113106
});
114107
this.api.addListener(CONTROLLER_EVENT.error, this.handleAPIErrors);
115-
116-
if (data.modeButton && this.permissions.can_annotate) {
117-
this.modeButton = data.modeButton;
118-
this.showButton();
119-
}
120108
}
121109

122110
/**
@@ -151,44 +139,6 @@ class AnnotationModeController extends EventEmitter {
151139
return this.headerElement.querySelector(annotatorSelector);
152140
}
153141

154-
/**
155-
* Shows the annotate button for the specified mode
156-
*
157-
* @return {void}
158-
*/
159-
showButton(): void {
160-
if (!this.permissions.can_annotate) {
161-
return;
162-
}
163-
164-
this.buttonEl = this.getButton(this.modeButton.selector);
165-
// $FlowFixMe
166-
if (this.buttonEl) {
167-
this.buttonEl.classList.remove(CLASS_HIDDEN);
168-
169-
// $FlowFixMe
170-
this.toggleMode = this.toggleMode.bind(this);
171-
// $FlowFixMe
172-
this.buttonEl.addEventListener('click', this.toggleMode);
173-
}
174-
}
175-
176-
/**
177-
* Hides the annotate button for the specified mode
178-
*
179-
* @return {void}
180-
*/
181-
hideButton() {
182-
if (!this.permissions.can_annotate || !this.modeButton) {
183-
return;
184-
}
185-
186-
this.buttonEl = this.getButton(this.modeButton.selector);
187-
if (this.buttonEl) {
188-
this.buttonEl.classList.add(CLASS_HIDDEN);
189-
}
190-
}
191-
192142
/**
193143
* Toggles annotation modes on and off. When an annotation mode is
194144
* on, annotation threads will be created at that location.

src/controllers/DrawingModeController.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@ import {
77
TYPES,
88
STATES,
99
THREAD_EVENT,
10-
SELECTOR_ANNOTATION_BUTTON_DRAW_CANCEL,
11-
SELECTOR_ANNOTATION_BUTTON_DRAW_POST,
12-
SELECTOR_ANNOTATION_BUTTON_DRAW_UNDO,
13-
SELECTOR_ANNOTATION_BUTTON_DRAW_REDO,
1410
SELECTOR_DRAW_MODE_HEADER,
1511
CLASS_ANNOTATION_LAYER_DRAW,
1612
CLASS_ANNOTATION_DRAW_MODE,
1713
CLASS_ANNOTATION_POINT_MARKER,
1814
ANNOTATOR_TYPE,
1915
CLASS_ANNOTATION_LAYER_DRAW_IN_PROGRESS,
2016
} from '../constants';
21-
import messages from '../messages';
2217

2318
// $FlowFixMe
2419
import shell from './drawingShell.html';
@@ -27,18 +22,6 @@ class DrawingModeController extends AnnotationModeController {
2722
/** @property {AnnotationThread} - The currently selected DrawingThread */
2823
selectedThread: AnnotationThread;
2924

30-
/** @property {HTMLElement} - The button to cancel the pending drawing thread */
31-
cancelButtonEl: HTMLElement;
32-
33-
/** @property {HTMLElement} - The button to commit the pending drawing thread */
34-
postButtonEl: HTMLElement;
35-
36-
/** @property {HTMLElement} - The button to undo a stroke on the pending drawing thread */
37-
undoButtonEl: HTMLElement;
38-
39-
/** @property {HTMLElement} - The button to redo a stroke on the pending drawing thread */
40-
redoButtonEl: HTMLElement;
41-
4225
/** @property {AnnotationThread} */
4326
currentThread: AnnotationThread;
4427

@@ -58,28 +41,6 @@ class DrawingModeController extends AnnotationModeController {
5841
}
5942
}
6043

61-
showButton(): void {
62-
super.showButton();
63-
64-
this.buttonEl.title = this.intl.formatMessage(messages.annotationDrawToggle);
65-
}
66-
67-
/** @inheritdoc */
68-
setupHeader(container: HTMLElement, header: HTMLElement): void {
69-
super.setupHeader(container, header);
70-
71-
this.cancelButtonEl = this.getButton(SELECTOR_ANNOTATION_BUTTON_DRAW_CANCEL);
72-
this.cancelButtonEl.textContent = this.intl.formatMessage(messages.annotationsCancel);
73-
74-
this.postButtonEl = this.getButton(SELECTOR_ANNOTATION_BUTTON_DRAW_POST);
75-
76-
// TODO(@spramod): Remove '||' string, once doneButton is properly localized within Preview
77-
this.postButtonEl.textContent = this.intl.formatMessage(messages.annotationsDone);
78-
79-
this.undoButtonEl = this.getButton(SELECTOR_ANNOTATION_BUTTON_DRAW_UNDO);
80-
this.redoButtonEl = this.getButton(SELECTOR_ANNOTATION_BUTTON_DRAW_REDO);
81-
}
82-
8344
/**
8445
* Prevents click events from triggering other annotation types
8546
*
@@ -167,10 +128,6 @@ class DrawingModeController extends AnnotationModeController {
167128
this.drawingStartHandler = this.drawingStartHandler.bind(this);
168129

169130
this.pushElementHandler(this.annotatedElement, 'click', this.stopPropagation, true);
170-
this.pushElementHandler(this.cancelButtonEl, 'click', this.cancelDrawing);
171-
this.pushElementHandler(this.postButtonEl, 'click', this.postDrawing);
172-
this.pushElementHandler(this.undoButtonEl, 'click', this.undoDrawing);
173-
this.pushElementHandler(this.redoButtonEl, 'click', this.redoDrawing);
174131

175132
// Both click and touch listeners are bound for touch-enabled laptop edge cases
176133
this.pushElementHandler(this.annotatedElement, ['mousedown', 'touchstart'], this.drawingStartHandler, true);

src/controllers/PointModeController.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@ import {
88
THREAD_EVENT,
99
CLASS_ACTIVE,
1010
SELECTOR_POINT_MODE_HEADER,
11-
SELECTOR_ANNOTATION_BUTTON_POINT_EXIT,
1211
CLASS_ANNOTATION_POINT_MODE,
1312
ANNOTATOR_TYPE,
1413
} from '../constants';
15-
import messages from '../messages';
1614
import { replaceHeader, isInAnnotationOrMarker } from '../util';
1715

1816
// $FlowFixMe
1917
import shell from './pointShell.html';
2018

2119
class PointModeController extends AnnotationModeController {
22-
/** @property {HTMLElement} - The button to exit point annotation mode */
23-
exitButtonEl: HTMLElement;
24-
2520
/** @inheritdoc */
2621
init(data: Object): void {
2722
super.init(data);
@@ -35,21 +30,6 @@ class PointModeController extends AnnotationModeController {
3530
}
3631
}
3732

38-
showButton(): void {
39-
super.showButton();
40-
this.buttonEl.title = this.intl.formatMessage(messages.annotationPointToggle);
41-
}
42-
43-
/** @inheritdoc */
44-
setupHeader(container: HTMLElement, header: HTMLElement): void {
45-
super.setupHeader(container, header);
46-
47-
this.exitButtonEl = this.getButton(SELECTOR_ANNOTATION_BUTTON_POINT_EXIT);
48-
49-
// TODO(@spramod): Remove '||' string, once closeButton is properly localized
50-
this.exitButtonEl.textContent = this.intl.formatMessage(messages.annotationsClose);
51-
}
52-
5333
/** @inheritdoc */
5434
setupHandlers(): void {
5535
// $FlowFixMe
@@ -59,7 +39,6 @@ class PointModeController extends AnnotationModeController {
5939

6040
// Get handlers
6141
this.pushElementHandler(this.annotatedElement, ['click', 'touchstart'], this.pointClickHandler, true);
62-
this.pushElementHandler(this.exitButtonEl, 'click', this.toggleMode);
6342
}
6443

6544
/** @inheritdoc */

src/controllers/__tests__/AnnotationModeController-test.js

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import rbush from 'rbush';
33
import AnnotationModeController from '../AnnotationModeController';
44
import * as util from '../../util';
55
import {
6-
CLASS_HIDDEN,
76
CLASS_ACTIVE,
87
CLASS_ANNOTATION_MODE,
98
CLASS_ANNNOTATION_MODE_BACKGROUND,
@@ -67,7 +66,6 @@ describe('controllers/AnnotationModeController', () => {
6766
permissions: { can_annotate: true },
6867
intl: intlMock,
6968
});
70-
expect(controller.showButton).toBeCalled();
7169
});
7270

7371
it('should not show modeButton if none provided', () => {
@@ -129,95 +127,6 @@ describe('controllers/AnnotationModeController', () => {
129127
});
130128
});
131129

132-
describe('showButton()', () => {
133-
let buttonEl;
134-
135-
beforeEach(() => {
136-
controller.modeButton = {
137-
type: {
138-
title: 'Annotation Mode',
139-
selector: '.selector',
140-
},
141-
};
142-
buttonEl = document.createElement('button');
143-
buttonEl.title = controller.modeButton.title;
144-
buttonEl.classList.add(CLASS_HIDDEN);
145-
buttonEl.classList.add('selector');
146-
buttonEl.addEventListener = jest.fn();
147-
148-
controller.permissions = { can_annotate: true };
149-
controller.getButton = jest.fn().mockReturnValue(buttonEl);
150-
});
151-
152-
it('should do nothing if user cannot annotate', () => {
153-
controller.permissions.can_annotate = false;
154-
controller.showButton();
155-
expect(buttonEl.classList).toContain(CLASS_HIDDEN);
156-
});
157-
158-
it('should do nothing if the button is not in the container', () => {
159-
controller.getButton = jest.fn();
160-
controller.showButton();
161-
expect(buttonEl.classList).toContain(CLASS_HIDDEN);
162-
});
163-
164-
it('should set up and show an annotate button', () => {
165-
controller.showButton();
166-
expect(buttonEl.classList).not.toContain(CLASS_HIDDEN);
167-
expect(buttonEl.addEventListener).toBeCalledWith('click', controller.toggleMode);
168-
});
169-
it('should set up and show an annotate button', () => {
170-
controller.showButton();
171-
expect(buttonEl.classList).not.toContain(CLASS_HIDDEN);
172-
expect(buttonEl.addEventListener).toBeCalledWith('click', controller.toggleMode);
173-
});
174-
});
175-
176-
describe('hideButton()', () => {
177-
let buttonEl;
178-
179-
beforeEach(() => {
180-
controller.modeButton = {
181-
type: {
182-
title: 'Annotation Mode',
183-
selector: '.selector',
184-
},
185-
};
186-
buttonEl = document.createElement('button');
187-
buttonEl.title = controller.modeButton.title;
188-
buttonEl.classList.remove(CLASS_HIDDEN);
189-
buttonEl.classList.add('selector');
190-
buttonEl.addEventListener = jest.fn();
191-
192-
controller.permissions = { can_annotate: true };
193-
controller.getButton = jest.fn().mockReturnValue(buttonEl);
194-
});
195-
196-
it('should do nothing if user cannot annotate', () => {
197-
controller.permissions.can_annotate = false;
198-
controller.hideButton();
199-
expect(buttonEl.classList).not.toContain(CLASS_HIDDEN);
200-
});
201-
202-
it('should do nothing if button is not found', () => {
203-
controller.getButton = jest.fn();
204-
controller.hideButton();
205-
expect(buttonEl.classList).not.toContain(CLASS_HIDDEN);
206-
});
207-
208-
it('should add the bp-is-hidden class to the button', () => {
209-
controller.hideButton();
210-
expect(buttonEl.classList).toContain(CLASS_HIDDEN);
211-
});
212-
213-
it('should do nothing if no modeButton', () => {
214-
controller.modeButton = undefined;
215-
controller.permissions.can_annotate = false;
216-
controller.hideButton();
217-
expect(buttonEl.classList).not.toContain(CLASS_HIDDEN);
218-
});
219-
});
220-
221130
describe('toggleMode()', () => {
222131
beforeEach(() => {
223132
controller.emit = jest.fn();

0 commit comments

Comments
 (0)