code refactor: add $.remove() and $$.remove()
This commit is contained in:
parent
d4c0930723
commit
0de69e306d
12
edit/edit.js
12
edit/edit.js
|
@ -289,9 +289,7 @@ function initCodeMirror() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (index >= total) {
|
if (index >= total) {
|
||||||
if (progress) {
|
$.remove(progress);
|
||||||
progress.remove();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!progress &&
|
if (!progress &&
|
||||||
|
@ -1015,9 +1013,7 @@ function setupGlobalSearch() {
|
||||||
|
|
||||||
const dlg = $('.CodeMirror-dialog', cm.getWrapperElement());
|
const dlg = $('.CodeMirror-dialog', cm.getWrapperElement());
|
||||||
if (!dlg || cmp === 0 || wrapAround && CodeMirror.cmpPos(cm.getCursor(), origPos) >= 0) {
|
if (!dlg || cmp === 0 || wrapAround && CodeMirror.cmpPos(cm.getCursor(), origPos) >= 0) {
|
||||||
if (dlg) {
|
$.remove(dlg);
|
||||||
dlg.remove();
|
|
||||||
}
|
|
||||||
doReplace();
|
doReplace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2061,7 +2057,7 @@ function setGlobalProgress(done, total) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
progressElement.title = progress + '%';
|
progressElement.title = progress + '%';
|
||||||
});
|
});
|
||||||
} else if (progressElement) {
|
} else {
|
||||||
progressElement.remove();
|
$.remove(progressElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@
|
||||||
|
|
||||||
$('.header').classList.add('meta-init');
|
$('.header').classList.add('meta-init');
|
||||||
$('.header').classList.remove('meta-init-error');
|
$('.header').classList.remove('meta-init-error');
|
||||||
setTimeout(() => $('.lds-spinner') && $('.lds-spinner').remove(), 1000);
|
setTimeout(() => $.remove('.lds-spinner'), 1000);
|
||||||
|
|
||||||
showError('');
|
showError('');
|
||||||
requestAnimationFrame(adjustCodeHeight);
|
requestAnimationFrame(adjustCodeHeight);
|
||||||
|
@ -195,8 +195,7 @@
|
||||||
function install(style) {
|
function install(style) {
|
||||||
installed = style;
|
installed = style;
|
||||||
|
|
||||||
$$('.warning')
|
$$.remove('.warning');
|
||||||
.forEach(el => el.remove());
|
|
||||||
$('button.install').disabled = true;
|
$('button.install').disabled = true;
|
||||||
$('button.install').classList.add('installed');
|
$('button.install').classList.add('installed');
|
||||||
$('h2.installed').classList.add('active');
|
$('h2.installed').classList.add('active');
|
||||||
|
|
18
js/dom.js
18
js/dom.js
|
@ -11,6 +11,19 @@ for (const type of [NodeList, NamedNodeMap, HTMLCollection, HTMLAllCollection])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$.remove = (selector, base = document) => {
|
||||||
|
const el = selector instanceof Node ? selector : $(selector, base);
|
||||||
|
if (el) {
|
||||||
|
el.remove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$$.remove = (selector, base = document) => {
|
||||||
|
for (const el of base.querySelectorAll(selector)) {
|
||||||
|
el.remove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
// display a full text tooltip on buttons with ellipsis overflow and no inherent title
|
// display a full text tooltip on buttons with ellipsis overflow and no inherent title
|
||||||
const addTooltipsToEllipsized = () => {
|
const addTooltipsToEllipsized = () => {
|
||||||
|
@ -41,10 +54,7 @@ for (const type of [NodeList, NamedNodeMap, HTMLCollection, HTMLAllCollection])
|
||||||
}
|
}
|
||||||
|
|
||||||
onDOMready().then(() => {
|
onDOMready().then(() => {
|
||||||
const el = $('#firefox-transitions-bug-suppressor');
|
$.remove('#firefox-transitions-bug-suppressor');
|
||||||
if (el) {
|
|
||||||
el.remove();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!chrome.app && chrome.windows) {
|
if (!chrome.app && chrome.windows) {
|
||||||
|
|
|
@ -348,7 +348,7 @@ Object.assign(handleEvent, {
|
||||||
indicator(event) {
|
indicator(event) {
|
||||||
const entry = handleEvent.getClickedStyleElement(event);
|
const entry = handleEvent.getClickedStyleElement(event);
|
||||||
const info = template.regexpProblemExplanation.cloneNode(true);
|
const info = template.regexpProblemExplanation.cloneNode(true);
|
||||||
$$('#' + info.id).forEach(el => el.remove());
|
$.remove('#' + info.id);
|
||||||
$$('a', info).forEach(el => (el.onclick = handleEvent.openURLandHide));
|
$$('a', info).forEach(el => (el.onclick = handleEvent.openURLandHide));
|
||||||
$$('button', info).forEach(el => (el.onclick = handleEvent.closeExplanation));
|
$$('button', info).forEach(el => (el.onclick = handleEvent.closeExplanation));
|
||||||
entry.appendChild(info);
|
entry.appendChild(info);
|
||||||
|
@ -420,14 +420,14 @@ function handleUpdate(style) {
|
||||||
// Add an entry when a new style for the current url is installed
|
// Add an entry when a new style for the current url is installed
|
||||||
if (tabURL && BG.getApplicableSections({style, matchUrl: tabURL, stopOnFirst: true}).length) {
|
if (tabURL && BG.getApplicableSections({style, matchUrl: tabURL, stopOnFirst: true}).length) {
|
||||||
document.body.classList.remove('blocked');
|
document.body.classList.remove('blocked');
|
||||||
$$('.blocked-info, #no-styles').forEach(el => el.remove());
|
$$.remove('.blocked-info, #no-styles');
|
||||||
createStyleElement({style});
|
createStyleElement({style});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleDelete(id) {
|
function handleDelete(id) {
|
||||||
$$(ENTRY_ID_PREFIX + id).forEach(el => el.remove());
|
$.remove(ENTRY_ID_PREFIX + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user