Skip to content

Commit

Permalink
[skip ci] update javascript documentation (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
benkoshy authored Apr 29, 2021
1 parent 3f13014 commit e91e4da
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/api/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ If your app uses Webpacker, ensure that the webpacker `erb` loader is installed:
bundle exec rails webpacker:install:erb
```

Then create a `pagy.js.erb` in order to render the content of `pagy.js` and add the event listener into it:
Then create a `pagy.js.erb` (in `app/javascript/packs/`) in order to render the contents of `pagy.js` and add an event listener to it (to allow the library to reinitialise when you click a new link):

```erb
<%= Pagy.root.join('javascripts', 'pagy.js').read %>
window.addEventListener("load", Pagy.init)
window.addEventListener("turbo:load", Pagy.init) # if using turbo-rails OR
# window.addEventListener("turbolinks:load", Pagy.init) # if turbolinks OR
# window.addEventListener("load", Pagy.init) # if using no library
```

and import it in `app/javascript/application.js`:

```js
import '../src/javascripts/pagy.js.erb'
import './pagy.js.erb'
```

**Notice**:
Expand Down

0 comments on commit e91e4da

Please sign in to comment.