Last active
November 9, 2017 07:33
-
-
Save VitalyKondratiev/a328eeab7c8e8e55296d0ff6ff4edecc to your computer and use it in GitHub Desktop.
Открытие выпадающих списков по наведению (Bootstrap)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is_touch_device() { | |
try { | |
document.createEvent("TouchEvent"); | |
return true; | |
} catch (e) { | |
return false; | |
} | |
} | |
if (is_touch_device) return; | |
$('.pane-system-main-menu .nav .dropdown .dropdown-toggle').hover(function() { | |
$('.dropdown').removeClass('open'); | |
$(this).parent().addClass('open'); | |
$(this).attr('aria-expanded', true); | |
}); | |
$('.pane-system-main-menu .nav .dropdown').on('mouseleave', function(e) { | |
var cursorX; | |
var cursorY; | |
document.onmousemove = function(e) { | |
cursorX = e.pageX - window.pageXOffset; | |
cursorY = e.pageY - window.pageYOffset; | |
} | |
var canCloseDropdown = function(dropdown) { | |
var onParent = $(document.elementFromPoint(cursorX, cursorY)).parent()[0] === dropdown.parent()[0]; | |
var inMenu = $.contains(dropdown[0], $(document.elementFromPoint(cursorX, cursorY))[0]); | |
if (!onParent && !inMenu) { | |
$(dropdown).parent().removeClass('open'); | |
$(dropdown).parent().find('.dropdown-toggle').attr('aria-expanded', false); | |
} | |
} | |
setTimeout(canCloseDropdown, 500, $(this).find('.dropdown-menu')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment