pagy 2.1.5 → 3.0.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: b070d610f896a8b61e0f100c733e83d8eed0bfce6976ff24ed6e533f329c1ad2
4
- data.tar.gz: 6c3654d072aea0dede29f6bf15069cc82ee3d6869ef812db6b78b0dda401013d
3
+ metadata.gz: 447cda63901d2154f660b143ad95fdc1033bdf8a2f4df8daa1cc3458af6a3b3c
4
+ data.tar.gz: 325d74734f50dc0b486ec94870b91c73890ea6d63f2ccf12d8b940ceacc864b0
5
5
  SHA512:
6
- metadata.gz: c4172ff22491bc6506fe9041e71ef6e7abf92c3bee1dbf17f7f067e7a25fd9fa0124f3e5c54dbf30807f2d3df9b49fc432d8683cc8fde0d8434aa4c1686823a6
7
- data.tar.gz: 87f78b815480fa7bd1392b4b2991d4af65783acf55ada2dea2724546a1b7c2e0e046e0c5ea838b6c200c8a655d3850f1db9360ae7ee514419e667980759d61f4
6
+ metadata.gz: 37a5279f51672130fe868a903564584f270ceb952f25cd9d7b2290a4a2c3d9801ad759a7312f9edf97ad5bbe74440326025d7f774017b46ce46bfb99c3b9aaa8
7
+ data.tar.gz: 61045baceee37a1d1d21e0f2d51303386bc3055afff72f745c6e42d2a6a1b2a34ef373c5058078824dac3a2c841fb952eebba2363e19c6e785ce5edbe1a3ddc2
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- # Pagy initializer file (2.1.5)
4
+ # Pagy initializer file (3.0.0)
5
5
  # Customize only what you really need and notice that Pagy works also without any of the following lines.
6
6
  # Should you just cherry pick part of this file, please maintain the require-order of the extras
7
7
 
@@ -32,35 +32,35 @@
32
32
 
33
33
  # Frontend Extras
34
34
 
35
- # Bootstrap extra: Add nav, responsive and compact helpers and templates for Bootstrap pagination
35
+ # Bootstrap extra: Add nav, nav_js and combo_nav_js helpers and templates for Bootstrap pagination
36
36
  # See https://ddnexus.github.io/pagy/extras/bootstrap
37
37
  # require 'pagy/extras/bootstrap'
38
38
 
39
- # Bulma extra: Add nav, responsive and compact helpers and templates for Bulma pagination
39
+ # Bulma extra: Add nav, nav_js and combo_nav_js helpers and templates for Bulma pagination
40
40
  # See https://ddnexus.github.io/pagy/extras/bulma
41
41
  # require 'pagy/extras/bulma'
42
42
 
43
- # Foundation extra: Add nav, responsive and compact helpers and templates for Foundation pagination
43
+ # Foundation extra: Add nav, nav_js and combo_nav_js helpers and templates for Foundation pagination
44
44
  # See https://ddnexus.github.io/pagy/extras/foundation
45
45
  # require 'pagy/extras/foundation'
46
46
 
47
- # Materialize extra: Nav, responsive and compact helpers for Materialize pagination
47
+ # Materialize extra: Add nav, nav_js and combo_nav_js helpers for Materialize pagination
48
48
  # See https://ddnexus.github.io/pagy/extras/materialize
49
49
  # require 'pagy/extras/materialize'
50
50
 
51
- # Plain extra: Add responsive and compact nav plain helpers
51
+ # Navs extra: Add nav_js and combo_nav_js javascript helpers
52
52
  # Notice: the other frontend extras add their own framework-styled versions,
53
- # so require this extra only if you need the plain unstyled version
54
- # See https://ddnexus.github.io/pagy/extras/plain
55
- # require 'pagy/extras/plain'
53
+ # so require this extra only if you need the unstyled version
54
+ # See https://ddnexus.github.io/pagy/extras/navs
55
+ # require 'pagy/extras/navs'
56
56
 
57
- # Semantic extra: Nav, responsive and compact helpers for Semantic UI pagination
57
+ # Semantic extra: Add nav, nav_js and combo_nav_js helpers for Semantic UI pagination
58
58
  # See https://ddnexus.github.io/pagy/extras/semantic
59
59
  # require 'pagy/extras/semantic'
60
60
 
61
- # Breakpoints var used by the responsive nav helpers
62
- # See https://ddnexus.github.io/pagy/extras/plain#breakpoints
63
- # Pagy::VARS[:breakpoints] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] }
61
+ # Multi size var used by the *_nav_js helpers
62
+ # See https://ddnexus.github.io/pagy/extras/navs#steps
63
+ # Pagy::VARS[:steps] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] } # example
64
64
 
65
65
 
66
66
  # Feature Extras
@@ -109,12 +109,12 @@
109
109
  # Pagy::VARS[:params] = {} # default
110
110
  # Pagy::VARS[:anchor] = '#anchor' # example
111
111
  # Pagy::VARS[:link_extra] = 'data-remote="true"' # example
112
- # Pagy::VARS[:item_path] = 'activerecord.models.product' # example
113
112
 
114
113
 
115
114
  # Rails
116
115
 
117
- # Rails: extras assets path required by the compact and responsive navs, and the items extra
116
+ # Rails: extras assets path required by the helpers that use javascript
117
+ # (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_selector_js)
118
118
  # See https://ddnexus.github.io/pagy/extras#javascript
119
119
  # Rails.application.config.assets.paths << Pagy.root.join('javascripts')
120
120
 
@@ -153,3 +153,6 @@
153
153
  # than the default pagy internal i18n (see above)
154
154
  # See https://ddnexus.github.io/pagy/extras/i18n
155
155
  # require 'pagy/extras/i18n'
156
+
157
+ # Default i18n key
158
+ # Pagy::VARS[:i18n_key] = 'pagy.item_name' # default
@@ -1,8 +1,94 @@
1
1
  // See the Pagy documentation: https://ddnexus.github.io/pagy/extras#javascript
2
2
 
3
- // Pagy namespace
4
3
  function Pagy(){}
5
4
 
5
+ Pagy.init = function(arg){
6
+ var target = arg instanceof Event || arg === undefined ? document : arg,
7
+ jsonTags = target.getElementsByClassName('pagy-json');
8
+ for (var i = 0, len = jsonTags.length; i < len; i++) {
9
+ var args = JSON.parse(jsonTags[i].innerHTML);
10
+ Pagy[args.shift()].apply(null, args);
11
+ }
12
+ };
13
+
14
+ Pagy.nav = function(id, marker, tags, sequels){
15
+ var pagyEl = document.getElementById(id),
16
+ container = pagyEl.parentElement,
17
+ lastWidth = undefined,
18
+ timeoutId = 0,
19
+ marker_re = new RegExp(marker, 'g'),
20
+ widths = [];
21
+ for (var width in sequels) { widths.push(parseInt(width)) } // fine with sequels structure
22
+ widths.sort(function(a, b){return b-a});
23
+
24
+ var render = function(){
25
+ if (container.clientWidth === 0) { rendering() }
26
+ var width, i, len;
27
+ for (i = 0, len = widths.length; i < len; i++) {
28
+ if (container.clientWidth > widths[i]) { width = widths[i]; break }
29
+ }
30
+ if (width !== lastWidth) {
31
+ while (pagyEl.firstChild) { pagyEl.removeChild(pagyEl.firstChild) }
32
+ var html = tags.before,
33
+ series = sequels[width];
34
+ for (i = 0, len = series.length; i < len; i++) {
35
+ var item = series[i];
36
+ if (typeof(item) === 'number') { html += tags.link.replace(marker_re, item) }
37
+ else if (item === 'gap') { html += tags.gap }
38
+ else if (typeof(item) === 'string') { html += tags.active.replace(marker_re, item) }
39
+ }
40
+ html += tags.after;
41
+ pagyEl.insertAdjacentHTML('beforeend', html);
42
+ lastWidth = width;
43
+ }
44
+ },
45
+ // suppress rapid firing rendering
46
+ rendering = function(){ clearTimeout(timeoutId); timeoutId = setTimeout(render, 150) };
47
+
48
+ if (widths.length > 1) {
49
+ // refresh the window resize listener (avoiding rendering multiple times)
50
+ window.removeEventListener('resize', Pagy.windowListeners[id], true);
51
+ window.addEventListener('resize', rendering, true);
52
+ Pagy.windowListeners[id] = rendering;
53
+ }
54
+ render();
55
+ };
56
+
57
+ Pagy.combo_nav = function(id, marker, page, trim){
58
+ var pagyEl = document.getElementById(id),
59
+ input = pagyEl.getElementsByTagName('input')[0],
60
+ link = pagyEl.getElementsByTagName('a')[0],
61
+ linkP1 = pagyEl.getElementsByTagName('a')[1],
62
+ go = function(){
63
+ if (page !== input.value) {
64
+ if (trim === true && input.value === '1') { linkP1.click() }
65
+ else {
66
+ var href = link.getAttribute('href').replace(marker, input.value);
67
+ link.setAttribute('href', href);
68
+ link.click();
69
+ }
70
+ }
71
+ };
72
+ Pagy.addInputEventListeners(input, go);
73
+ };
74
+
75
+ Pagy.items_selector = function(id, marker, from){
76
+ var pagyEl = document.getElementById(id),
77
+ input = pagyEl.getElementsByTagName('input')[0],
78
+ current = input.value,
79
+ link = pagyEl.getElementsByTagName('a')[0],
80
+ go = function(){
81
+ var items = input.value;
82
+ if (current !== items) {
83
+ var page = Math.max(Math.ceil(from / items),1);
84
+ var href = link.getAttribute('href').replace(marker+'-page-', page).replace(marker+'-items-', items);
85
+ link.setAttribute('href', href);
86
+ link.click();
87
+ }
88
+ };
89
+ Pagy.addInputEventListeners(input, go);
90
+ };
91
+
6
92
  Pagy.windowListeners = {};
7
93
 
8
94
  Pagy.addInputEventListeners = function(input, handler){
@@ -14,81 +100,3 @@ Pagy.addInputEventListeners = function(input, handler){
14
100
  input.addEventListener('keyup', function(e){ if (e.which === 13) handler() }.bind(this));
15
101
  };
16
102
 
17
- Pagy.compact = function(id, marker, page, trim){
18
- var pagyEl = document.getElementById(id),
19
- input = pagyEl.getElementsByTagName('input')[0],
20
- link = pagyEl.getElementsByTagName('a')[0],
21
- linkP1 = pagyEl.getElementsByTagName('a')[1],
22
- go = function(){
23
- if (page !== input.value) {
24
- if (trim === true && input.value === '1') { linkP1.click() }
25
- else {
26
- var href = link.getAttribute('href').replace(marker, input.value);
27
- link.setAttribute('href', href);
28
- link.click();
29
- }
30
- }
31
- };
32
- Pagy.addInputEventListeners(input, go);
33
- };
34
-
35
- Pagy.items = function(id, marker, from){
36
- var pagyEl = document.getElementById(id),
37
- input = pagyEl.getElementsByTagName('input')[0],
38
- current = input.value,
39
- link = pagyEl.getElementsByTagName('a')[0],
40
- go = function(){
41
- var items = input.value;
42
- if (current !== items) {
43
- var page = Math.max(Math.ceil(from / items),1);
44
- var href = link.getAttribute('href').replace(marker+'-page-', page).replace(marker+'-items-', items);
45
- link.setAttribute('href', href);
46
- link.click();
47
- }
48
- };
49
- Pagy.addInputEventListeners(input, go);
50
- };
51
-
52
- Pagy.responsive = function(id, tags, widths, series){
53
- var pagyEl = document.getElementById(id),
54
- container = pagyEl.parentElement,
55
- lastWidth = undefined,
56
- timeoutId = 0,
57
- render = function(){
58
- if (container.clientWidth === 0) { rendering() }
59
- var width, i, len;
60
- for (i = 0, len = widths.length; i < len; i++) {
61
- if (container.clientWidth > widths[i]) { width = widths[i]; break }
62
- }
63
- if (width !== lastWidth) {
64
- while (pagyEl.firstChild) { pagyEl.removeChild(pagyEl.firstChild) }
65
- var html = tags['before'],
66
- items = series[width];
67
- for (i = 0, len = items.length; i < len; i++) { html += tags[items[i]] }
68
- html += tags['after'];
69
- pagyEl.insertAdjacentHTML('beforeend', html);
70
- lastWidth = width;
71
- }
72
- },
73
- // suppress rapid firing rendering
74
- rendering = function(){ clearTimeout(timeoutId); timeoutId = setTimeout(render, 150) };
75
- // refresh the window resize listener (avoiding rendering multiple times)
76
- window.removeEventListener('resize', Pagy.windowListeners[id], true);
77
- window.addEventListener('resize', rendering, true);
78
- Pagy.windowListeners[id] = rendering;
79
- render();
80
- };
81
-
82
- Pagy.init = function(arg){
83
- var target = arg instanceof Event || arg === undefined ? document : arg,
84
- jsonTags = target.getElementsByClassName('pagy-json');
85
- for (var i = 0, len = jsonTags.length; i < len; i++) {
86
- var args = JSON.parse(jsonTags[i].innerHTML);
87
- Pagy[args.shift()].apply(null, args);
88
- }
89
- };
90
-
91
- // namespace for custom init functions
92
- function PagyInit(){}
93
-
94
- Pagy.applyInit = function(name, payload){ PagyInit[name].apply(null, [payload]) };
@@ -2,11 +2,24 @@
2
2
 
3
3
  ### Please, submit your translation!
4
4
 
5
+ If you find that some translation could be improved, please, create an issue.
6
+
5
7
  If you are using pagy with some language missing from the dictionary files, please, submit your translation!
6
8
 
7
- The `pagy.info.single_page`, `pagy.info.item_name` and `pagy.items` keys of the yaml file are pluralized according to the plural rules of the language.
9
+ You can create a Pull Request for your language, and get all the help you need to correctly complete it. Here is a check list.
10
+
11
+ ### Check list for a new dictionary file:
12
+
13
+ - [ ] Find the pluralization rule for your language
14
+ - find the locale file you need in the [list of pluralizations](https://github.com/svenfuchs/rails-i18n/tree/master/rails/pluralization) and check the pluralization rule in it. For example for `en.rb` it is`::RailsI18n::Pluralization::OneOther.with_locale(:en)`. Note the rule part i.e. `OneOther`. In pagy that translates to the symbol `:one_other`.
15
+
16
+ - [ ] add/edit the first line comment in the language rule in your dictionary file (e.g. `# :one_other pluralization ...`
17
+
18
+ - [ ] The mandatory pluralized entry in the dictionary file is the `item_name`. Please, provide all the plurals needed by your language. E.g. if your language uses the `:east_slavic` you should provide the plurals for `one`, `few`, `many` and `other`, if it uses `:one_other`, you should provide `one` and `other` plurals. If it uses `:other` you should only provide a single value. Look into other dictionary files to get some example. Ask if in doubt.
19
+
20
+ - [ ] The other entries in the dictionary file don't need any plural variant in most languages since the pluralization of the `item_name` in the sentence is enough. However, in some language, the whole sentence needs to be written in a different way for different plurals. In that case you should add the different plurals for the sentence and they will get triggered by the `count`.
8
21
 
9
- If you are going to submit a dictionary, please check wether the pluralization type of your language exists in the [lib/locales/utils/p11n.rb](utils/p11n.rb) file. If it is missing, please, report it. Thanks.
22
+ Feel free to ask for help in your Pull Request.
10
23
 
11
24
  ### Useful Links
12
25
 
@@ -1,20 +1,22 @@
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
1
3
  de:
2
4
  pagy:
5
+
6
+ item_name:
7
+ one: "Eintrag"
8
+ other: "Einträge"
9
+
3
10
  nav:
4
11
  prev: "&lsaquo;&nbsp;Zurück"
5
12
  next: "Weiter&nbsp;&rsaquo;"
6
13
  gap: "&hellip;"
14
+
7
15
  info:
8
- single_page:
9
- zero: "Kein %{item_name} gefunden"
10
- one: "Zeige <b>1</b> %{item_name}"
11
- other: "Zeige <b>alle %{count}</b> %{item_name}"
16
+ no_items: "Kein %{item_name} gefunden"
17
+ single_page: "Zeige <b>%{count}</b> %{item_name}"
12
18
  multiple_pages: "Zeige %{item_name} <b>%{from}-%{to}</b> von <b>%{count}</b> gesamt"
13
- item_name:
14
- zero: "Eintrag"
15
- one: "Eintrag"
16
- other: "Einträge"
17
- compact: "Seite %{page_input} von %{pages}"
18
- items:
19
- one: "Zeige %{items_input} Eintrag pro Seite"
20
- other: "Zeige %{items_input} Einträge pro Seite"
19
+
20
+ combo_nav_js: "Seite %{page_input} von %{pages}"
21
+
22
+ items_selector_js: "Zeige %{items_input} %{item_name} pro Seite"
@@ -1,20 +1,22 @@
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
1
3
  en:
2
4
  pagy:
5
+
6
+ item_name:
7
+ one: "item"
8
+ other: "items"
9
+
3
10
  nav:
4
11
  prev: "&lsaquo;&nbsp;Prev"
5
12
  next: "Next&nbsp;&rsaquo;"
6
13
  gap: "&hellip;"
14
+
7
15
  info:
8
- single_page:
9
- zero: "No %{item_name} found"
10
- one: "Displaying <b>1</b> %{item_name}"
11
- other: "Displaying <b>all %{count}</b> %{item_name}"
16
+ no_items: "No %{item_name} found"
17
+ single_page: "Displaying <b>%{count}</b> %{item_name}"
12
18
  multiple_pages: "Displaying %{item_name} <b>%{from}-%{to}</b> of <b>%{count}</b> in total"
13
- item_name:
14
- zero: "items"
15
- one: "item"
16
- other: "items"
17
- compact: "Page %{page_input} of %{pages}"
18
- items:
19
- one: "Show %{items_input} item per page"
20
- other: "Show %{items_input} items per page"
19
+
20
+ combo_nav_js: "Page %{page_input} of %{pages}"
21
+
22
+ items_selector_js: "Show %{items_input} %{item_name} per page"
@@ -1,20 +1,22 @@
1
+ # :one_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
1
3
  es:
2
4
  pagy:
5
+
6
+ item_name:
7
+ one: "ítem"
8
+ other: "ítems"
9
+
3
10
  nav:
4
11
  prev: "&lsaquo;&nbsp;Prev"
5
12
  next: "Siguiente&nbsp;&rsaquo;"
6
13
  gap: "&hellip;"
14
+
7
15
  info:
8
- single_page:
9
- zero: "Sin resultados"
10
- one: "Mostrando 1 %{item_name}"
11
- other: "Mostrando %{count} %{item_name}"
16
+ no_items: "Sin resultados"
17
+ single_page: "Mostrando %{count} %{item_name}"
12
18
  multiple_pages: "Mostrando %{item_name} %{from}-%{to} de %{count} en total"
13
- item_name:
14
- zero: "ítems"
15
- one: "ítem"
16
- other: "ítems"
17
- compact: "Página %{page_input} de %{pages}"
18
- items:
19
- one: "Mostrar %{items_input} ítem por página"
20
- other: "Mostrar %{items_input} ítems por página"
19
+
20
+ combo_nav_js: "Página %{page_input} de %{pages}"
21
+
22
+ items_selector_js: "Mostrar %{items_input} %{item_name} por página"
@@ -0,0 +1,22 @@
1
+ # :one_upto_two_other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
3
+ fr:
4
+ pagy:
5
+
6
+ item_name:
7
+ one: "élement"
8
+ other: "élements"
9
+
10
+ nav:
11
+ prev: "&lsaquo;&nbsp;Précédent"
12
+ next: "Suivant&nbsp;&rsaquo;"
13
+ gap: "&hellip;"
14
+
15
+ info:
16
+ no_items: "Aucun %{item_name} trouvé"
17
+ single_page: "Affichage de <b>%{count}</b> %{item_name}"
18
+ multiple_pages: "Affichage des %{item_name} <b>%{from} à %{to}</b> sur <b>%{count}</b> au total"
19
+
20
+ combo_nav_js: "Page %{page_input} sur %{pages}"
21
+
22
+ items_selector_js: "Afficher %{items_input} %{item_name} par page"
@@ -1,20 +1,20 @@
1
+ # :other pluralization (see https://github.com/ddnexus/pagy/blob/master/lib/locales/utils/p11n.rb)
2
+
1
3
  id:
2
4
  pagy:
5
+
6
+ item_name: "item"
7
+
3
8
  nav:
4
- prev: "&lsaquo;&nbsp;Balik"
5
- next: "Lanjut&nbsp;&rsaquo;"
9
+ prev: "&lsaquo;&nbsp;Sebelumnya"
10
+ next: "Selanjutnya&nbsp;&rsaquo;"
6
11
  gap: "&hellip;"
12
+
7
13
  info:
8
- single_page:
9
- zero: "Tidak ditemukan %{item_name}"
10
- one: "Menampilkan <b>1</b> %{item_name}"
11
- other: "Menampilkan <b>semua %{count}</b> %{item_name}"
14
+ no_items: "Tidak ditemukan %{item_name}"
15
+ single_page: "Menampilkan <b>%{count}</b> %{item_name}"
12
16
  multiple_pages: "Menampilkan %{item_name} <b>%{from}-%{to}</b> dari total <b>%{count}</b>"
13
- item_name:
14
- zero: "item"
15
- one: "item"
16
- other: "item"
17
- compact: "Halaman %{page_input} dari %{pages}"
18
- items:
19
- one: "Tampilkan %{items_input} item per halaman"
20
- other: "Tampilkan %{items_input} item per halaman"
17
+
18
+ combo_nav_js: "Halaman %{page_input} dari %{pages}"
19
+
20
+ items_selector_js: "Tampilkan %{items_input} %{item_name} per halaman"