mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-06-22 22:40:22 +02:00
fix: #11875, simplify alerts and show progress
add alerts.info and alerts.warning
This commit is contained in:
@@ -61,6 +61,8 @@
|
|||||||
|
|
||||||
"alert.success": "Success",
|
"alert.success": "Success",
|
||||||
"alert.error": "Error",
|
"alert.error": "Error",
|
||||||
|
"alert.warning": "Warning",
|
||||||
|
"alert.info": "Info",
|
||||||
|
|
||||||
"alert.banned": "Banned",
|
"alert.banned": "Banned",
|
||||||
"alert.banned.message": "You have just been banned, your access is now restricted.",
|
"alert.banned.message": "You have just been banned, your access is now restricted.",
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
@import "./extend/widgets";
|
@import "./extend/widgets";
|
||||||
@import "settings";
|
@import "settings";
|
||||||
|
|
||||||
@import "./modules/alerts";
|
@import "../modules/alerts";
|
||||||
@import "./modules/selectable";
|
@import "./modules/selectable";
|
||||||
@import "./modules/nprogress";
|
@import "./modules/nprogress";
|
||||||
@import "./modules/search";
|
@import "./modules/search";
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
.alert-window {
|
|
||||||
position: fixed;
|
|
||||||
width: 300px;
|
|
||||||
z-index: 10002;
|
|
||||||
|
|
||||||
right: 20px;
|
|
||||||
bottom: 0px;
|
|
||||||
|
|
||||||
.alert {
|
|
||||||
&::before {
|
|
||||||
position: relative;
|
|
||||||
top: -15px;
|
|
||||||
left: -15px;
|
|
||||||
display: block;
|
|
||||||
height: 2px;
|
|
||||||
width: 0;
|
|
||||||
transition: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.alert-info {
|
|
||||||
color: $info;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.alert-warning {
|
|
||||||
color: $warning;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.alert-success {
|
|
||||||
color: $success;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.alert-danger {
|
|
||||||
color: $danger;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.animate {
|
|
||||||
&.alert-info::before {
|
|
||||||
background-color: lighten($info, 25%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.alert-warning::before {
|
|
||||||
background-color: lighten($warning, 25%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.alert-success::before {
|
|
||||||
background-color: lighten($success, 25%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.alert-danger::before {
|
|
||||||
background-color: lighten($danger, 25%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&::before {
|
|
||||||
width: calc(100% + 50px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
background-color: var(--bs-body-bg);
|
|
||||||
border: 0;
|
|
||||||
border-left: 5px solid !important;
|
|
||||||
box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.25), 0px 2px 10px 0px rgba(0, 0, 0, 0.25);
|
|
||||||
|
|
||||||
strong {
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
padding: 10px 0px 0px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,4 +4,5 @@
|
|||||||
@import "modals";
|
@import "modals";
|
||||||
@import "modules/picture-switcher";
|
@import "modules/picture-switcher";
|
||||||
@import "modules/bottom-sheet";
|
@import "modules/bottom-sheet";
|
||||||
@import "modules/icon-picker";
|
@import "modules/icon-picker";
|
||||||
|
@import "modules/alerts.scss";
|
||||||
45
public/scss/modules/alerts.scss
Normal file
45
public/scss/modules/alerts.scss
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
.alert-window {
|
||||||
|
position: fixed;
|
||||||
|
width: 300px;
|
||||||
|
z-index: 10002;
|
||||||
|
|
||||||
|
right: 20px;
|
||||||
|
bottom: 0px;
|
||||||
|
|
||||||
|
.alert {
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.alert-progress {
|
||||||
|
width: 0;
|
||||||
|
&.animate {
|
||||||
|
width: calc(100% + 50px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.alert-info {
|
||||||
|
color: $info;
|
||||||
|
.alert-progress { background-color: $info; }
|
||||||
|
}
|
||||||
|
|
||||||
|
&.alert-warning {
|
||||||
|
color: $warning;
|
||||||
|
.alert-progress { background-color: $warning; }
|
||||||
|
}
|
||||||
|
|
||||||
|
&.alert-success {
|
||||||
|
color: $success;
|
||||||
|
.alert-progress { background-color: $success; }
|
||||||
|
}
|
||||||
|
|
||||||
|
&.alert-danger {
|
||||||
|
color: $danger;
|
||||||
|
.alert-progress { background-color: $danger; }
|
||||||
|
}
|
||||||
|
|
||||||
|
background-color: var(--bs-body-bg);
|
||||||
|
border: 0;
|
||||||
|
border-left: 5px solid !important;
|
||||||
|
box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.25), 0px 2px 10px 0px rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,26 @@ export function success(message, timeout) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function info(message, timeout) {
|
||||||
|
alert({
|
||||||
|
alert_id: utils.generateUUID(),
|
||||||
|
title: '[[global:alert.info]]',
|
||||||
|
message: message,
|
||||||
|
type: 'info',
|
||||||
|
timeout: timeout || 5000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function warning(message, timeout) {
|
||||||
|
alert({
|
||||||
|
alert_id: utils.generateUUID(),
|
||||||
|
title: '[[global:alert.warning]]',
|
||||||
|
message: message,
|
||||||
|
type: 'warning',
|
||||||
|
timeout: timeout || 5000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function error(message, timeout) {
|
export function error(message, timeout) {
|
||||||
message = (message && message.message) || message;
|
message = (message && message.message) || message;
|
||||||
|
|
||||||
@@ -52,7 +72,8 @@ export function remove(id) {
|
|||||||
function updateAlert(alert, params) {
|
function updateAlert(alert, params) {
|
||||||
alert.find('strong').translateHtml(params.title);
|
alert.find('strong').translateHtml(params.title);
|
||||||
alert.find('p').translateHtml(params.message);
|
alert.find('p').translateHtml(params.message);
|
||||||
alert.attr('class', 'alert alert-dismissable alert-' + params.type + ' clearfix');
|
alert.removeClass('alert-success alert-danger alert-info alert-warning')
|
||||||
|
.addClass(`alert-${params.type}`);
|
||||||
|
|
||||||
clearTimeout(parseInt(alert.attr('timeoutId'), 10));
|
clearTimeout(parseInt(alert.attr('timeoutId'), 10));
|
||||||
if (params.timeout) {
|
if (params.timeout) {
|
||||||
@@ -67,10 +88,10 @@ function updateAlert(alert, params) {
|
|||||||
alert
|
alert
|
||||||
.addClass('pointer')
|
.addClass('pointer')
|
||||||
.on('click', function (e) {
|
.on('click', function (e) {
|
||||||
if (!$(e.target).is('.close')) {
|
if (!$(e.target).is('.btn-close')) {
|
||||||
params.clickfn();
|
params.clickfn();
|
||||||
}
|
}
|
||||||
fadeOut(alert);
|
close(alert);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,17 +103,20 @@ function createNew(params) {
|
|||||||
return updateAlert(alert, params);
|
return updateAlert(alert, params);
|
||||||
}
|
}
|
||||||
alert = html;
|
alert = html;
|
||||||
alert.fadeIn(200);
|
|
||||||
|
|
||||||
components.get('toaster/tray').prepend(alert);
|
alert.hide().fadeIn(200).prependTo(components.get('toaster/tray'));
|
||||||
|
|
||||||
if (typeof params.closefn === 'function') {
|
alert.on('close.bs.alert', function () {
|
||||||
alert.find('button').on('click', function () {
|
if (typeof params.closefn === 'function') {
|
||||||
params.closefn();
|
params.closefn();
|
||||||
fadeOut(alert);
|
}
|
||||||
return false;
|
const timeoutId = alert.attr('timeoutId');
|
||||||
});
|
|
||||||
}
|
if (timeoutId) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
alert.removeAttr('timeoutId');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (params.timeout) {
|
if (params.timeout) {
|
||||||
startTimeout(alert, params);
|
startTimeout(alert, params);
|
||||||
@@ -102,10 +126,10 @@ function createNew(params) {
|
|||||||
alert
|
alert
|
||||||
.addClass('pointer')
|
.addClass('pointer')
|
||||||
.on('click', function (e) {
|
.on('click', function (e) {
|
||||||
if (!$(e.target).is('.close')) {
|
if (!$(e.target).is('.btn-close')) {
|
||||||
params.clickfn(alert, params);
|
params.clickfn(alert, params);
|
||||||
}
|
}
|
||||||
fadeOut(alert);
|
close(alert);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,17 +137,16 @@ function createNew(params) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function fadeOut(alert) {
|
function close(alert) {
|
||||||
alert.fadeOut(500, function () {
|
alert.alert('close');
|
||||||
$(this).remove();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function startTimeout(alert, params) {
|
function startTimeout(alert, params) {
|
||||||
const timeout = params.timeout;
|
const timeout = params.timeout;
|
||||||
|
|
||||||
const timeoutId = setTimeout(function () {
|
const timeoutId = setTimeout(function () {
|
||||||
fadeOut(alert);
|
alert.removeAttr('timeoutId');
|
||||||
|
close(alert);
|
||||||
|
|
||||||
if (typeof params.timeoutfn === 'function') {
|
if (typeof params.timeoutfn === 'function') {
|
||||||
params.timeoutfn(alert, params);
|
params.timeoutfn(alert, params);
|
||||||
@@ -133,20 +156,21 @@ function startTimeout(alert, params) {
|
|||||||
alert.attr('timeoutId', timeoutId);
|
alert.attr('timeoutId', timeoutId);
|
||||||
|
|
||||||
// Reset and start animation
|
// Reset and start animation
|
||||||
alert.css('transition-property', 'none');
|
const alertProgress = alert.find('.alert-progress');
|
||||||
alert.removeClass('animate');
|
alertProgress.css('transition-property', 'none');
|
||||||
|
alertProgress.removeClass('animate');
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
alert.css('transition-property', '');
|
alertProgress.css('transition-property', '');
|
||||||
alert.css('transition', 'width ' + (timeout + 450) + 'ms linear, background-color ' + (timeout + 450) + 'ms ease-in');
|
alertProgress.css('transition', 'width ' + (timeout + 450) + 'ms linear');
|
||||||
alert.addClass('animate');
|
alertProgress.addClass('animate');
|
||||||
hooks.fire('action:alert.animate', { alert, params });
|
hooks.fire('action:alert.animate', { alert, alertProgress, params });
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
// Handle mouseenter/mouseleave
|
// Handle mouseenter/mouseleave
|
||||||
alert
|
alert
|
||||||
.on('mouseenter', function () {
|
.on('mouseenter', function () {
|
||||||
$(this).css('transition-duration', 0);
|
alertProgress.css('transition-duration', 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user