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

Fixed:modify some code ,then can work in Bootstrap 4 #56

Open
wants to merge 2 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
130 changes: 43 additions & 87 deletions lib/jquery.bootpag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
* @preserve
* bootpag - jQuery plugin for dynamic pagination
*
* Copyright (c) 2015 [email protected]
* Copyright (c) 2013 [email protected]
*
* 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.7.1
*
* Fixed:modify some code ,then can work in Bootstrap 4
*
*/
(function($, window) {
Expand All @@ -19,70 +21,49 @@

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 || {});
total: 0,
page: 1,
maxVisible: null,
leaps: true,
href: 'javascript:void(0);',
hrefVariable: '{{number}}',
next: '&raquo;',
prev: '&laquo;'
},
$owner.data('settings') || {},
options || {});

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

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

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

function renderPage($bootpag, page){

page = parseInt(page, 10);
var lp,
maxV = settings.maxVisible == 0 ? 1 : settings.maxVisible,
step = settings.maxVisible == 1 ? 0 : 1,
vis = Math.floor((page - 1) / maxV) * maxV,
$page = $bootpag.find('li');
settings.page = page = page < 0 ? 0 : page > settings.total ? settings.total : page;
$page.removeClass(settings.activeClass);
$page.removeClass('disabled');
lp = page - 1 < 1 ? 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);
}

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

lfirst
.toggleClass(settings.disabledClass, page === 1)
settings.leaps && page - 1 >= settings.maxVisible ?
Math.floor((page - 1) / maxV) * maxV : page - 1;
$page
.first()
.toggleClass('disabled', page === 1)
.attr('data-lp', lp)
.find('a').attr('href', href(lp));

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;

Expand All @@ -91,25 +72,16 @@
llast = llast.prev();
}

llast
.toggleClass(settings.disabledClass, page === settings.total)
$page
.last()
.toggleClass('disabled', page === settings.total)
.attr('data-lp', lp)
.find('a').attr('href', href(lp));

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

.find('a').attr('href', href(lp));;

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

var clist = "." + [settings.nextClass,
settings.prevClass,
settings.firstClass,
settings.lastClass].join(",.");
if(!$currPage.not(clist).length){
if(!$currPage.not('.next,.prev').length){
var d = page <= vis ? -settings.maxVisible : 0;
$page.not(clist).each(function(index){
$page.not('.next,.prev').each(function(index){
lp = index + 1 + vis + d;
$(this)
.attr('data-lp', lp)
Expand All @@ -118,7 +90,8 @@
});
$currPage = $page.filter('[data-lp='+page+']');
}
$currPage.not(clist).addClass(settings.activeClass);
$currPage.addClass('disabled');
$owner.trigger('page', page);
$owner.data('settings', settings);
}

Expand All @@ -130,50 +103,33 @@
return this.each(function(){

var $bootpag, lp, me = $(this),
p = ['<ul class="', settings.wrapClass, ' bootpag">'];
p = ['<nav aria-label="Page navigation example"><ul class="bootpag pagination">'];

if(settings.firstLastUse){
p = p.concat(['<li data-lp="1" class="', settings.firstClass,
'"><a 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 && settings.total>1){
p.push('<li data-lp="1" class="prev page-item"><a href="'+href(1)+'" class="page-link">'+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>']);
p.push('<li data-lp="'+c+'" class="page-item"><a href="'+href(c)+'" class="page-link">'+c+'</a></li>');
}
if(settings.next){
if(settings.next && settings.total >1){
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>']);
p.push('<li data-lp="'+lp+'" class="next page-item"><a href="'+href(lp)+'" class="page-link">'+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>']);
}
p.push('</ul>');
p.push('</ul></nav>');
me.find('ul.bootpag').remove();
me.append(p.join(''));
me.append(p.join('')).addClass('pagination');
$bootpag = me.find('ul.bootpag');

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

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

$owner.trigger('page', page);
renderPage($bootpag, parseInt(me.attr('data-lp'), 10));
});
renderPage($bootpag, settings.page);
});
}

})(jQuery, window);
})(jQuery, window);
39 changes: 18 additions & 21 deletions lib/jquery.bootpag.min.js

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