wxiaoguang 2023-05-10 23:50:58 +08:00 committed by GitHub
parent 54f399c4df
commit 23ae939ef3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 111 additions and 39 deletions

View file

@ -1,3 +1,5 @@
import {debounce} from 'throttle-debounce';
function elementsCall(el, func, ...args) {
if (typeof el === 'string' || el instanceof String) {
el = document.querySelectorAll(el);
@ -42,6 +44,13 @@ export function toggleElem(el, force) {
elementsCall(el, toggleShown, force);
}
export function isElemHidden(el) {
const res = [];
elementsCall(el, (e) => res.push(e.classList.contains('gt-hidden')));
if (res.length > 1) throw new Error(`isElemHidden doesn't work for multiple elements`);
return res[0];
}
export function onDomReady(cb) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', cb);
@ -170,3 +179,7 @@ export function autosize(textarea, {viewportMarginBottom = 0} = {}) {
}
};
}
export function onInputDebounce(fn) {
return debounce(300, fn);
}