Add more documentation and tests for options.currentUrlFullReload

Closes #17
This commit is contained in:
Behind The Math
2018-02-01 14:02:35 -05:00
parent 2ec4c14a46
commit a2aced4f36
3 changed files with 28 additions and 0 deletions

View File

@@ -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. 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`) ##### `timeout` (Integer, default: `0`)
The timeout in milliseconds for the XHR requests. Set to 0 to disable the timeout. The timeout in milliseconds for the XHR requests. Set to 0 to disable the timeout.

View File

@@ -24,6 +24,7 @@ module.exports = function(options) {
options.cacheBust = (typeof options.cacheBust === "undefined") ? true : options.cacheBust options.cacheBust = (typeof options.cacheBust === "undefined") ? true : options.cacheBust
options.debug = options.debug || false options.debug = options.debug || false
options.timeout = options.timeout || 0 options.timeout = options.timeout || 0
options.currentUrlFullReload = (typeof options.currentUrlFullReload === "undefined") ? false : options.currentUrlFullReload
// We cant replace body.outerHTML or head.outerHTML. // We cant replace body.outerHTML or head.outerHTML.
// It creates a bug where a new body or head are created in the DOM. // It creates a bug where a new body or head are created in the DOM.

View File

@@ -23,6 +23,7 @@ tape("test parse initalization options function", function(t) {
t.equal(pjax.options.scrollRestoration, true) t.equal(pjax.options.scrollRestoration, true)
t.equal(pjax.options.cacheBust, true) t.equal(pjax.options.cacheBust, true)
t.equal(pjax.options.debug, false) t.equal(pjax.options.debug, false)
t.equal(pjax.options.currentUrlFullReload, false)
t.end() t.end()
}) })