Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh jquery.masonry when deleting an item

How do I refresh Masonry when an item is deleted via Ajax? This is the code I'm using to delete the item:

if($deletes = $('a[rel=delete]')) {
    $deletes.click(function() {
        if(!window.confirm('Are you sure you wish to delete this picture?'))
            return false;
        $t = $(this);
        $.post(
            $t.attr('href'),
            {},
            function(data) {
                if(data == "success")
                    $t.parents('.deleteable:first').fadeOut();
            }
        );
        return false;           
    });
}

The reason I want a refresh is to eliminate the resulting spaces after items are deleted.

like image 336
Freeman Avatar asked Feb 25 '23 21:02

Freeman


1 Answers

Add a callback to your fadeOut() to actually call .remove() your deleted element once it's faded out, then just call .masonry() on the container again.

like image 57
John Flatness Avatar answered Mar 12 '23 07:03

John Flatness