if same id is used it replaces the current alerts contents

v1.18.x
Baris Usakli 12 years ago
parent 58d12c9c7c
commit 3c0b86689a

@ -55,7 +55,7 @@ var socket,
title: 'Disconnect',
message: 'You have disconnected from NodeBB, we will try to reconnect!',
type: 'error',
timeout: 1000
timeout: 5000
});
});
@ -113,51 +113,64 @@ var socket,
// timeout default = permanent
// location : notification_window (default) or content
app.alert = function(params) {
var div = document.createElement('div'),
button = document.createElement('button'),
strong = document.createElement('strong'),
p = document.createElement('p');
var alert_id = 'alert_button_' + ((params.alert_id) ? params.alert_id : new Date().getTime());
jQuery('#'+alert_id).fadeOut(500, function() {
this.remove();
});
var alert = $('#'+alert_id);
p.innerHTML = params.message;
strong.innerHTML = params.title;
if(alert.length > 0) {
alert.find('strong').html(params.title);
alert.find('p').html(params.message);
alert.attr('class', "alert toaster-alert " + ((params.type=='warning') ? '' : "alert-" + params.type));
}
else {
div.className = "alert toaster-alert " + ((params.type=='warning') ? '' : "alert-" + params.type);
var div = document.createElement('div'),
button = document.createElement('button'),
strong = document.createElement('strong'),
p = document.createElement('p');
div.setAttribute('id', alert_id);
div.appendChild(button);
div.appendChild(strong);
div.appendChild(p);
/*jQuery('#'+alert_id).fadeOut(500, function() {
this.remove();
});*/
button.className = 'close';
button.innerHTML = '×';
button.onclick = function(ev) {
div.parentNode.removeChild(div);
}
p.innerHTML = params.message;
strong.innerHTML = params.title;
if (params.location == null) params.location = 'notification_window';
div.className = "alert toaster-alert " + ((params.type=='warning') ? '' : "alert-" + params.type);
jQuery('#'+params.location).prepend(jQuery(div).fadeIn('100'));
div.setAttribute('id', alert_id);
div.appendChild(button);
div.appendChild(strong);
div.appendChild(p);
if (params.timeout) {
setTimeout(function() {
jQuery(div).fadeOut(1000, function() {
this.remove();
});
}, params.timeout)
}
button.className = 'close';
button.innerHTML = '×';
button.onclick = function(ev) {
div.parentNode.removeChild(div);
}
if (params.clickfn) {
div.onclick = function() {
params.clickfn();
jQuery(div).fadeOut(500, function() {
this.remove();
});
if (params.location == null)
params.location = 'notification_window';
jQuery('#'+params.location).prepend(jQuery(div).fadeIn('100'));
if (params.timeout) {
setTimeout(function() {
jQuery(div).fadeOut(1000, function() {
this.remove();
});
}, params.timeout)
}
if (params.clickfn) {
div.onclick = function() {
params.clickfn();
jQuery(div).fadeOut(500, function() {
this.remove();
});
}
}
}
}

Loading…
Cancel
Save