Sha256: 09a29178c50a67cf3fbbed28d797f10b1c34e726d863ef2fae200c90dd8c2ae6
Contents?: true
Size: 1.39 KB
Versions: 4
Compression:
Stored size: 1.39 KB
Contents
(function(Dropdown, $) { Dropdown.setup = function(link) { var menu = Dropdown.findMenu(link); // Attach click handler to toggle dropdown $(link).off('click').on('click', function(event) { event.preventDefault(); event.stopPropagation(); var $link = $(this); var $menuWrapper = $link.siblings("div.dropdown_wrapper"); if ($menuWrapper.is(':visible')) { // If already visible, hide it $menuWrapper.css('z-index', '').slideUp(); $link.removeClass('selected'); } else { // Close other dropdowns $('.dropdown_wrapper').css('z-index', '').slideUp(); $('a.dropdown').removeClass('selected'); // Show the current dropdown with priority z-index $menuWrapper.css('z-index', '1000').slideDown(); $link.addClass('selected'); } }); }; Dropdown.findMenu = function(link) { var match = $(link).attr('href').match(/#(.+)$/)[1]; return $('#' + match); }; // Close dropdown when clicking anywhere else $(document).on('click', function(event) { if (!$(event.target).closest('.dropdown_wrapper, a.dropdown').length) { $('.dropdown_wrapper').css('z-index', '').slideUp(); $('a.dropdown').removeClass('selected'); } }); }(window.Dropdown = window.Dropdown || {}, jQuery)); $(function () { $('a.dropdown').each(function() { Dropdown.setup(this); }); });
Version data entries
4 entries across 4 versions & 1 rubygems