From 3854e0b591f3c0b616e4276a3a496fb66cd3ac79 Mon Sep 17 00:00:00 2001 From: thiggins Date: Mon, 7 Dec 2015 16:13:57 +0000 Subject: [PATCH] Add new dropdown option to persist hover over pane. This reimplements old v5 default functionality. --- js/foundation.dropdown.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/js/foundation.dropdown.js b/js/foundation.dropdown.js index a4d5e51c6..4233c31ac 100644 --- a/js/foundation.dropdown.js +++ b/js/foundation.dropdown.js @@ -40,6 +40,12 @@ * @example false */ hover: false, + /** + * Don't close dropdown when hovering over dropdown pane + * @option + * @example true + */ + hoverPane: false, /** * Number of pixels between the dropdown pane and the triggering element on open. * @option @@ -199,17 +205,29 @@ this.$anchor.off('mouseenter.zf.dropdown mouseleave.zf.dropdown') .on('mouseenter.zf.dropdown', function(){ clearTimeout(_this.timeout); - _this.timeOut = setTimeout(function(){ + _this.timeout = setTimeout(function(){ _this.open(); _this.$anchor.data('hover', true); }, _this.options.hoverDelay); }).on('mouseleave.zf.dropdown', function(){ clearTimeout(_this.timeout); - _this.timeOut = setTimeout(function(){ + _this.timeout = setTimeout(function(){ _this.close(); _this.$anchor.data('hover', false); }, _this.options.hoverDelay); }); + if(this.options.hoverPane){ + this.$element.off('mouseenter.zf.dropdown mouseleave.zf.dropdown') + .on('mouseenter.zf.dropdown', function(){ + clearTimeout(_this.timeout); + }).on('mouseleave.zf.dropdown', function(){ + clearTimeout(_this.timeout); + _this.timeout = setTimeout(function(){ + _this.close(); + _this.$anchor.data('hover', false); + }, _this.options.hoverDelay); + }); + } } this.$anchor.add(this.$element).on('keydown.zf.dropdown', function(e) { @@ -266,7 +284,7 @@ this._setPosition(); this.$element.addClass('is-open') .attr({'aria-hidden': false}); - + if(this.options.autoFocus){ var $focusable = Foundation.Keyboard.findFocusable(this.$element); if($focusable.length){ -- 2.47.2