Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 1x 2x 2x 3x 4x 1x 3x 3x 4x 1x 1x 1x | /**
* Toast object for displaying toast messages.
* @namespace Toast
*/
const Toast = {
messageTagsMapping: {
debug: 'text-bg-secondary',
info: 'text-bg-info',
success: 'text-bg-success',
warning: 'text-bg-warning',
error: 'text-bg-danger'
},
params: {
messageTags: 'info',
message: 'Hello, world!',
delay: 4,
autoHide: true
},
paramsToFunction: {
messageTags: messageTag => Toast.setColor(Toast.messageTagsMapping[messageTag]),
message: newMessage => Toast.setMessage(newMessage)
},
setMessage: message => Toast.params.element.querySelector('.toast-body').innerText = message,
removePreviousColorClass: () => Array.from(Toast.params.element.classList).forEach(className =>
className.startsWith('text-bg-') && Toast.params.element.classList.remove(className)),
setColor: newClass => {
Toast.removePreviousColorClass();
Toast.params.element.classList.add(newClass);
},
processParameters: (o, f) => Object.keys(f).forEach(k => f[k](o[k])),
show: () => {
Toast.processParameters(Toast.params, Toast.paramsToFunction);
new bootstrap.Toast(Toast.params.element, {
animation: true,
autohide: Toast.params.autoHide,
delay: Toast.params.delay * 1000
}).show();
}
};
(typeof module !== 'undefined' && module.exports) && (module.exports = Toast); |