Comments (8)
@Bahanix I am using the function.apply(null, array)
in the global refactoring of the pagy.js
passing it a simple array as in your example. It is just wrapped by a loop of the 3 extras.
Pagy.init = function(){
['compact', 'items', 'responsive'].forEach(function(name){
Array.from(document.getElementsByClassName("pagy-"+name)).forEach(function(json) {
Pagy[name].apply(null, JSON.parse(json.innerHTML))
})
})
};
I will push to dev
the refactoring in a few hours. It works well for all the extras already, but I have just to adapt the tests and update the doc. Thanks for your effort and help.
from pagy.
@Bahanix please, try the dev
branch and let me know if the docs is clear enough and if it works. Thanks.
from pagy.
Hi @Bahanix. Yeah, the inline script maybe a little brutal, I know :)
The reason is there is that is almost self contained, in the sense that the user has only to add the pagy-responsive.js
and the helper will take care of the rest.
Of course your PR would be welcome! However, please, keep in mind this 2 concepts:
- the changes should not require any more writing from the user if possible (and I think it is)
- the changes should be generic as much as possible (e.g.
"turbolink:load"
would be very specific)
If you have different possible alternative about how to implement it, please, feel free to discuss it in the chat in advance.
Thanks!
from pagy.
What about using a nonce
? Maybe passing it as an extra variable, so it will become totally optional and its generation will be up to the user.
from pagy.
Actually, the only advantage of a nonce
is that it wouldn't break the current implementation, but using it is probably more complex than using your approach of removing the inline script all together.
We could create a PagyResponsiveLoad
function that will encapsulate the code for executing all the PagyReponsive
calls (your code), and it could be used in an addEventListener
like for example:
window.addEventListener("turbolinks:load", PagyReponsiveLoad)
That will break the current implementation and require to write an extra line, but it would be quite easy to use.
Waiting for your PR ;)
from pagy.
My WIP: Bahanix@dc0f24e
I had to replace a lot of simple-quotes and double-quotes since valid JSON need double-quotes for strings and keys to be parsed through JSON.parse
. (I still did not updated tests for this quite painful change)
For testing purpose, I am writting the JS part in my app before adding it in Pagy:
Array.from(document.getElementsByClassName("pagy-responsive")).forEach(function(pagination) {
PagyResponsive.apply(null, JSON.parse(pagination.innerHTML));
});
Note that function.apply(null, array)
is a JS equivalent to ruby function(*array)
. I think it may be useful if we end by using this pattern for every Pagy JS extra that currently inject JS in the view.
So, it correctly triggers the Pagy render method on resize, but it does nothing. At this point I had no idea why, so I disabled CSP to give it a try without my WIP. It doesn't work, because my JS is included in the bottom of my <body>
for performance purpose, so the PagyResponsive
is still not defined when the Pagy <script>
are injected. I think it makes this PR a bit more essential!
So, still for testing purpose, I moved my application.js
to the <head>
and it still not work. At this point I have no more idea to continue my work, I take a break :)
from pagy.
@ddnexus it works perfectly!
from pagy.
Great then. Thanks.
from pagy.
Related Issues (20)
- Docs: Which branch should PRs be made against? HOT 3
- Docs: Update performance metrics HOT 5
- Trim doesn't call with pagy_nav_js when first page is active
- Bug: Adapt with Mongoid add extention HOT 1
- Bug: Pagy::Backend#pagy_get_vars `count_args` gets ignored HOT 3
- Docs: https://ddnexus.github.io/pagy/quick-start/#configure HOT 1
- Bug: Missing initializer in documentation HOT 1
- Bug: wrong number of arguments (given 2, expected 0) HOT 2
- Bug: wrong number of arguments (given 2, expected 0) HOT 1
- Bug: Pagy not working with Geocoder gem
- Bug: Undocumented backwards-incompatible change of empty "page" parameter introduced in 6.4.0 HOT 3
- Docs: lost section about wrap existing pagination with pagy_calendar HOT 1
- Bug: Request for Pagy Gem: Making Commands Platform Independent HOT 1
- Bug: Pagy 8.4.0 is broken with MS SQL server HOT 18
- Bug: Only Limit 1 Query HOT 3
- Documentation: `anchor_string` option in `pagy_bootstrap_nav` (example from documentation) doesn't appear to be working HOT 1
- Docs: Some improvements in the documentation
- Bug: pagy_nav does not support `fragment` HOT 1
- Bug: Crashes when running rails server after upgrade HOT 2
- Bug: Anchor_string does not apply to disabled anchors HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pagy.