/** * @module layout */ import { flush } from "../haven/buffer"; import { block as inputBlock, isBlocked as isInputBlocked, unblock as inputUnblock } from "../haven/input"; import { container } from "../haven/window"; /** * Blocks the UI so that the user can't type anything or click any elements. * Note that this only applies to built-in input and features, for custom * features use [[isBlocked]] to check whether input should be accepted. * * Use [[unblock]] to remove the block. */ export function block(): void { $( ".vorple-link" ).addClass( "disabled" ); inputBlock(); } /** * Close a tag that is currently open. * * Because the tags are added as DOM elements, the tag isn't really "open" * in the sense that it would be missing the closing tag. Instead we jump * out of the tag and set output focus back to its parent element. * * @see [[openTag]] * * @param targetWindow The target window in the Haven engine. This is practically always 0. * @returns Returns true if a tag was open, false if we were already at the top window level and nothing was done. */ export function closeTag( targetWindow = 0 ): boolean { const current = container.get( targetWindow ); if( current.id === "window0" ) { return false; } flush( targetWindow ); container.set( current.parentNode, targetWindow ); return true; } /** * Set output focus to an element. * * @param targetElement A jQuery object or selector * @param targetWindow The target window in the Haven engine. This is practically always 0. * * @returns Returns true if the focus was set successfully, false if the element wasn't found. */ export function focus( targetElement: string | JQuery.PlainObject, targetWindow = 0 ): boolean { const $target: JQuery = $( targetElement ); if( $target.length === 0 ) { return false; } flush( targetWindow ); container.set( $target.last().get( 0 ), targetWindow ); return true; } /** * Checks whether user input is blocked. * * @returns Returns true if input is blocked, otherwise false. * @since 3.2.6 */ export function isBlocked(): boolean { return isInputBlocked(); } /** * Create a new HTML element, append it to the target window, and set the output * focus to the element. * * Example: * ``` * vorple.layout.openTag( 'div', 'vorple' ) -->
* ``` * * @param tagName Name of the tag to create * @param classes Class names to add to the element * @param targetWindow The target window in the Haven engine. This is practically always 0. * * @see [[closeTag]] * * @returns Returns true. */ export function openTag( tagName: string, classes: string, targetWindow = 0 ): true { const elem = document.createElement( tagName ); const current = container.get( targetWindow ); elem.className = classes; flush( targetWindow ); container.append( elem, current ); container.set( elem, targetWindow ); return true; } /** * Scroll an element into view. Scrolling is initiated only if the element * isn't already fully in view or its top position is not in the top * half of the page. * * If the element doesn't exist, the function doesn't do anything. * * @param target The target element * @param speed The duration of the scroll animation in milliseconds * * @returns Returns a promise that resolves to true when the scroll animation * ends, or resolves to false if no scrolling was needed (element doesn't * exist or is already in view.) */ export function scrollTo( target: string | JQuery.PlainObject, speed = 500 ): Promise