pagy 4.4.0 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config/pagy.rb +1 -1
- data/lib/javascripts/pagy.js +102 -95
- data/lib/pagy.rb +1 -1
- data/lib/pagy/extras/semantic.rb +2 -2
- data/lib/pagy/extras/uikit.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea6862ff93b09769c9810860307a4a63a88de1ecf8d6a4f8176f6cb90e22565f
|
4
|
+
data.tar.gz: 5564e6b0f2e006b098dc9fe07ea8409ce4748bd6a32acb0f19bdb56e6f8b791d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b299c1727379ba77ace97691cce28df77e81a25bfaac7d0fff7668f1f5b8178b60963ec8f5fd27fb824ef5f0f067ee3070b846f7d975269cec83ddec5db6763b
|
7
|
+
data.tar.gz: daeb51d6b08394c64833938a5b594d46a189ae27357885361b6d0fb6dc1fa91c78def2b47cb09ec649fdebe39326577f989ac2569f32190ae8a756a7ccb591bf
|
data/lib/config/pagy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (4.
|
3
|
+
# Pagy initializer file (4.5.0)
|
4
4
|
# Customize only what you really need and notice that Pagy works also without any of the following lines.
|
5
5
|
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
6
6
|
|
data/lib/javascripts/pagy.js
CHANGED
@@ -2,109 +2,116 @@
|
|
2
2
|
|
3
3
|
function Pagy(){}
|
4
4
|
|
5
|
-
Pagy.version = '4.
|
5
|
+
Pagy.version = '4.5.0'
|
6
6
|
|
7
|
-
Pagy.
|
7
|
+
Pagy.delay = 100
|
8
8
|
|
9
|
-
Pagy.
|
9
|
+
Pagy.init =
|
10
|
+
function(arg) {
|
11
|
+
var target = arg instanceof Event || arg === undefined ? document : arg,
|
12
|
+
jsonTags = target.getElementsByClassName('pagy-json')
|
13
|
+
for (var i = 0, len = jsonTags.length; i < len; i++) {
|
14
|
+
var args = JSON.parse(jsonTags[i].innerHTML),
|
15
|
+
fname = args.shift()
|
16
|
+
args.unshift(jsonTags[i].previousSibling)
|
17
|
+
Pagy[fname].apply(null, args)
|
18
|
+
}
|
19
|
+
}
|
10
20
|
|
11
|
-
Pagy.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
21
|
-
|
22
|
-
Pagy.nav = function(pagyEl, tags, sequels, param) {
|
23
|
-
var lastWidth = undefined,
|
24
|
-
timeoutId = 0,
|
25
|
-
pageREg = new RegExp(/__pagy_page__/g),
|
26
|
-
widths = [],
|
27
|
-
wait = function() { clearTimeout(timeoutId); timeoutId = setTimeout(pagyEl.render, Pagy.timeout) };
|
21
|
+
Pagy.nav =
|
22
|
+
function(pagyEl, tags, sequels, trimParam) {
|
23
|
+
var lastWidth,
|
24
|
+
pageREg = new RegExp(/__pagy_page__/g),
|
25
|
+
widths = []
|
26
|
+
for (var width in sequels) {
|
27
|
+
if (sequels.hasOwnProperty(width)) { widths.push(parseInt(width, 10)) }
|
28
|
+
}
|
29
|
+
widths.sort(function(a, b) { return b - a })
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
pagyEl.render =
|
32
|
+
function() {
|
33
|
+
var width, i, len
|
34
|
+
for (i = 0, len = widths.length; i < len; i++) {
|
35
|
+
if (this.parentElement.clientWidth > widths[i]) { width = widths[i]; break }
|
36
|
+
}
|
37
|
+
if (width !== lastWidth) {
|
38
|
+
var html = tags.before,
|
39
|
+
series = sequels[width]
|
40
|
+
for (i = 0, len = series.length; i < len; i++) {
|
41
|
+
var item = series[i]
|
42
|
+
if (typeof(trimParam) === 'string' && item === 1) { html += Pagy.trim(tags.link.replace(pageREg, item), trimParam) }
|
43
|
+
else if (typeof(item) === 'number') { html += tags.link.replace(pageREg, item) }
|
44
|
+
else if (item === 'gap') { html += tags.gap }
|
45
|
+
else if (typeof(item) === 'string') { html += tags.active.replace(pageREg, item) }
|
46
|
+
}
|
47
|
+
html += tags.after
|
48
|
+
this.innerHTML = ''
|
49
|
+
this.insertAdjacentHTML('afterbegin', html)
|
50
|
+
lastWidth = width
|
51
|
+
}
|
52
|
+
}.bind(pagyEl)
|
53
|
+
pagyEl.render()
|
54
|
+
}
|
31
55
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
else if (typeof(item) === 'string') { html += tags.active.replace(pageREg, item) }
|
47
|
-
}
|
48
|
-
html += tags.after;
|
49
|
-
this.innerHTML = '';
|
50
|
-
this.insertAdjacentHTML('afterbegin', html);
|
51
|
-
lastWidth = width;
|
52
|
-
}
|
53
|
-
}.bind(pagyEl);
|
54
|
-
pagyEl.render();
|
55
|
-
}
|
56
|
-
|
57
|
-
Pagy.combo_nav = function(pagyEl, page, link, param) {
|
58
|
-
var input = pagyEl.getElementsByTagName('input')[0],
|
59
|
-
go = function() {
|
60
|
-
if (page !== input.value) {
|
61
|
-
var html = link.replace(/__pagy_page__/, input.value);
|
62
|
-
if (typeof (param) === 'string' && input.value === '1') { html = Pagy.trim(html, param) }
|
63
|
-
pagyEl.insertAdjacentHTML('afterbegin', html);
|
64
|
-
pagyEl.getElementsByTagName('a')[0].click();
|
65
|
-
}
|
66
|
-
};
|
67
|
-
Pagy.addInputEventListeners(input, go);
|
68
|
-
}
|
56
|
+
Pagy.combo_nav =
|
57
|
+
function(pagyEl, page, link, trimParam) {
|
58
|
+
var input = pagyEl.getElementsByTagName('input')[0],
|
59
|
+
toPage =
|
60
|
+
function() {
|
61
|
+
if (page !== input.value) {
|
62
|
+
var html = link.replace(/__pagy_page__/, input.value)
|
63
|
+
if (typeof (trimParam) === 'string' && input.value === '1') { html = Pagy.trim(html, trimParam) }
|
64
|
+
pagyEl.insertAdjacentHTML('afterbegin', html)
|
65
|
+
pagyEl.getElementsByTagName('a')[0].click()
|
66
|
+
}
|
67
|
+
}
|
68
|
+
Pagy.addInputEventListeners(input, toPage)
|
69
|
+
}
|
69
70
|
|
70
|
-
Pagy.items_selector =
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
71
|
+
Pagy.items_selector =
|
72
|
+
function(pagyEl, from, link, param) {
|
73
|
+
var input = pagyEl.getElementsByTagName('input')[0],
|
74
|
+
current = input.value,
|
75
|
+
toPage =
|
76
|
+
function() {
|
77
|
+
var items = input.value
|
78
|
+
if (current !== items) {
|
79
|
+
var page = Math.max(Math.ceil(from / items), 1),
|
80
|
+
html = link.replace(/__pagy_page__/, page).replace(/__pagy_items__/, items)
|
81
|
+
if (typeof (param) === 'string' && page === 1) { html = Pagy.trim(html, param) }
|
82
|
+
pagyEl.insertAdjacentHTML('afterbegin', html)
|
83
|
+
pagyEl.getElementsByTagName('a')[0].click()
|
84
|
+
}
|
85
|
+
}
|
86
|
+
Pagy.addInputEventListeners(input, toPage)
|
87
|
+
}
|
85
88
|
|
86
|
-
Pagy.addInputEventListeners =
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
Pagy.addInputEventListeners =
|
90
|
+
function(input, toPage) {
|
91
|
+
// select the content on click: easier for typing a number
|
92
|
+
input.addEventListener('click', function() { this.select() })
|
93
|
+
// toPage when the input looses focus
|
94
|
+
input.addEventListener('focusout', toPage)
|
95
|
+
// … and when pressing enter inside the input
|
96
|
+
input.addEventListener('keyup', function(e) { if (e.which === 13) {toPage()} }.bind(this))
|
97
|
+
}
|
94
98
|
|
95
|
-
Pagy.trim =
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
+
Pagy.trim =
|
100
|
+
function(html, param) {
|
101
|
+
var re = new RegExp('[?&]' + param + '=1\\b(?!&)|\\b' + param + '=1&')
|
102
|
+
return html.replace(re, '')
|
103
|
+
}
|
99
104
|
|
100
|
-
Pagy.
|
101
|
-
|
102
|
-
|
103
|
-
|
105
|
+
Pagy.renderNavs =
|
106
|
+
function() {
|
107
|
+
var navs = document.getElementsByClassName('pagy-njs') // 'pagy-njs' is common to all *nav_js helpers
|
108
|
+
for (var i = 0, len = navs.length; i < len; i++) { navs[i].render() }
|
109
|
+
}
|
104
110
|
|
105
|
-
Pagy.
|
106
|
-
|
107
|
-
|
108
|
-
|
111
|
+
Pagy.waitForMe =
|
112
|
+
function() {
|
113
|
+
if (typeof(Pagy.tid) === 'number') { clearTimeout(Pagy.tid) }
|
114
|
+
Pagy.tid = setTimeout(Pagy.renderNavs, Pagy.delay)
|
115
|
+
}
|
109
116
|
|
110
|
-
window.addEventListener('resize', Pagy.
|
117
|
+
window.addEventListener('resize', Pagy.waitForMe, true)
|
data/lib/pagy.rb
CHANGED
data/lib/pagy/extras/semantic.rb
CHANGED
@@ -15,8 +15,8 @@ class Pagy
|
|
15
15
|
html << pagy_semantic_prev_html(pagy, link)
|
16
16
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
17
|
html << case item
|
18
|
-
when Integer then link.call item
|
19
|
-
when String then %(<a class="item active">#{item}</a>)
|
18
|
+
when Integer then link.call item # page link
|
19
|
+
when String then %(<a class="item active">#{item}</a>) # current page
|
20
20
|
when :gap then %(<div class="disabled item">#{pagy_t 'pagy.nav.gap'}</div>) # page gap
|
21
21
|
end
|
22
22
|
end
|
data/lib/pagy/extras/uikit.rb
CHANGED
@@ -31,7 +31,7 @@ class Pagy
|
|
31
31
|
tags = { 'before' => pagy_uikit_prev_html(pagy, link),
|
32
32
|
'link' => %(<li>#{link.call(PAGE_PLACEHOLDER)}</li>),
|
33
33
|
'active' => %(<li class="uk-active"><span>#{PAGE_PLACEHOLDER}</span></li>),
|
34
|
-
'gap' => %(<li class="uk-disabled"><span>#{pagy_t
|
34
|
+
'gap' => %(<li class="uk-disabled"><span>#{pagy_t 'pagy.nav.gap'}</span></li>),
|
35
35
|
'after' => pagy_uikit_next_html(pagy, link) }
|
36
36
|
|
37
37
|
html = %(<ul#{p_id} class="pagy-njs pagy-uikit-nav-js uk-pagination uk-flex-center"></ul>)
|