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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48e9fa30f5123b3b985a58c0f20e00803b8708662d25e4b8116f786264adf382
4
- data.tar.gz: fd51c8bf8bb897c01382459c4ab1a6baf3e28c7c9437213652382cbf5d01b8f8
3
+ metadata.gz: ea6862ff93b09769c9810860307a4a63a88de1ecf8d6a4f8176f6cb90e22565f
4
+ data.tar.gz: 5564e6b0f2e006b098dc9fe07ea8409ce4748bd6a32acb0f19bdb56e6f8b791d
5
5
  SHA512:
6
- metadata.gz: 073dd75676b37ba14baaccd30a58ce008e8d32dd8e1dfd8508bc02abf0f1d85bfe8a503a4790b4157cd8a36f3e8b1c89284ae3d83c0ea8cb6565e5e32a74985d
7
- data.tar.gz: 449da76a99d14327a89fcc30fad843dc5581c8225fab8c5678aa72f9888b160ebbd09d6c1b6946d8bcd1002267803a72b97a28de7797ac1a0be28ece704475f6
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.4.0)
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
 
@@ -2,109 +2,116 @@
2
2
 
3
3
  function Pagy(){}
4
4
 
5
- Pagy.version = '4.4.0';
5
+ Pagy.version = '4.5.0'
6
6
 
7
- Pagy.timeout = 100;
7
+ Pagy.delay = 100
8
8
 
9
- Pagy.timeoutId = 0;
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.init = function(arg) {
12
- var target = arg instanceof Event || arg === undefined ? document : arg,
13
- jsonTags = target.getElementsByClassName('pagy-json');
14
- for (var i = 0, len = jsonTags.length; i < len; i++) {
15
- var args = JSON.parse(jsonTags[i].innerHTML),
16
- fname = args.shift();
17
- args.unshift(jsonTags[i].previousSibling);
18
- Pagy[fname].apply(null, args);
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
- for (var width in sequels) { widths.push(parseInt(width)) } // fine with sequels structure
30
- widths.sort(function(a, b) { return b - a });
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
- pagyEl.render = function() {
33
- if (this.parentElement.clientWidth === 0) { return wait() } // not ready yet
34
- var width, i, len;
35
- for (i = 0, len = widths.length; i < len; i++) {
36
- if (this.parentElement.clientWidth > widths[i]) { width = widths[i]; break }
37
- }
38
- if (width !== lastWidth) {
39
- var html = tags.before,
40
- series = sequels[width];
41
- for (i = 0, len = series.length; i < len; i++) {
42
- var item = series[i];
43
- if (typeof(param) === 'string' && item === 1) { html += Pagy.trim(tags.link.replace(pageREg, item), param) }
44
- else if (typeof(item) === 'number') { html += tags.link.replace(pageREg, item) }
45
- else if (item === 'gap') { html += tags.gap }
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 = function(pagyEl, from, link, param) {
71
- var input = pagyEl.getElementsByTagName('input')[0],
72
- current = input.value,
73
- go = function() {
74
- var items = input.value;
75
- if (current !== items) {
76
- var page = Math.max(Math.ceil(from / items), 1),
77
- html = link.replace(/__pagy_page__/, page).replace(/__pagy_items__/, items);
78
- if (typeof (param) === 'string' && page === 1) { html = Pagy.trim(html, param) }
79
- pagyEl.insertAdjacentHTML('afterbegin', html);
80
- pagyEl.getElementsByTagName('a')[0].click();
81
- }
82
- };
83
- Pagy.addInputEventListeners(input, go);
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 = function(input, handler) {
87
- // select the content on click: easier for typing a number
88
- input.addEventListener('click', function() { this.select() });
89
- // go when the input looses focus
90
- input.addEventListener('focusout', handler);
91
- // … and when pressing enter inside the input
92
- input.addEventListener('keyup', function(e) { if (e.which === 13) {handler()} }.bind(this));
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 = function(html, param) {
96
- var re = new RegExp('[?&]' + param + '=1\\b(?!&)|\\b' + param + '=1&');
97
- return html.replace(re, '');
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.renderNjs = function() {
101
- var navs = document.getElementsByClassName('pagy-njs');
102
- for (var i = 0, len = navs.length; i < len; i++) { navs[i].render() }
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.wait = function() {
106
- clearTimeout(Pagy.timeoutId);
107
- Pagy.timeoutId = setTimeout(Pagy.renderNjs, Pagy.timeout);
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.wait, true);
117
+ window.addEventListener('resize', Pagy.waitForMe, true)
data/lib/pagy.rb CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
5
5
 
6
6
  # main class
7
7
  class Pagy
8
- VERSION = '4.4.0'
8
+ VERSION = '4.5.0'
9
9
 
10
10
  # Root pathname to get the path of Pagy files like templates or dictionaries
11
11
  def self.root
@@ -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 # page link
19
- when String then %(<a class="item active">#{item}</a>) # current page
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
@@ -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('pagy.nav.gap')}</span></li>),
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>)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagy
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Domizio Demichelis