Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Bootstrap 4 #16

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rpage
=====

Highly responsive pagination for Bootstrap (http://auxiliary.github.io/rpage/)
Highly responsive pagination for Bootstrap 4 (http://auxiliary.github.io/rpage/)

### [Demo](http://auxiliary.github.io/rpage/demo.html)

Expand Down
298 changes: 149 additions & 149 deletions responsive-paginate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,178 +8,178 @@
var $this = $(this);
for(var i = 0, max = $this.length; i < max; i++)
{
new rPage($($this[i]));
new rPage($($this[i]));
}

function rPage($container)
{
this.label = function()
{
var active_index = this.els.filter(".active").index();
var rp = this;
this.els.each(function(){
if (rp.isNextOrPrevLink($(this)) == false)
{
$(this).addClass("page-away-" + (Math.abs(active_index - $(this).index())).toString());
}
else
{
if ($(this).index() > active_index)
{
$(this).addClass("right-etc");
}
else
{
$(this).addClass("left-etc");
}
}
});
}
this.label = function()
{
var active_index = this.els.filter(".active").index();
var rp = this;
this.els.each(function(){
if (rp.isNextOrPrevLink($(this)) == false)
{
$(this).addClass("page-away-" + (Math.abs(active_index - $(this).index())).toString());
}
else
{
if ($(this).index() > active_index)
{
$(this).addClass("right-etc");
}
else
{
$(this).addClass("left-etc");
}
}
});
}

this.makeResponsive = function()
{
this.reset();
var width = this.calculateWidth();
this.makeResponsive = function()
{
this.reset();
var width = this.calculateWidth();

while (width > this.els.parent().parent().outerWidth() - 10)
{
var did_remove = this.removeOne();
if (did_remove == false)
{
break;
}
width = this.calculateWidth();
}
}
while (width > this.els.parent().parent().outerWidth() - 10)
{
var did_remove = this.removeOne();
if (did_remove == false)
{
break;
}
width = this.calculateWidth();
}
}

this.isNextOrPrevLink = function(element)
{
this.isNextOrPrevLink = function(element)
{
return (
element.hasClass('pagination-prev')
|| element.hasClass('pagination-next')
|| element.text() == "»"
|| element.text() == "«"
);
}
}

this.isRemovable = function(element)
{
if (this.isNextOrPrevLink(element))
{
return false;
}
var index = this.els.filter(element).index();
if (index == 1 || this.isNextOrPrevLink($container.find("li").eq(index + 1)))
{
return false;
}
if (element.text() == "...")
{
return false;
}
return true;
}
this.isRemovable = function(element)
{
if (this.isNextOrPrevLink(element))
{
return false;
}
var index = this.els.filter(element).index();
if (index == 1 || this.isNextOrPrevLink($container.find("li").eq(index + 1)))
{
return false;
}
if (element.text() == "...")
{
return false;
}
return true;
}

this.removeOne = function()
{
var active_index = this.els.filter(".active").index();
var farthest_index = $container.find("li").length - 1;
var next = active_index + 1;
var prev = active_index - 1;
this.removeOne = function()
{
var active_index = this.els.filter(".active").index();
var farthest_index = $container.find("li").length - 1;
var next = active_index + 1;
var prev = active_index - 1;

for (var i = farthest_index - 1; i > 0; i--)
{
var candidates = this.els.filter(".page-away-" + i.toString());
var candidate = candidates.filter(function(){
return this.style["display"] != "none";
});
if (candidate.length > 0)
{
for (var j = 0; j < candidate.length; j++)
{
var candid_candidate = candidate.eq(j);
if (this.isRemovable(candid_candidate))
{
candid_candidate.css("display", "none");
if (this.needsEtcSign(active_index, farthest_index - 1))
{
this.els.eq(farthest_index - 2).before("<li class='disabled removable'><span>...</span></li>");
}
if (this.needsEtcSign(1, active_index))
{
this.els.eq(1).after("<li class='disabled removable'><span>...</span></li>");
}
return true;
}
}
}
}
return false;
}
for (var i = farthest_index - 1; i > 0; i--)
{
var candidates = this.els.filter(".page-away-" + i.toString());
var candidate = candidates.filter(function(){
return this.style["display"] != "none";
});
if (candidate.length > 0)
{
for (var j = 0; j < candidate.length; j++)
{
var candid_candidate = candidate.eq(j);
if (this.isRemovable(candid_candidate))
{
candid_candidate.css("display", "none");
if (this.needsEtcSign(active_index, farthest_index - 1))
{
this.els.eq(farthest_index - 2).before("<li class='page-item disabled removable'><a class=\"page-link\">...</a></li>");
}
if (this.needsEtcSign(1, active_index))
{
this.els.eq(1).after("<li class='page-item disabled removable'><a class=\"page-link\">...</a></li>");
}
return true;
}
}
}
}
return false;
}

this.needsEtcSign = function(el1_index, el2_index)
{
if (el2_index - el1_index <= 1)
{
return false;
}
else
{
var hasEtcSign = false;
var hasHiddenElement = false;
for (var i = el1_index + 1; i < el2_index; i++)
{
var el = $container.find("li").eq(i);
if (el.css("display") == "none")
{
hasHiddenElement = true;
}
if (el.text() == "...")
{
hasEtcSign = true;
}
}
if (hasHiddenElement == true && hasEtcSign == false)
{
return true;
}
}
return false;
}
this.needsEtcSign = function(el1_index, el2_index)
{
if (el2_index - el1_index <= 1)
{
return false;
}
else
{
var hasEtcSign = false;
var hasHiddenElement = false;
for (var i = el1_index + 1; i < el2_index; i++)
{
var el = $container.find("li").eq(i);
if (el.css("display") == "none")
{
hasHiddenElement = true;
}
if (el.text() == "...")
{
hasEtcSign = true;
}
}
if (hasHiddenElement == true && hasEtcSign == false)
{
return true;
}
}
return false;
}

this.reset = function()
{
for (var i = 0; i < this.els.length; i++)
{
this.els.eq(i).css("display", "inline");
}
$container.find("li").filter(".removable").remove();
}
this.reset = function()
{
for (var i = 0; i < this.els.length; i++)
{
this.els.eq(i).css("display", "inline");
}
$container.find("li").filter(".removable").remove();
}

this.calculateWidth = function()
{
var width = 0;
for (var i = 0; i < $container.find("li").length; i++)
{
width += $container.find("li").eq(i).children("a").eq(0).outerWidth();
width += $container.find("li").eq(i).children("span").eq(0).outerWidth();
}
return width;
}
this.calculateWidth = function()
{
var width = 0;
for (var i = 0; i < $container.find("li").length; i++)
{
width += $container.find("li").eq(i).children("a").eq(0).outerWidth();
width += $container.find("li").eq(i).children("span").eq(0).outerWidth();
}
return width;
}

this.els = $container.find("li");
this.label();
this.makeResponsive();
this.els = $container.find("li");
this.label();
this.makeResponsive();

var resize_timer;
var resize_timer;

$(window).resize(
$.proxy(function()
{
clearTimeout(resize_timer);
resize_timer = setTimeout($.proxy(function(){this.makeResponsive()}, this), 100);
}, this)
$.proxy(function()
{
clearTimeout(resize_timer);
resize_timer = setTimeout($.proxy(function(){this.makeResponsive()}, this), 50);
}, this)
);
}
};
}(jQuery));
}(jQuery));
11 changes: 5 additions & 6 deletions sample/css/bootstrap.min.css

Large diffs are not rendered by default.

Loading