pythad
pythad

Reputation: 4267

How to get killed methods back in django-endless-pagination?

After ajax added new containers it killed methods initialized for them, what can I do to make django-endless-pagination add some JQuery to its generated containers? For example i have:

$(".fact").each(function() {
   $(this).css('border-top', '5px solid ' + colors[Math.floor(Math.random() * colors.length)]);
});

and i want to add this to each .fact generated after ajax call.

Upvotes: 0

Views: 63

Answers (1)

The Django Ninja
The Django Ninja

Reputation: 493

Take a look at the Attaching callbacks section from the documentation :)

Supposing this is your endless pagination initialisation you can add some code to be executed on each new reload.

<script>
    $.endlessPaginate({
        paginateOnScroll: true,
        paginateOnScrollMargin: 100,
        paginateOnScrollChunkSize: 5,
        // add your code in onCompleted 
        onCompleted: function(context, fragment) {
            $(".fact").each(function() {
                $(this).css('border-top', '5px solid ' + colors[Math.floor(Math.random() * colors.length)]);
                });
            });

        }
    });
</script>

Upvotes: 0

Related Questions