Skip to content

Commit

Permalink
New: Adding README.md for Annotations codebase + cleanup (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Oct 17, 2017
1 parent b3a6407 commit 7df251e
Show file tree
Hide file tree
Showing 20 changed files with 1,395 additions and 726 deletions.
74 changes: 37 additions & 37 deletions src/lib/annotations/AnnotationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,38 +335,6 @@ class AnnotationDialog extends EventEmitter {
}
}

/**
* Keydown handler for dialog.
*
* @protected
* @param {Event} event - DOM event
* @return {void}
*/
keydownHandler(event) {
event.stopPropagation();

const key = annotatorUtil.decodeKeydown(event);
if (key === 'Escape') {
this.hide();
} else {
const dataType = annotatorUtil.findClosestDataType(event.target);
if (dataType === CLASS_REPLY_TEXTAREA) {
this.activateReply();
}
}
}

/**
* Stops propagation of DOM event.
*
* @protected
* @param {Event} event - DOM event
* @return {void}
*/
stopPropagation(event) {
event.stopPropagation();
}

/**
* Mouseenter handler. Clears hide timeout.
*
Expand Down Expand Up @@ -400,10 +368,46 @@ class AnnotationDialog extends EventEmitter {
}
}

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------

/**
* Keydown handler for dialog.
*
* @private
* @param {Event} event - DOM event
* @return {void}
*/
keydownHandler(event) {
event.stopPropagation();

const key = annotatorUtil.decodeKeydown(event);
if (key === 'Escape') {
this.hide();
} else {
const dataType = annotatorUtil.findClosestDataType(event.target);
if (dataType === CLASS_REPLY_TEXTAREA) {
this.activateReply();
}
}
}

/**
* Stops propagation of DOM event.
*
* @private
* @param {Event} event - DOM event
* @return {void}
*/
stopPropagation(event) {
event.stopPropagation();
}

/**
* Click handler on dialog.
*
* @protected
* @private
* @param {Event} event - DOM event
* @return {void}
*/
Expand Down Expand Up @@ -461,10 +465,6 @@ class AnnotationDialog extends EventEmitter {
}
}

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------

/**
* Adds an annotation to the dialog.
*
Expand Down
125 changes: 63 additions & 62 deletions src/lib/annotations/AnnotationThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class AnnotationThread extends EventEmitter {

// Changing state from pending
this.state = STATES.hover;

// Save annotation on server
return this.annotationService
.create(annotationData)
Expand Down Expand Up @@ -262,50 +263,6 @@ class AnnotationThread extends EventEmitter {
});
}

/**
* Scroll annotation into the center of the viewport, if possible
*
* @private
* @return {void}
*/
scrollIntoView() {
const yPos = parseInt(this.location.y, 10);
this.scrollToPage();
this.centerAnnotation(this.annotatedElement.scrollTop + yPos);
}

/**
* Scroll to the annotation's page
*
* @private
* @return {void}
*/
scrollToPage() {
// Ignore if annotation does not have a location or page
if (!this.location || !this.location.page) {
return;
}

const pageEl = this.annotatedElement.querySelector(`[data-page-number="${this.location.page}"]`);
pageEl.scrollIntoView();
}

/**
* Adjust page scroll position so annotation is centered in viewport
*
* @private
* @param {number} scrollVal - scroll value to adjust so annotation is
centered in the viewport
* @return {void}
*/
centerAnnotation(scrollVal) {
if (scrollVal < this.annotatedElement.scrollHeight) {
this.annotatedElement.scrollTop = scrollVal;
} else {
this.annotatedElement.scrollTop = this.annotatedElement.scrollBottom;
}
}

//--------------------------------------------------------------------------
// Abstract
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -456,32 +413,53 @@ class AnnotationThread extends EventEmitter {
this.destroy();
}

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------

/**
* Generate threadData with relevant information to be emitted with an
* annotation thread event
* Scroll annotation into the center of the viewport, if possible
*
* @protected
* @return {Object} threadData - Annotation event thread data
* @private
* @return {void}
*/
getThreadEventData() {
const threadData = {
type: this.type,
threadID: this.threadID
};
scrollIntoView() {
const yPos = parseInt(this.location.y, 10);
this.scrollToPage();
this.centerAnnotation(this.annotatedElement.scrollTop + yPos);
}

if (this.annotationService.user.id > 0) {
threadData.userId = this.annotationService.user.id;
}
if (this.threadNumber) {
threadData.threadNumber = this.threadNumber;
/**
* Scroll to the annotation's page
*
* @private
* @return {void}
*/
scrollToPage() {
// Ignore if annotation does not have a location or page
if (!this.location || !this.location.page) {
return;
}

return threadData;
const pageEl = this.annotatedElement.querySelector(`[data-page-number="${this.location.page}"]`);
pageEl.scrollIntoView();
}

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* Adjust page scroll position so annotation is centered in viewport
*
* @private
* @param {number} scrollVal - scroll value to adjust so annotation is
centered in the viewport
* @return {void}
*/
centerAnnotation(scrollVal) {
if (scrollVal < this.annotatedElement.scrollHeight) {
this.annotatedElement.scrollTop = scrollVal;
} else {
this.annotatedElement.scrollTop = this.annotatedElement.scrollBottom;
}
}

/**
* Update a temporary annotation with the annotation saved on the backend. Set the threadNumber if it has not
Expand Down Expand Up @@ -632,6 +610,29 @@ class AnnotationThread extends EventEmitter {
/* eslint-enable no-console */
}

/**
* Generate threadData with relevant information to be emitted with an
* annotation thread event
*
* @private
* @return {Object} threadData - Annotation event thread data
*/
getThreadEventData() {
const threadData = {
type: this.type,
threadID: this.threadID
};

if (this.annotationService.user.id > 0) {
threadData.userId = this.annotationService.user.id;
}
if (this.threadNumber) {
threadData.threadNumber = this.threadNumber;
}

return threadData;
}

/**
* Emits a generic viewer event
*
Expand Down
Loading

0 comments on commit 7df251e

Please sign in to comment.