From 2a51eb4564b9f96be08ab9784d7a7a9f6048d443 Mon Sep 17 00:00:00 2001
From: Thomas Steur <thomas.steur@gmail.com>
Date: Sat, 26 Oct 2013 23:19:46 +0000
Subject: [PATCH] refs #4179 better var naming

---
 plugins/CoreHome/javascripts/notification.js | 35 ++++++++++++--------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/plugins/CoreHome/javascripts/notification.js b/plugins/CoreHome/javascripts/notification.js
index 9f0423475a..c28b6452d1 100644
--- a/plugins/CoreHome/javascripts/notification.js
+++ b/plugins/CoreHome/javascripts/notification.js
@@ -52,49 +52,56 @@
         template += message;
         template += '</div>';
 
-        var notificationNode = $(template).appendTo('#notificationContainer');
+        var $notificationNode = $(template).appendTo('#notificationContainer');
 
         if ('persistent' == options.type) {
-            addPersistentEvent(notificationNode);
+            addPersistentEvent($notificationNode);
         }
 
         if ('toast' == options.type) {
-            addToastEvent(notificationNode);
+            addToastEvent($notificationNode);
         }
 
         if (!options.noclear) {
-            addCloseEvent(notificationNode);
+            addCloseEvent($notificationNode);
         }
     };
 
     exports.Notification = Notification;
 
-    function addToastEvent(notificationNode)
+    function addToastEvent($notificationNode)
     {
         setTimeout(function () {
-            notificationNode.fadeOut( 'slow', function() {
-                notificationNode.remove();
-                notificationNode = null;
+            $notificationNode.fadeOut( 'slow', function() {
+                $notificationNode.remove();
+                $notificationNode = null;
             });
         }, 15 * 1000);
     }
 
-    function addCloseEvent(notificationNode) {
-        $(notificationNode).on('click', '.close', function (event) {
-            if (event.delegateTarget) {
+    function addCloseEvent($notificationNode) {
+        $notificationNode.on('click', '.close', function (event) {
+            if (event && event.delegateTarget) {
                 $(event.delegateTarget).remove();
             }
         });
     };
 
-    function addPersistentEvent(notificationNode) {
-        $(notificationNode).on('click', '.close', function (event) {
+    function addPersistentEvent($notificationNode) {
+
+        var notificationId = $notificationNode.data('id');
+
+        if (!notificationId) {
+            return;
+        }
+
+        $notificationNode.on('click', '.close', function (event) {
             var ajaxHandler = new ajaxHelper();
             ajaxHandler.addParams({
                 module: 'CoreHome',
                 action: 'markNotificationAsRead'
             }, 'GET');
-            ajaxHandler.addParams({notificationId: $(notificationNode).data('id')}, 'POST');
+            ajaxHandler.addParams({notificationId: notificationId}, 'POST');
             ajaxHandler.send(true);
         });
     };
-- 
GitLab