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

Temp hide show ui for plain and comment highlights #348

Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
650591d
New: Temporary checks to hide ui base on disabled type
Aug 29, 2017
2b38cc9
Chore: Fixed warning
Aug 29, 2017
1503281
Chore: feedback on PR
Aug 30, 2017
d374903
Chore: Styling for mobile UI on disabled types
Aug 30, 2017
a2f21bc
Merge branch 'master' of github.com:JustinHoldstock/box-content-previ…
Aug 30, 2017
88c92fb
Chore: linter warnings
Aug 30, 2017
4b8e2d2
Chore: Tests for highlight enabled/disabled guards
Aug 31, 2017
ad2f66b
Merge branch 'master' of github.com:JustinHoldstock/box-content-previ…
Aug 31, 2017
28c649e
Merge branch 'master' into Temp-hide-show-ui-for-plain-and-comment-hi…
JustinHoldstock Sep 1, 2017
52b6d45
Chore: Change binding of filter
Sep 1, 2017
21c8c70
Merge branch 'Temp-hide-show-ui-for-plain-and-comment-highlights' of …
Sep 1, 2017
0062a42
Merge branch 'master' of github.com:JustinHoldstock/box-content-previ…
Sep 1, 2017
f529a37
New: Temporary checks to hide ui base on disabled type
Aug 29, 2017
e6da085
Chore: Fixed warning
Aug 29, 2017
2aa6104
Chore: feedback on PR
Aug 30, 2017
9d5e0f8
Chore: Styling for mobile UI on disabled types
Aug 30, 2017
a2c63a0
Chore: linter warnings
Aug 30, 2017
cf9c347
Chore: Tests for highlight enabled/disabled guards
Aug 31, 2017
840246d
Chore: Change binding of filter
Sep 1, 2017
eb2c45c
Merge branch 'Temp-hide-show-ui-for-plain-and-comment-highlights' of …
Sep 1, 2017
00909f5
Merge branch 'master' into Temp-hide-show-ui-for-plain-and-comment-hi…
JustinHoldstock Sep 5, 2017
7bc4a32
Chore: fixed tests
Sep 5, 2017
c52901f
Merge branch 'master' of github.com:JustinHoldstock/box-content-previ…
Sep 5, 2017
ba00e80
Chore: forgot to save before commit
Sep 5, 2017
daca4a0
Chore: Feedback
Sep 5, 2017
99bd679
Chore: missing test fix
Sep 5, 2017
b6c1705
Merge branch 'master' of github.com:JustinHoldstock/box-content-previ…
Sep 5, 2017
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
4 changes: 4 additions & 0 deletions src/lib/annotations/Annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ class Annotator extends EventEmitter {

const pageThreads = this.getThreadsOnPage(pageNum);
Object.values(pageThreads).forEach((thread) => {
if (!this.isModeAnnotatable(thread.type)) {
return;
}

thread.show();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/annotations/BoxAnnotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ANNOTATORS = [
NAME: 'Document',
CONSTRUCTOR: DocAnnotator,
VIEWER: ['Document', 'Presentation'],
TYPE: [TYPES.point, TYPES.highlight]
TYPE: [TYPES.point, TYPES.highlight, TYPES.highlight_comment]
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

},
{
NAME: 'Image',
Expand Down
9 changes: 5 additions & 4 deletions src/lib/annotations/MobileAnnotator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,21 @@ $tablet: "(min-width: 768px)";
z-index: 9999;

.bp-annotation-highlight-btns {
display: flex;
justify-content: flex-start;
padding: 0;

button {
float: left;
flex-grow: 1;
padding: 15px 0;
width: 50%;

&:first-child::after {
&:nth-child(2)::before {
border-right: 1px solid $seesee;
bottom: 17px;
content: "";
height: 25px;
left: 50%;
position: absolute;
right: 50%;
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/lib/annotations/__tests__/Annotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,21 @@ describe('lib/annotations/Annotator', () => {
stubs.threadMock3.expects('show').never();
annotator.renderAnnotationsOnPage(1);
});

it('should not call show() if the thread type is disabled', () => {
const badType = 'not_accepted';
stubs.thread3.type = badType;
stubs.thread2.type = 'type';

stubs.threadMock3.expects('show').never();
stubs.threadMock2.expects('show').once();

const isModeAnn = sandbox.stub(annotator, 'isModeAnnotatable');
isModeAnn.withArgs(badType).returns(false);
isModeAnn.withArgs('type').returns(true);

annotator.renderAnnotationsOnPage('2');
});
});

describe('rotateAnnotations()', () => {
Expand Down
134 changes: 87 additions & 47 deletions src/lib/annotations/doc/CreateHighlightDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ const TITLE_HIGHLIGHT_TOGGLE = __('annotation_highlight_toggle');
const TITLE_HIGHLIGHT_COMMENT = __('annotation_highlight_comment');
const DATA_TYPE_HIGHLIGHT = 'add-highlight-btn';
const DATA_TYPE_ADD_HIGHLIGHT_COMMENT = 'add-highlight-comment-btn';
const CREATE_HIGHLIGHT_DIALOG_TEMPLATE = `
<div class="${constants.CLASS_ANNOTATION_CARET}" style="left: 50%;"></div>
<div>
<div class="${constants.CLASS_ANNOTATION_HIGHLIGHT_DIALOG}">
<span class="${constants.CLASS_HIGHLIGHT_BTNS}">
<button class="bp-btn-plain ${constants.CLASS_ADD_HIGHLIGHT_BTN}"
data-type="${DATA_TYPE_HIGHLIGHT}"
title="${TITLE_HIGHLIGHT_TOGGLE}">
${ICON_HIGHLIGHT}
</button>
<button class="bp-btn-plain ${constants.CLASS_ADD_HIGHLIGHT_COMMENT_BTN}"
data-type="${DATA_TYPE_ADD_HIGHLIGHT_COMMENT}""
title="${TITLE_HIGHLIGHT_COMMENT}">
${ICON_HIGHLIGHT_COMMENT}
</button>
</span>
</div>
</div>`.trim();

const CARAT_TEMPLATE = `<div class="${constants.CLASS_ANNOTATION_CARET}" style="left: 50%;"></div>`;
const HIGHLIGHT_BUTTON_TEMPLATE = `
<button class="bp-btn-plain ${constants.CLASS_ADD_HIGHLIGHT_BTN}"
data-type="${DATA_TYPE_HIGHLIGHT}"
title="${TITLE_HIGHLIGHT_TOGGLE}">
${ICON_HIGHLIGHT}
</button>`.trim();
const COMMENT_BUTTON_TEMPLATE = `
<button class="bp-btn-plain ${constants.CLASS_ADD_HIGHLIGHT_COMMENT_BTN}"
data-type="${DATA_TYPE_ADD_HIGHLIGHT_COMMENT}""
title="${TITLE_HIGHLIGHT_COMMENT}">
${ICON_HIGHLIGHT_COMMENT}
</button>`.trim();

/**
* Events emitted by this component.
Expand Down Expand Up @@ -71,6 +67,12 @@ class CreateHighlightDialog extends EventEmitter {
/** @property {boolean} - Whether or not this is visible. */
isVisible;

/** @property {boolean} - Whether or not to allow plain highlight interaction. */
allowHighlight;

/** @property {boolean} - Whether or not to allow comment interactions. */
allowComment;

/**
* A dialog used to create plain and comment highlights.
*
Expand All @@ -88,12 +90,19 @@ class CreateHighlightDialog extends EventEmitter {
this.parentEl = parentEl;
this.isMobile = config.isMobile || false;
this.hasTouch = config.hasTouch || false;
this.allowHighlight = config.allowHighlight !== undefined ? !!config.allowHighlight : true;
this.allowComment = config.allowComment !== undefined ? !!config.allowComment : true;

// Explicit scope binding for event listeners
this.onHighlightClick = this.onHighlightClick.bind(this);
this.onCommentClick = this.onCommentClick.bind(this);
this.onCommentPost = this.onCommentPost.bind(this);
this.onCommentCancel = this.onCommentCancel.bind(this);
if (this.allowHighlight) {
this.onHighlightClick = this.onHighlightClick.bind(this);
}

if (this.allowComment) {
this.onCommentClick = this.onCommentClick.bind(this);
this.onCommentPost = this.onCommentPost.bind(this);
this.onCommentCancel = this.onCommentCancel.bind(this);
}
}

/**
Expand Down Expand Up @@ -162,8 +171,10 @@ class CreateHighlightDialog extends EventEmitter {

hideElement(this.containerEl);

this.commentBox.hide();
this.commentBox.clear();
if (this.commentBox) {
this.commentBox.hide();
this.commentBox.clear();
}
}

/**
Expand All @@ -186,8 +197,6 @@ class CreateHighlightDialog extends EventEmitter {
// Event listeners
this.highlightCreateEl.removeEventListener('click', this.onHighlightClick);
this.commentCreateEl.removeEventListener('click', this.onCommentClick);
this.commentBox.removeListener(CommentBox.CommentEvents.post, this.onCommentPost);
this.commentBox.removeListener(CommentBox.CommentEvents.cancel, this.onCommentCancel);

if (this.hasTouch) {
this.highlightCreateEl.removeEventListener('touchstart', this.stopPropagation);
Expand All @@ -201,8 +210,12 @@ class CreateHighlightDialog extends EventEmitter {
this.containerEl = null;
this.parentEl = null;

this.commentBox.destroy();
this.commentBox = null;
if (this.commentBox) {
this.commentBox.removeListener(CommentBox.CommentEvents.post, this.onCommentPost);
this.commentBox.removeListener(CommentBox.CommentEvents.cancel, this.onCommentCancel);
this.commentBox.destroy();
this.commentBox = null;
}
}

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -315,50 +328,77 @@ class CreateHighlightDialog extends EventEmitter {
* @return {HTMLElement} The element containing Highlight creation UI
*/
createElement() {
const caretTemplate = this.isMobile ? '' : CARAT_TEMPLATE;
const highlightTemplate = this.allowHighlight ? HIGHLIGHT_BUTTON_TEMPLATE : '';
const commentTemplate = this.allowComment ? COMMENT_BUTTON_TEMPLATE : '';

const createHighlightDialogTemplate = `
${caretTemplate}
<div>
<div class="${constants.CLASS_ANNOTATION_HIGHLIGHT_DIALOG}">
<span class="${constants.CLASS_HIGHLIGHT_BTNS}">
${highlightTemplate}
${commentTemplate}
</span>
</div>
</div>`.trim();

const highlightDialogEl = document.createElement('div');
highlightDialogEl.classList.add(CLASS_CREATE_DIALOG);
highlightDialogEl.innerHTML = CREATE_HIGHLIGHT_DIALOG_TEMPLATE;
highlightDialogEl.innerHTML = createHighlightDialogTemplate;

// Get rid of the caret
if (this.isMobile) {
highlightDialogEl.classList.add('bp-mobile-annotation-dialog');
highlightDialogEl.classList.add('bp-annotation-dialog');
highlightDialogEl.querySelector('.bp-annotation-caret').remove();
}

const containerEl = highlightDialogEl.querySelector(constants.SELECTOR_ANNOTATION_HIGHLIGHT_DIALOG);

// Reference HTML
this.highlightCreateEl = containerEl.querySelector(constants.SELECTOR_ADD_HIGHLIGHT_BTN);
this.commentCreateEl = containerEl.querySelector(`.${constants.CLASS_ADD_HIGHLIGHT_COMMENT_BTN}`);
this.buttonsEl = containerEl.querySelector(constants.SELECTOR_HIGHLIGHT_BTNS);

// Create comment box
this.commentBox = new CommentBox(containerEl);

// Stop interacting with this element from triggering outside actions
highlightDialogEl.addEventListener('click', this.stopPropagation);
highlightDialogEl.addEventListener('mouseup', this.stopPropagation);
highlightDialogEl.addEventListener('dblclick', this.stopPropagation);

// Event listeners
this.highlightCreateEl.addEventListener('click', this.onHighlightClick);
this.commentCreateEl.addEventListener('click', this.onCommentClick);
this.commentBox.addListener(CommentBox.CommentEvents.post, this.onCommentPost);
this.commentBox.addListener(CommentBox.CommentEvents.cancel, this.onCommentCancel);
// Events for highlight button
if (this.allowHighlight) {
this.highlightCreateEl = containerEl.querySelector(constants.SELECTOR_ADD_HIGHLIGHT_BTN);
this.highlightCreateEl.addEventListener('click', this.onHighlightClick);

if (this.hasTouch) {
this.highlightCreateEl.addEventListener('touchstart', this.stopPropagation);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move the adding of these 2 event handlers into its own method? so you can just call it anywhere on w/e element you pass in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure this'd be valid for the touchend -> highlightClick event binding, as it only ever happens once. Would it be valid abstracting the binding for stopPropagation()?

Maybe instead of

element.addEventListener('event', this.stopPropagation);

We'd do

this.bindStopPropagation(element, event);

Though, after seeing it, I'm not sure what the benefit of that is

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm true. I guess it wouldn't really clean up too much.

this.highlightCreateEl.addEventListener('touchend', this.onHighlightClick);
}
}

// Events for comment button
if (this.allowComment) {
// Create comment box
this.commentBox = new CommentBox(containerEl);
this.commentCreateEl = containerEl.querySelector(`.${constants.CLASS_ADD_HIGHLIGHT_COMMENT_BTN}`);
this.commentCreateEl.addEventListener('click', this.onCommentClick);

// Event listeners
Copy link
Contributor

Choose a reason for hiding this comment

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

new line above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

this.commentBox.addListener(CommentBox.CommentEvents.post, this.onCommentPost);
this.commentBox.addListener(CommentBox.CommentEvents.cancel, this.onCommentCancel);

// Hide comment box, by default
Copy link
Contributor

Choose a reason for hiding this comment

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

new line before comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

this.commentBox.hide();

if (this.hasTouch) {
this.commentCreateEl.addEventListener('touchstart', this.stopPropagation);
this.commentCreateEl.addEventListener('touchend', this.onCommentClick);
}
}

// touch events
if (this.hasTouch) {
this.highlightCreateEl.addEventListener('touchstart', this.stopPropagation);
this.commentCreateEl.addEventListener('touchstart', this.stopPropagation);
this.highlightCreateEl.addEventListener('touchend', this.onHighlightClick);
this.commentCreateEl.addEventListener('touchend', this.onCommentClick);
highlightDialogEl.addEventListener('touchend', this.stopPropagation);
}

// Hide comment box, by default
this.commentBox.hide();

return highlightDialogEl;
}
}
Expand Down
Loading