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.
45 lines
995 B
45 lines
995 B
7 years ago
|
/** Module for toggling a modal overlay */
|
||
|
(function () {
|
||
7 years ago
|
let modal = {}
|
||
|
let curCloseCb = null
|
||
7 years ago
|
|
||
7 years ago
|
modal.show = function (sel, closeCb) {
|
||
7 years ago
|
let $m = $(sel)
|
||
|
$m.removeClass('hidden visible')
|
||
7 years ago
|
setTimeout(function () {
|
||
7 years ago
|
$m.addClass('visible')
|
||
|
}, 1)
|
||
|
curCloseCb = closeCb
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
modal.hide = function (sel) {
|
||
7 years ago
|
let $m = $(sel)
|
||
|
$m.removeClass('visible')
|
||
7 years ago
|
setTimeout(function () {
|
||
7 years ago
|
$m.addClass('hidden')
|
||
|
if (curCloseCb) curCloseCb()
|
||
|
}, 500) // transition time
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
modal.init = function () {
|
||
|
// close modal by click outside the dialog
|
||
|
$('.Modal').on('click', function () {
|
||
7 years ago
|
if ($(this).hasClass('no-close')) return // this is a no-close modal
|
||
|
modal.hide(this)
|
||
|
})
|
||
7 years ago
|
|
||
7 years ago
|
$('.Dialog').on('click', function (e) {
|
||
7 years ago
|
e.stopImmediatePropagation()
|
||
|
})
|
||
7 years ago
|
|
||
7 years ago
|
// Hide all modals on esc
|
||
|
$(window).on('keydown', function (e) {
|
||
7 years ago
|
if (e.which === 27) {
|
||
7 years ago
|
modal.hide('.Modal')
|
||
7 years ago
|
}
|
||
7 years ago
|
})
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
window.Modal = modal
|
||
|
})()
|