Skip to content

Commit

Permalink
Chore: Rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Nov 15, 2018
1 parent b0d50c9 commit e23ffcb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
13 changes: 5 additions & 8 deletions src/Annotator.js
Expand Up @@ -396,25 +396,22 @@ class Annotator extends EventEmitter {
}
/**
* Resets any popoverUI on render/scale events
* Resets any annotation UI on render/scale events
*
* @param {number} [pageNum] - optional page number
* @return {void}
*/
/* eslint-disable-next-line no-unused-vars */
resetPopoverUI(pageNum?: number) {}
resetAnnotationUI(pageNum?: number) {}
/**
* Renders annotations from memory.
*
* @return {void}
*/
render() {
this.resetPopoverUI();
Object.keys(this.modeControllers).forEach((mode) => {
const controller = this.modeControllers[mode];
controller.render();
});
this.resetAnnotationUI();
Object.keys(this.modeControllers).forEach((mode) => this.modeControllers[mode].render());
}
/**
Expand All @@ -424,8 +421,8 @@ class Annotator extends EventEmitter {
* @return {void}
*/
renderPage(pageNum: number) {
this.resetAnnotationUI(pageNum);
Object.keys(this.modeControllers).forEach((mode) => this.modeControllers[mode].renderPage(pageNum));
this.resetPopoverUI(pageNum);
}
/**
Expand Down
2 changes: 1 addition & 1 deletion src/doc/CreateHighlightDialog.js
Expand Up @@ -83,14 +83,14 @@ class CreateHighlightDialog extends EventEmitter {
return;
}

this.isVisible = false;
const popoverLayers = this.container.querySelectorAll('.ba-dialog-layer');
if (!this.createPopoverComponent || popoverLayers.length === 0) {
return;
}

popoverLayers.forEach(unmountComponentAtNode);
this.createPopoverComponent = null;
this.isVisible = false;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/doc/DocAnnotator.js
Expand Up @@ -77,7 +77,7 @@ class DocAnnotator extends Annotator {
// $FlowFixMe
this.onSelectionChange = this.onSelectionChange.bind(this);
// $FlowFixMe
this.resetPopoverUI = this.resetPopoverUI.bind(this);
this.resetAnnotationUI = this.resetAnnotationUI.bind(this);
}

/**
Expand Down Expand Up @@ -243,7 +243,7 @@ class DocAnnotator extends Annotator {
};

/** @inheritdoc */
resetPopoverUI(pageNum?: number) {
resetAnnotationUI(pageNum?: number) {
// $FlowFixMe
document.getSelection().removeAllRanges();
if (this.highlighter) {
Expand Down Expand Up @@ -328,7 +328,7 @@ class DocAnnotator extends Annotator {
bindDOMListeners() {
super.bindDOMListeners();

this.container.addEventListener('resize', this.resetPopoverUI);
this.container.addEventListener('resize', this.resetAnnotationUI);

// Highlight listeners on desktop & mobile
if (this.plainHighlightEnabled || this.commentHighlightEnabled) {
Expand Down Expand Up @@ -364,7 +364,7 @@ class DocAnnotator extends Annotator {
unbindDOMListeners() {
super.unbindDOMListeners();

this.container.removeEventListener('resize', this.resetPopoverUI);
this.container.removeEventListener('resize', this.resetAnnotationUI);
this.annotatedElement.removeEventListener('wheel', this.hideCreateDialog);
this.annotatedElement.removeEventListener('touchend', this.hideCreateDialog);
this.annotatedElement.removeEventListener('click', this.clickHandler);
Expand Down Expand Up @@ -694,7 +694,7 @@ class DocAnnotator extends Annotator {
highlightMouseupHandler = (event: Event) => {
this.isCreatingHighlight = false;

if (!event || util.isInAnnotationOrMarker(event, this.container)) {
if (util.isInAnnotationOrMarker(event, this.container)) {
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/doc/__tests__/DocAnnotator-test.js
Expand Up @@ -409,7 +409,7 @@ describe('doc/DocAnnotator', () => {
});
});

describe('resetPopoverUI()', () => {
describe('resetAnnotationUI()', () => {
beforeEach(() => {
document.getSelection = jest.fn().mockReturnValue({
removeAllRanges: jest.fn()
Expand All @@ -421,13 +421,13 @@ describe('doc/DocAnnotator', () => {
});

it('should clear and hide createHighlightDialog', () => {
annotator.resetPopoverUI();
annotator.resetAnnotationUI();
expect(annotator.scaleAnnotationCanvases).not.toBeCalled();
expect(annotator.createHighlightDialog.unmountPopover).toBeCalled();
});

it('should scale annotation canvases if page number is provided', () => {
annotator.resetPopoverUI(1);
annotator.resetAnnotationUI(1);
expect(annotator.scaleAnnotationCanvases).toBeCalledWith(1);
expect(annotator.createHighlightDialog.unmountPopover).toBeCalled();
});
Expand Down Expand Up @@ -525,7 +525,7 @@ describe('doc/DocAnnotator', () => {

it('should bind DOM listeners if user can annotate and highlight', () => {
annotator.bindDOMListeners();
expect(annotator.container.addEventListener).toBeCalledWith('resize', annotator.resetPopoverUI);
expect(annotator.container.addEventListener).toBeCalledWith('resize', annotator.resetAnnotationUI);
expect(annotator.annotatedElement.addEventListener).toBeCalledWith(
'mouseup',
annotator.highlightMouseupHandler
Expand Down Expand Up @@ -634,7 +634,7 @@ describe('doc/DocAnnotator', () => {
annotator.permissions.can_annotate = true;

annotator.unbindDOMListeners();
expect(annotator.container.removeEventListener).toBeCalledWith('resize', annotator.resetPopoverUI);
expect(annotator.container.removeEventListener).toBeCalledWith('resize', annotator.resetAnnotationUI);
expect(annotator.annotatedElement.removeEventListener).toBeCalledWith(
'mouseup',
annotator.highlightMouseupHandler
Expand Down
3 changes: 1 addition & 2 deletions src/drawing/DrawingThread.js
Expand Up @@ -431,10 +431,9 @@ class DrawingThread extends AnnotationThread {
* Create an annotation data object to pass to annotation service.
*
* @param {string} type - Type of annotation
* @param {string} message - Annotation text
* @return {Object} Annotation data
*/
createAnnotationData(type, message) {
createAnnotationData(type) {
return {
item: {
id: this.fileVersionId,
Expand Down

0 comments on commit e23ffcb

Please sign in to comment.