Просмотр исходного кода

Avoid flooding user with alerts

Rafał Pitoń 10 лет назад
Родитель
Сommit
3da66af511

+ 3 - 3
misago/static/misago/css/misago/alerts.less

@@ -5,7 +5,7 @@
 
 .misago-alert-close(@text, @bg) {
   background-color: lighten(@bg, 10%);
-	border: 1px solid lighten(@bg, 10%);
+  border: 1px solid lighten(@bg, 10%);
   border-radius: @border-radius-small;
   .box-shadow(none);
   float: none;
@@ -19,14 +19,14 @@
 
   &:hover {
     background-color: darken(@bg, 15%);
-  	border-color: darken(@bg, 15%);
+    border-color: darken(@bg, 15%);
 
     color: @text;
   }
 
   &:active, &:focus {
     background-color: @text;
-  	border: 1px solid @text;
+    border: 1px solid @text;
 
     color: @bg;
   }

+ 26 - 7
misago/static/misago/js/misago-alerts.js

@@ -35,24 +35,43 @@
         var $alert = $(this).parent().parent();
         controller.$height -= $alert.height();
         controller.$alerts.animate({height: controller.$height}, {queue: false});
-        $alert.slideUp();
+        $alert.slideUp(400, function() {
+          $(this).remove();
+        });
       });
     }
     bindCloseEvents(this);
 
+    // Heartbeat alert
+    function heartbeat($element) {
+      $element.fadeTo(300, 0.8).fadeTo(1000, 1, function() {
+        heartbeat($element);
+      });
+    }
+
     // Alerts functions
     this.add_alert = function(template, message) {
       if (message == undefined) {
         message = this.options.generic_error;
       }
 
-      var $alert = $(template.replace('%message%', message));
-      this.$alerts_list.append($alert);
+      var repeated_alert = false;
+      $alerts_list.find('.alert').each(function() {
+        if ($(this).text().indexOf(message) == 0 ) {
+          repeated_alert = true;
+          heartbeat($(this));
+        }
+      });
+
+      if (!repeated_alert) {
+        var $alert = $(template.replace('%message%', message));
+        this.$alerts_list.append($alert);
 
-      this.$height += $alert.height();
-      $alert.hide();
-      this.$alerts.animate({height: this.$height}, {queue: false});
-      $alert.slideDown();
+        this.$height += $alert.height();
+        $alert.hide();
+        this.$alerts.animate({height: this.$height}, {queue: false});
+        $alert.slideDown();
+      }
     }
 
     this.error = function(message) {