Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change demos version from 1.0 to 1.1
  • Loading branch information
Eugene Simakin committed Jan 7, 2014
1 parent 055bb2a commit ea0d17b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.html
Expand Up @@ -15,7 +15,7 @@

<script src="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script src="js/jquery.twbsPagination-1.0.js" type="text/javascript"></script>
<script src="js/jquery.twbsPagination.js" type="text/javascript"></script>
<script src="js/main.js" type="text/javascript"></script>

<!--[if lt IE 9]>
Expand Down Expand Up @@ -76,7 +76,7 @@ <h3>
<p>Here is corresponding piece of code:</p>
<pre><code class="highlight"> $(<span class="s">'#pagination-demo'</span>).twbsPagination({
totalPages: <span class="il">35</span>,
visiblePages: <span class="il">8</span>,
visiblePages: <span class="il">7</span>,
onPageClick: <span class="k">function</span> (event, page) {
$(<span class="s">'#page-content'</span>).text(<span class="s">'Page '</span> + page);
}
Expand Down
56 changes: 52 additions & 4 deletions js/jquery.twbsPagination-1.0.js → js/jquery.twbsPagination.js
Expand Up @@ -28,7 +28,17 @@
init: function (options) {
this.options = $.extend({}, this.options, options);

this.currentPages = this.getPages(this.options.startPage);
switch (this.options.version) {
case '1.0':
this.currentPages = this.getPages_v_1_0(this.options.startPage);
break;
case '1.1':
this.currentPages = this.getPages_v_1_1(this.options.startPage);
break;
default:
this.currentPages = this.getPages_v_1_1(this.options.startPage);
break;
}

if (this.options.startPage < 1 || this.options.startPage > this.options.totalPages) {
throw new Error('Start page option is incorrect');
Expand Down Expand Up @@ -71,7 +81,18 @@
throw new Error('Page is incorrect.');
}

this.render(this.getPages(page));
switch (this.options.version) {
case '1.0':
this.render(this.getPages_v_1_0(page));
break;
case '1.1':
this.render(this.getPages_v_1_1(page));
break;
default:
this.render(this.getPages_v_1_1(page));
break;
}

this.setupEvents();

this.$element.trigger('page', page);
Expand Down Expand Up @@ -135,7 +156,7 @@
return itemContainer;
},

getPages: function (currentPage) {
getPages_v_1_0: function (currentPage) {
var pages = [];

var startPage;
Expand All @@ -154,6 +175,32 @@
return {"currentPage": currentPage, "numeric": pages};
},

getPages_v_1_1: function (currentPage) {
var pages = [];

var half = Math.floor(this.options.visiblePages / 2);
var start = currentPage - half + 1 - this.options.visiblePages % 2;
var end = currentPage + half;

// handle boundary case
if (start <= 0) {
start = 1;
end = this.options.visiblePages;
}
if (end > this.options.totalPages) {
start = this.options.totalPages - this.options.visiblePages + 1;
end = this.options.totalPages;
}

var itPage = start;
while (itPage <= end) {
pages.push(itPage);
itPage++;
}

return {"currentPage": currentPage, "numeric": pages};
},

render: function (pages) {
if (!this.equals(this.currentPages.numeric, pages.numeric)) {
this.$listContainer.children().remove();
Expand Down Expand Up @@ -239,7 +286,8 @@
next: 'Next',
last: 'Last',
paginationClass: 'pagination',
onPageClick: null
onPageClick: null,
version: '1.0'
};

$.fn.twbsPagination.Constructor = TwbsPagination;
Expand Down
6 changes: 4 additions & 2 deletions js/main.js
@@ -1,7 +1,8 @@
$(document).ready(function () {
$('#pagination-demo').twbsPagination({
totalPages: 35,
visiblePages: 8,
visiblePages: 7,
version: '1.1',
onPageClick: function (event, page) {
$('#page-content').text('Page ' + page);
}
Expand All @@ -15,7 +16,8 @@ $(document).ready(function () {

$('#visible-pages-example').twbsPagination({
totalPages: 35,
visiblePages: 10
visiblePages: 10,
version: '1.1'
});

});
Expand Down

0 comments on commit ea0d17b

Please sign in to comment.