Skip to content

Commit

Permalink
code cosmetics: rename toggleClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Dec 25, 2024
1 parent 9849662 commit 7aa2d41
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/js/dom-init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {$, $toggleClasses, dom, mqCompact} from './dom';
import {$, dom, mqCompact, toggleClasses} from './dom';
import {waitForSelector} from './dom-util';
import * as prefs from './prefs';
import {FIREFOX, MOBILE, OPERA, VIVALDI, WINDOWS} from './ua';
Expand Down Expand Up @@ -52,7 +52,7 @@ prefs.ready.then(() => {
if (mqCompact) {
const toggleCompact = mq => {
mq = mq.matches;
$toggleClasses($.root, {
toggleClasses($.root, {
'compact-layout': mq,
'normal-layout': !mq,
});
Expand Down
16 changes: 8 additions & 8 deletions src/js/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ export function $detach(el, state = true) {
return state;
}

/** Moves child nodes to a new document fragment */
export function $toFragment(el) {
const bin = document.createDocumentFragment();
bin.append(...el.childNodes);
return bin;
}

/**
* construct a new className:
* 1. add a class if value is truthy
Expand All @@ -185,21 +192,14 @@ export function $detach(el, state = true) {
* @param {HTMLElement} el
* @param {object} newClasses
*/
export function $toggleClasses(el, newClasses) {
export function toggleClasses(el, newClasses) {
const list = new Set();
for (const c of el.classList) list.add(c);
for (const c in newClasses) if (newClasses[c]) list.add(c); else list.delete(c);
let res = ''; for (const c of list) res += res ? ' ' + c : c;
if (el.className !== res) el.className = res;
}

/** Moves child nodes to a new document fragment */
export function $toFragment(el) {
const bin = document.createDocumentFragment();
bin.append(...el.childNodes);
return bin;
}

export function toggleDataset(el, prop, state) {
if (!el) return;
const wasEnabled = el.dataset[prop] != null; // avoids mutating DOM unnecessarily
Expand Down
4 changes: 2 additions & 2 deletions src/manage/updater-ui.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {$, $$, $create, $detach, $toggleClasses} from '@/js/dom';
import {$, $$, $create, $detach, toggleClasses} from '@/js/dom';
import {messageBox, scrollElementIntoView} from '@/js/dom-util';
import {template} from '@/js/localization';
import {API} from '@/js/msg';
Expand Down Expand Up @@ -192,7 +192,7 @@ function reportUpdateState({updated, style, error, STATES}) {
}
}

$toggleClasses(entry, newClasses);
toggleClasses(entry, newClasses);

if (filtersSelector.hide && isCheckAll) {
filterAndAppend({entry}).then(updateStripes);
Expand Down

0 comments on commit 7aa2d41

Please # to comment.