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

fix(prefetch): allow event bubbling (progressive) #355

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ Or, for the opposite effect, use something like @cihadturhan's [jQuery.aim](http
$('#main').smoothState({ prefetchOn: 'aim' });
```

### `prefetchBubblesOn`

The name of the events that are to bubble up to their parents when prefetching.

```js
// Default
$('#main').smoothState({ prefetchBubblesOn: 'mouseover' });
```

By default, `smoothState` will stop propagation of prefetch events. This allows you to customize events that will not be stopped by the prefetch handler.

### `locationHeader`

A field name to lookup among the headers from the HTTP response to alert smoothState.js of any redirected URL.
Expand Down
9 changes: 7 additions & 2 deletions src/jquery.smoothState.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@

/** The name of the event we will listen to from anchors if we're prefetching */
prefetchOn: 'mouseover touchstart',

/** The name of the events that are to bubble up to their parents when prefetching. */
prefetchBubblesOn: '',

/** jQuery selector to specify elements which should not be prefetched */
prefetchBlacklist: '.no-prefetch',
Expand Down Expand Up @@ -640,7 +643,9 @@
$anchor = $(event.currentTarget);

if (utility.shouldLoadAnchor($anchor, options.blacklist, options.hrefRegex) && !isTransitioning) {
event.stopPropagation();
if(options.prefetchBubblesOn.indexOf(event.type) === -1){
event.stopPropagation();
}
request = utility.translate($anchor.prop('href'));
request = options.alterRequest(request);
fetch(request);
Expand Down Expand Up @@ -835,4 +840,4 @@
/* expose the default options */
$.fn.smoothState.options = defaults;

}));
}));