ColorlibHQ/AdminLTE

Events firing twice or more

Closed this issue · 6 comments

I'm using Turbolinks jquery to with AdminLTE and after each request events handlers execute more than once. After some investigation I found out that you binds you document inside a $(function()) block. This is not a good idea generally and should we should avoid such mistakes. For instance, this example below can be a common occurrence and should be avoided:

/* BAD: don't bind 'document' events while inside $()! */
$(function() {
  $(document).on('click', 'button', function() { ... })
});

You should be binding your events outside a $(function()) block. This will ensure that your events will only ever be bound once.

/* Good: events are bound outside a $() wrapper. */
$(document).on('click', 'button', function() { ... })

Interesting observation. I will look into it as soon as I get a chance. Thanks for letting us know.

cool, If I find some free time I'll fix it too

How can we test that these events are really firing more than once?

It's a bit complicated but I can test it for you if you want .

@almasaeed2010 dist/js/app.js does not generate automatically from other js sources, right ?

Right