Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/ts/adminlte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import { initAccessibility } from './accessibility.js'
*/

onDOMContentLoaded(() => {
/**
* Initialize AdminLTE Core Components
* -------------------------------
*/
const layout = new Layout(document.body)
layout.holdTransition()

/**
* Initialize Accessibility Features - WCAG 2.1 AA Compliance
* --------------------------------------------------------
Expand All @@ -33,14 +26,9 @@ onDOMContentLoaded(() => {
keyboardNavigation: true,
reducedMotion: true
})

// Add semantic landmarks
accessibilityManager.addLandmarks()

// Mark app as loaded after initialization
setTimeout(() => {
document.body.classList.add('app-loaded')
}, 400)
})

export {
Expand Down
59 changes: 43 additions & 16 deletions src/ts/layout.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,78 @@
/**
* --------------------------------------------
* ----------------------------------------------------------------------------
* @file AdminLTE layout.ts
* @description Layout for AdminLTE.
* @license MIT
* --------------------------------------------
* ----------------------------------------------------------------------------
*/

import {
onDOMContentLoaded
} from './util/index'

/**
* ------------------------------------------------------------------------
* ----------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
* ----------------------------------------------------------------------------
*/

const CLASS_NAME_HOLD_TRANSITIONS = 'hold-transition'
const CLASS_NAME_APP_LOADED = 'app-loaded'

/**
* ----------------------------------------------------------------------------
* Class Definition
* ====================================================
* ----------------------------------------------------------------------------
*/

class Layout {
_element: HTMLElement
_holdTransitionTimer: ReturnType<typeof setTimeout> | undefined

constructor(element: HTMLElement) {
this._element = element
this._holdTransitionTimer = undefined
}

holdTransition(): void {
let resizeTimer: ReturnType<typeof setTimeout>
window.addEventListener('resize', () => {
document.body.classList.add(CLASS_NAME_HOLD_TRANSITIONS)
clearTimeout(resizeTimer)
resizeTimer = setTimeout(() => {
document.body.classList.remove(CLASS_NAME_HOLD_TRANSITIONS)
}, 400)
})
/*
* Hold the layout transitions by the specified time. This will disable CSS
* transitions and animations of the main layout elements (sidebar, navbar,
* content) for the given time.
*
* @param time Number of milliseconds to hold the transitions.
*/
holdTransition(time: number = 100): void {
// If a timer is already running, clear it

if (this._holdTransitionTimer) {
clearTimeout(this._holdTransitionTimer)
}

// Add the hold-transition class to the body, and remove it after the
// specified time.

document.body.classList.add(CLASS_NAME_HOLD_TRANSITIONS)

this._holdTransitionTimer = setTimeout(() => {
document.body.classList.remove(CLASS_NAME_HOLD_TRANSITIONS)
}, time)
}
}

/**
* ----------------------------------------------------------------------------
* Data Api implementation
* ----------------------------------------------------------------------------
*/

onDOMContentLoaded(() => {
const data = new Layout(document.body)
data.holdTransition()
// Hold layout transitions on window resize.

const layout = new Layout(document.body)
window.addEventListener('resize', () => layout.holdTransition(200))

// Mark app as loaded after initialization.

setTimeout(() => {
document.body.classList.add(CLASS_NAME_APP_LOADED)
}, 400)
Expand Down
Loading