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

better handling of beforeSend #32

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
15 changes: 10 additions & 5 deletions pjax-standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@
// Add link HREF to object
options.url = node.href;

// Add link reference to object allowing beforeSend access to clicked node
options.node = node;

// If PJAX data is specified, use as container
if(node.getAttribute('data-pjax')) {
options.container = node.getAttribute('data-pjax');
Expand All @@ -177,6 +174,10 @@
if(event.preventDefault){ event.preventDefault(); }else{ event.returnValue = false; }
// Take no action if we are already on said page?
if(document.location.href === options.url) return false;
// Store the source click event
options.srcEvent = event;
// A shortcut to the clicked node
options.srcNode = event.target;
// handle the load.
internal.handle(options);
});
Expand Down Expand Up @@ -340,8 +341,12 @@
*/
internal.handle = function(options) {

// Fire beforeSend Event.
internal.triggerEvent(options.container, 'beforeSend', options);
// Allow early abort in the beforeSend function.
if (options.beforeSend){
if(options.beforeSend(options) === false) {
return;
}
}

// Do the request
internal.request(options.url, function(html, headers) {
Expand Down