8 changes: 4 additions & 4 deletions jquery.twbsPagination.min.js
8 changes: 6 additions & 2 deletions package.json
@@ -1,13 +1,13 @@
{
"name": "twbs-pagination",
"nativeName": "jQuery Bootstrap Pagination",
"version": "1.3.1",
"version": "1.4.0",
"homepage": "https://github.com/esimakin/twbs-pagination",
"author": "Eugene Simakin <eugenesimakin@mail.ru>",
"description": "jQuery simple pagination plugin for bootstrap-style webpages",
"main": "jquery.twbsPagination",
"dependencies": {
"jquery": ">=1.7.0"
"jquery": ">=1.7"
},
"devDependencies": {
"grunt": "^0.4.5",
Expand All @@ -16,6 +16,10 @@
"grunt-contrib-uglify": "^0.9.2",
"load-grunt-tasks": "^3.1.0"
},
"repository": {
"type": "git",
"url": "git://github.com/esimakin/twbs-pagination.git"
},
"keywords": [
"pagination",
"jQuery",
Expand Down
4 changes: 2 additions & 2 deletions tests/run-test.html → tests/run-test-jquery-1.8.1.html
Expand Up @@ -6,8 +6,8 @@

<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="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>
Expand Down
21 changes: 21 additions & 0 deletions tests/run-test-jquery-latest.html
@@ -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-3.1.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>
126 changes: 118 additions & 8 deletions tests/test.js
@@ -1,11 +1,17 @@
(function () {
(function ($) {

var pag1 = $('#pagination');
pag1.twbsPagination({
totalPages: 30

QUnit.test("Test destroy called before initialization", function () {
ok(pag1.twbsPagination('destroy'));
});

test("Test 'getPages' method (EVEN visible pages number)", function () {
QUnit.test("Test 'getPages' method (EVEN visible pages number)", function () {
pag1.twbsPagination('destroy');
pag1.twbsPagination({
totalPages: 30
});

var expected1 = {currentPage: 1, numeric: [1, 2, 3, 4, 5]};
deepEqual(pag1.twbsPagination('getPages', 1), expected1);
var expected2 = {currentPage: 2, numeric: [1, 2, 3, 4, 5]};
Expand All @@ -30,9 +36,13 @@
deepEqual(pag1.twbsPagination('getPages', 30), expected30);
});

test("Test 'getPages' method (ODD visible pages number)", function () {
QUnit.test("Test 'getPages' method (ODD visible pages number)", function () {
pag1.twbsPagination('destroy');
pag1.twbsPagination({totalPages: 30, visiblePages: 6});
pag1.twbsPagination({
totalPages: 30,
visiblePages: 6
});

var expected1 = {currentPage: 1, numeric: [1, 2, 3, 4, 5, 6]};
deepEqual(pag1.twbsPagination('getPages', 1), expected1);
var expected2 = {currentPage: 2, numeric: [1, 2, 3, 4, 5, 6]};
Expand All @@ -57,7 +67,7 @@
deepEqual(pag1.twbsPagination('getPages', 30), expected30);
});

test("Test 'getPages' method (total < visible)", function () {
QUnit.test("Test 'getPages' method (total < visible)", function () {
pag1.twbsPagination('destroy');
pag1.twbsPagination({
totalPages: 3,
Expand All @@ -71,4 +81,104 @@
deepEqual(pag1.twbsPagination('getPages', 3), exp3);
});

})();
QUnit.test("Test classes appended for pagination", function () {
pag1.twbsPagination('destroy');
pag1.twbsPagination({
totalPages: 3,
visiblePages: 5
});
equal(pag1.find('.page-item').length, 7);
equal(pag1.find('.next').length, 1);
equal(pag1.find('.prev').length, 1);
equal(pag1.find('.last').length, 1);
equal(pag1.find('.first').length, 1);
equal(pag1.find('.page-item.active').length, 1);
equal(pag1.find('.prev.disabled').length, 1);
equal(pag1.find('.first.disabled').length, 1);
});

QUnit.test("Test custom classes appended for pagination", function () {
pag1.twbsPagination('destroy');
pag1.twbsPagination({
totalPages: 10,
visiblePages: 5,
pageClass: 'my-page',
nextClass: 'my-next-page',
prevClass: 'my-prev-page',
lastClass: 'my-last-page',
firstClass: 'my-first-page',
activeClass: 'my-active-class',
disabledClass: 'my-disabled-class'
});
equal(pag1.find('.my-page').length, 5);
equal(pag1.find('.my-next-page').length, 1);
equal(pag1.find('.my-prev-page').length, 1);
equal(pag1.find('.my-last-page').length, 1);
equal(pag1.find('.my-first-page').length, 1);
equal(pag1.find('.my-page.my-active-class').length, 1);
equal(pag1.find('.my-prev-page.my-disabled-class').length, 1);
equal(pag1.find('.my-first-page.my-disabled-class').length, 1);
});

QUnit.test("Test page numbers text", function () {
pag1.twbsPagination('destroy');
pag1.twbsPagination({
totalPages: 2
});
equal(pag1.find('.page-item:eq(2)').text(), '1');
equal(pag1.find('.next').text(), 'Next');
equal(pag1.find('.prev').text(), 'Previous');
equal(pag1.find('.first').text(), 'First');
equal(pag1.find('.last').text(), 'Last');
});

QUnit.test("Test custom texts", function () {
pag1.twbsPagination('destroy');
pag1.twbsPagination({
totalPages: 2,
page: '[{{page}}]',
first: '(first)',
prev: '<<',
next: '>>',
last: '(last)[{{total_pages}}]'
});
equal(pag1.find('.page-item:eq(2)').text(), '[1]');
equal(pag1.find('.next').text(), '>>');
equal(pag1.find('.prev').text(), '<<');
equal(pag1.find('.first').text(), '(first)');
equal(pag1.find('.last').text(), '(last)[2]');
});

QUnit.test("Test 'getPageFromQueryString' method", function () {
pag1.twbsPagination('destroy');
pag1.twbsPagination({pageVariable: 'page'});
equal(pag1.twbsPagination('getPageFromQueryString', '?page=1'), 1);
equal(pag1.twbsPagination('getPageFromQueryString', '?page='), null);
equal(pag1.twbsPagination('getPageFromQueryString', '?page'), null);
equal(pag1.twbsPagination('getPageFromQueryString', '?'), null);
equal(pag1.twbsPagination('getPageFromQueryString', ''), null)
;
equal(pag1.twbsPagination('getPageFromQueryString', '?page=2'), 2);
equal(pag1.twbsPagination('getPageFromQueryString', '?page=3&param=taram'), 3);
equal(pag1.twbsPagination('getPageFromQueryString', '?page=4&param=test&opilki'), 4);
equal(pag1.twbsPagination('getPageFromQueryString', '?page=5&param=test or not&opilki='), 5);
equal(pag1.twbsPagination('getPageFromQueryString', '?ID=1&keyWord=net&page=6'), 6);
});

QUnit.test("Test 'generateQueryString' method", function () {
pag1.twbsPagination('destroy');
pag1.twbsPagination({pageVariable: 'page'});
equal(pag1.twbsPagination('generateQueryString', 1, '?page=1'), '?page=1');
equal(pag1.twbsPagination('generateQueryString', 1, '?page='), '?page=1');
equal(pag1.twbsPagination('generateQueryString', 1, '?page'), '?page=1');
equal(pag1.twbsPagination('generateQueryString', 1, '?'), '');
equal(pag1.twbsPagination('generateQueryString', 1, ''), window.location.search);

equal(pag1.twbsPagination('generateQueryString', 2, '?page=1'), '?page=2');
equal(pag1.twbsPagination('generateQueryString', 3, '?page=2&param=taram'), '?page=3&param=taram');
equal(pag1.twbsPagination('generateQueryString', 4, '?page=3&param=test&opilki'), '?page=4&param=test&opilki');
equal(pag1.twbsPagination('generateQueryString', 5, '?page=4&param=test or not&opilki='), '?page=5&param=test or not&opilki=');
equal(pag1.twbsPagination('generateQueryString', 6, '?ID=1&keyWord=net&page=50'), '?ID=1&keyWord=net&page=6');
});

})(window.jQuery);
4 changes: 2 additions & 2 deletions twbs-pagination.jquery.json
@@ -1,6 +1,6 @@
{
"name": "twbs-pagination",
"version": "1.3.1",
"version": "1.4.0",
"title": "jQuery Bootstrap Pagination",
"author": {
"name": "Eugene Simakin",
Expand All @@ -9,7 +9,7 @@
},
"licenses": [
{
"type": "Apache 2.0",
"type": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
],
Expand Down