/* Override the default confirm dialog defined by jQuery UJS */ $.rails.allowAction = function(link) { if (link.data('confirm') == undefined) { return true; } $.rails.showConfirmationDialog(link); return false; } /* Remove the data-confirm from the link so Rails doesn't re-trigger the modal. Then trigger a click of the link. */ $.rails.confirmed = function(link) { link.data('confirm', null); if (link.data('method')){ // let rails handle non-GET requests // (i.e. data-method="delete") return link.trigger('click.rails'); } window.location.href = link.attr('href'); } /* Toggle the Foundation reveal modal when a data-confirm element is clicked. */ $.rails.showConfirmationDialog = function(link) { var el = link.data('confirm'); var modal = $('[data-' + el + ']'); var key = link.data('reveal-confirm-key'); if (key && key.length) { modal.data('reveal-confirm-key', key); } modal.foundation('open'); } /* Single Link/Single Modal: Link Delete Modal
... OK ...
Multiple Links/Single Modal: Links Delete Delete Modal
... OK ...
*/ $(document).on('click', '*[data-reveal-confirm]', function(e) { e.preventDefault(); var target = e.currentTarget; var el = $(target).data('reveal-confirm'); var modal = $('[data-' + el + ']'); var key = $(modal).data('reveal-confirm-key'); var link = $('[data-confirm="'+ el + '"]'); if (key && key.length) { link = $('[data-reveal-confirm-key=' + key + ']'); } $(modal).foundation('close'); $(modal).data('reveal-confirm-key', null); $.rails.confirmed(link); });