botmonster / jquery-bootpag

BootPag - boostrap dynamic pagination jQuery plugin
MIT License
524 stars 263 forks source link

onpage function-call triggers twice #42

Open q4z1 opened 8 years ago

q4z1 commented 8 years ago

Using the following code triggers the onpage function-call twice when clicking a pagination link (workaround is included):

var page = 1; // global variable $('.sbpagination').bootpag({ total: Math.ceil(numPosts / 50), maxVisible: 3, firstLastUse: true, }).on("page", function(event, p){ // @XXX: bug in bootpag? - small workaround in order to avoid double requests and refresh-timeouts if(page == p){ return; } page = p; refreshShoutbox(((p-1)*50), 50); // $.post() is called inside this function which updates the content });

gtrbarbarian commented 8 years ago

I ran into this as well. The strange thing is that the jquery trigger (line 173) is only called once (indicating to me, that -bootpag- is working correctly), but the number of calls to the callback bound to the 'page' event seems to be doubling every time a 'page' event is triggered. i.e. on the first page, 1 call, on the 2nd page 2 calls, on the 3rd page 4 calls..then 8 , 16 ,32 ,64 (calls of the callback function). Looking at the posts in the net window in firebug, it is always multiples of the same page number being requested, which is why q4z1's workaround works (immediate return from callback on duplicate page request). This seems like a bug in the jquery event code, not the bootpag code (as evidenced by only one call to 'page' trigger.) I tried adding an unbind() to the trigger line to see if old event bindings were the culprit, but no dice.