loadUrl enhancements (#134)

`loadUrl` enhancements

- Make `options` parameter optional
- Allow partial overriding of instance options when calling `loadUrl` directly
- Make `requestOptions` optional
- Document `loadUrl` usage and provide examples
This commit was merged in pull request #134.
This commit is contained in:
Robin North
2018-03-06 10:06:38 +00:00
committed by GitHub
parent f98f2dd63b
commit 05fa833169
15 changed files with 148 additions and 62 deletions

View File

@@ -1,4 +1,31 @@
/* global Pjax */
var pjax;
var initButtons = function() {
var buttons = document.querySelectorAll("button[data-manual-trigger]")
if (!buttons) {
return
}
// jshint -W083
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", function(e) {
var el = e.currentTarget
if (el.getAttribute("data-manual-trigger-override") === "true") {
// Manually load URL with overridden Pjax instance options
pjax.loadUrl("/example/page2.html", {cacheBust: false})
}
else
{
// Manually load URL with current Pjax instance options
pjax.loadUrl("/example/page2.html")
}
})
}
// jshint +W083
}
console.log("Document initialized:", window.location.href)
document.addEventListener("pjax:send", function() {
@@ -15,14 +42,20 @@ document.addEventListener("pjax:error", function() {
document.addEventListener("pjax:success", function() {
console.log("Event: pjax:success", arguments)
// Init page content
initButtons()
})
document.addEventListener("DOMContentLoaded", function() {
var pjax = new Pjax({
// Init Pjax instance
pjax = new Pjax({
elements: [".js-Pjax"],
selectors: [".body", "title"],
cacheBust: true,
// currentUrlFullReload: true,
cacheBust: true
})
console.log("Pjax initialized.", pjax)
// Init page content
initButtons()
})