Add more documentation and tests for options.currentUrlFullReload
Closes #17
This commit is contained in:
26
README.md
26
README.md
@@ -402,6 +402,32 @@ Enables verbose mode. Useful to debug page layout differences.
|
||||
|
||||
When set to true, clicking on a link that points to the current URL will trigger a full page reload.
|
||||
|
||||
The default is `false`, so clicking on such a link will do nothing.
|
||||
If you want to add some custom behavior, add a click listener to the link,
|
||||
and set `preventDefault` to true, to prevent Pjax from receiving the event.
|
||||
|
||||
Here is some sample code:
|
||||
|
||||
```js
|
||||
var links = document.querySelectorAll(".js-Pjax");
|
||||
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
var el = links[i]
|
||||
|
||||
el.addEventListener("click", function(e) {
|
||||
if (el.href === window.location.href.split("#")[0]) {
|
||||
e.preventDefault();
|
||||
console.log("Link to current page clicked");
|
||||
// Custom code goes here.
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
(Note that if `cacheBust` is set to true, the code that checks if the href
|
||||
is the same as the current page's URL will not work, due to the query string
|
||||
appended to force a cache bust).
|
||||
|
||||
##### `timeout` (Integer, default: `0`)
|
||||
|
||||
The timeout in milliseconds for the XHR requests. Set to 0 to disable the timeout.
|
||||
|
||||
@@ -24,6 +24,7 @@ module.exports = function(options) {
|
||||
options.cacheBust = (typeof options.cacheBust === "undefined") ? true : options.cacheBust
|
||||
options.debug = options.debug || false
|
||||
options.timeout = options.timeout || 0
|
||||
options.currentUrlFullReload = (typeof options.currentUrlFullReload === "undefined") ? false : options.currentUrlFullReload
|
||||
|
||||
// We can’t replace body.outerHTML or head.outerHTML.
|
||||
// It creates a bug where a new body or head are created in the DOM.
|
||||
|
||||
@@ -23,6 +23,7 @@ tape("test parse initalization options function", function(t) {
|
||||
t.equal(pjax.options.scrollRestoration, true)
|
||||
t.equal(pjax.options.cacheBust, true)
|
||||
t.equal(pjax.options.debug, false)
|
||||
t.equal(pjax.options.currentUrlFullReload, false)
|
||||
t.end()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user