From be25ab06a02aed3df0718a3eca9860a7aaaf3ecd Mon Sep 17 00:00:00 2001
From: Thomas Steur <thomas.steur@gmail.com>
Date: Sun, 27 Oct 2013 22:05:33 +0000
Subject: [PATCH] refs #4179 extract some code into functions, added
 possibility to place notification in any node by specifying property placeAt

---
 plugins/CoreHome/javascripts/notification.js | 55 +++++++++++++-------
 1 file changed, 37 insertions(+), 18 deletions(-)

diff --git a/plugins/CoreHome/javascripts/notification.js b/plugins/CoreHome/javascripts/notification.js
index 2d44688613..056c34af7a 100644
--- a/plugins/CoreHome/javascripts/notification.js
+++ b/plugins/CoreHome/javascripts/notification.js
@@ -22,38 +22,26 @@
             options = {};
         }
 
-        if ('persistent' == options.type && options.noclear) {
+        if ('persistent' == options.type) {
             // otherwise it is never possible to dismiss the notification
             options.noclear = false;
         }
 
-        var template = '<div class="notification';
-
-        if (options.context) {
-            template += ' notification-' + options.context;
-        }
-
-        template += '"';
-
-        if (options.id) {
-            template += ' data-id="' + options.id + '"';
-        }
-
-        template += '>';
+        var template = buildNotificationStart(options);
 
         if (!options.noclear) {
-            template += '<button type="button" class="close" data-dismiss="alert">&times;</button>';
+            template += buildClearButton();
         }
 
         if (options.title) {
-            template += '<strong>' + options.title + '</strong> ';
+            template += buildTitle(options);
         }
 
         template += message;
-        template += '</div>';
+        template += buildNotificationEnd();
 
         var $notificationNode = $(template).appendTo('#notificationContainer').hide();
-        $('#notificationContainer').append($notificationNode);
+        $(options.placeAt || '#notificationContainer').append($notificationNode);
         $notificationNode.fadeIn(1000);
 
         if ('persistent' == options.type) {
@@ -71,6 +59,37 @@
 
     exports.Notification = Notification;
 
+
+    function buildNotificationStart(options) {
+        var template = '<div class="notification';
+
+        if (options.context) {
+            template += ' notification-' + options.context;
+        }
+
+        template += '"';
+
+        if (options.id) {
+            template += ' data-id="' + options.id + '"';
+        }
+
+        template += '>';
+
+        return template;
+    }
+
+    function buildNotificationEnd() {
+        return '</div>';
+    }
+
+    function buildClearButton() {
+        return '<button type="button" class="close" data-dismiss="alert">&times;</button>';
+    }
+
+    function buildTitle(options) {
+        return '<strong>' + options.title + '</strong> ';
+    }
+
     function addToastEvent($notificationNode)
     {
         setTimeout(function () {
-- 
GitLab