Improve display tags (#1117)
* Update tag style * Add styles/HTML for notifications * Add DisplayNotification class * Add support for tag notifications * Simplify notification content
This commit is contained in:
parent
c3e772fadc
commit
bf34905012
@ -65,6 +65,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="content-footer-container1"><div class="content-footer-container2"><div class="content-footer" id="content-footer"></div><div class="scrollbar-spacer scrollbar"></div></div></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -87,6 +88,7 @@
|
|||||||
<script src="/mixed/js/display.js"></script>
|
<script src="/mixed/js/display.js"></script>
|
||||||
<script src="/mixed/js/display-generator.js"></script>
|
<script src="/mixed/js/display-generator.js"></script>
|
||||||
<script src="/mixed/js/display-history.js"></script>
|
<script src="/mixed/js/display-history.js"></script>
|
||||||
|
<script src="/mixed/js/display-notification.js"></script>
|
||||||
<script src="/mixed/js/dynamic-loader.js"></script>
|
<script src="/mixed/js/dynamic-loader.js"></script>
|
||||||
<script src="/mixed/js/media-loader.js"></script>
|
<script src="/mixed/js/media-loader.js"></script>
|
||||||
<script src="/mixed/js/scroll.js"></script>
|
<script src="/mixed/js/scroll.js"></script>
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="content-footer-container1"><div class="content-footer-container2"><div class="content-footer" id="content-footer"></div><div class="scrollbar-spacer scrollbar"></div></div></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="content-sidebar scrollbar" id="content-sidebar" hidden>
|
<div class="content-sidebar scrollbar" id="content-sidebar" hidden>
|
||||||
<div class="content-sidebar-inner">
|
<div class="content-sidebar-inner">
|
||||||
@ -91,6 +92,7 @@
|
|||||||
<script src="/mixed/js/display.js"></script>
|
<script src="/mixed/js/display.js"></script>
|
||||||
<script src="/mixed/js/display-generator.js"></script>
|
<script src="/mixed/js/display-generator.js"></script>
|
||||||
<script src="/mixed/js/display-history.js"></script>
|
<script src="/mixed/js/display-history.js"></script>
|
||||||
|
<script src="/mixed/js/display-notification.js"></script>
|
||||||
<script src="/mixed/js/dynamic-loader.js"></script>
|
<script src="/mixed/js/dynamic-loader.js"></script>
|
||||||
<script src="/mixed/js/frame-endpoint.js"></script>
|
<script src="/mixed/js/frame-endpoint.js"></script>
|
||||||
<script src="/mixed/js/media-loader.js"></script>
|
<script src="/mixed/js/media-loader.js"></script>
|
||||||
|
@ -126,6 +126,10 @@
|
|||||||
--progress-bar-track-color: #cccccc;
|
--progress-bar-track-color: #cccccc;
|
||||||
--progress-bar-indicator-color: var(--accent-color);
|
--progress-bar-indicator-color: var(--accent-color);
|
||||||
--entry-current-indicator-color: var(--accent-color);
|
--entry-current-indicator-color: var(--accent-color);
|
||||||
|
|
||||||
|
--notification-text-color: #ffffff;
|
||||||
|
--notification-background-color: #333333;
|
||||||
|
--notification-shadow-color: rgba(0, 0, 0, 0.5);
|
||||||
}
|
}
|
||||||
:root[data-theme=dark] {
|
:root[data-theme=dark] {
|
||||||
/* Colors */
|
/* Colors */
|
||||||
@ -182,6 +186,10 @@
|
|||||||
--progress-bar-track-color: #3a3a3a;
|
--progress-bar-track-color: #3a3a3a;
|
||||||
--progress-bar-indicator-color: var(--accent-color);
|
--progress-bar-indicator-color: var(--accent-color);
|
||||||
--entry-current-indicator-color: var(--accent-color);
|
--entry-current-indicator-color: var(--accent-color);
|
||||||
|
|
||||||
|
--notification-text-color: #2f2f2f;
|
||||||
|
--notification-background-color: #e1e1e1;
|
||||||
|
--notification-shadow-color: rgba(255, 255, 255, 0.25);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -252,6 +260,13 @@ a {
|
|||||||
:root:not([data-theme=default]) .scrollbar::-webkit-scrollbar-corner {
|
:root:not([data-theme=default]) .scrollbar::-webkit-scrollbar-corner {
|
||||||
background-color: var(--scrollbar-track-color);
|
background-color: var(--scrollbar-track-color);
|
||||||
}
|
}
|
||||||
|
.scrollbar-spacer {
|
||||||
|
display: inline-block;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: scroll;
|
||||||
|
visibility: hidden;
|
||||||
|
flex: 0 1 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Main layout */
|
/* Main layout */
|
||||||
@ -284,6 +299,27 @@ a {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
padding: var(--main-content-vertical-padding) var(--main-content-horizontal-padding);
|
padding: var(--main-content-vertical-padding) var(--main-content-horizontal-padding);
|
||||||
}
|
}
|
||||||
|
.content-footer-container1 {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row nowrap;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
max-height: 100%;
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 5;
|
||||||
|
}
|
||||||
|
.content-footer-container2 {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row nowrap;
|
||||||
|
justify-content: center;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
.content-footer {
|
||||||
|
max-width: var(--main-content-size);
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Sidebar layout */
|
/* Sidebar layout */
|
||||||
@ -519,6 +555,7 @@ button.action-button {
|
|||||||
background-color: var(--tag-default-background-color);
|
background-color: var(--tag-default-background-color);
|
||||||
border: var(--tag-border-size) var(--tag-border-style) var(--tag-border-color);
|
border: var(--tag-border-size) var(--tag-border-style) var(--tag-border-color);
|
||||||
margin-right: 0.375em;
|
margin-right: 0.375em;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.tag[data-category=name] {
|
.tag[data-category=name] {
|
||||||
background-color: var(--tag-name-background-color);
|
background-color: var(--tag-name-background-color);
|
||||||
@ -1165,6 +1202,57 @@ button.action-button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Footer notifications */
|
||||||
|
.footer-notification {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row nowrap;
|
||||||
|
align-items: center;
|
||||||
|
pointer-events: auto;
|
||||||
|
border-radius: 0.25em;
|
||||||
|
background-color: var(--notification-background-color);
|
||||||
|
box-shadow: 0 0.125em 0.25em 0 var(--notification-shadow-color);
|
||||||
|
color: var(--notification-text-color);
|
||||||
|
margin: 0.5em;
|
||||||
|
padding: 0.5em 0.75em;
|
||||||
|
transition: opacity var(--animation-duration) ease-out;
|
||||||
|
}
|
||||||
|
.footer-notification[hidden] {
|
||||||
|
display: flex;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity var(--animation-duration) ease-in;
|
||||||
|
}
|
||||||
|
.footer-notification-body {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
padding-right: 0.5em;
|
||||||
|
}
|
||||||
|
.footer-notification-close-button {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
background-color: transparent;
|
||||||
|
margin: -0.25em;
|
||||||
|
padding: 0.5em;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: inherit;
|
||||||
|
}
|
||||||
|
.footer-notification-close-button-icon {
|
||||||
|
display: block;
|
||||||
|
width: calc(12em / var(--font-size-no-units));
|
||||||
|
height: calc(12em / var(--font-size-no-units));
|
||||||
|
mask-repeat: no-repeat;
|
||||||
|
mask-position: center center;
|
||||||
|
mask-mode: alpha;
|
||||||
|
mask-size: var(--sidebar-button-icon-size) var(--sidebar-button-icon-size);
|
||||||
|
mask-image: url(/mixed/img/cross.svg);
|
||||||
|
-webkit-mask-repeat: no-repeat;
|
||||||
|
-webkit-mask-position: center center;
|
||||||
|
-webkit-mask-mode: alpha;
|
||||||
|
-webkit-mask-size: var(--sidebar-button-icon-size) var(--sidebar-button-icon-size);
|
||||||
|
-webkit-mask-image: url(/mixed/img/cross.svg);
|
||||||
|
background-color: var(--notification-text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Conditional styles */
|
/* Conditional styles */
|
||||||
:root:not([data-enable-search-tags=true]) .tag[data-category=search] {
|
:root:not([data-enable-search-tags=true]) .tag[data-category=search] {
|
||||||
display: none;
|
display: none;
|
||||||
|
@ -117,4 +117,10 @@
|
|||||||
</span>
|
</span>
|
||||||
</span></template>
|
</span></template>
|
||||||
|
|
||||||
|
<!-- Extra -->
|
||||||
|
<template id="footer-notification-template"><div class="footer-notification">
|
||||||
|
<div class="footer-notification-body"></div>
|
||||||
|
<button class="footer-notification-close-button"><span class="footer-notification-close-button-icon"></span></button>
|
||||||
|
</div></template>
|
||||||
|
|
||||||
</body></html>
|
</body></html>
|
||||||
|
@ -117,6 +117,10 @@ class DisplayGenerator {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createEmptyFooterNotification() {
|
||||||
|
return this._templates.instantiate('footer-notification');
|
||||||
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
|
||||||
_createTermExpression(details) {
|
_createTermExpression(details) {
|
||||||
@ -310,6 +314,7 @@ class DisplayGenerator {
|
|||||||
|
|
||||||
node.title = details.notes;
|
node.title = details.notes;
|
||||||
inner.textContent = details.name;
|
inner.textContent = details.name;
|
||||||
|
node.dataset.details = details.notes || details.name;
|
||||||
node.dataset.category = details.category;
|
node.dataset.category = details.category;
|
||||||
if (details.redundant) { node.dataset.redundant = 'true'; }
|
if (details.redundant) { node.dataset.redundant = 'true'; }
|
||||||
|
|
||||||
@ -472,6 +477,7 @@ class DisplayGenerator {
|
|||||||
node.dataset.readingIsSame = `${reading === expression}`;
|
node.dataset.readingIsSame = `${reading === expression}`;
|
||||||
node.dataset.dictionary = dictionary;
|
node.dataset.dictionary = dictionary;
|
||||||
node.dataset.frequency = frequency;
|
node.dataset.frequency = frequency;
|
||||||
|
node.dataset.details = `${dictionary}: ${frequency}`;
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -486,6 +492,7 @@ class DisplayGenerator {
|
|||||||
node.dataset.character = character;
|
node.dataset.character = character;
|
||||||
node.dataset.dictionary = dictionary;
|
node.dataset.dictionary = dictionary;
|
||||||
node.dataset.frequency = frequency;
|
node.dataset.frequency = frequency;
|
||||||
|
node.dataset.details = `${dictionary}: ${frequency}`;
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
90
ext/mixed/js/display-notification.js
Normal file
90
ext/mixed/js/display-notification.js
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017-2020 Yomichan Authors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class DisplayNotification {
|
||||||
|
constructor(container, node) {
|
||||||
|
this._container = container;
|
||||||
|
this._node = node;
|
||||||
|
this._body = node.querySelector('.footer-notification-body');
|
||||||
|
this._closeButton = node.querySelector('.footer-notification-close-button');
|
||||||
|
this._eventListeners = new EventListenerCollection();
|
||||||
|
this._closeTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
open() {
|
||||||
|
if (!this.isClosed()) { return; }
|
||||||
|
|
||||||
|
this._clearTimer();
|
||||||
|
|
||||||
|
const node = this._node;
|
||||||
|
this._container.appendChild(node);
|
||||||
|
const style = getComputedStyle(node);
|
||||||
|
node.hidden = true;
|
||||||
|
style.getPropertyValue('opacity'); // Force CSS update, allowing animation
|
||||||
|
node.hidden = false;
|
||||||
|
this._eventListeners.addEventListener(this._closeButton, 'click', this._onCloseButtonClick.bind(this), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(animate=false) {
|
||||||
|
if (this.isClosed()) { return; }
|
||||||
|
|
||||||
|
if (animate) {
|
||||||
|
if (this._closeTimer !== null) { return; }
|
||||||
|
|
||||||
|
this._node.hidden = true;
|
||||||
|
this._closeTimer = setTimeout(this._onDelayClose.bind(this), 200);
|
||||||
|
} else {
|
||||||
|
this._clearTimer();
|
||||||
|
|
||||||
|
this._eventListeners.removeAllEventListeners();
|
||||||
|
const parent = this._node.parentNode;
|
||||||
|
if (parent !== null) {
|
||||||
|
parent.removeChild(this._node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setContent(text) {
|
||||||
|
this._body.textContent = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
isClosing() {
|
||||||
|
return this._closeTimer !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
isClosed() {
|
||||||
|
return this._node.parentNode === null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Private
|
||||||
|
|
||||||
|
_onCloseButtonClick() {
|
||||||
|
this.close(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onDelayClose() {
|
||||||
|
this._closeTimer = null;
|
||||||
|
this.close(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_clearTimer() {
|
||||||
|
if (this._closeTimer !== null) {
|
||||||
|
clearTimeout(this._closeTimer);
|
||||||
|
this._closeTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@
|
|||||||
* AudioSystem
|
* AudioSystem
|
||||||
* DisplayGenerator
|
* DisplayGenerator
|
||||||
* DisplayHistory
|
* DisplayHistory
|
||||||
|
* DisplayNotification
|
||||||
* DocumentUtil
|
* DocumentUtil
|
||||||
* FrameEndpoint
|
* FrameEndpoint
|
||||||
* Frontend
|
* Frontend
|
||||||
@ -114,6 +115,8 @@ class Display extends EventDispatcher {
|
|||||||
this._frameResizeStartSize = null;
|
this._frameResizeStartSize = null;
|
||||||
this._frameResizeStartOffset = null;
|
this._frameResizeStartOffset = null;
|
||||||
this._frameResizeEventListeners = new EventListenerCollection();
|
this._frameResizeEventListeners = new EventListenerCollection();
|
||||||
|
this._tagNotification = null;
|
||||||
|
this._tagNotificationContainer = document.querySelector('#content-footer');
|
||||||
|
|
||||||
this.registerActions([
|
this.registerActions([
|
||||||
['close', () => { this.onEscape(); }],
|
['close', () => { this.onEscape(); }],
|
||||||
@ -543,6 +546,7 @@ class Display extends EventDispatcher {
|
|||||||
this._closePopups();
|
this._closePopups();
|
||||||
this._eventListeners.removeAllEventListeners();
|
this._eventListeners.removeAllEventListeners();
|
||||||
this._mediaLoader.unloadAll();
|
this._mediaLoader.unloadAll();
|
||||||
|
this._hideTagNotification(false);
|
||||||
|
|
||||||
// Prepare
|
// Prepare
|
||||||
const urlSearchParams = new URLSearchParams(location.search);
|
const urlSearchParams = new URLSearchParams(location.search);
|
||||||
@ -799,6 +803,27 @@ class Display extends EventDispatcher {
|
|||||||
this._entrySetCurrent(index);
|
this._entrySetCurrent(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onTagClick(e) {
|
||||||
|
const node = e.currentTarget;
|
||||||
|
const {dataset: {details}} = node;
|
||||||
|
this._showTagNotification(details);
|
||||||
|
}
|
||||||
|
|
||||||
|
_showTagNotification(content) {
|
||||||
|
if (this._tagNotification === null) {
|
||||||
|
const node = this._displayGenerator.createEmptyFooterNotification();
|
||||||
|
this._tagNotification = new DisplayNotification(this._tagNotificationContainer, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._tagNotification.setContent(content);
|
||||||
|
this._tagNotification.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
_hideTagNotification(animate) {
|
||||||
|
if (this._tagNotification === null) { return; }
|
||||||
|
this._tagNotification.close(animate);
|
||||||
|
}
|
||||||
|
|
||||||
_updateDocumentOptions(options) {
|
_updateDocumentOptions(options) {
|
||||||
const data = document.documentElement.dataset;
|
const data = document.documentElement.dataset;
|
||||||
data.ankiEnabled = `${options.anki.enable}`;
|
data.ankiEnabled = `${options.anki.enable}`;
|
||||||
@ -1720,6 +1745,7 @@ class Display extends EventDispatcher {
|
|||||||
this._addMultipleEventListeners(entry, '.action-play-audio', 'click', this._onAudioPlay.bind(this));
|
this._addMultipleEventListeners(entry, '.action-play-audio', 'click', this._onAudioPlay.bind(this));
|
||||||
this._addMultipleEventListeners(entry, '.kanji-link', 'click', this._onKanjiLookup.bind(this));
|
this._addMultipleEventListeners(entry, '.kanji-link', 'click', this._onKanjiLookup.bind(this));
|
||||||
this._addMultipleEventListeners(entry, '.debug-log-link', 'click', this._onDebugLogClick.bind(this));
|
this._addMultipleEventListeners(entry, '.debug-log-link', 'click', this._onDebugLogClick.bind(this));
|
||||||
|
this._addMultipleEventListeners(entry, '.tag', 'click', this._onTagClick.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateDefinitionTextScanner(options) {
|
_updateDefinitionTextScanner(options) {
|
||||||
|
Loading…
Reference in New Issue
Block a user