minor bug fixes
This commit is contained in:
@@ -30,26 +30,26 @@ const CLASS_NAME_DIRECT_CHAT_OPEN = 'direct-chat-contacts-open'
|
||||
*/
|
||||
|
||||
class DirectChat {
|
||||
_element: HTMLElement | undefined
|
||||
_element: HTMLElement
|
||||
_config: undefined
|
||||
constructor(element: HTMLElement | undefined, config: undefined) {
|
||||
constructor(element: HTMLElement, config: undefined) {
|
||||
this._element = element
|
||||
this._config = config
|
||||
}
|
||||
|
||||
toggle(): void {
|
||||
if (this._element?.classList.contains(CLASS_NAME_DIRECT_CHAT_OPEN)) {
|
||||
if (this._element.classList.contains(CLASS_NAME_DIRECT_CHAT_OPEN)) {
|
||||
const event = new Event(EVENT_COLLAPSED)
|
||||
|
||||
this._element?.classList.remove(CLASS_NAME_DIRECT_CHAT_OPEN)
|
||||
this._element.classList.remove(CLASS_NAME_DIRECT_CHAT_OPEN)
|
||||
|
||||
this._element?.dispatchEvent(event)
|
||||
this._element.dispatchEvent(event)
|
||||
} else {
|
||||
const event = new Event(EVENT_EXPANDED)
|
||||
|
||||
this._element?.classList.add(CLASS_NAME_DIRECT_CHAT_OPEN)
|
||||
this._element.classList.add(CLASS_NAME_DIRECT_CHAT_OPEN)
|
||||
|
||||
this._element?.dispatchEvent(event)
|
||||
this._element.dispatchEvent(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,9 +67,12 @@ domReady(() => {
|
||||
btn.addEventListener('click', event => {
|
||||
event.preventDefault()
|
||||
const target = event.target as HTMLElement
|
||||
const chatPane = target?.closest(SELECTOR_DIRECT_CHAT) as HTMLElement | undefined
|
||||
const data = new DirectChat(chatPane, undefined)
|
||||
data.toggle()
|
||||
const chatPane = target.closest(SELECTOR_DIRECT_CHAT) as HTMLElement | undefined
|
||||
|
||||
if (chatPane) {
|
||||
const data = new DirectChat(chatPane, undefined)
|
||||
data.toggle()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -46,48 +46,40 @@ type Config = {
|
||||
class Treeview {
|
||||
_element: HTMLElement
|
||||
_config: Config
|
||||
_navItem: HTMLElement | undefined
|
||||
_childNavItem: HTMLElement | undefined | undefined
|
||||
_childNavItem: HTMLElement | undefined
|
||||
|
||||
constructor(element: HTMLElement, config: Config) {
|
||||
this._element = element
|
||||
this._config = { ...Default, ...config }
|
||||
this._navItem = this._element?.closest(SELECTOR_NAV_ITEM) as HTMLElement | undefined
|
||||
this._childNavItem = this._navItem?.querySelector(SELECTOR_TREEVIEW_MENU) as HTMLElement | undefined
|
||||
this._childNavItem = this._element.querySelector(SELECTOR_TREEVIEW_MENU) as HTMLElement | undefined
|
||||
}
|
||||
|
||||
open(): void {
|
||||
const event = new Event(EVENT_EXPANDED)
|
||||
|
||||
if (this._navItem) {
|
||||
this._navItem.classList.add(CLASS_NAME_MENU_OPEN)
|
||||
}
|
||||
this._element.classList.add(CLASS_NAME_MENU_OPEN)
|
||||
|
||||
if (this._childNavItem) {
|
||||
slideDown(this._childNavItem, this._config.animationSpeed)
|
||||
}
|
||||
|
||||
this._element?.dispatchEvent(event)
|
||||
this._element.dispatchEvent(event)
|
||||
}
|
||||
|
||||
close(): void {
|
||||
const event = new Event(EVENT_COLLAPSED)
|
||||
|
||||
window.setTimeout(() => {
|
||||
if (this._navItem) {
|
||||
this._navItem.classList.remove(CLASS_NAME_MENU_OPEN)
|
||||
}
|
||||
}, this._config.animationSpeed)
|
||||
this._element.classList.remove(CLASS_NAME_MENU_OPEN)
|
||||
|
||||
if (this._childNavItem) {
|
||||
slideUp(this._childNavItem, this._config.animationSpeed)
|
||||
}
|
||||
|
||||
this._element?.dispatchEvent(event)
|
||||
this._element.dispatchEvent(event)
|
||||
}
|
||||
|
||||
toggle(): void {
|
||||
if (this._navItem?.classList.contains(CLASS_NAME_MENU_OPEN)) {
|
||||
if (this._element.classList.contains(CLASS_NAME_MENU_OPEN)) {
|
||||
this.close()
|
||||
} else {
|
||||
this.open()
|
||||
@@ -106,10 +98,13 @@ domReady(() => {
|
||||
|
||||
for (const btn of button) {
|
||||
btn.addEventListener('click', event => {
|
||||
const treeviewMenu = event.target as HTMLElement
|
||||
const target = event.target as HTMLElement
|
||||
const targetItem = target.closest(SELECTOR_NAV_ITEM) as HTMLElement | undefined
|
||||
|
||||
const data = new Treeview(treeviewMenu, Default)
|
||||
data.toggle()
|
||||
if (targetItem) {
|
||||
const data = new Treeview(targetItem, Default)
|
||||
data.toggle()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user