diff --git a/bootstrap-hover-dropdown.js b/bootstrap-hover-dropdown.js index d933827..b9b8b07 100644 --- a/bootstrap-hover-dropdown.js +++ b/bootstrap-hover-dropdown.js @@ -40,14 +40,14 @@ }, showEvent = 'show.bs.dropdown', hideEvent = 'hide.bs.dropdown', - // shownEvent = 'shown.bs.dropdown', - // hiddenEvent = 'hidden.bs.dropdown', + // shownEvent = 'shown.bs.dropdown', + // hiddenEvent = 'hidden.bs.dropdown', settings = $.extend(true, {}, defaults, options, data), timeout, timeoutHover; $parent.hover(function (event) { // so a neighbor can't open the dropdown - if(!$parent.hasClass('open') && !$this.is(event.target)) { + if(!$parent.hasClass('open') && !$.contains($this[0], $(event.target)[0])) { // stop this event, stop executing any code // in this callback but continue to propagate return true; @@ -68,7 +68,7 @@ $this.hover(function (event) { // this helps prevent a double event from firing. // see https://github.com/CWSpear/bootstrap-hover-dropdown/issues/55 - if(!$parent.hasClass('open') && !$parent.is(event.target)) { + if(!$parent.hasClass('open') && !$.contains($parent[0], $(event.target)[0])) { // stop this event, stop executing any code // in this callback but continue to propagate return true; @@ -105,14 +105,14 @@ window.clearTimeout(timeout); // restart hover timer window.clearTimeout(timeoutHover); - + // delay for hover event. timeoutHover = window.setTimeout(function () { $allDropdowns.find(':focus').blur(); if(settings.instantlyCloseOthers === true) $allDropdowns.removeClass('open'); - + // clear timer for hover event window.clearTimeout(timeoutHover); $this.attr('aria-expanded', 'true'); diff --git a/bootstrap-hover-dropdown.min.js b/bootstrap-hover-dropdown.min.js index 6918463..9d56030 100644 --- a/bootstrap-hover-dropdown.min.js +++ b/bootstrap-hover-dropdown.min.js @@ -9,4 +9,4 @@ * License: MIT * Homepage: http://cameronspear.com/blog/bootstrap-dropdown-on-hover-plugin/ */ -!function(e,n){var o=e();e.fn.dropdownHover=function(t){return"ontouchstart"in document?this:(o=o.add(this.parent()),this.each(function(){function r(){d.parents(".navbar").find(".navbar-toggle").is(":visible")||(n.clearTimeout(a),n.clearTimeout(i),i=n.setTimeout(function(){o.find(":focus").blur(),v.instantlyCloseOthers===!0&&o.removeClass("open"),n.clearTimeout(i),d.attr("aria-expanded","true"),s.addClass("open"),d.trigger(h)},v.hoverDelay))}var a,i,d=e(this),s=d.parent(),u={delay:500,hoverDelay:0,instantlyCloseOthers:!0},l={delay:e(this).data("delay"),hoverDelay:e(this).data("hover-delay"),instantlyCloseOthers:e(this).data("close-others")},h="show.bs.dropdown",c="hide.bs.dropdown",v=e.extend(!0,{},u,t,l);s.hover(function(e){return s.hasClass("open")||d.is(e.target)?void r(e):!0},function(){n.clearTimeout(i),a=n.setTimeout(function(){d.attr("aria-expanded","false"),s.removeClass("open"),d.trigger(c)},v.delay)}),d.hover(function(e){return s.hasClass("open")||s.is(e.target)?void r(e):!0}),s.find(".dropdown-submenu").each(function(){var o,t=e(this);t.hover(function(){n.clearTimeout(o),t.children(".dropdown-menu").show(),t.siblings().children(".dropdown-menu").hide()},function(){var e=t.children(".dropdown-menu");o=n.setTimeout(function(){e.hide()},v.delay)})})}))},e(document).ready(function(){e('[data-hover="dropdown"]').dropdownHover()})}(jQuery,window); \ No newline at end of file +!function(e,n,o){var t=e();e.fn.dropdownHover=function(o){return"ontouchstart"in document?this:(t=t.add(this.parent()),this.each(function(){function r(e){d.parents(".navbar").find(".navbar-toggle").is(":visible")||(n.clearTimeout(a),n.clearTimeout(i),i=n.setTimeout(function(){t.find(":focus").blur(),v.instantlyCloseOthers===!0&&t.removeClass("open"),n.clearTimeout(i),d.attr("aria-expanded","true"),s.addClass("open"),d.trigger(h)},v.hoverDelay))}var a,i,d=e(this),s=d.parent(),u={delay:500,hoverDelay:0,instantlyCloseOthers:!0},l={delay:e(this).data("delay"),hoverDelay:e(this).data("hover-delay"),instantlyCloseOthers:e(this).data("close-others")},h="show.bs.dropdown",c="hide.bs.dropdown",v=e.extend(!0,{},u,o,l);s.hover(function(n){return!s.hasClass("open")&&!e.contains(d[0],e(n.target)[0])||void r(n)},function(){n.clearTimeout(i),a=n.setTimeout(function(){d.attr("aria-expanded","false"),s.removeClass("open"),d.trigger(c)},v.delay)}),d.hover(function(n){return!s.hasClass("open")&&!e.contains(s[0],e(n.target)[0])||void r(n)}),s.find(".dropdown-submenu").each(function(){var o,t=e(this);t.hover(function(){n.clearTimeout(o),t.children(".dropdown-menu").show(),t.siblings().children(".dropdown-menu").hide()},function(){var e=t.children(".dropdown-menu");o=n.setTimeout(function(){e.hide()},v.delay)})})}))},e(document).ready(function(){e('[data-hover="dropdown"]').dropdownHover()})}(jQuery,window); \ No newline at end of file diff --git a/package.json b/package.json index 8106da1..5f07965 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "gulp-filter": "^2.0.0", "gulp-git": "^0.5.6", "gulp-rename": "^1.2.0", + "gulp-replace": "^0.5.4", "gulp-tag-version": "^1.2.1", "gulp-uglify": "^1.1.0", "streamqueue": "^0.1.1"