61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
/**
|
|
* Zibll-compatible frontend notifications.
|
|
*
|
|
* @package AKSRT
|
|
*/
|
|
|
|
(function ($, window, document) {
|
|
'use strict';
|
|
|
|
function closeNotyf($element) {
|
|
$element.addClass('notyn-out');
|
|
window.setTimeout(function () {
|
|
$element.remove();
|
|
}, 1000);
|
|
}
|
|
|
|
function notyf(message, type, time, id) {
|
|
var $body = $(document.body);
|
|
|
|
if (!$('.notyn').length) {
|
|
$body.append('<div class="notyn"></div>');
|
|
}
|
|
|
|
type = type || 'success';
|
|
if (type === 'error') {
|
|
type = 'danger';
|
|
}
|
|
|
|
time = time || 5000;
|
|
time = time < 100 ? time * 1000 : time;
|
|
|
|
var idAttribute = id ? ' id="' + id + '"' : '';
|
|
var $notification = $('<div class="noty1"' + idAttribute + '><div class="notyf ' + type + '">' + message + '</div></div>');
|
|
var shouldClose = !id;
|
|
|
|
if (id && $('#' + id).length) {
|
|
$('#' + id)
|
|
.find('.notyf')
|
|
.removeClass()
|
|
.addClass('notyf ' + type)
|
|
.html(message);
|
|
$notification = $('#' + id);
|
|
shouldClose = true;
|
|
} else {
|
|
$('.notyn').append($notification);
|
|
}
|
|
|
|
if (shouldClose) {
|
|
window.setTimeout(function () {
|
|
closeNotyf($notification);
|
|
}, time);
|
|
}
|
|
}
|
|
|
|
$(document.body).on('click', '.noty1', function () {
|
|
closeNotyf($(this));
|
|
});
|
|
|
|
window.notyf = notyf;
|
|
})(jQuery, window, document);
|