Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update plugin
  • Loading branch information
Eugene Simakin committed Nov 2, 2015
1 parent 2ba2200 commit e589eb2
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions js/jquery.twbsPagination.js
@@ -1,5 +1,5 @@
/*!
* jQuery pagination plugin v1.2.5
* jQuery pagination plugin v1.2.6
* http://esimakin.github.io/twbs-pagination/
*
* Copyright 2014, Eugene Simakin
Expand Down Expand Up @@ -67,6 +67,10 @@
this.render(this.getPages(this.options.startPage));
this.setupEvents();

if (this.options.initiateStartPageClick) {
this.$element.trigger('page', this.options.startPage);
}

return this;
};

Expand Down Expand Up @@ -184,29 +188,38 @@
},

render: function (pages) {
var that = this;
this.$listContainer.children().remove();
this.$listContainer.append(this.buildListItems(pages));

var children = this.$listContainer.children();
children.filter(function () {
return $(this).data('page') === pages.currentPage && $(this).data('page-type') === 'page';
}).addClass(this.options.activeClass);

children.filter(function () {
return $(this).data('page-type') === 'first';
}).toggleClass(this.options.disabledClass, pages.currentPage === 1);

children.filter(function () {
return $(this).data('page-type') === 'last';
}).toggleClass(this.options.disabledClass, pages.currentPage === this.options.totalPages);

children.filter(function () {
return $(this).data('page-type') === 'prev';
}).toggleClass(this.options.disabledClass, !this.options.loop && pages.currentPage === 1);
this.$listContainer.children().each(function () {
var $this = $(this),
pageType = $this.data('page-type');

switch (pageType) {
case 'page':
if ($this.data('page') === pages.currentPage) {
$this.addClass(that.options.activeClass);
}
break;
case 'first':
$this.toggleClass(that.options.disabledClass, pages.currentPage === 1);
break;
case 'last':
$this.toggleClass(that.options.disabledClass, pages.currentPage === that.options.totalPages);
break;
case 'prev':
$this.toggleClass(that.options.disabledClass, !that.options.loop && pages.currentPage === 1);
break;
case 'next':
$this.toggleClass(that.options.disabledClass,
!that.options.loop && pages.currentPage === that.options.totalPages);
break;
default:
break;
}

children.filter(function () {
return $(this).data('page-type') === 'next';
}).toggleClass(this.options.disabledClass, !this.options.loop && pages.currentPage === this.options.totalPages);
});
},

setupEvents: function () {
Expand Down Expand Up @@ -254,6 +267,7 @@
totalPages: 0,
startPage: 1,
visiblePages: 5,
initiateStartPageClick: true,
href: false,
hrefVariable: '{{number}}',
first: 'First',
Expand Down

0 comments on commit e589eb2

Please sign in to comment.