mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 02:46:04 +01:00 
			
		
		
		
	Add toggleClass function in dom.ts (#34063)
This PR adds a toggleClass function in dom.ts, aiming to implement DOM class toggling functionality. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -25,32 +25,34 @@ function elementsCall(el: ElementArg, func: ElementsCallbackWithArgs, ...args: a | ||||
|   } | ||||
| } | ||||
|  | ||||
| export function toggleClass(el: ElementArg, className: string, force?: boolean) { | ||||
|   elementsCall(el, (e: Element) => { | ||||
|     if (force === true) { | ||||
|       e.classList.add(className); | ||||
|     } else if (force === false) { | ||||
|       e.classList.remove(className); | ||||
|     } else if (force === undefined) { | ||||
|       e.classList.toggle(className); | ||||
|     } else { | ||||
|       throw new Error('invalid force argument'); | ||||
|     } | ||||
|   }); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * @param el Element | ||||
|  * @param el ElementArg | ||||
|  * @param force force=true to show or force=false to hide, undefined to toggle | ||||
|  */ | ||||
| function toggleShown(el: Element, force: boolean) { | ||||
|   if (force === true) { | ||||
|     el.classList.remove('tw-hidden'); | ||||
|   } else if (force === false) { | ||||
|     el.classList.add('tw-hidden'); | ||||
|   } else if (force === undefined) { | ||||
|     el.classList.toggle('tw-hidden'); | ||||
|   } else { | ||||
|     throw new Error('invalid force argument'); | ||||
|   } | ||||
| export function toggleElem(el: ElementArg, force?: boolean) { | ||||
|   toggleClass(el, 'tw-hidden', !force); | ||||
| } | ||||
|  | ||||
| export function showElem(el: ElementArg) { | ||||
|   elementsCall(el, toggleShown, true); | ||||
|   toggleElem(el, true); | ||||
| } | ||||
|  | ||||
| export function hideElem(el: ElementArg) { | ||||
|   elementsCall(el, toggleShown, false); | ||||
| } | ||||
|  | ||||
| export function toggleElem(el: ElementArg, force?: boolean) { | ||||
|   elementsCall(el, toggleShown, force); | ||||
|   toggleElem(el, false); | ||||
| } | ||||
|  | ||||
| export function isElemHidden(el: ElementArg) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user