From e589eb21e360032836d7b807a637b816ef10ac23 Mon Sep 17 00:00:00 2001 From: Eugene Simakin Date: Mon, 2 Nov 2015 20:23:44 +0300 Subject: [PATCH] Update plugin --- js/jquery.twbsPagination.js | 54 +++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/js/jquery.twbsPagination.js b/js/jquery.twbsPagination.js index 9327f6d..f96332a 100644 --- a/js/jquery.twbsPagination.js +++ b/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 @@ -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; }; @@ -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 () { @@ -254,6 +267,7 @@ totalPages: 0, startPage: 1, visiblePages: 5, + initiateStartPageClick: true, href: false, hrefVariable: '{{number}}', first: 'First',