josecebe / twbs-pagination

jQuery pagination plugin (bootstrap powered)
http://josecebe.github.io/twbs-pagination/
Other
1.1k stars 402 forks source link

After using destroy and then init, onPageClick happens twice #15

Closed ecarloslr closed 10 years ago

ecarloslr commented 10 years ago

Hello there, I think there is a bug when redefining the totalPages using destroy and then init: Every times I do this, the onPageClick is called twice whenever I click on a page.

Here's a jsFiddle:

http://jsfiddle.net/7tLbhkt1/1/

Try clicking the Reset button a couple of times and then selecting a page.

My workaround was to set settings.onPageClick to null before calling the 'init' method. It seems the previous onPageClick is not removed from the new pagination, and I don't think that was intended.

I'm still kinda new to github and jsFiddle so I'm sorry if the link doesn't work or I'm not describing the problem clear enough.

Also, thank you for making this library. I really like how it handles the visible pages and how easy it is to use.

ecarloslr commented 10 years ago

I forgot to mention, for the workaround when calling 'init' after destroy, it's not enough to just pass new parameters without onPageClick on them, it has to be explicitly set to null.

eugenesimakin commented 10 years ago

I created branch issue15 and cleaned the code. You can try it here: http://jsfiddle.net/0ovnxusv/

Please, check it and then I'll merge it to master. P.S. And do not use script from gh-pages. It can be out of date.

ecarloslr commented 10 years ago

At first I tested it in my app and it wasn't working, but then I noticed you removed the init method. After changing the method call to just twbsPagination(settings), it worked fine.

Thanks a lot! And I didn't know about rawgit.com, thanks for that too. Keep up the good work!