From 9fe37a1bc3870e899e75c67dcef91d8480f2d00b Mon Sep 17 00:00:00 2001 From: Daniel Wurzer Date: Tue, 17 Dec 2024 10:51:31 +0100 Subject: [PATCH] refactor: remove unused code --- spec/tests/modal/modalSpec.js | 2 +- src/modal.ts | 134 ++++------------------------------ 2 files changed, 17 insertions(+), 119 deletions(-) diff --git a/spec/tests/modal/modalSpec.js b/spec/tests/modal/modalSpec.js index 06ca4d1e16..22b96acbed 100644 --- a/spec/tests/modal/modalSpec.js +++ b/spec/tests/modal/modalSpec.js @@ -41,7 +41,7 @@ describe('Modal:', () => { }, 10); }); - // Modals should not be dismissible, use a Popover then + // use a Popover or use show() instead of showModal() /* it('Should have a dismissible option', (done) => { diff --git a/src/modal.ts b/src/modal.ts index 1793846085..b179dd0b03 100644 --- a/src/modal.ts +++ b/src/modal.ts @@ -1,5 +1,7 @@ import { Component, BaseOptions, InitElements, MElement } from './component'; +// Obsolete for versions > 2.1.1 + export interface ModalOptions extends BaseOptions { /** * Opacity of the modal overlay. @@ -78,11 +80,11 @@ export class Modal extends Component { /** * ID of the modal element. */ - id: string; + //id: string; /** * If the modal is open. */ - isOpen: boolean; + //isOpen: boolean; //private _openingTrigger: any; //private _overlay: HTMLDivElement; @@ -91,20 +93,11 @@ export class Modal extends Component { constructor(el: HTMLElement, options: Partial) { super(el, options, Modal); (this.el as any).M_Modal = this; - this.options = { ...Modal.defaults, ...options }; - - this.isOpen = false; - //this.id = this.el.id; - //this._openingTrigger = undefined; - //this._overlay = document.createElement('div'); - //this._overlay.classList.add('modal-overlay'); this.el.tabIndex = 0; - //this._nthModalOpened = 0; - //Modal._count++; this._setupEventHandlers(); } @@ -151,118 +144,27 @@ export class Modal extends Component { (this.el as any).M_Modal = undefined; } - _setupEventHandlers() { - // if (Modal._count === 1) { - // document.body.addEventListener('click', this._handleTriggerClick); - // } - //this._overlay.addEventListener('click', this._handleOverlayClick); - //this.el.addEventListener('click', this._handleModalCloseClick); - } - - _removeEventHandlers() { - //if (Modal._count === 0) { - // document.body.removeEventListener('click', this._handleTriggerClick); - //} - //this._overlay.removeEventListener('click', this._handleOverlayClick); - //this.el.removeEventListener('click', this._handleModalCloseClick); - } - - // todo: modal-trigger has no function anymore, remove and use native html5 dialog - _handleTriggerClick = (e: MouseEvent) => { - // const trigger = (e.target as HTMLElement).closest('.modal-trigger'); - // if (!trigger) return; - // const modalId = Utils.getIdFromTrigger(trigger as HTMLElement); - // const modalInstance = (document.getElementById(modalId) as any).M_Modal; - // if (modalInstance) modalInstance.open(trigger); - // e.preventDefault(); - }; - - _handleOverlayClick = () => { - //if (this.options.dismissible) this.close(); - }; - - // todo: modal-close is also obsolete - _handleModalCloseClick = (e: MouseEvent) => { - // const closeTrigger = (e.target as HTMLElement).closest('.modal-close'); - // if (closeTrigger) this.close(); - }; - - _handleKeydown = (e: KeyboardEvent) => { - //if (Utils.keys.ESC.includes(e.key) && this.options.dismissible) this.close(); - }; - - _handleFocus = (e: FocusEvent) => { - // Only trap focus if this modal is the last model opened (prevents loops in nested modals). - // if (!this.el.contains(e.target as HTMLElement) && this._nthModalOpened === Modal._modalsOpen) { - // this.el.focus(); - // } - }; + _setupEventHandlers() {} + _removeEventHandlers() {} + _handleTriggerClick = (e: MouseEvent) => {}; + _handleOverlayClick = () => {}; + _handleModalCloseClick = (e: MouseEvent) => {}; + _handleKeydown = (e: KeyboardEvent) => {}; + _handleFocus = (e: FocusEvent) => {}; /** * Open modal. */ - open = (trigger?: HTMLElement): Modal => { - if (this.isOpen) return; - // this.isOpen = true; - // Modal._modalsOpen++; - // this._nthModalOpened = Modal._modalsOpen; - // // Set Z-Index based on number of currently open modals - // this._overlay.style.zIndex = (1000 + Modal._modalsOpen * 2).toString(); - // this.el.style.zIndex = (1000 + Modal._modalsOpen * 2 + 1).toString(); - // // Set opening trigger, undefined indicates modal was opened by javascript - // this._openingTrigger = !!trigger ? trigger : undefined; - // // onOpenStart callback - // if (typeof this.options.onOpenStart === 'function') { - // this.options.onOpenStart.call(this, this.el, this._openingTrigger); - // } - // if (this.options.preventScrolling) { - // const hasVerticalScrollBar = - // document.documentElement.scrollHeight > document.documentElement.clientHeight; - // if (hasVerticalScrollBar) { - // const scrollTop = document.documentElement.scrollTop; - // document.documentElement.style.top = '-' + scrollTop + 'px'; - // document.documentElement.classList.add('noscroll'); - // } - // } - // this.el.classList.add('open'); - // this.el.insertAdjacentElement('afterend', this._overlay); - // if (this.options.dismissible) { - // document.addEventListener('keydown', this._handleKeydown); - // document.addEventListener('focus', this._handleFocus, true); - // } - // this._animateIn(); - // // Focus modal - // this.el.focus(); + open(): Modal { return this; - }; + } /** * Close modal. */ - close = () => { - if (!this.isOpen) return; - // this.isOpen = false; - // Modal._modalsOpen--; - // this._nthModalOpened = 0; - // // Call onCloseStart callback - // if (typeof this.options.onCloseStart === 'function') { - // this.options.onCloseStart.call(this, this.el); - // } - // this.el.classList.remove('open'); - // // Enable body scrolling only if there are no more modals open. - // if (Modal._modalsOpen === 0) { - // const scrollTop = -parseInt(document.documentElement.style.top); - // document.documentElement.style.removeProperty('top'); - // document.documentElement.classList.remove('noscroll'); - // document.documentElement.scrollTop = scrollTop; - // } - // if (this.options.dismissible) { - // document.removeEventListener('keydown', this._handleKeydown); - // document.removeEventListener('focus', this._handleFocus, true); - // } - // this._animateOut(); + close(): Modal { return this; - }; + } // Experimental! // also note: https://stackoverflow.com/a/35385518/8830502 @@ -277,10 +179,6 @@ export class Modal extends Component { `; } - static createElement() {} - static { - //Modal._modalsOpen = 0; - //Modal._count = 0; - } + static {} }