diff --git a/jquery.pjax.js b/jquery.pjax.js index 28390ffe..4a7c402e 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -169,6 +169,7 @@ function handleSubmit(event, container, options) { // // Returns whatever $.ajax returns. function pjax(options) { + var context; options = $.extend(true, {}, $.ajaxSettings, pjax.defaults, options) if ($.isFunction(options.url)) { @@ -200,6 +201,21 @@ function pjax(options) { return !event.isDefaultPrevented() } + function updateOptions(opts) { + var hasBeenPushed = options.push && !options.replace; + + // Update options + options = $.extend(true, {}, options, opts); + + // Update container + context = options.context = findContainerFor(options.container); + + // Replace state, we were not supposed to push + if (hasBeenPushed && !options.push) { + window.history.replaceState(pjax.state, pjax.state.title, pjax.state.url) + } + } + var timeoutTimer options.beforeSend = function(xhr, settings) { @@ -259,6 +275,8 @@ function pjax(options) { var latestVersion = xhr.getResponseHeader('X-PJAX-Version') + fire('pjax:beforeApply', [xhr, data, updateOptions], {}) + var container = extractContainer(data, xhr, options) var url = parseURL(container.url)