Popup preview update (#994)
* Add options.global.showPopupPreview option * Add preview visibility control using a checkbox * Add attribute on page load * Disable animation until page is loaded
This commit is contained in:
parent
b62c48822e
commit
9c6ff387a0
@ -15,8 +15,15 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--animation-duration: 0s;
|
||||||
|
}
|
||||||
|
:root[data-loaded=true] {
|
||||||
|
--animation-duration: 0.25s;
|
||||||
|
}
|
||||||
|
|
||||||
html {
|
html {
|
||||||
transition: background-color 0.25s linear 0s, color 0.25s linear 0s;
|
transition: background-color var(--animation-duration) linear 0s, color var(--animation-duration) linear 0s;
|
||||||
background-color: rgba(255, 255, 255, 0);
|
background-color: rgba(255, 255, 255, 0);
|
||||||
color: #333333;
|
color: #333333;
|
||||||
}
|
}
|
||||||
@ -81,7 +88,7 @@ body {
|
|||||||
color: inherit;
|
color: inherit;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
white-space: pre;
|
white-space: pre;
|
||||||
transition: background-color 0.25s linear 0s, border-color 0.25s linear 0s;
|
transition: background-color var(--animation-duration) linear 0s, border-color var(--animation-duration) linear 0s;
|
||||||
}
|
}
|
||||||
.example-text:hover,
|
.example-text:hover,
|
||||||
.example-text-input {
|
.example-text-input {
|
||||||
@ -114,12 +121,12 @@ body {
|
|||||||
flex: 0 1 auto;
|
flex: 0 1 auto;
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transition: opacity 0.5s linear 0s, visibility 0s linear 0.5s;
|
transition: opacity var(--animation-duration) linear 0s, visibility 0s linear var(--animation-duration);
|
||||||
}
|
}
|
||||||
.placeholder-info.placeholder-info-visible {
|
.placeholder-info.placeholder-info-visible {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transition: opacity 0.5s linear 0s, visibility 0s linear 0s;
|
transition: opacity var(--animation-duration) linear 0s, visibility 0s linear 0s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.theme-button {
|
.theme-button {
|
||||||
|
@ -790,7 +790,8 @@
|
|||||||
"global": {
|
"global": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"database"
|
"database",
|
||||||
|
"showPopupPreview"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"database": {
|
"database": {
|
||||||
@ -804,6 +805,10 @@
|
|||||||
"default": false
|
"default": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"showPopupPreview": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -612,7 +612,9 @@ class OptionsUtil {
|
|||||||
async _updateVersion6(options) {
|
async _updateVersion6(options) {
|
||||||
// Version 6 changes:
|
// Version 6 changes:
|
||||||
// Updated handlebars templates to include "conjugation" definition.
|
// Updated handlebars templates to include "conjugation" definition.
|
||||||
|
// Added global option showPopupPreview.
|
||||||
await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v6.handlebars');
|
await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v6.handlebars');
|
||||||
|
options.global.showPopupPreview = false;
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,11 @@ class PopupPreviewController {
|
|||||||
this._previewTextInput = null;
|
this._previewTextInput = null;
|
||||||
this._customCss = null;
|
this._customCss = null;
|
||||||
this._customOuterCss = null;
|
this._customOuterCss = null;
|
||||||
|
this._previewFrameContainer = null;
|
||||||
|
this._showPopupPreviewCheckbox = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare() {
|
async prepare() {
|
||||||
const button = document.querySelector('#settings-popup-preview-button');
|
const button = document.querySelector('#settings-popup-preview-button');
|
||||||
if (button !== null) {
|
if (button !== null) {
|
||||||
button.addEventListener('click', this._onShowPopupPreviewButtonClick.bind(this), false);
|
button.addEventListener('click', this._onShowPopupPreviewButtonClick.bind(this), false);
|
||||||
@ -38,13 +40,20 @@ class PopupPreviewController {
|
|||||||
this._frame = document.querySelector('#popup-preview-frame');
|
this._frame = document.querySelector('#popup-preview-frame');
|
||||||
this._customCss = document.querySelector('#custom-popup-css');
|
this._customCss = document.querySelector('#custom-popup-css');
|
||||||
this._customOuterCss = document.querySelector('#custom-popup-outer-css');
|
this._customOuterCss = document.querySelector('#custom-popup-outer-css');
|
||||||
|
this._previewFrameContainer = document.querySelector('.preview-frame-container');
|
||||||
|
this._showPopupPreviewCheckbox = document.querySelector('#show-preview-checkbox');
|
||||||
|
|
||||||
this._customCss.addEventListener('input', this._onCustomCssChange.bind(this), false);
|
this._customCss.addEventListener('input', this._onCustomCssChange.bind(this), false);
|
||||||
this._customCss.addEventListener('settingChanged', this._onCustomCssChange.bind(this), false);
|
this._customCss.addEventListener('settingChanged', this._onCustomCssChange.bind(this), false);
|
||||||
this._customOuterCss.addEventListener('input', this._onCustomOuterCssChange.bind(this), false);
|
this._customOuterCss.addEventListener('input', this._onCustomOuterCssChange.bind(this), false);
|
||||||
this._customOuterCss.addEventListener('settingChanged', this._onCustomOuterCssChange.bind(this), false);
|
this._customOuterCss.addEventListener('settingChanged', this._onCustomOuterCssChange.bind(this), false);
|
||||||
this._frame.addEventListener('load', this._onFrameLoad2.bind(this), false);
|
this._frame.addEventListener('load', this._onFrameLoad2.bind(this), false);
|
||||||
|
this._showPopupPreviewCheckbox.addEventListener('change', this._onShowPreviewCheckboxChange.bind(this), false);
|
||||||
this._settingsController.on('optionsContextChanged', this._onOptionsContextChange.bind(this));
|
this._settingsController.on('optionsContextChanged', this._onOptionsContextChange.bind(this));
|
||||||
|
|
||||||
|
const {global: {showPopupPreview}} = await this._settingsController.getOptionsFull();
|
||||||
|
this._showPopupPreviewCheckbox.checked = showPopupPreview;
|
||||||
|
this._updatePopupPreviewVisibility();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +65,10 @@ class PopupPreviewController {
|
|||||||
this._previewVisible = true;
|
this._previewVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onShowPreviewCheckboxChange() {
|
||||||
|
this._updatePopupPreviewVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
_showAppearancePreview() {
|
_showAppearancePreview() {
|
||||||
const container = document.querySelector('#settings-popup-preview-container');
|
const container = document.querySelector('#settings-popup-preview-container');
|
||||||
const buttonContainer = document.querySelector('#settings-popup-preview-button-container');
|
const buttonContainer = document.querySelector('#settings-popup-preview-button-container');
|
||||||
@ -124,4 +137,10 @@ class PopupPreviewController {
|
|||||||
if (this._frame === null || this._frame.contentWindow === null) { return; }
|
if (this._frame === null || this._frame.contentWindow === null) { return; }
|
||||||
this._frame.contentWindow.postMessage({action, params}, this._targetOrigin);
|
this._frame.contentWindow.postMessage({action, params}, this._targetOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_updatePopupPreviewVisibility() {
|
||||||
|
const value = this._showPopupPreviewCheckbox.checked;
|
||||||
|
this._previewFrameContainer.classList.toggle('preview-frame-container-visible', value);
|
||||||
|
this._settingsController.setGlobalSetting('global.showPopupPreview', value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
const preview = new PopupPreviewFrame(frameId, popupFactory);
|
const preview = new PopupPreviewFrame(frameId, popupFactory);
|
||||||
await preview.prepare();
|
await preview.prepare();
|
||||||
|
|
||||||
|
document.documentElement.dataset.loaded = 'true';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yomichan.logError(e);
|
yomichan.logError(e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user