mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
moved alert to its own requirejs module
This commit is contained in:
@@ -166,114 +166,33 @@ var socket,
|
||||
});
|
||||
};
|
||||
|
||||
// use unique alert_id to have multiple alerts visible at a time, use the same alert_id to fade out the current instance
|
||||
// type : error, success, info, warning/notify
|
||||
// title = bolded title text
|
||||
// message = alert message content
|
||||
// timeout default = permanent
|
||||
// location : alert_window (default) or content
|
||||
app.alert = function (params) {
|
||||
var alert_id = 'alert_button_' + ((params.alert_id) ? params.alert_id : new Date().getTime());
|
||||
|
||||
var alert = $('#' + alert_id);
|
||||
var title = params.title || '';
|
||||
|
||||
function fadeOut() {
|
||||
alert.fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}
|
||||
|
||||
function startTimeout(timeout) {
|
||||
var timeoutId = setTimeout(function () {
|
||||
fadeOut();
|
||||
}, timeout);
|
||||
|
||||
alert.attr('timeoutId', timeoutId);
|
||||
}
|
||||
|
||||
if (alert.length > 0) {
|
||||
alert.find('strong').html(title);
|
||||
alert.find('p').html(params.message);
|
||||
alert.attr('class', 'alert alert-dismissable alert-' + params.type);
|
||||
|
||||
clearTimeout(alert.attr('timeoutId'));
|
||||
startTimeout(params.timeout);
|
||||
|
||||
alert.children().fadeOut('100');
|
||||
translator.translate(alert.html(), function(translatedHTML) {
|
||||
alert.children().fadeIn('100');
|
||||
alert.html(translatedHTML);
|
||||
});
|
||||
} else {
|
||||
alert = $('<div id="' + alert_id + '" class="alert alert-dismissable alert-' + params.type +'"></div>');
|
||||
|
||||
alert.append($('<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>'))
|
||||
.append($('<strong>' + title + '</strong>'));
|
||||
|
||||
if (params.message) {
|
||||
alert.append($('<p>' + params.message + '</p>'));
|
||||
}
|
||||
|
||||
if (!params.location) {
|
||||
params.location = 'alert_window';
|
||||
}
|
||||
|
||||
translator.translate(alert.html(), function(translatedHTML) {
|
||||
alert.html(translatedHTML);
|
||||
$('#' + params.location).prepend(alert.fadeIn('100'));
|
||||
|
||||
if(typeof params.closefn === 'function') {
|
||||
alert.find('button').on('click', function() {
|
||||
params.closefn();
|
||||
fadeOut();
|
||||
return false;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (params.timeout) {
|
||||
startTimeout(params.timeout);
|
||||
}
|
||||
|
||||
if (typeof params.clickfn === 'function') {
|
||||
alert.on('click', function (e) {
|
||||
if(!$(e.target).is('.close')) {
|
||||
params.clickfn();
|
||||
}
|
||||
fadeOut();
|
||||
});
|
||||
}
|
||||
}
|
||||
require(['alerts'], function(alerts) {
|
||||
alerts.alert(params);
|
||||
});
|
||||
};
|
||||
|
||||
app.removeAlert = function(id) {
|
||||
$('#' + 'alert_button_' + id).remove();
|
||||
require(['alerts'], function(alerts) {
|
||||
alerts.remove(id);
|
||||
});
|
||||
};
|
||||
|
||||
app.alertSuccess = function (message, timeout) {
|
||||
if (!timeout) {
|
||||
timeout = 2000;
|
||||
}
|
||||
|
||||
app.alert({
|
||||
title: '[[global:alert.success]]',
|
||||
message: message,
|
||||
type: 'success',
|
||||
timeout: timeout
|
||||
timeout: timeout ? timeout : 2000
|
||||
});
|
||||
};
|
||||
|
||||
app.alertError = function (message, timeout) {
|
||||
if (!timeout) {
|
||||
timeout = 2000;
|
||||
}
|
||||
|
||||
app.alert({
|
||||
title: '[[global:alert.error]]',
|
||||
message: message,
|
||||
type: 'danger',
|
||||
timeout: timeout
|
||||
timeout: timeout ? timeout : 2000
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user