summaryrefslogtreecommitdiff
path: root/ext/mixed
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mixed')
-rw-r--r--ext/mixed/css/display.css50
-rw-r--r--ext/mixed/css/popup-outer.css3
-rw-r--r--ext/mixed/js/display.js74
3 files changed, 125 insertions, 2 deletions
diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css
index 605c0148..0a676a8f 100644
--- a/ext/mixed/css/display.css
+++ b/ext/mixed/css/display.css
@@ -1119,6 +1119,52 @@ button.action-button {
}
+/* Frame resizer */
+.frame-resizer-container {
+ position: fixed;
+ bottom: 0;
+ right: 0;
+ z-index: 100;
+ background: transparent;
+ pointer-events: none;
+ user-select: none;
+}
+.frame-resizer-sizer1 {
+ padding-top: 100%;
+ line-height: 0;
+}
+.frame-resizer-sizer2 {
+ display: inline-block;
+ overflow-x: hidden;
+ overflow-y: scroll;
+ vertical-align: bottom;
+}
+.frame-resizer-sizer2.frame-resizer-sizer2-with-min-size {
+ min-width: 1em;
+}
+.frame-resizer-svg {
+ display: block;
+ position: absolute;
+ bottom: 0;
+ right: 0;
+ width: 75%;
+ height: 75%;
+}
+.frame-resizer-handle {
+ fill: var(--default-text-color);
+ opacity: 0.125;
+ cursor: se-resize;
+ pointer-events: auto;
+ transition:
+ fill var(--animation-duration) linear,
+ opacity var(--animation-duration) linear;
+}
+.frame-resizer-handle:hover {
+ fill: var(--accent-color);
+ opacity: 1;
+}
+
+
/* Conditional styles */
:root:not([data-enable-search-tags=true]) .tag[data-category=search] {
display: none;
@@ -1221,3 +1267,7 @@ button.action-button {
:root:not([data-glossary-layout-mode=compact]) .term-glossary-image-description {
display: block;
}
+
+:root[data-popup-display-mode=full-width] .frame-resizer-container {
+ display: none;
+}
diff --git a/ext/mixed/css/popup-outer.css b/ext/mixed/css/popup-outer.css
index 74307d9f..0ee8df9e 100644
--- a/ext/mixed/css/popup-outer.css
+++ b/ext/mixed/css/popup-outer.css
@@ -22,7 +22,7 @@ iframe.yomichan-popup {
border: 1em solid #999999;
box-shadow: 0 0 10em rgba(0, 0, 0, 0.5);
position: fixed;
- resize: both;
+ resize: none;
visibility: hidden;
z-index: 2147483647;
box-sizing: border-box;
@@ -38,7 +38,6 @@ iframe.yomichan-popup[data-outer-theme=auto][data-site-color=dark] {
iframe.yomichan-popup[data-popup-display-mode=full-width] {
border-left: none;
border-right: none;
- resize: none;
}
iframe.yomichan-popup[data-popup-display-mode=full-width][data-below=true] {
border-bottom: none;
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index b9daa9a0..b19d07e2 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -109,6 +109,11 @@ class Display extends EventDispatcher {
this._browser = null;
this._copyTextarea = null;
this._definitionTextScanner = null;
+ this._frameResizeToken = null;
+ this._frameResizeHandle = document.querySelector('#frame-resizer-handle');
+ this._frameResizeStartSize = null;
+ this._frameResizeStartOffset = null;
+ this._frameResizeEventListeners = new EventListenerCollection();
this.registerActions([
['close', () => { this.onEscape(); }],
@@ -228,6 +233,10 @@ class Display extends EventDispatcher {
this._navigationNextButton.addEventListener('click', this._onNextTermView.bind(this), false);
}
+ if (this._frameResizeHandle !== null) {
+ this._frameResizeHandle.addEventListener('mousedown', this._onFrameResizerMouseDown.bind(this), false);
+ }
+
// Final preparation
this._updateFocusedElement();
}
@@ -801,6 +810,7 @@ class Display extends EventDispatcher {
data.showPitchAccentPositionNotation = `${options.general.showPitchAccentPositionNotation}`;
data.showPitchAccentGraph = `${options.general.showPitchAccentGraph}`;
data.debug = `${options.general.debugInfo}`;
+ data.popupDisplayMode = `${options.general.popupDisplayMode}`;
}
_updateTheme(themeName) {
@@ -1795,4 +1805,68 @@ class Display extends EventDispatcher {
this._definitionTextScanner.clearSelection(true);
this.setContent(details);
}
+
+ _onFrameResizerMouseDown(e) {
+ if (e.button !== 0) { return; }
+ // Don't do e.preventDefault() here; this allows mousemove events to be processed
+ // if the pointer moves out of the frame.
+ this._startFrameResize(e);
+ }
+
+ _onFrameResizerMouseUp() {
+ this._stopFrameResize();
+ }
+
+ _onFrameResizerWindowBlur() {
+ this._stopFrameResize();
+ }
+
+ _onFrameResizerMouseMove(e) {
+ if ((e.buttons & 0x1) === 0x0) {
+ this._stopFrameResize();
+ } else {
+ if (this._frameResizeStartSize === null) { return; }
+ const {clientX: x, clientY: y} = e;
+ this._updateFrameSize(x, y);
+ }
+ }
+
+ _startFrameResize(e) {
+ if (this._frameResizeToken !== null) { return; }
+
+ const {clientX: x, clientY: y} = e;
+ const token = {};
+ this._frameResizeToken = token;
+ this._frameResizeStartOffset = {x, y};
+ this._frameResizeEventListeners.addEventListener(window, 'mouseup', this._onFrameResizerMouseUp.bind(this), false);
+ this._frameResizeEventListeners.addEventListener(window, 'blur', this._onFrameResizerWindowBlur.bind(this), false);
+ this._frameResizeEventListeners.addEventListener(window, 'mousemove', this._onFrameResizerMouseMove.bind(this), false);
+
+ this._initializeFrameResize(token);
+ }
+
+ async _initializeFrameResize(token) {
+ const size = await this._invokeOwner('getFrameSize');
+ if (this._frameResizeToken !== token) { return; }
+ this._frameResizeStartSize = size;
+ }
+
+ _stopFrameResize() {
+ if (this._frameResizeToken === null) { return; }
+
+ this._frameResizeEventListeners.removeAllEventListeners();
+ this._frameResizeStartSize = null;
+ this._frameResizeStartOffset = null;
+ this._frameResizeToken = null;
+ }
+
+ async _updateFrameSize(x, y) {
+ const handleSize = this._frameResizeHandle.getBoundingClientRect();
+ let {width, height} = this._frameResizeStartSize;
+ width += x - this._frameResizeStartOffset.x;
+ height += y - this._frameResizeStartOffset.y;
+ width = Math.max(Math.max(0, handleSize.width), width);
+ height = Math.max(Math.max(0, handleSize.height), height);
+ await this._invokeOwner('setFrameSize', {width, height});
+ }
}