Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native support beforeSend and fix for asynchronous requests #423

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions jquery.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ function pjax(options) {
}

var timeoutTimer

if(typeof options.beforeSend === 'function'){
if(!options.beforeSend()) {
return false;
}
};

options.beforeSend = function(xhr, settings) {
// No timeout for non-GET requests
Expand Down Expand Up @@ -281,6 +287,7 @@ function pjax(options) {
state: pjax.state,
previousState: previousState
})
executeScriptTags(container.scripts)
context.html(container.contents)

// FF bug: Won't autofocus fields that are inserted via JS.
Expand All @@ -293,8 +300,6 @@ function pjax(options) {
autofocusEl.focus();
}

executeScriptTags(container.scripts)

// Scroll to top by default
if (typeof options.scrollTo === 'number')
$(window).scrollTop(options.scrollTo)
Expand Down Expand Up @@ -723,7 +728,12 @@ function executeScriptTags(scripts) {
var script = document.createElement('script')
script.type = $(this).attr('type')
script.src = $(this).attr('src')
document.head.appendChild(script)
if(pjax.options.async) {
document.head.appendChild(script)
}
else {
$(document.body).append(script)
}
})
}

Expand Down