Skip to content

Commit

Permalink
Add note about reinitializing plugins after navigation
Browse files Browse the repository at this point in the history
Fixes #560
  • Loading branch information
mislav committed May 23, 2017
1 parent 5deb2f8 commit 153262e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ $(document).on('pjax:timeout', function(event) {

## Advanced configuration

### Reinitializing plugins/widget on new page content

The whole point of pjax is that it fetches and inserts new content _without_
refreshing the page. However, other jQuery plugins or libraries that are set to
react on page loaded event (such as `DOMContentLoaded`) will not pick up on
these changes. Therefore, it's usually a good idea to configure these plugins to
reinitialize in the scope of the updated page content. This can be done like so:

``` js
$(document).on('ready pjax:end', function(event) {
$(event.target).initializeMyPlugin()
})
```

This will make `$.fn.initializeMyPlugin()` be called at the document level on
normal page load, and on the container level after any pjax navigation (either
after clicking on a link or going Back in the browser).

### Response types that force a reload

By default, pjax will force a full reload of the page if it receives one of the
Expand Down

0 comments on commit 153262e

Please sign in to comment.