Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Option 'initiateStartPageClick' added + small optimization. Issues jo…
  • Loading branch information
Eugene Simakin committed Oct 26, 2015
1 parent fbdd6fc commit 9895cfa
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
3 changes: 3 additions & 0 deletions TODO
@@ -0,0 +1,3 @@
Update documentation:
1) Describe 'initiateStartPageClick' option
2) Add example for using 'href' and 'hrefVariable' (maybe rename it with back compability)
54 changes: 34 additions & 20 deletions 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
6 changes: 3 additions & 3 deletions jquery.twbsPagination.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "twbs-pagination",
"version": "1.2.5",
"version": "1.2.6",
"homepage": "https://github.com/esimakin/twbs-pagination",
"author": "Eugene Simakin <eugenesimakin@mail.ru>",
"description": "jQuery simple pagination plugin for bootstrap-style webpages",
Expand Down
2 changes: 1 addition & 1 deletion twbs-pagination.jquery.json
@@ -1,6 +1,6 @@
{
"name": "twbs-pagination",
"version": "1.1.0",
"version": "1.2.6",
"title": "Twbs Pagination",
"author": {
"name": "Eugene Simakin",
Expand Down

0 comments on commit 9895cfa

Please sign in to comment.