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 is contained in:
@@ -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()
|
||||
})
|
||||
|
||||
@@ -13,6 +13,13 @@
|
||||
Go to <a href="page2.html" class="js-Pjax">Page 2</a> or <a href="page3.html" class="js-Pjax">Page 3</a> and view your console to see Pjax events.
|
||||
Clicking on <a href="index.html">this page</a> will just reload the page entirely.
|
||||
|
||||
<h2>Manual URL loading</h2>
|
||||
|
||||
You can use Pjax's <i>loadUrl</i> method to manually load a URL. Click the buttons below to try it out!<br /><br />
|
||||
|
||||
<button data-manual-trigger>loadUrl with current options</button><br /><br />
|
||||
<button data-manual-trigger data-manual-trigger-override="true">loadUrl with overridden options (no cache busting)</button>
|
||||
|
||||
<h2>Forms</h2>
|
||||
|
||||
You can submit GET or POST forms with Pjax! Go to the <a href="forms.html">form examples</a> to try it out.
|
||||
|
||||
Reference in New Issue
Block a user