From e1adabf2fb1f52e94dc6184387d3006346f38628 Mon Sep 17 00:00:00 2001 From: Eugene Simakin Date: Sun, 25 Sep 2016 16:58:11 +0300 Subject: [PATCH] 'setupEvents' method moved to event delegation (issue #75 fixed) --- examples/index.html | 7 +++---- jquery.twbsPagination.js | 14 +++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/examples/index.html b/examples/index.html index 9854100..5100d39 100644 --- a/examples/index.html +++ b/examples/index.html @@ -19,13 +19,12 @@ var obj = $('#pagination').twbsPagination({ totalPages: 35, visiblePages: 10, - href: true, - pageVariable: 'page', onPageClick: function (event, page) { - console.info(page); + console.info(page + ' (from options)'); } + }).on('page', function (event, page) { + console.info(page + ' (from event listening)'); }); - console.info(obj.data()); }); diff --git a/jquery.twbsPagination.js b/jquery.twbsPagination.js index 9d17d3c..b1735af 100644 --- a/jquery.twbsPagination.js +++ b/jquery.twbsPagination.js @@ -210,18 +210,14 @@ setupEvents: function () { var _this = this; - this.$listContainer.find('li').each(function () { + this.$listContainer.off('click').on('click', 'li', function (evt) { var $this = $(this); - $this.off(); if ($this.hasClass(_this.options.disabledClass) || $this.hasClass(_this.options.activeClass)) { - $this.on('click', false); - return; + return false; } - $this.click(function (evt) { - // Prevent click event if href is not set. - !_this.options.href && evt.preventDefault(); - _this.show(parseInt($this.data('page'))); - }); + // Prevent click event if href is not set. + !_this.options.href && evt.preventDefault(); + _this.show(parseInt($this.data('page'))); }); },