From 4ce35b5b95571ca407933c3929f684c3eaa6fc53 Mon Sep 17 00:00:00 2001
From: Thomas Gelf <thomas@gelf.net>
Date: Mon, 24 Mar 2014 09:22:20 +0000
Subject: [PATCH] Delay tab dropdown disappearance

---
 public/js/icinga/events.js | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js
index a2f8d5d7c..50a43a8a5 100644
--- a/public/js/icinga/events.js
+++ b/public/js/icinga/events.js
@@ -101,16 +101,32 @@
 
             $(document).on('mouseenter', '.historycolorgrid td', this.historycolorgridHover);
             $(document).on('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
+            $(document).on('mouseenter', 'li.dropdown', this.dropdownHover);
+            $(document).on('mouseleave', 'li.dropdown', this.dropdownLeave);
 
             $(document).on('click', '.tree .handle', { self: this }, this.treeNodeToggle);
 
+
             // TBD: a global autocompletion handler
             // $(document).on('keyup', 'form.auto input', this.formChangeDelayed);
             // $(document).on('change', 'form.auto input', this.formChanged);
             // $(document).on('change', 'form.auto select', this.submitForm);
         },
 
-        treeNodeToggle: function (event) {
+        dropdownHover: function () {
+            $(this).addClass('hover');
+        },
+
+        dropdownLeave: function () {
+            var $li = $(this);
+            setTimeout(function () {
+                if (! $li.is('li:hover')) {
+                    $li.removeClass('hover');
+                }
+            }, 300);
+        },
+
+        treeNodeToggle: function () {
             var $parent = $(this).closest('li');
             if ($parent.hasClass('collapsed')) {
                 $('li', $parent).addClass('collapsed');
@@ -309,7 +325,9 @@
             $(document).off('click', 'button', this.submitForm);
             $(document).off('change', 'form select.autosubmit', this.submitForm);
             $(document).off('mouseenter', '.historycolorgrid td', this.historycolorgridHover);
-            $(document).off('mouseenter', '.historycolorgrid td', this.historycolorgidUnhover);
+            $(document).off('mouseleave', '.historycolorgrid td', this.historycolorgidUnhover);
+            $(document).off('mouseenter', 'li.dropdown', this.dropdownHover);
+            $(document).off('mouseleave', 'li.dropdown', this.dropdownLeave);
         },
 
         destroy: function() {