diff --git a/README.md b/README.md index e35d9ec..c80e6af 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,8 @@ notie.alert({ text: String, stay: Boolean, // optional, default = false time: Number, // optional, default = 3, minimum = 1, - position: String // optional, default = 'top', enum: ['top', 'bottom'] + position: String, // optional, default = 'top', enum: ['top', 'bottom'] + callback: Function // optional }) notie.force({ diff --git a/src/notie.js b/src/notie.js index 03d1d27..be06996 100644 --- a/src/notie.js +++ b/src/notie.js @@ -177,7 +177,7 @@ export const alert = ({ time = options.alertTime, stay = false, position = options.positions.alert || position.top -}) => { +}, callbackArg) => { blur() hideAlerts() @@ -189,7 +189,10 @@ export const alert = ({ element.classList.add(typeToClassLookup[type]) element.classList.add(options.classes.alert) element.innerHTML = `
` - element.onclick = () => removeFromDocument(id, position) + element.onclick = () => { + removeFromDocument(id, position) + if (callbackArg) callbackArg() + } element.listener = event => { if (enterClicked(event) || escapeClicked(event)) hideAlerts() @@ -198,7 +201,10 @@ export const alert = ({ addToDocument(element, position) if (time && time < 1) time = 1 - if (!stay && time) wait(time).then(() => removeFromDocument(id, position)) + if (!stay && time) wait(time).then(() => { + removeFromDocument(id, position) + if (callbackArg) callbackArg() + }) } export const force = ({