simplify regexpTester::isShown
This commit is contained in:
parent
f8269c7424
commit
0bf1d365a3
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
define(require => {
|
define(require => {
|
||||||
const {URLS, openURL, tryRegExp} = require('/js/toolbox');
|
const {URLS, openURL, tryRegExp} = require('/js/toolbox');
|
||||||
const {$, $create} = require('/js/dom');
|
const {$create} = require('/js/dom');
|
||||||
const t = require('/js/localization');
|
const t = require('/js/localization');
|
||||||
const {helpPopup} = require('./util');
|
const {helpPopup} = require('./util');
|
||||||
|
|
||||||
|
@ -12,27 +12,28 @@ define(require => {
|
||||||
const OWN_ICON = chrome.runtime.getManifest().icons['16'];
|
const OWN_ICON = chrome.runtime.getManifest().icons['16'];
|
||||||
const cachedRegexps = new Map();
|
const cachedRegexps = new Map();
|
||||||
let currentRegexps = [];
|
let currentRegexps = [];
|
||||||
let isWatching;
|
let isWatching = false;
|
||||||
|
let isShown = false;
|
||||||
const isShown = () => Boolean($('.regexp-report'));
|
|
||||||
|
|
||||||
const regexpTester = /** @namespace RegExpTester */{
|
const regexpTester = /** @namespace RegExpTester */{
|
||||||
|
|
||||||
toggle(state = !isShown()) {
|
toggle(state = !isShown) {
|
||||||
if (state && !isShown()) {
|
if (state && !isShown) {
|
||||||
if (!isWatching) {
|
if (!isWatching) {
|
||||||
isWatching = true;
|
isWatching = true;
|
||||||
chrome.tabs.onUpdated.addListener(onTabUpdate);
|
chrome.tabs.onUpdated.addListener(onTabUpdate);
|
||||||
}
|
}
|
||||||
helpPopup.show('', $create('.regexp-report'));
|
helpPopup.show('', $create('.regexp-report'));
|
||||||
} else if (!state && isShown()) {
|
isShown = true;
|
||||||
|
} else if (!state && isShown) {
|
||||||
unwatch();
|
unwatch();
|
||||||
helpPopup.close();
|
helpPopup.close();
|
||||||
|
isShown = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async update(newRegexps) {
|
async update(newRegexps) {
|
||||||
if (!isShown()) {
|
if (!isShown) {
|
||||||
unwatch();
|
unwatch();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -188,5 +189,7 @@ define(require => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.on('closeHelp', () => regexpTester.toggle(false));
|
||||||
|
|
||||||
return regexpTester;
|
return regexpTester;
|
||||||
});
|
});
|
||||||
|
|
|
@ -94,10 +94,10 @@ define(require => {
|
||||||
document.activeElement.matches(':not(input), .can-close-on-esc')
|
document.activeElement.matches(':not(input), .can-close-on-esc')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (!canClose) {
|
const div = $('#help-popup');
|
||||||
|
if (!canClose || !div) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const div = $('#help-popup');
|
|
||||||
if (event && div.codebox && !div.codebox.options.readOnly && !div.codebox.isClean()) {
|
if (event && div.codebox && !div.codebox.options.readOnly && !div.codebox.isClean()) {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const ok = await messageBoxProxy.confirm(t('confirmDiscardChanges'));
|
const ok = await messageBoxProxy.confirm(t('confirmDiscardChanges'));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user