From 25470dda367e5b683b022f3e20c13c50f1c76e3f Mon Sep 17 00:00:00 2001
From: Domizio Demichelis
Date: Thu, 4 Apr 2019 12:03:49 +0700
Subject: [PATCH] renamed items_selector > items_selector_js
---
docs/extras.md | 6 +++---
docs/extras/items.md | 4 ++--
lib/javascripts/pagy.js | 32 ++++++++++++++++----------------
lib/pagy/extras/items.rb | 4 ++--
test/pagy/extras/items_test.rb | 10 +++-------
5 files changed, 26 insertions(+), 30 deletions(-)
diff --git a/docs/extras.md b/docs/extras.md
index df1e0afc1..3def4ebdb 100644
--- a/docs/extras.md
+++ b/docs/extras.md
@@ -45,11 +45,11 @@ A few extras require the [pagy/extras/shared](https://github.com/ddnexus/pagy/bl
## Javascript
-A few helpers use javascript:
+A few helpers use javascript, and they are clearly recognizable by the `js` suffix:
-- `pagy_*_compact_nav_js`
- `pagy_*_nav_js`
-- `pagy_items_selector`
+- `pagy_*_compact_nav_js`
+- `pagy_items_selector_js`
If you use any of them you should load the [pagy.js](https://github.com/ddnexus/pagy/blob/master/lib/javascripts/pagy.js) file, and run `Pagy.init()` on window load and eventually on [AJAX-load](#using-ajax-with-javascript-enabled-helpers).
diff --git a/docs/extras/items.md b/docs/extras/items.md
index 254d39250..9de015381 100644
--- a/docs/extras/items.md
+++ b/docs/extras/items.md
@@ -20,7 +20,7 @@ Pagy::VARS[:items_param] = :custom_param # default :items
Pagy::VARS[:max_items] = 100 # default
```
-Configure [javascript](../extras.md#javascript) (only if you use the `pagy_items_selector` UI)
+Configure [javascript](../extras.md#javascript) (only if you use the `pagy_items_selector_js` UI)
## Files
@@ -77,7 +77,7 @@ This extra overrides the `pagy_countless_get_vars` method of the `Pagy::Backend`
This extra overrides also the `pagy_url_for` method of the `Pagy::Frontend` module in order to add the `:items_param` param to the url of the links.
-### pagy_items_selector(pagy)
+### pagy_items_selector_js(pagy)
This helper provides an items selector UI, which allows the user to select any arbitrary number of items per page (below the `:max_items` number) in a numeric input field. It looks like:
diff --git a/lib/javascripts/pagy.js b/lib/javascripts/pagy.js
index d75301528..ed1c46fb1 100644
--- a/lib/javascripts/pagy.js
+++ b/lib/javascripts/pagy.js
@@ -32,22 +32,22 @@ Pagy.compact_nav = function(id, marker, page, trim){
Pagy.addInputEventListeners(input, go);
};
-Pagy.items = function(id, marker, from){
- var pagyEl = document.getElementById(id),
- input = pagyEl.getElementsByTagName('input')[0],
- current = input.value,
- link = pagyEl.getElementsByTagName('a')[0],
- go = function(){
- var items = input.value;
- if (current !== items) {
- var page = Math.max(Math.ceil(from / items),1);
- var href = link.getAttribute('href').replace(marker+'-page-', page).replace(marker+'-items-', items);
- link.setAttribute('href', href);
- link.click();
- }
- };
- Pagy.addInputEventListeners(input, go);
- };
+Pagy.items_selector = function(id, marker, from){
+ var pagyEl = document.getElementById(id),
+ input = pagyEl.getElementsByTagName('input')[0],
+ current = input.value,
+ link = pagyEl.getElementsByTagName('a')[0],
+ go = function(){
+ var items = input.value;
+ if (current !== items) {
+ var page = Math.max(Math.ceil(from / items),1);
+ var href = link.getAttribute('href').replace(marker+'-page-', page).replace(marker+'-items-', items);
+ link.setAttribute('href', href);
+ link.click();
+ }
+ };
+ Pagy.addInputEventListeners(input, go);
+ };
Pagy.nav = function(id, marker, tags, series){
var pagyEl = document.getElementById(id),
diff --git a/lib/pagy/extras/items.rb b/lib/pagy/extras/items.rb
index aa588ab63..108658939 100644
--- a/lib/pagy/extras/items.rb
+++ b/lib/pagy/extras/items.rb
@@ -46,14 +46,14 @@ def pagy_url_for_with_items(page, pagy, url=false)
alias_method :pagy_url_for, :pagy_url_for_with_items
# Return the items selector HTML. For example "Show [20] items per page"
- def pagy_items_selector(pagy, id=pagy_id)
+ def pagy_items_selector_js(pagy, id=pagy_id)
p_vars = pagy.vars; p_items = p_vars[:items]; p_vars[:items] = "#{MARKER}-items-"
html = %() + %()
p_vars[:items] = p_items # restore the items
input = %()
html << %(#{pagy_t('pagy.items', items_input: input, count: p_items)})
- html << %(#{pagy_json_tag(:items, id, MARKER, pagy.from)})
+ html << %(#{pagy_json_tag(:items_selector, id, MARKER, pagy.from)})
end
end
diff --git a/test/pagy/extras/items_test.rb b/test/pagy/extras/items_test.rb
index 0fbce2bda..2af3bfce4 100644
--- a/test/pagy/extras/items_test.rb
+++ b/test/pagy/extras/items_test.rb
@@ -200,18 +200,14 @@
end
- describe '#pagy_items_selector' do
+ describe '#pagy_items_selector_js' do
it 'renders items selector' do
@pagy = Pagy.new count: 1000, page: 3
- html = frontend.pagy_items_selector(@pagy, 'test-id')
+ html = frontend.pagy_items_selector_js(@pagy, 'test-id')
html.must_equal \
- %() +
- %() +
- %(Show items per page) +
- %() +
- %()
+ "Show items per page"
end
end