From 526a0883a20a6a3f3b188638840ffe1ea170bc9f Mon Sep 17 00:00:00 2001 From: Tim Trinidad Date: Tue, 23 Jan 2018 13:22:31 -0500 Subject: [PATCH] Clone options in attach-link to prevent requestOptions changes from persisting --- lib/proto/attach-form.js | 5 +++-- lib/proto/attach-link.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/proto/attach-form.js b/lib/proto/attach-form.js index 1a0ca83..f6775a2 100644 --- a/lib/proto/attach-form.js +++ b/lib/proto/attach-form.js @@ -6,10 +6,11 @@ var clone = require("../clone") var attrClick = "data-pjax-click-state" var formAction = function(el, event) { - // Since we'll be modifying request options, clone the existing options - // so these changes don't persist + // Since loadUrl modifies options and we may add our own modifications below, + // clone it so the changes don't persist var options = clone(this.options); + // Initialize requestOptions options.requestOptions = { requestUrl: el.getAttribute("action") || window.location.href, requestMethod: el.getAttribute("method") || "GET", diff --git a/lib/proto/attach-link.js b/lib/proto/attach-link.js index 2a0e641..69945bc 100644 --- a/lib/proto/attach-link.js +++ b/lib/proto/attach-link.js @@ -7,6 +7,13 @@ var attrClick = "data-pjax-click-state" var attrKey = "data-pjax-keyup-state" var linkAction = function(el, event) { + // Since loadUrl modifies options and we may add our own modifications below, + // clone it so the changes don't persist + var options = clone(this.options); + + // Initialize requestOptions since loadUrl expects it to be an object + options.requestOptions = {}; + // Don’t break browser special behavior on links (like page in new window) if (event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) { el.setAttribute(attrClick, "modifier") @@ -51,10 +58,9 @@ var linkAction = function(el, event) { this.reload() return } - this.options.requestOptions = this.options.requestOptions || {}; + el.setAttribute(attrClick, "load") - var options = clone(this.options) options.triggerElement = el this.loadUrl(el.href, options) }