-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.html
More file actions
55 lines (53 loc) · 2.16 KB
/
index.html
File metadata and controls
55 lines (53 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<title>jQuery Demonstration</title>
<script src="jquery-3.7.1.slim.min.js"></script>
<style>
.pager { margin: 5px 10px; user-select: none; -webkit-user-select: none; font-family: sans-serif; }
.pager .page { display: inline-block; padding: 0px 5px; cursor: pointer; }
.pager .page:active { color: red; }
.selected { font-weight: bold; color: red; }
.paged-content { font: bold 250% sans-serif; padding: 25px 10px; }
</style>
<script>
$.fn.pagedContent = function(operation, value) {
if($.isEmptyObject(this.data())) {
this.data("page", (operation && operation.page) || 1);
this.data("pages", (operation && operation.pages) || 5);
}
if(operation === "page" && value) this.data("page", value);
else if(operation === "page") return this.data("page");
else if(operation === "pages") return this.data("pages");
this.empty().append($("<div>").text("Page " + this.data("page")));
return this;
};
$.fn.pager = function(content) {
let that = this;
let pages = content.pagedContent("pages");
let page = content.pagedContent("page");
function createPage(page, selected) {
return $("<span>")
.addClass("page" + (selected ? " selected" : ""))
.text(page)
.click(function() {
content.pagedContent("page", page);
that.pager(content);
});
}
this.empty().append($("<span>").text("Page: "));
for(let i=0; i<pages; i++) {
this.append(createPage(i+1, (page === i+1)));
}
};
$(document).ready(function() {
$(".pager").pager($("#content").pagedContent({page: 1, pages: 5}));
});
</script>
</head>
<body>
<div id="top_pager" class="pager"></div>
<div id="content" class="paged-content"></div>
<div id="bottom_pager" class="pager"></div>
</body>
</html>