Skip to content

Commit

Permalink
One listener per pagination look for data attributes instead
Browse files Browse the repository at this point in the history
Useful for #452
  • Loading branch information
javve committed Feb 4, 2017
1 parent b3db0de commit 7610c59
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = function(list) {
var refresh = function(pagingList, options) {
if (list.page < 1) {
list.listContainer.style.display = 'none';
isHidden = true
isHidden = true;
return;
} else if (isHidden){
list.listContainer.style.display = 'block';
Expand Down Expand Up @@ -39,7 +39,8 @@ module.exports = function(list) {
if (className) {
classes(item.elm).add(className);
}
addEvent(item.elm, i, page);
item.elm.firstChild.setAttribute('data-i', i);
item.elm.firstChild.setAttribute('data-page', page);
} else if (is.dotted(pagingList, i, left, right, currentPage, innerWindow, pagingList.size())) {
item = pagingList.add({
page: "...",
Expand Down Expand Up @@ -78,12 +79,6 @@ module.exports = function(list) {
}
};

var addEvent = function(elm, i, page) {
events.bind(elm, 'click', function() {
list.show((i-1)*page + 1, page);
});
};

return function(options) {
var pagingList = new List(list.listContainer.id, {
listClass: options.paginationClass || 'pagination',
Expand All @@ -93,6 +88,13 @@ module.exports = function(list) {
sortClass: 'pagination-sort-that-is-not-supposed-to-exist'
});

events.bind(pagingList.listContainer, 'click', function(e) {
var target = e.target || e.srcElement
, page = list.utils.getAttribute(target, 'data-page')
, i = list.utils.getAttribute(target, 'data-i');
list.show((i-1)*page + 1, page);
});

list.on('updated', function() {
refresh(pagingList, options);
});
Expand Down

0 comments on commit 7610c59

Please sign in to comment.