Commit 4d5fc292 authored by Robert Knight's avatar Robert Knight

Make `width`, `height` and `view` instance properties

parent f333e64f
...@@ -151,7 +151,7 @@ class Adder { ...@@ -151,7 +151,7 @@ class Adder {
// so that we can compute its size in order to position it before display. // so that we can compute its size in order to position it before display.
this.element.style.visibility = 'hidden'; this.element.style.visibility = 'hidden';
var view = this.element.ownerDocument.defaultView; this._view = this.element.ownerDocument.defaultView;
this._enterTimeout = null; this._enterTimeout = null;
var handleCommand = (event) => { var handleCommand = (event) => {
...@@ -174,8 +174,8 @@ class Adder { ...@@ -174,8 +174,8 @@ class Adder {
this.element.querySelector(HIGHLIGHT_BTN_SELECTOR) this.element.querySelector(HIGHLIGHT_BTN_SELECTOR)
.addEventListener('click', handleCommand); .addEventListener('click', handleCommand);
var width = () => this.element.getBoundingClientRect().width; this._width = () => this.element.getBoundingClientRect().width;
var height = () => this.element.getBoundingClientRect().height; this._height = () => this.element.getBoundingClientRect().height;
/** Hide the adder */ /** Hide the adder */
this.hide = () => { this.hide = () => {
...@@ -211,32 +211,32 @@ class Adder { ...@@ -211,32 +211,32 @@ class Adder {
// and close to the end. // and close to the end.
var hMargin = Math.min(ARROW_H_MARGIN, targetRect.width); var hMargin = Math.min(ARROW_H_MARGIN, targetRect.width);
if (isSelectionBackwards) { if (isSelectionBackwards) {
left = targetRect.left - width() / 2 + hMargin; left = targetRect.left - this._width() / 2 + hMargin;
} else { } else {
left = targetRect.left + targetRect.width - width() / 2 - hMargin; left = targetRect.left + targetRect.width - this._width() / 2 - hMargin;
} }
// Flip arrow direction if adder would appear above the top or below the // Flip arrow direction if adder would appear above the top or below the
// bottom of the viewport. // bottom of the viewport.
if (targetRect.top - height() < 0 && if (targetRect.top - this._height() < 0 &&
arrowDirection === ARROW_POINTING_DOWN) { arrowDirection === ARROW_POINTING_DOWN) {
arrowDirection = ARROW_POINTING_UP; arrowDirection = ARROW_POINTING_UP;
} else if (targetRect.top + height() > view.innerHeight) { } else if (targetRect.top + this._height() > this._view.innerHeight) {
arrowDirection = ARROW_POINTING_DOWN; arrowDirection = ARROW_POINTING_DOWN;
} }
if (arrowDirection === ARROW_POINTING_UP) { if (arrowDirection === ARROW_POINTING_UP) {
top = targetRect.top + targetRect.height + ARROW_HEIGHT; top = targetRect.top + targetRect.height + ARROW_HEIGHT;
} else { } else {
top = targetRect.top - height() - ARROW_HEIGHT; top = targetRect.top - this._height() - ARROW_HEIGHT;
} }
// Constrain the adder to the viewport. // Constrain the adder to the viewport.
left = Math.max(left, 0); left = Math.max(left, 0);
left = Math.min(left, view.innerWidth - width()); left = Math.min(left, this._view.innerWidth - this._width());
top = Math.max(top, 0); top = Math.max(top, 0);
top = Math.min(top, view.innerHeight - height()); top = Math.min(top, this._view.innerHeight - this._height());
return {top, left, arrowDirection}; return {top, left, arrowDirection};
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment