web/_javascript/modules/components/mode-watcher.js
Cotes Chung b69d3d7edd
refactor(build): modularize JS code
- replace gulp with rollup
- remove JS output from repo
2023-03-15 21:51:37 +08:00

21 lines
498 B
JavaScript

/**
* Add listener for theme mode toggle
*/
const $toggleElem = $('.mode-toggle');
export function modeWatcher() {
if ($toggleElem.length === 0) {
return;
}
$toggleElem.off().on('click', (e) => {
const $target = $(e.target);
let $btn =
$target.prop('tagName') === 'button'.toUpperCase()
? $target
: $target.parent();
modeToggle.flipMode(); // modeToggle: `_includes/mode-toggle.html`
$btn.trigger('blur'); // remove the clicking outline
});
}