Skip to content

Commit 153262e

Browse files
committed
Add note about reinitializing plugins after navigation
Fixes #560
1 parent 5deb2f8 commit 153262e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,24 @@ $(document).on('pjax:timeout', function(event) {
295295

296296
## Advanced configuration
297297

298+
### Reinitializing plugins/widget on new page content
299+
300+
The whole point of pjax is that it fetches and inserts new content _without_
301+
refreshing the page. However, other jQuery plugins or libraries that are set to
302+
react on page loaded event (such as `DOMContentLoaded`) will not pick up on
303+
these changes. Therefore, it's usually a good idea to configure these plugins to
304+
reinitialize in the scope of the updated page content. This can be done like so:
305+
306+
``` js
307+
$(document).on('ready pjax:end', function(event) {
308+
$(event.target).initializeMyPlugin()
309+
})
310+
```
311+
312+
This will make `$.fn.initializeMyPlugin()` be called at the document level on
313+
normal page load, and on the container level after any pjax navigation (either
314+
after clicking on a link or going Back in the browser).
315+
298316
### Response types that force a reload
299317

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

0 commit comments

Comments
 (0)