Skip to content

Commit

Permalink
Merge branch 'feature/show-total-pages-#23' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	jquery.twbsPagination.min.js
  • Loading branch information
Eugene Simakin committed Nov 7, 2015
2 parents 9b91c76 + 1007991 commit 7a26fba
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 54 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twbs-pagination",
"version": "1.3.1",
"version": "1.4",
"homepage": "https://github.com/esimakin/twbs-pagination",
"authors": [
"Eugene Simakin <[email protected]>"
Expand All @@ -11,7 +11,7 @@
"globals"
],
"dependencies": {
"jquery": ">=1.7.0"
"jquery": ">=1.8.1"
},
"keywords": [
"pagination",
Expand Down
59 changes: 22 additions & 37 deletions jquery.twbsPagination.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* jQuery pagination plugin v1.2.6
* jQuery pagination plugin v1.4
* http://esimakin.github.io/twbs-pagination/
*
* Copyright 2014, Eugene Simakin
* Copyright 2014-2015, Eugene Simakin
* Released under Apache 2.0 license
* http://apache.org/licenses/LICENSE-2.0.html
*/
Expand Down Expand Up @@ -42,7 +42,7 @@

if (this.options.href) {
var match, regexp = this.options.href.replace(/[-\/\\^$*+?.|[\]]/g, '\\$&');
regexp = regexp.replace(this.options.hrefVariable, '(\\d+)');
regexp = regexp.replace(this.options.pageVariable, '(\\d+)');
if ((match = new RegExp(regexp, 'i').exec(window.location.href)) != null) {
this.options.startPage = parseInt(match[1], 10);
}
Expand Down Expand Up @@ -101,24 +101,25 @@
buildListItems: function (pages) {
var listItems = [];

// Add "first" page button
if (this.options.first) {
listItems.push(this.buildItem('first', 1));
}

// Add "previous" page button
if (this.options.prev) {
var prev = pages.currentPage > 1 ? pages.currentPage - 1 : this.options.loop ? this.options.totalPages : 1;
listItems.push(this.buildItem('prev', prev));
}

// Add "pages"
for (var i = 0; i < pages.numeric.length; i++) {
listItems.push(this.buildItem('page', pages.numeric[i]));
}

// Add "next" page button
if (this.options.next) {
var next = pages.currentPage < this.options.totalPages ? pages.currentPage + 1 : this.options.loop ? 1 : this.options.totalPages;
listItems.push(this.buildItem('next', next));
}

// Add "last" page button
if (this.options.last) {
listItems.push(this.buildItem('last', this.options.totalPages));
}
Expand All @@ -131,31 +132,8 @@
$itemContent = $('<a></a>'),
itemText = null;

switch (type) {
case 'page':
itemText = page;
$itemContainer.addClass(this.options.pageClass);
break;
case 'first':
itemText = this.options.first;
$itemContainer.addClass(this.options.firstClass);
break;
case 'prev':
itemText = this.options.prev;
$itemContainer.addClass(this.options.prevClass);
break;
case 'next':
itemText = this.options.next;
$itemContainer.addClass(this.options.nextClass);
break;
case 'last':
itemText = this.options.last;
$itemContainer.addClass(this.options.lastClass);
break;
default:
break;
}

itemText = this.options[type] ? this.makeText(this.options[type], page) : page;
$itemContainer.addClass(this.options[type + 'Class']);
$itemContainer.data('page', page);
$itemContainer.data('page-type', type);
$itemContainer.append($itemContent.attr('href', this.makeHref(page)).html(itemText));
Expand Down Expand Up @@ -244,8 +222,13 @@
});
},

makeHref: function (c) {
return this.options.href ? this.options.href.replace(this.options.hrefVariable, c) : "#";
makeHref: function (page) {
return this.options.href ? this.makeText(this.options.href, page) : "#";
},

makeText: function (text, page) {
return text.replace(this.options.pageVariable, page)
.replace(this.options.totalPagesVariable, this.options.totalPages)
}

};
Expand All @@ -258,7 +241,7 @@

var $this = $(this);
var data = $this.data('twbs-pagination');
var options = typeof option === 'object' && option;
var options = typeof option === 'object' ? option : {};

if (!data) $this.data('twbs-pagination', (data = new TwbsPagination(this, options) ));
if (typeof option === 'string') methodReturn = data[ option ].apply(data, args);
Expand All @@ -267,12 +250,14 @@
};

$.fn.twbsPagination.defaults = {
totalPages: 0,
totalPages: 1,
startPage: 1,
visiblePages: 5,
initiateStartPageClick: true,
href: false,
hrefVariable: '{{number}}',
pageVariable: '{{page}}',
totalPagesVariable: '{{total_pages}}',
page: null,
first: 'First',
prev: 'Previous',
next: 'Next',
Expand Down
4 changes: 2 additions & 2 deletions jquery.twbsPagination.min.js

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "twbs-pagination",
"nativeName": "jQuery Bootstrap Pagination",
"version": "1.3.1",
"version": "1.4",
"homepage": "https://github.com/esimakin/twbs-pagination",
"author": "Eugene Simakin <[email protected]>",
"description": "jQuery simple pagination plugin for bootstrap-style webpages",
"main": "jquery.twbsPagination",
"dependencies": {
"jquery": ">=1.7.0"
"jquery": ">=1.8.1"
},
"devDependencies": {
"grunt": "^0.4.5",
Expand Down
21 changes: 21 additions & 0 deletions tests/run-test-jquery-1.8.1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tests</title>

<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.13.0.css">

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

</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<ul id="pagination" style="display: none;"></ul>

<script src="http://code.jquery.com/qunit/qunit-1.13.0.js"></script>
<script src="./test.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion tests/run-test.html → tests/run-test-jquery-latest.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.13.0.css">

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

</head>
<body>
Expand Down
Loading

0 comments on commit 7a26fba

Please sign in to comment.