eldarion / eldarion-ajax

a library for adding declarative ajax functionality to your website
BSD 3-Clause "New" or "Revised" License
758 stars 153 forks source link

Keep dropdown open when clicking on <a> #71

Closed bblue closed 10 years ago

bblue commented 10 years ago

I am successfully using eldarion to load data from the server, but I have an issue where I have an ajax link within a dropdown menu.

Every single "normal" workaround I have found stops the event to bubble up on click, hence the eldarion ajax calls never happen.

$('a.ajax').on('click', function() {return false; }); does not work, and neither does:
$('a.ajax').on('click', function(e) {e.stopPropagiation(); });

How can I stop my dropdown menu from closing (using bootstrap), and still have eldarion do its magic?

bblue commented 10 years ago

Never mind, I found a way. Ugly, but it works.

$('a.ajax').on('click', function() {
    $(this).closest('.dropdown').addClass('keep-open');
});
$('.dropdown').on({
    "hide.bs.dropdown":  function() { return (!$(this).hasClass('keep-open')); }
});
$(document).on("eldarion-ajax:complete", function(evt, $el, jqXHR, textStatus) {
    $el.closest('.dropdown.keep-open').removeClass('keep-open');
});