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

Breaking: Remove hover behavior to display dialogs #155

Merged
merged 16 commits into from May 15, 2018

Conversation

pramodsum
Copy link
Contributor

@pramodsum pramodsum commented Mar 28, 2018

  • Remove min-height animation when opening dialog
  • Remove hover to open/close dialogs, dialogs open when indicator is clicked and close when you click outside

Based off of #137

remove_hover

@boxcla
Copy link

boxcla commented Mar 28, 2018

Verified that @pramodsum has signed the CLA. Thanks for the pull request!

@pramodsum pramodsum changed the title Breaking: Remove hover behavior for Annotations Breaking: Remove hover behavior to display annotation dialogs Mar 29, 2018
@pramodsum pramodsum changed the title Breaking: Remove hover behavior to display annotation dialogs Breaking: Remove hover behavior to display dialogs Mar 29, 2018
- Remove min-height animation when opening dialog
- Remove hover to open/close dialogs, dialogs open when indicator is clicked and close when you click outside
Copy link
Contributor

@jeremypress jeremypress left a comment

Choose a reason for hiding this comment

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

Great start! This will remove a ton of tech debt

@@ -59,11 +59,6 @@ class AnnotationDialog extends EventEmitter {
this.clickHandler = this.clickHandler.bind(this);
this.stopPropagation = this.stopPropagation.bind(this);
this.validateTextArea = this.validateTextArea.bind(this);

if (!this.isMobile) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🍾

@@ -356,6 +351,11 @@ class AnnotationDialog extends EventEmitter {
this.element.addEventListener('wheel', this.stopPropagation);
this.element.addEventListener('mouseup', this.stopPropagation);

if (!this.isMobile) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this being bound earlier now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no particular reason. I think it was just shuffled around

break;
// Clicking inside reply text area
case constants.DATA_TYPE_REPLY_TEXTAREA:
this.activateReply();
break;
// Canceling a reply
case constants.DATA_TYPE_CANCEL_REPLY:
this.deactivateReply(true);
// this.deactivateReply(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line

break;
// Clicking inside reply text area
case constants.DATA_TYPE_REPLY_TEXTAREA:
this.activateReply();
break;
// Canceling a reply
case constants.DATA_TYPE_CANCEL_REPLY:
this.deactivateReply(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

we weren't hiding the dialog before on comment cancel, should we now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. Undoing this

@@ -132,7 +132,11 @@ class AnnotationThread extends EventEmitter {
* @return {void}
*/
showDialog() {
// Prevents the annotations dialog from being created each mousemove
if (this.state !== STATES.pending && util.isInAnnotationMode(this.container, TYPES.point)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we allow showing a dialog in point mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's more for consistency w/ drawing annotations. I'm on board w/ allowing users to select existing drawings while in drawing mode if that's a behavior we want to add.

return;
}

// Prevents the annotations dialog from being every call
Copy link
Contributor

Choose a reason for hiding this comment

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

can you clarify this comment a bit?

@@ -177,6 +178,12 @@ class DrawingModeController extends AnnotationModeController {
thread.handleStart(location);
}

/** @inheritdoc */
exit() {
this.annotatedElement.classList.remove(CLASS_ANNOTATION_DRAW_MODE);
Copy link
Contributor

Choose a reason for hiding this comment

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

What are the mode CSS classes used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Functional tests mostly

}

// Hide open threads when clicking on document
this.annotatedElement.addEventListener(
Copy link
Contributor

Choose a reason for hiding this comment

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

make this click if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -164,6 +164,10 @@ class DocDrawingDialog extends AnnotationDialog {
this.pageEl = this.annotatedElement.querySelector(`[data-page-number="${this.location.page}"]`);
}

if (!this.element) {
this.setup([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Kinda weird that we have to pass in an empty array here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Fixed

pramodsum and others added 8 commits April 24, 2018 10:30
- Point mode: All point annotations are triggerable
- Drawing mode: No existing dialogs are triggerable
- When not in a mode: all existing annotation dialogs are triggerable
this.pushElementHandler(
this.annotatedElement,
'click',
(event) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you extract this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did it for all the drawing handlers while i was at it

@@ -373,8 +370,7 @@ class AnnotationDialog extends EventEmitter {

if (!this.isMobile) {
this.element.addEventListener('click', this.clickHandler);
this.element.addEventListener('mouseenter', this.mouseenterHandler);
this.element.addEventListener('mouseleave', this.mouseleaveHandler);
this.element.addEventListener('click', 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.

Why is this needed? And why not just add stopPropagation() to the clickHandler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out it's already there in clickHandler

@@ -428,6 +420,8 @@ class AnnotationThread extends EventEmitter {
this.dialog.removeAllListeners('annotationcreate');
this.dialog.removeAllListeners('annotationcancel');
this.dialog.removeAllListeners('annotationdelete');
this.dialog.removeAllListeners('annotationshow');
Copy link
Contributor

Choose a reason for hiding this comment

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

Either switch to removeListener or pass in an array https://nodejs.org/api/events.html#events_emitter_removealllisteners_eventname

@@ -296,6 +297,27 @@ class Annotator extends EventEmitter {
this.mobileDialogEl.removeChild(this.mobileDialogEl.lastChild);
}

/**
* Hides all non-pending annotations if mouse event occurs outside an
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if you have a pending annotation open and you click on a different point icon?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it'll close the pending annotation and open the clicked on one

Copy link
Contributor

Choose a reason for hiding this comment

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

does that data get saved in the pending annotation so you can come back to it?

@@ -213,6 +209,7 @@ class AnnotationDialog extends EventEmitter {

util.hideElement(this.element);
this.deactivateReply();
this.emit('annotationhide');
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a requirement to merge but you do have most of these as constants elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea i think I never moved the constants that were are emitted from AnnotationDialog.js. I can clean it up later

@@ -330,6 +333,12 @@ class AnnotationModeController extends EventEmitter {
this.hadPendingThreads = false;
this.emit(data.event, data.data);
break;
case THREAD_EVENT.show:
this.visibleThreadID = data.data.threadID;
Copy link
Contributor

Choose a reason for hiding this comment

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

unpack data and event at the top for readability?

@@ -362,17 +371,19 @@ class AnnotationModeController extends EventEmitter {
* @param {HTMLElement} element - The element to bind the listener to
* @param {Array|string} type - An array of event types to listen for or the event name to listen for
* @param {Function} handlerFn - The callback to be invoked when the element emits a specified eventname
* @param {boolean} useCapture - Whether or not to prioritize handler call
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this prioritize or block the event from reaching other places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prioritize

},
true
);
this.pushElementHandler(this.annotatedElement, ['mousedown', 'touchstart'], this.drawingStartHandler, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty confusing, can you add a comment why we need to push two element handlers? and why is click separated from mousedown and touchstart?

Copy link
Contributor Author

@pramodsum pramodsum May 15, 2018

Choose a reason for hiding this comment

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

both are needed for the surface edge cases and click is separate because it more or less just prevents any click events other than drawing ones from ever triggering on the document specifically

@@ -678,142 +659,6 @@ class DocAnnotator extends Annotator {
}
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

as Justin would say, "10/10"

src/util.js Outdated
* @param {Event} event Mouse event
* @return {boolean} Whether or not mouse is inside dialog
*/
export function isInAnnotation(event) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename this because it applies to either being in an annotation or clicking on an annotation icon.

this.undoDrawing = this.undoDrawing.bind(this);
this.redoDrawing = this.redoDrawing.bind(this);

this.pushElementHandler(this.annotatedElement, 'click', this.stopPropagation, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

why not stop propagation to drawingStart?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants