mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 16:35:47 +01:00
if same id is used it replaces the current alerts contents
This commit is contained in:
@@ -55,7 +55,7 @@ var socket,
|
|||||||
title: 'Disconnect',
|
title: 'Disconnect',
|
||||||
message: 'You have disconnected from NodeBB, we will try to reconnect!',
|
message: 'You have disconnected from NodeBB, we will try to reconnect!',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
timeout: 1000
|
timeout: 5000
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -113,51 +113,64 @@ var socket,
|
|||||||
// timeout default = permanent
|
// timeout default = permanent
|
||||||
// location : notification_window (default) or content
|
// location : notification_window (default) or content
|
||||||
app.alert = function(params) {
|
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());
|
var alert_id = 'alert_button_' + ((params.alert_id) ? params.alert_id : new Date().getTime());
|
||||||
|
|
||||||
jQuery('#'+alert_id).fadeOut(500, function() {
|
var alert = $('#'+alert_id);
|
||||||
this.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
p.innerHTML = params.message;
|
if(alert.length > 0) {
|
||||||
strong.innerHTML = params.title;
|
alert.find('strong').html(params.title);
|
||||||
|
alert.find('p').html(params.message);
|
||||||
div.className = "alert toaster-alert " + ((params.type=='warning') ? '' : "alert-" + params.type);
|
alert.attr('class', "alert toaster-alert " + ((params.type=='warning') ? '' : "alert-" + params.type));
|
||||||
|
|
||||||
div.setAttribute('id', alert_id);
|
|
||||||
div.appendChild(button);
|
|
||||||
div.appendChild(strong);
|
|
||||||
div.appendChild(p);
|
|
||||||
|
|
||||||
button.className = 'close';
|
|
||||||
button.innerHTML = '×';
|
|
||||||
button.onclick = function(ev) {
|
|
||||||
div.parentNode.removeChild(div);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
if (params.location == null) params.location = 'notification_window';
|
var div = document.createElement('div'),
|
||||||
|
button = document.createElement('button'),
|
||||||
|
strong = document.createElement('strong'),
|
||||||
|
p = document.createElement('p');
|
||||||
|
|
||||||
jQuery('#'+params.location).prepend(jQuery(div).fadeIn('100'));
|
/*jQuery('#'+alert_id).fadeOut(500, function() {
|
||||||
|
this.remove();
|
||||||
|
});*/
|
||||||
|
|
||||||
if (params.timeout) {
|
p.innerHTML = params.message;
|
||||||
setTimeout(function() {
|
strong.innerHTML = params.title;
|
||||||
jQuery(div).fadeOut(1000, function() {
|
|
||||||
this.remove();
|
|
||||||
});
|
|
||||||
}, params.timeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params.clickfn) {
|
div.className = "alert toaster-alert " + ((params.type=='warning') ? '' : "alert-" + params.type);
|
||||||
div.onclick = function() {
|
|
||||||
params.clickfn();
|
div.setAttribute('id', alert_id);
|
||||||
jQuery(div).fadeOut(500, function() {
|
div.appendChild(button);
|
||||||
this.remove();
|
div.appendChild(strong);
|
||||||
});
|
div.appendChild(p);
|
||||||
|
|
||||||
|
button.className = 'close';
|
||||||
|
button.innerHTML = '×';
|
||||||
|
button.onclick = function(ev) {
|
||||||
|
div.parentNode.removeChild(div);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,7 +269,7 @@ var socket,
|
|||||||
|
|
||||||
app.close_post_window = function() {
|
app.close_post_window = function() {
|
||||||
console.log('closing post window');
|
console.log('closing post window');
|
||||||
|
|
||||||
post_window = post_window || document.getElementById('post_window');
|
post_window = post_window || document.getElementById('post_window');
|
||||||
jQuery(post_window).slideUp(250);
|
jQuery(post_window).slideUp(250);
|
||||||
$(document.body).removeClass('composing');
|
$(document.body).removeClass('composing');
|
||||||
|
|||||||
Reference in New Issue
Block a user