You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.4 KiB
65 lines
1.4 KiB
window.Notify = (function () {
|
|
let nt = {}
|
|
const sel = '#notif'
|
|
let $balloon
|
|
|
|
let timerHideBegin // timeout to start hiding (transition)
|
|
let timerHideEnd // timeout to add the hidden class
|
|
let timerCanCancel
|
|
let canCancel = false
|
|
|
|
let stopTimeouts = function () {
|
|
clearTimeout(timerHideBegin)
|
|
clearTimeout(timerHideEnd)
|
|
}
|
|
|
|
nt.show = function (message, timeout, isError) {
|
|
$balloon.toggleClass('error', isError === true)
|
|
$balloon.html(message)
|
|
Modal.show($balloon)
|
|
stopTimeouts()
|
|
|
|
if (undef(timeout) || timeout === null || timeout <= 0) {
|
|
timeout = 2500
|
|
}
|
|
|
|
timerHideBegin = setTimeout(nt.hide, timeout)
|
|
|
|
canCancel = false
|
|
timerCanCancel = setTimeout(function () {
|
|
canCancel = true
|
|
}, 500)
|
|
}
|
|
|
|
nt.hide = function () {
|
|
let $m = $(sel)
|
|
$m.removeClass('visible')
|
|
timerHideEnd = setTimeout(function () {
|
|
$m.addClass('hidden')
|
|
}, 250) // transition time
|
|
}
|
|
|
|
nt.init = function () {
|
|
$balloon = $(sel)
|
|
|
|
// close by click outside
|
|
$(document).on('click', function () {
|
|
if (!canCancel) return
|
|
nt.hide(this)
|
|
})
|
|
|
|
// click caused by selecting, prevent it from bubbling
|
|
$balloon.on('click', function (e) {
|
|
e.stopImmediatePropagation()
|
|
return false
|
|
})
|
|
|
|
// stop fading if moused
|
|
$balloon.on('mouseenter', function () {
|
|
stopTimeouts()
|
|
$balloon.removeClass('hidden').addClass('visible')
|
|
})
|
|
}
|
|
|
|
return nt
|
|
})()
|
|
|