Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Bootstrap4 compatibility #60

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 1 addition & 2 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@ECHO OFF
:: Using closure compiler (https://github.com/google/closure-compiler)
:: http://dl.google.com/closure-compiler/compiler-latest.zip
java -jar ../compiler-latest/compiler.jar --js lib/jquery.bootpag.js --js_output_file lib/jquery.bootpag.min.js
npx google-closure-compiler --js=lib/jquery.bootpag.js --js_output_file=lib/jquery.bootpag.min.js
3 changes: 1 addition & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/bash
# Using closure compiler (https://github.com/google/closure-compiler)
# http://dl.google.com/closure-compiler/compiler-latest.zip
java -jar ../compiler-latest/compiler.jar --js lib/jquery.bootpag.js --js_output_file lib/jquery.bootpag.min.js
npx google-closure-compiler --js=lib/jquery.bootpag.js --js_output_file=lib/jquery.bootpag.min.js
176 changes: 92 additions & 84 deletions lib/jquery.bootpag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,55 @@
* @preserve
* bootpag - jQuery plugin for dynamic pagination
*
* Copyright (c) 2015 botmonster@7items.com
* Copyright (c) 2020 botmonster@7items.com
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* http://botmonster.com/jquery-bootpag/
*
* Version: 1.0.7
* Version: 1.0.8
*
*/
(function($, window) {

$.fn.bootpag = function(options){
$.fn.bootpag = function(options) {

var $owner = this,
settings = $.extend({
total: 0,
page: 1,
maxVisible: null,
leaps: true,
href: 'javascript:void(0);',
hrefVariable: '{{number}}',
next: '»',
prev: '«',
firstLastUse: false,
first: '<span aria-hidden="true">&larr;</span>',
last: '<span aria-hidden="true">&rarr;</span>',
wrapClass: 'pagination',
activeClass: 'active',
disabledClass: 'disabled',
nextClass: 'next',
prevClass: 'prev',
lastClass: 'last',
firstClass: 'first'
},
$owner.data('settings') || {},
options || {});

if(settings.total <= 0)
total: 0,
page: 1,
maxVisible: null,
leaps: true,
href: 'javascript:void(0);',
hrefVariable: '{{number}}',
next: '&raquo;',
prev: '&laquo;',
firstLastUse: false,
first: '<span aria-hidden="true">&larr;</span>',
last: '<span aria-hidden="true">&rarr;</span>',
wrapClass: 'pagination',
activeClass: 'active',
disabledClass: 'disabled',
nextClass: 'next',
prevClass: 'prev',
lastClass: 'last',
firstClass: 'first'
},
$owner.data('settings') || {},
options || {});

if (settings.total <= 0)
return this;

if(!$.isNumeric(settings.maxVisible) && !settings.maxVisible){
if (!$.isNumeric(settings.maxVisible) && !settings.maxVisible) {
settings.maxVisible = parseInt(settings.total, 10);
}

$owner.data('settings', settings);

function renderPage($bootpag, page){
function renderPage($bootpag, page) {

page = parseInt(page, 10);
var lp,
Expand All @@ -61,112 +61,120 @@
settings.page = page = page < 0 ? 0 : page > settings.total ? settings.total : page;
$page.removeClass(settings.activeClass);
lp = page - 1 < 1 ? 1 :
settings.leaps && page - 1 >= settings.maxVisible ?
Math.floor((page - 1) / maxV) * maxV : page - 1;
settings.leaps && page - 1 >= settings.maxVisible ?
Math.floor((page - 1) / maxV) * maxV : page - 1;

if(settings.firstLastUse) {
$page
.first()
.toggleClass(settings.disabledClass, page === 1);
}
if (settings.firstLastUse) {
$page
.first()
.toggleClass(settings.disabledClass, page === 1);
}

var lfirst = $page.first();
if(settings.firstLastUse) {
lfirst = lfirst.next();
}
var lfirst = $page.first();
if (settings.firstLastUse) {
lfirst = lfirst.next();
}

lfirst
lfirst
.toggleClass(settings.disabledClass, page === 1)
.attr('data-lp', lp)
.find('a').attr('href', href(lp));
.addClass('page-item')
.find('a').attr('href', href(lp)).addClass('page-link');

var step = settings.maxVisible == 1 ? 0 : 1;

lp = page + 1 > settings.total ? settings.total :
settings.leaps && page + 1 <= settings.total - settings.maxVisible ?
vis + settings.maxVisible + step: page + 1;
settings.leaps && page + 1 <= settings.total - settings.maxVisible ?
vis + settings.maxVisible + step : page + 1;

var llast = $page.last();
if(settings.firstLastUse) {
llast = llast.prev();
}
var llast = $page.last();
if (settings.firstLastUse) {
llast = llast.prev();
}

llast
llast
.toggleClass(settings.disabledClass, page === settings.total)
.attr('data-lp', lp)
.find('a').attr('href', href(lp));
.addClass('page-item')
.find('a').attr('href', href(lp)).addClass('page-link');

$page
.last()
.toggleClass(settings.disabledClass, page === settings.total);
$page
.last()
.toggleClass(settings.disabledClass, page === settings.total);


var $currPage = $page.filter('[data-lp='+page+']');
var $currPage = $page.filter('[data-lp=' + page + ']');

var clist = "." + [settings.nextClass,
settings.prevClass,
settings.firstClass,
settings.lastClass].join(",.");
if(!$currPage.not(clist).length){
var clist = "." + [settings.nextClass,
settings.prevClass,
settings.firstClass,
settings.lastClass
].join(",.");
if (!$currPage.not(clist).length) {
var d = page <= vis ? -settings.maxVisible : 0;
$page.not(clist).each(function(index){
$page.not(clist).each(function(index) {
lp = index + 1 + vis + d;
$(this)
.attr('data-lp', lp)
.addClass('page-item')
.toggle(lp <= settings.total)
.find('a').html(lp).attr('href', href(lp));
.find('a').html(lp).attr('href', href(lp)).addClass('page-link');
});
$currPage = $page.filter('[data-lp='+page+']');
$currPage = $page.filter('[data-lp=' + page + ']');
}
$currPage.not(clist).addClass(settings.activeClass);
$owner.data('settings', settings);
}

function href(c){
function href(c) {

return settings.href.replace(settings.hrefVariable, c);
}

return this.each(function(){
return this.each(function() {

var $bootpag, lp, me = $(this),
p = ['<ul class="', settings.wrapClass, ' bootpag">'];

if(settings.firstLastUse){
p = p.concat(['<li data-lp="1" class="', settings.firstClass,
'"><a href="', href(1), '">', settings.first, '</a></li>']);
if (settings.firstLastUse) {
p = p.concat(['<li data-lp="1" class="page-item ', settings.firstClass,
'"><a class="page-link" href="', href(1), '">', settings.first, '</a></li>'
]);
}
if(settings.prev){
p = p.concat(['<li data-lp="1" class="', settings.prevClass,
'"><a href="', href(1), '">', settings.prev, '</a></li>']);
if (settings.prev) {
p = p.concat(['<li data-lp="1" class="page-item ', settings.prevClass,
'"><a class="page-link" href="', href(1), '">', settings.prev, '</a></li>'
]);
}
for(var c = 1; c <= Math.min(settings.total, settings.maxVisible); c++){
p = p.concat(['<li data-lp="', c, '"><a href="', href(c), '">', c, '</a></li>']);
for (var c = 1; c <= Math.min(settings.total, settings.maxVisible); c++) {
p = p.concat(['<li class="page-item" data-lp="', c, '"><a class="page-link" href="', href(c), '">', c, '</a></li>']);
}
if(settings.next){
lp = settings.leaps && settings.total > settings.maxVisible
? Math.min(settings.maxVisible + 1, settings.total) : 2;
p = p.concat(['<li data-lp="', lp, '" class="',
settings.nextClass, '"><a href="', href(lp),
'">', settings.next, '</a></li>']);
if (settings.next) {
lp = settings.leaps && settings.total > settings.maxVisible ?
Math.min(settings.maxVisible + 1, settings.total) : 2;
p = p.concat(['<li data-lp="', lp, '" class="page-item ',
settings.nextClass, '"><a class="page-link" href="', href(lp),
'">', settings.next, '</a></li>'
]);
}
if(settings.firstLastUse){
p = p.concat(['<li data-lp="', settings.total, '" class="last"><a href="',
href(settings.total),'">', settings.last, '</a></li>']);
if (settings.firstLastUse) {
p = p.concat(['<li data-lp="', settings.total, '" class="page-item last"><a class="page-link" href="',
href(settings.total), '">', settings.last, '</a></li>'
]);
}
p.push('</ul>');
me.find('ul.bootpag').remove();
me.append(p.join(''));
$bootpag = me.find('ul.bootpag');

me.find('li').click(function paginationClick(){
me.find('li').click(function paginationClick() {

var me = $(this);
if(me.hasClass(settings.disabledClass) || me.hasClass(settings.activeClass)){
if (me.hasClass(settings.disabledClass) || me.hasClass(settings.activeClass)) {
return;
}
var page = parseInt(me.attr('data-lp'), 10);
$owner.find('ul.bootpag').each(function(){
$owner.find('ul.bootpag').each(function() {
renderPage($(this), page);
});

Expand All @@ -176,4 +184,4 @@
});
}

})(jQuery, window);
})(jQuery, window);
22 changes: 14 additions & 8 deletions lib/jquery.bootpag.min.js

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

Loading