pagy 4.0.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 +30 -24
- data/lib/javascripts/pagy.js +104 -93
- data/lib/locales/bs.yml +24 -0
- data/lib/locales/hr.yml +24 -0
- data/lib/locales/sr.yml +23 -0
- data/lib/locales/utils/i18n.rb +0 -1
- data/lib/locales/utils/loader.rb +7 -5
- data/lib/locales/utils/p11n.rb +27 -20
- data/lib/pagy.rb +50 -26
- data/lib/pagy/backend.rb +5 -3
- data/lib/pagy/countless.rb +12 -9
- data/lib/pagy/deprecation.rb +27 -0
- data/lib/pagy/exceptions.rb +7 -5
- data/lib/pagy/extras/arel.rb +4 -3
- data/lib/pagy/extras/array.rb +4 -3
- data/lib/pagy/extras/bootstrap.rb +62 -30
- data/lib/pagy/extras/bulma.rb +61 -38
- data/lib/pagy/extras/countless.rb +7 -5
- data/lib/pagy/extras/elasticsearch_rails.rb +8 -6
- data/lib/pagy/extras/foundation.rb +62 -32
- data/lib/pagy/extras/headers.rb +13 -9
- data/lib/pagy/extras/i18n.rb +7 -4
- data/lib/pagy/extras/items.rb +21 -26
- data/lib/pagy/extras/materialize.rb +59 -35
- data/lib/pagy/extras/metadata.rb +27 -21
- data/lib/pagy/extras/navs.rb +45 -20
- data/lib/pagy/extras/overflow.rb +12 -13
- data/lib/pagy/extras/searchkick.rb +9 -7
- data/lib/pagy/extras/semantic.rb +56 -30
- data/lib/pagy/extras/shared.rb +12 -11
- data/lib/pagy/extras/standalone.rb +71 -0
- data/lib/pagy/extras/support.rb +20 -11
- data/lib/pagy/extras/trim.rb +14 -9
- data/lib/pagy/extras/uikit.rb +65 -35
- data/lib/pagy/frontend.rb +62 -30
- metadata +8 -5
- data/lib/locales/README.md +0 -35
- data/pagy.gemspec +0 -16
@@ -1,22 +1,23 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/countless
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/countless'
|
6
5
|
|
7
6
|
class Pagy
|
8
7
|
|
9
|
-
module Backend
|
8
|
+
module Backend
|
9
|
+
private # the whole module is private so no problem with including it in a controller
|
10
10
|
|
11
11
|
# Return Pagy object and items
|
12
12
|
def pagy_countless(collection, vars={})
|
13
13
|
pagy = Pagy::Countless.new(pagy_countless_get_vars(collection, vars))
|
14
|
-
|
14
|
+
[ pagy, pagy_countless_get_items(collection, pagy) ]
|
15
15
|
end
|
16
16
|
|
17
17
|
# Sub-method called only by #pagy_countless: here for easy customization of variables by overriding
|
18
18
|
def pagy_countless_get_vars(_collection, vars)
|
19
|
-
vars
|
19
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
20
|
+
vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ]
|
20
21
|
vars
|
21
22
|
end
|
22
23
|
|
@@ -26,7 +27,8 @@ class Pagy
|
|
26
27
|
items = collection.offset(pagy.offset).limit(pagy.items + 1).to_a
|
27
28
|
items_size = items.size
|
28
29
|
items.pop if items_size == pagy.items + 1
|
29
|
-
|
30
|
+
# finalize may adjust pagy.items, so must be used after checking the size
|
31
|
+
pagy.finalize(items_size)
|
30
32
|
items
|
31
33
|
end
|
32
34
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/elasticsearch_rails
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
@@ -28,7 +27,8 @@ class Pagy
|
|
28
27
|
end
|
29
28
|
|
30
29
|
# Add specialized backend methods to paginate ElasticsearchRails searches
|
31
|
-
module Backend
|
30
|
+
module Backend
|
31
|
+
private
|
32
32
|
|
33
33
|
# Return Pagy object and items
|
34
34
|
def pagy_elasticsearch_rails(pagy_search_args, vars={})
|
@@ -39,17 +39,19 @@ class Pagy
|
|
39
39
|
response = model.search(query_or_payload, **options)
|
40
40
|
total = response.respond_to?(:raw_response) ? response.raw_response['hits']['total'] : response.response['hits']['total']
|
41
41
|
vars[:count] = total.is_a?(Hash) ? total['value'] : total
|
42
|
+
|
42
43
|
pagy = Pagy.new(vars)
|
43
44
|
# with :last_page overflow we need to re-run the method in order to get the hits
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
return pagy_elasticsearch_rails(pagy_search_args, vars.merge(page: pagy.page)) \
|
46
|
+
if defined?(Pagy::UseOverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
|
47
|
+
|
48
|
+
[ pagy, called.empty? ? response : response.send(*called) ]
|
48
49
|
end
|
49
50
|
|
50
51
|
# Sub-method called only by #pagy_elasticsearch_rails: here for easy customization of variables by overriding
|
51
52
|
# the _collection argument is not available when the method is called
|
52
53
|
def pagy_elasticsearch_rails_get_vars(_collection, vars)
|
54
|
+
pagy_set_items_from_params(vars) if defined?(UseItemsExtra)
|
53
55
|
vars[:items] ||= VARS[:items]
|
54
56
|
vars[:page] ||= (params[ vars[:page_param] || VARS[:page_param] ] || 1).to_i
|
55
57
|
vars
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/foundation
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/extras/shared'
|
@@ -8,50 +7,81 @@ class Pagy
|
|
8
7
|
module Frontend
|
9
8
|
|
10
9
|
# Pagination for Foundation: it returns the html with the series of links to the pages
|
11
|
-
def pagy_foundation_nav(pagy)
|
12
|
-
|
10
|
+
def pagy_foundation_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
12
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
13
13
|
|
14
|
-
html =
|
15
|
-
|
14
|
+
html = +%(<nav#{p_id} class="pagy-foundation-nav" role="navigation" aria-label="Pagination"><ul class="pagination">)
|
15
|
+
html << pagy_foundation_prev_html(pagy, link)
|
16
16
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
17
|
-
html <<
|
18
|
-
|
19
|
-
|
17
|
+
html << case item
|
18
|
+
when Integer then %(<li>#{link.call item}</li>) # page link
|
19
|
+
when String then %(<li class="current">#{item}</li>) # active page
|
20
|
+
when :gap then %(<li class="ellipsis gap" aria-hidden="true"></li>) # page gap
|
20
21
|
end
|
21
22
|
end
|
22
|
-
html << (
|
23
|
-
|
24
|
-
%(<nav class="pagy-foundation-nav" role="navigation" aria-label="Pagination"><ul class="pagination">#{html}</ul></nav>)
|
23
|
+
html << pagy_foundation_next_html(pagy, link)
|
24
|
+
html << %(</ul></nav>)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Javascript pagination for foundation: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
28
|
-
def pagy_foundation_nav_js(pagy,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
'link' => %(<li>#{link.call
|
28
|
+
def pagy_foundation_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
|
29
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
30
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
31
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
32
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_foundation_prev_html pagy, link}),
|
33
|
+
'link' => %(<li>#{link.call PAGE_PLACEHOLDER}</li>),
|
34
34
|
'active' => %(<li class="current">#{pagy.page}</li>),
|
35
35
|
'gap' => %(<li class="ellipsis gap" aria-hidden="true"></li>),
|
36
|
-
'after' =>
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
'after' => %(#{pagy_foundation_next_html pagy, link}</ul>) }
|
37
|
+
|
38
|
+
html = %(<nav#{p_id} class="pagy-njs pagy-foundation-nav-js" role="navigation" aria-label="Pagination"></nav>)
|
39
|
+
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
|
40
40
|
end
|
41
41
|
|
42
42
|
# Javascript combo pagination for Foundation: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
43
|
-
def pagy_foundation_combo_nav_js(pagy,
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
input
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
43
|
+
def pagy_foundation_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
44
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
45
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
46
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
47
|
+
p_page = pagy.page
|
48
|
+
p_pages = pagy.pages
|
49
|
+
input = %(<input class="input-group-field cell shrink" type="number" min="1" max="#{p_pages}" value="#{p_page}" style="width: #{p_pages.to_s.length+1}rem; padding: 0 0.3rem; margin: 0 0.3rem;">)
|
50
|
+
|
51
|
+
%(<nav#{p_id} class="pagy-foundation-combo-nav-js" role="navigation" aria-label="Pagination"><div class="input-group">#{
|
52
|
+
if (p_prev = pagy.prev)
|
53
|
+
link.call p_prev, pagy_t('pagy.nav.prev'), 'style="margin-bottom: 0px;" aria-label="previous" class="prev button primary"'
|
54
|
+
else
|
55
|
+
%(<a style="margin-bottom: 0px;" class="prev button primary disabled" href="#">#{pagy_t 'pagy.nav.prev'}</a>)
|
56
|
+
end
|
57
|
+
}<span class="input-group-label">#{pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages}</span>#{
|
58
|
+
if (p_next = pagy.next)
|
59
|
+
link.call p_next, pagy_t('pagy.nav.next'), 'style="margin-bottom: 0px;" aria-label="next" class="next button primary"'
|
60
|
+
else
|
61
|
+
%(<a style="margin-bottom: 0px;" class="next button primary disabled" href="#">#{pagy_t 'pagy.nav.next'}</a>)
|
62
|
+
end
|
63
|
+
}</div></nav>#{
|
64
|
+
pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link)
|
65
|
+
})
|
54
66
|
end
|
55
67
|
|
68
|
+
private
|
69
|
+
|
70
|
+
def pagy_foundation_prev_html(pagy, link)
|
71
|
+
if (p_prev = pagy.prev)
|
72
|
+
%(<li class="prev">#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'}</li>)
|
73
|
+
else
|
74
|
+
%(<li class="prev disabled">#{pagy_t 'pagy.nav.prev' }</li>)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def pagy_foundation_next_html(pagy, link)
|
79
|
+
if (p_next = pagy.next)
|
80
|
+
%(<li class="next">#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}</li>)
|
81
|
+
else
|
82
|
+
%(<li class="next disabled">#{pagy_t 'pagy.nav.next'}</li>)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
56
86
|
end
|
57
87
|
end
|
data/lib/pagy/extras/headers.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/headers
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
6
5
|
# Add specialized backend methods to add pagination response headers
|
7
|
-
module Backend
|
6
|
+
module Backend
|
7
|
+
private
|
8
8
|
|
9
9
|
VARS[:headers] = { page: 'Current-Page', items: 'Page-Items', count: 'Total-Count', pages: 'Total-Pages' }
|
10
10
|
|
@@ -15,17 +15,21 @@ class Pagy
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def pagy_headers(pagy)
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
pagy_headers_hash(pagy).tap do |hash|
|
19
|
+
hash['Link'] = hash['Link'].map{|rel, link| %(<#{link}>; rel="#{rel}")}.join(', ')
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def pagy_headers_hash(pagy)
|
24
24
|
countless = defined?(Pagy::Countless) && pagy.is_a?(Pagy::Countless)
|
25
|
-
rels
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
rels = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }
|
26
|
+
rels['last'] = pagy.last unless countless
|
27
|
+
url_str = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute: true)
|
28
|
+
hash = { 'Link' => rels.filter_map do |rel, num|
|
29
|
+
next unless num
|
30
|
+
[ rel, url_str.sub(PAGE_PLACEHOLDER, num.to_s) ]
|
31
|
+
end.to_h }
|
32
|
+
headers = pagy.vars[:headers]
|
29
33
|
hash[headers[:page]] = pagy.page.to_s if headers[:page]
|
30
34
|
hash[headers[:items]] = pagy.vars[:items].to_s if headers[:items]
|
31
35
|
unless countless
|
data/lib/pagy/extras/i18n.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/i18n
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
class Pagy
|
@@ -8,12 +7,16 @@ class Pagy
|
|
8
7
|
|
9
8
|
::I18n.load_path += Dir[Pagy.root.join('locales', '*.yml')]
|
10
9
|
|
11
|
-
|
10
|
+
# unload the pagy default constant for efficiency
|
11
|
+
Pagy::I18n.clear.instance_eval do
|
12
|
+
undef :load
|
13
|
+
undef :t
|
14
|
+
end
|
12
15
|
|
13
|
-
module
|
16
|
+
module UseI18nGem
|
14
17
|
def pagy_t(key, **opts) = ::I18n.t(key, **opts)
|
15
18
|
end
|
16
|
-
prepend
|
19
|
+
prepend UseI18nGem
|
17
20
|
|
18
21
|
end
|
19
22
|
end
|
data/lib/pagy/extras/items.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/items
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/extras/shared'
|
@@ -10,47 +9,43 @@ class Pagy
|
|
10
9
|
VARS[:items_param] = :items
|
11
10
|
VARS[:max_items] = 100
|
12
11
|
|
12
|
+
VARS[:enable_items_extra] = true
|
13
|
+
|
13
14
|
ITEMS_PLACEHOLDER = '__pagy_items__'
|
14
15
|
|
15
|
-
module
|
16
|
+
module UseItemsExtra; end
|
17
|
+
|
18
|
+
module Backend
|
19
|
+
private
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
super(collection, vars)
|
23
|
-
end
|
21
|
+
def pagy_set_items_from_params(vars)
|
22
|
+
return if vars[:items]
|
23
|
+
return unless vars.key?(:enable_item_extra) ? vars[:enable_item_extra] : VARS[:enable_items_extra]
|
24
|
+
return unless (items = params[vars[:items_param] || VARS[:items_param]]) # :items from :items_param
|
25
|
+
vars[:items] = [items.to_i, vars.key?(:max_items) ? vars[:max_items] : VARS[:max_items]].compact.min # :items capped to :max_items
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
28
|
end
|
28
|
-
Backend.prepend Items
|
29
|
-
|
30
29
|
|
31
30
|
module Frontend
|
32
31
|
|
33
|
-
module Items
|
34
|
-
def pagy_url_for(page, pagy, url=false)
|
35
|
-
p_vars = pagy.vars; params = request.GET.merge(p_vars[:params]); params[p_vars[:page_param].to_s] = page
|
36
|
-
params[p_vars[:items_param].to_s] = p_vars[:items]
|
37
|
-
"#{request.base_url if url}#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
prepend Items
|
41
|
-
|
42
32
|
# Return the items selector HTML. For example "Show [20] items per page"
|
43
|
-
def pagy_items_selector_js(pagy,
|
33
|
+
def pagy_items_selector_js(pagy, deprecated_id=nil, pagy_id: nil, item_name: nil, i18n_key: nil, link_extra: '')
|
34
|
+
return '' unless pagy.vars[:enable_items_extra]
|
35
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
36
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
44
37
|
p_vars = pagy.vars
|
45
38
|
p_items = p_vars[:items]
|
46
39
|
p_vars[:items] = ITEMS_PLACEHOLDER
|
47
|
-
link = pagy_marked_link(pagy_link_proc(pagy))
|
40
|
+
link = pagy_marked_link(pagy_link_proc(pagy, link_extra: link_extra))
|
48
41
|
p_vars[:items] = p_items # restore the items
|
49
42
|
|
50
|
-
html
|
43
|
+
html = %(<span#{p_id} class="pagy-items-selector-js">)
|
51
44
|
input = %(<input type="number" min="1" max="#{p_vars[:max_items]}" value="#{p_items}" style="padding: 0; text-align: center; width: #{p_items.to_s.length+1}rem;">)
|
52
|
-
html <<
|
53
|
-
|
45
|
+
html << pagy_t('pagy.items_selector_js', item_name: item_name || pagy_t(i18n_key || p_vars[:i18n_key], count: p_items),
|
46
|
+
items_input: input,
|
47
|
+
count: p_items)
|
48
|
+
html << %(</span>#{pagy_json_tag pagy, :items_selector, pagy.from, link})
|
54
49
|
end
|
55
50
|
|
56
51
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/materialize
|
2
|
-
# encoding: utf-8
|
3
2
|
# frozen_string_literal: true
|
4
3
|
|
5
4
|
require 'pagy/extras/shared'
|
@@ -8,52 +7,77 @@ class Pagy
|
|
8
7
|
module Frontend
|
9
8
|
|
10
9
|
# Pagination for materialize: it returns the html with the series of links to the pages
|
11
|
-
def pagy_materialize_nav(pagy)
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
def pagy_materialize_nav(pagy, pagy_id: nil, link_extra: '')
|
11
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
12
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
13
|
+
|
14
|
+
html = +%(<div#{p_id} class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">)
|
15
|
+
html << pagy_materialize_prev_html(pagy, link)
|
15
16
|
pagy.series.each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
|
16
|
-
html <<
|
17
|
-
|
18
|
-
|
17
|
+
html << case item
|
18
|
+
when Integer then %(<li class="waves-effect">#{link.call item}</li>) # page link
|
19
|
+
when String then %(<li class="active">#{link.call item}</li>) # active page
|
20
|
+
when :gap then %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>) # page gap
|
19
21
|
end
|
20
22
|
end
|
21
|
-
html << (
|
22
|
-
|
23
|
-
%(<div class="pagy-materialize-nav pagination" role="navigation" aria-label="pager"><ul class="pagination">#{html}</ul></div>)
|
23
|
+
html << pagy_materialize_next_html(pagy, link)
|
24
|
+
html << %(</ul></div>)
|
24
25
|
end
|
25
26
|
|
26
27
|
# Javascript pagination for materialize: it returns a nav and a JSON tag used by the Pagy.nav javascript
|
27
|
-
def pagy_materialize_nav_js(pagy,
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def pagy_materialize_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '', steps: nil)
|
29
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
30
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
31
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
32
|
+
|
33
|
+
tags = { 'before' => %(<ul class="pagination">#{pagy_materialize_prev_html pagy, link}),
|
32
34
|
'link' => %(<li class="waves-effect">#{mark = link.call(PAGE_PLACEHOLDER)}</li>),
|
33
35
|
'active' => %(<li class="active">#{mark}</li>),
|
34
|
-
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t
|
35
|
-
'after' =>
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
'gap' => %(<li class="gap disabled"><a href="#">#{pagy_t 'pagy.nav.gap'}</a></li>),
|
37
|
+
'after' => %(#{pagy_materialize_next_html pagy, link}</ul>) }
|
38
|
+
|
39
|
+
html = %(<div#{p_id} class="pagy-njs pagy-materialize-nav-js" role="navigation" aria-label="pager"></div>)
|
40
|
+
html << pagy_json_tag(pagy, :nav, tags, pagy.sequels(steps))
|
39
41
|
end
|
40
42
|
|
41
43
|
# Javascript combo pagination for materialize: it returns a nav and a JSON tag used by the Pagy.combo_nav javascript
|
42
|
-
def pagy_materialize_combo_nav_js(pagy,
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
44
|
+
def pagy_materialize_combo_nav_js(pagy, deprecated_id=nil, pagy_id: nil, link_extra: '')
|
45
|
+
pagy_id = Pagy.deprecated_arg(:id, deprecated_id, :pagy_id, pagy_id) if deprecated_id
|
46
|
+
p_id = %( id="#{pagy_id}") if pagy_id
|
47
|
+
link = pagy_link_proc(pagy, link_extra: link_extra)
|
48
|
+
p_page = pagy.page
|
49
|
+
p_pages = pagy.pages
|
50
|
+
style = ' style="vertical-align: middle;"'
|
51
|
+
input = %(<input type="number" class="browser-default" min="1" max="#{p_pages}" value="#{p_page}" style="padding: 2px; border: none; border-radius: 2px; text-align: center; width: #{p_pages.to_s.length+1}rem;">)
|
52
|
+
|
53
|
+
%(<div#{p_id} class="pagy-materialize-combo-nav-js pagination" role="navigation" aria-label="pager"><div class="pagy-compact-chip role="group" style="height: 35px; border-radius: 18px; background: #e4e4e4; display: inline-block;"><ul class="pagination" style="margin: 0px;">#{
|
54
|
+
pagy_materialize_prev_html pagy, link, style
|
55
|
+
}<div class="pagy-combo-input btn-flat" style="cursor: default; padding: 0px">#{
|
56
|
+
pagy_t 'pagy.combo_nav_js', page_input: input, count: p_page, pages: p_pages
|
57
|
+
}</div>#{
|
58
|
+
pagy_materialize_next_html pagy, link, style
|
59
|
+
}</ul></div>#{
|
60
|
+
pagy_json_tag pagy, :combo_nav, p_page, pagy_marked_link(link)
|
61
|
+
})
|
56
62
|
end
|
57
63
|
|
64
|
+
private
|
65
|
+
|
66
|
+
def pagy_materialize_prev_html(pagy, link, style='')
|
67
|
+
if (p_prev = pagy.prev)
|
68
|
+
%(<li class="waves-effect prev"#{style}>#{link.call p_prev, '<i class="material-icons">chevron_left</i>', 'aria-label="previous"'}</li>)
|
69
|
+
else
|
70
|
+
%(<li class="prev disabled"#{style}><a href="#"><i class="material-icons">chevron_left</i></a></li>)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def pagy_materialize_next_html(pagy, link, style='')
|
75
|
+
if (p_next = pagy.next)
|
76
|
+
%(<li class="waves-effect next"#{style}>#{link.call p_next, '<i class="material-icons">chevron_right</i>', 'aria-label="next"'}</li>)
|
77
|
+
else
|
78
|
+
%(<li class="next disabled"#{style}><a href="#"><i class="material-icons">chevron_right</i></a></li>)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
58
82
|
end
|
59
83
|
end
|