Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
se-panfilov committed Nov 15, 2017
1 parent fef8d78 commit 8dcc332
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions mini-toastr.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export function fadeOut (element, cb) {
} else {
element.style.opacity = 0.9
}
setTimeout(() => fadeOut.apply(this, [element, cb]), 1000 / 30)
setTimeout(() => fadeOut.apply(this, [element, cb]), 1000 / 30
)
}

export const LIB_NAME = 'mini-toastr'
Expand Down Expand Up @@ -159,6 +160,15 @@ export function addElem (node, text, className) {
node.appendChild(elem)
}

export function getTypeClass (type) {
if (type === SUCCESS) return SUCCESS_CLASS
if (type === WARN) return WARNING_CLASS
if (type === ERROR) return ERROR_CLASS
if (type === INFO) return INFO_CLASS

return ''
}

const miniToastr = {
config,
isInitialised: false,
Expand All @@ -168,8 +178,7 @@ const miniToastr = {
Object.assign(config, overrideConf)

const notificationElem = makeNode()
const typeClass = `${type.toUpperCase()}_CLASS`
notificationElem.className = `${NOTIFICATION_CLASS} ${typeClass}`
notificationElem.className = `${NOTIFICATION_CLASS} ${getTypeClass(type)}`

notificationElem.onclick = function () {
config.animation(notificationElem, null)
Expand All @@ -180,7 +189,8 @@ const miniToastr = {
if (message) addElem(notificationElem, message, MESSAGE_CLASS)

config.node.insertBefore(notificationElem, config.node.firstChild)
setTimeout(() => config.animation(notificationElem, cb), timeout || config.timeout)
setTimeout(() => config.animation(notificationElem, cb), timeout || config.timeout
)

if (cb) cb()
return this
Expand All @@ -199,11 +209,12 @@ const miniToastr = {
newConfig.appendTarget.appendChild(newConfig.node)

Object.keys(newConfig.types).forEach(v => {
exports[newConfig.types[v]] = function (message, title, timeout, cb, config) {
this.showMessage(message, title, newConfig.types[v], timeout, cb, config)
return this
}.bind(this)
})
this[newConfig.types[v]] = function (message, title, timeout, cb, config) {
this.showMessage(message, title, newConfig.types[v], timeout, cb, config)
return this
}.bind(this)
}
)

this.isInitialised = true;

Expand Down

0 comments on commit 8dcc332

Please sign in to comment.