Skip to content
Merged
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
41 changes: 28 additions & 13 deletions src/js/alert/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

get dismiss() { return this.getAttribute('dismiss'); }

get autodismiss() { return this.getAttribute('auto-dismiss'); }

get acknowledge() { return this.getAttribute('acknowledge'); }

get href() { return this.getAttribute('href'); }
Expand All @@ -35,6 +37,10 @@
this.appendCloseButton();
}

if (this.hasAttribute('auto-dismiss')) {
this.autoDismiss();
}

this.dispatchCustomEvent('joomla.alert.show');
}

Expand Down Expand Up @@ -70,6 +76,9 @@
this.removeCloseButton();
}
break;
case 'auto-dismiss':
this.autoDismiss();
break;
case 'href':
if (!newValue || newValue === '') {
this.removeCloseButton();
Expand All @@ -83,11 +92,15 @@
}

/* Method to close the alert */
close() {
close(element = null) {
this.dispatchCustomEvent('joomla.alert.close');
this.addEventListener('transitionend', () => {
this.dispatchCustomEvent('joomla.alert.closed');
this.parentNode.removeChild(this);
if (element) {
element.remove();
} else {
this.remove();
}
}, false);
this.classList.remove('joomla-alert--show');
}
Expand Down Expand Up @@ -148,25 +161,27 @@
});
}
}
}

if (this.hasAttribute('auto-dismiss')) {
setTimeout(() => {
self.dispatchCustomEvent('joomla.alert.buttonClicked');
if (self.hasAttribute('data-callback')) {
window[self.getAttribute('data-callback')]();
} else {
self.close();
}
}, self.getAttribute('auto-dismiss') ? parseInt(self.getAttribute('auto-dismiss'), 10) : 3000);
}
/* Method to auto-dismiss */
autoDismiss() {
const self = this;
setTimeout(() => {
self.dispatchCustomEvent('joomla.alert.buttonClicked');
if (self.hasAttribute('data-callback')) {
window[self.getAttribute('data-callback')]();
} else {
self.close(self);
}
}, parseInt(self.getAttribute('auto-dismiss'), 10) ? self.getAttribute('auto-dismiss') : 3000);
}

/* Method to remove the close button */
removeCloseButton() {
const button = this.querySelector('button');
if (button) {
button.removeEventListener('click', this);
button.parentNode.removeChild(button);
button.remove();
}
}

Expand Down