aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-15 17:23:27 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-16 19:54:41 -0500
commit8164ccfbfc257b81b5c35a38b1629d6c1178498d (patch)
tree718842a5dffcddf534852d06645dee939e13b90a /ext/fg/js/popup.js
parentfab0d703581a57aa7aa6d50a640b291a944708a2 (diff)
Group poup static functions together
Diffstat (limited to 'ext/fg/js/popup.js')
-rw-r--r--ext/fg/js/popup.js236
1 files changed, 118 insertions, 118 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 9e80a379..6aebc68e 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -138,99 +138,6 @@ class Popup {
}
}
- static getPositionForHorizontalText(elementRect, width, height, maxWidth, maxHeight, optionsGeneral) {
- let x = elementRect.left + optionsGeneral.popupHorizontalOffset;
- const overflowX = Math.max(x + width - maxWidth, 0);
- if (overflowX > 0) {
- if (x >= overflowX) {
- x -= overflowX;
- } else {
- width = maxWidth;
- x = 0;
- }
- }
-
- const preferBelow = (optionsGeneral.popupHorizontalTextPosition === 'below');
-
- const verticalOffset = optionsGeneral.popupVerticalOffset;
- const [y, h, below] = Popup.limitGeometry(
- elementRect.top - verticalOffset,
- elementRect.bottom + verticalOffset,
- height,
- maxHeight,
- preferBelow
- );
-
- return [x, y, width, h, below];
- }
-
- static getPositionForVerticalText(elementRect, width, height, maxWidth, maxHeight, optionsGeneral, writingMode) {
- const preferRight = Popup.isVerticalTextPopupOnRight(optionsGeneral.popupVerticalTextPosition, writingMode);
- const horizontalOffset = optionsGeneral.popupHorizontalOffset2;
- const verticalOffset = optionsGeneral.popupVerticalOffset2;
-
- const [x, w] = Popup.limitGeometry(
- elementRect.left - horizontalOffset,
- elementRect.right + horizontalOffset,
- width,
- maxWidth,
- preferRight
- );
- const [y, h, below] = Popup.limitGeometry(
- elementRect.bottom - verticalOffset,
- elementRect.top + verticalOffset,
- height,
- maxHeight,
- true
- );
- return [x, y, w, h, below];
- }
-
- static isVerticalTextPopupOnRight(positionPreference, writingMode) {
- switch (positionPreference) {
- case 'before':
- return !Popup.isWritingModeLeftToRight(writingMode);
- case 'after':
- return Popup.isWritingModeLeftToRight(writingMode);
- case 'left':
- return false;
- case 'right':
- return true;
- }
- }
-
- static isWritingModeLeftToRight(writingMode) {
- switch (writingMode) {
- case 'vertical-lr':
- case 'sideways-lr':
- return true;
- default:
- return false;
- }
- }
-
- static limitGeometry(positionBefore, positionAfter, size, limit, preferAfter) {
- let after = preferAfter;
- let position = 0;
- const overflowBefore = Math.max(0, size - positionBefore);
- const overflowAfter = Math.max(0, positionAfter + size - limit);
- if (overflowAfter > 0 || overflowBefore > 0) {
- if (overflowAfter < overflowBefore) {
- size = Math.max(0, size - overflowAfter);
- position = positionAfter;
- after = true;
- } else {
- size = Math.max(0, size - overflowBefore);
- position = Math.max(0, positionBefore - size);
- after = false;
- }
- } else {
- position = preferAfter ? positionAfter : positionBefore - size;
- }
-
- return [position, size, after];
- }
-
hide(changeFocus) {
if (!this.isVisible()) {
return;
@@ -296,31 +203,6 @@ class Popup {
return dark ? 'dark' : 'light';
}
- static addColor(target, color) {
- if (color === null) { return; }
-
- const a = color[3];
- if (a <= 0.0) { return; }
-
- const aInv = 1.0 - a;
- for (let i = 0; i < 3; ++i) {
- target[i] = target[i] * aInv + color[i] * a;
- }
- }
-
- static getColorInfo(cssColor) {
- const m = /^\s*rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)\s*$/.exec(cssColor);
- if (m === null) { return null; }
-
- const m4 = m[4];
- return [
- Number.parseInt(m[1], 10),
- Number.parseInt(m[2], 10),
- Number.parseInt(m[3], 10),
- m4 ? Math.max(0.0, Math.min(1.0, Number.parseFloat(m4))) : 1.0
- ];
- }
-
async containsPoint(x, y) {
for (let popup = this; popup !== null && popup.isVisible(); popup = popup.child) {
const rect = popup.container.getBoundingClientRect();
@@ -390,6 +272,124 @@ class Popup {
}
}
+ static getPositionForHorizontalText(elementRect, width, height, maxWidth, maxHeight, optionsGeneral) {
+ let x = elementRect.left + optionsGeneral.popupHorizontalOffset;
+ const overflowX = Math.max(x + width - maxWidth, 0);
+ if (overflowX > 0) {
+ if (x >= overflowX) {
+ x -= overflowX;
+ } else {
+ width = maxWidth;
+ x = 0;
+ }
+ }
+
+ const preferBelow = (optionsGeneral.popupHorizontalTextPosition === 'below');
+
+ const verticalOffset = optionsGeneral.popupVerticalOffset;
+ const [y, h, below] = Popup.limitGeometry(
+ elementRect.top - verticalOffset,
+ elementRect.bottom + verticalOffset,
+ height,
+ maxHeight,
+ preferBelow
+ );
+
+ return [x, y, width, h, below];
+ }
+
+ static getPositionForVerticalText(elementRect, width, height, maxWidth, maxHeight, optionsGeneral, writingMode) {
+ const preferRight = Popup.isVerticalTextPopupOnRight(optionsGeneral.popupVerticalTextPosition, writingMode);
+ const horizontalOffset = optionsGeneral.popupHorizontalOffset2;
+ const verticalOffset = optionsGeneral.popupVerticalOffset2;
+
+ const [x, w] = Popup.limitGeometry(
+ elementRect.left - horizontalOffset,
+ elementRect.right + horizontalOffset,
+ width,
+ maxWidth,
+ preferRight
+ );
+ const [y, h, below] = Popup.limitGeometry(
+ elementRect.bottom - verticalOffset,
+ elementRect.top + verticalOffset,
+ height,
+ maxHeight,
+ true
+ );
+ return [x, y, w, h, below];
+ }
+
+ static isVerticalTextPopupOnRight(positionPreference, writingMode) {
+ switch (positionPreference) {
+ case 'before':
+ return !Popup.isWritingModeLeftToRight(writingMode);
+ case 'after':
+ return Popup.isWritingModeLeftToRight(writingMode);
+ case 'left':
+ return false;
+ case 'right':
+ return true;
+ }
+ }
+
+ static isWritingModeLeftToRight(writingMode) {
+ switch (writingMode) {
+ case 'vertical-lr':
+ case 'sideways-lr':
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ static limitGeometry(positionBefore, positionAfter, size, limit, preferAfter) {
+ let after = preferAfter;
+ let position = 0;
+ const overflowBefore = Math.max(0, size - positionBefore);
+ const overflowAfter = Math.max(0, positionAfter + size - limit);
+ if (overflowAfter > 0 || overflowBefore > 0) {
+ if (overflowAfter < overflowBefore) {
+ size = Math.max(0, size - overflowAfter);
+ position = positionAfter;
+ after = true;
+ } else {
+ size = Math.max(0, size - overflowBefore);
+ position = Math.max(0, positionBefore - size);
+ after = false;
+ }
+ } else {
+ position = preferAfter ? positionAfter : positionBefore - size;
+ }
+
+ return [position, size, after];
+ }
+
+ static addColor(target, color) {
+ if (color === null) { return; }
+
+ const a = color[3];
+ if (a <= 0.0) { return; }
+
+ const aInv = 1.0 - a;
+ for (let i = 0; i < 3; ++i) {
+ target[i] = target[i] * aInv + color[i] * a;
+ }
+ }
+
+ static getColorInfo(cssColor) {
+ const m = /^\s*rgba?\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)\s*$/.exec(cssColor);
+ if (m === null) { return null; }
+
+ const m4 = m[4];
+ return [
+ Number.parseInt(m[1], 10),
+ Number.parseInt(m[2], 10),
+ Number.parseInt(m[3], 10),
+ m4 ? Math.max(0.0, Math.min(1.0, Number.parseFloat(m4))) : 1.0
+ ];
+ }
+
static isOnExtensionPage() {
try {
const url = chrome.runtime.getURL('/');