2015-11-13 10:43:22 +11:00
|
|
|
/* global Pjax */
|
2018-03-06 10:06:38 +00:00
|
|
|
var pjax;
|
|
|
|
|
var initButtons = function() {
|
2019-02-11 23:17:28 -05:00
|
|
|
var buttons = document.querySelectorAll("button[data-manual-trigger]");
|
2018-03-06 10:06:38 +00:00
|
|
|
|
|
|
|
|
if (!buttons) {
|
2019-02-11 23:17:28 -05:00
|
|
|
return;
|
2018-03-06 10:06:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// jshint -W083
|
|
|
|
|
for (var i = 0; i < buttons.length; i++) {
|
|
|
|
|
buttons[i].addEventListener("click", function(e) {
|
2019-02-11 23:17:28 -05:00
|
|
|
var el = e.currentTarget;
|
2018-03-06 10:06:38 +00:00
|
|
|
|
|
|
|
|
if (el.getAttribute("data-manual-trigger-override") === "true") {
|
|
|
|
|
// Manually load URL with overridden Pjax instance options
|
2019-02-11 23:17:28 -05:00
|
|
|
pjax.loadUrl("/example/page2.html", { cacheBust: false });
|
|
|
|
|
} else {
|
2018-03-06 10:06:38 +00:00
|
|
|
// Manually load URL with current Pjax instance options
|
2019-02-11 23:17:28 -05:00
|
|
|
pjax.loadUrl("/example/page2.html");
|
2018-03-06 10:06:38 +00:00
|
|
|
}
|
2019-02-11 23:17:28 -05:00
|
|
|
});
|
2018-03-06 10:06:38 +00:00
|
|
|
}
|
|
|
|
|
// jshint +W083
|
2019-02-11 23:17:28 -05:00
|
|
|
};
|
2018-03-06 10:06:38 +00:00
|
|
|
|
2019-02-11 23:17:28 -05:00
|
|
|
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() {
|
2019-02-11 23:17:28 -05:00
|
|
|
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() {
|
2019-02-11 23:17:28 -05:00
|
|
|
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() {
|
2019-02-11 23:17:28 -05:00
|
|
|
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() {
|
2019-02-11 23:17:28 -05:00
|
|
|
console.log("Event: pjax:success", arguments);
|
2018-03-06 10:06:38 +00:00
|
|
|
|
|
|
|
|
// Init page content
|
2019-02-11 23:17:28 -05:00
|
|
|
initButtons();
|
|
|
|
|
});
|
2015-11-13 10:40:59 +11:00
|
|
|
|
2015-11-13 10:43:22 +11:00
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
2018-03-06 10:06:38 +00:00
|
|
|
// Init Pjax instance
|
|
|
|
|
pjax = new Pjax({
|
2017-12-19 13:58:22 +01:00
|
|
|
elements: [".js-Pjax"],
|
2018-03-02 20:25:08 +00:00
|
|
|
selectors: [".body", "title"],
|
2018-03-06 10:06:38 +00:00
|
|
|
cacheBust: true
|
2019-02-11 23:17:28 -05:00
|
|
|
});
|
|
|
|
|
console.log("Pjax initialized.", pjax);
|
2018-03-06 10:06:38 +00:00
|
|
|
|
|
|
|
|
// Init page content
|
2019-02-11 23:17:28 -05:00
|
|
|
initButtons();
|
|
|
|
|
});
|