Skip to content

Commit

Permalink
refactor: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
wuda-io committed Dec 17, 2024
1 parent c9ede58 commit 9fe37a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 119 deletions.
2 changes: 1 addition & 1 deletion spec/tests/modal/modalSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
134 changes: 16 additions & 118 deletions src/modal.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -78,11 +80,11 @@ export class Modal extends Component<ModalOptions> {
/**
* ID of the modal element.
*/
id: string;
//id: string;
/**
* If the modal is open.
*/
isOpen: boolean;
//isOpen: boolean;

//private _openingTrigger: any;
//private _overlay: HTMLDivElement;
Expand All @@ -91,20 +93,11 @@ export class Modal extends Component<ModalOptions> {
constructor(el: HTMLElement, options: Partial<ModalOptions>) {
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();
}

Expand Down Expand Up @@ -151,118 +144,27 @@ export class Modal extends Component<ModalOptions> {
(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
Expand All @@ -277,10 +179,6 @@ export class Modal extends Component<ModalOptions> {
</div>
</dialog>`;
}
static createElement() {}

static {
//Modal._modalsOpen = 0;
//Modal._count = 0;
}
static {}
}

0 comments on commit 9fe37a1

Please sign in to comment.