Files
pjax/example/example.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-11-13 10:43:22 +11:00
/* 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);
2015-11-13 10:40:59 +11:00
2015-11-13 10:43:22 +11:00
document.addEventListener("pjax:send", function() {
console.log("Event: pjax:send", arguments);
});
2015-11-13 10:40:59 +11:00
2015-11-13 10:43:22 +11:00
document.addEventListener("pjax:complete", function() {
console.log("Event: pjax:complete", arguments);
});
2015-11-13 10:40:59 +11:00
2015-11-13 10:43:22 +11:00
document.addEventListener("pjax:error", function() {
console.log("Event: pjax:error", arguments);
});
2015-11-13 10:40:59 +11:00
2015-11-13 10:43:22 +11:00
document.addEventListener("pjax:success", function() {
console.log("Event: pjax:success", arguments);
// Init page content
initButtons();
});
2015-11-13 10:40:59 +11:00
2015-11-13 10:43:22 +11:00
document.addEventListener("DOMContentLoaded", function() {
// Init Pjax instance
pjax = new Pjax({
elements: [".js-Pjax"],
selectors: [".body", "title"],
cacheBust: true
});
console.log("Pjax initialized.", pjax);
// Init page content
initButtons();
});