From 4b5d4599858aa2d94e9a9650074c6182caf4d44b Mon Sep 17 00:00:00 2001 From: Armel Larcier Date: Fri, 19 Jan 2018 11:06:07 +0100 Subject: [PATCH 1/2] fix(prefetch): allow event bubbling (progressive) Fix #354 https://github.com/miguel-perez/smoothState.js/issues/354 --- src/jquery.smoothState.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/jquery.smoothState.js b/src/jquery.smoothState.js index b14ba7e..9e7a764 100644 --- a/src/jquery.smoothState.js +++ b/src/jquery.smoothState.js @@ -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', @@ -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); @@ -835,4 +840,4 @@ /* expose the default options */ $.fn.smoothState.options = defaults; -})); \ No newline at end of file +})); From 85e7d474c62cd89254fdad798a5482079679c5d3 Mon Sep 17 00:00:00 2001 From: Armel Larcier Date: Fri, 19 Jan 2018 11:06:39 +0100 Subject: [PATCH 2/2] Update README.md Fix #354 --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index fcfb0c5..6b429dc 100644 --- a/README.md +++ b/README.md @@ -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.