Hi,

I added support for the HTML5 history API to update the URL when facets are clicked as well as history support so people can use the 'back' button in their browser.

NOTE: This patch needs to be applied after this one (for Facet API Pretty Paths support)

Thanks!
drclaw

UPDATE:
Patch that adds support of browser history

Check status report page to get more info.
1. If there is not installed libraries module: https://sc-cdn.scaleengine.net/i/36b0658cdc4782a0b7beef06aa2dfa87.png
2. If libraries module installed but history.js not found: https://sc-cdn.scaleengine.net/i/b8cf0e9d8eb87546204e7421b186aa9c.png
3. If libraries module installed and history.js found: https://sc-cdn.scaleengine.net/i/c3812a240630c51bcba6908e90050c18.png
Thanks!
Loparev

Comments

eugene.ilyin’s picture

Status:Active» Postponed

This task is postponed

eugene.ilyin’s picture

Category:Feature request» Plan
Issue summary:View changes
rich.3po’s picture

Hi - just wondering if theres been any update on this one? I'm trying to make filter-enabled pages linkable and bookmarkable (ie RESTful), so that they can be linked to with pre-enabled filters from other content pages

The back-browsing functionality would also be nice, but not essential in my case

thanks

sachbearbeiter’s picture

+1 would be really useful to have ...
otherwise you have to open the full nodes via ajax or in a new window ...

umakart’s picture

For a search with more than 10 facets each with lot of options the back-browsing functionality would be really important. Please!

eugene.ilyin’s picture

Seems it's important feature. I'll try to find time to do it.

eugene.ilyin’s picture

Status:Postponed» Active
idebr’s picture

Ideally this feature would be compatible with Views ajax history or even let that module do the heavy lifting.

idebr’s picture

Status:Active» Needs review
StatusFileSize
new784 bytes

Attached patch adds integration with the Views ajax history. For this patch to work correctly, you also need the patch from #2610240: Allow other modules to use their own ajax urls

gunwald’s picture

Patch in #9 does not work for me.

Attached patch adds integration with the Views ajax history. For this patch to work correctly, you also need the patch from #2610240: Allow other modules to use their own ajax urls

I did as suggested, both patches were applied cleanly, but can't see any effect.

Loparev’s picture

StatusFileSize
new6.07 KB

Hi. I have "ported" this patch from @drclaw for 7.x-3.4 (maybe it can be applied to 7.x-3.x dev).

Now all successful ajax requests from facets pushes into html5 browser history. And if click on back button then view would be refreshed with previous selected facets. It works for me.

Could someone check and review it?

Loparev’s picture

Assigned:Unassigned» Loparev
gunwald’s picture

Seems to work as expected. I could apply patch to 7.x-3.4:

git apply -v ajax_facets-html5-states-2105177-11.patch
Checking patch misc/ajax_facets.js...
warning: misc/ajax_facets.js has type 100755, expected 100644
Applied patch misc/ajax_facets.js cleanly.

Facets are pushed to history updating the URL.

Thank you! Please commit this patch as soon as possible.

Loparev’s picture

I have improved patch: for now it uses history.js library. It means that ajax history functionality will work in html4 browsers. But it also means that ajax_facets module has dependencies: libraries module.

So, before applying this patch you need to:
1. Download and install libraries module.
2. Download and unpack history js library to sites/all/libraries/history.js (or another libraries) directory.

I think it is justified to use libraries module and history.js library. Because for now there is a lot of html4 browsers in which history feature does not work.

Here is the patch.

Loparev’s picture

StatusFileSize
new8.39 KB
new1.74 KB

Sorry, there are some errors in previous patch. Fixed.

Loparev’s picture

Version:7.x-2.x-dev» 7.x-3.4
BR0kEN’s picture

+++ b/misc/ajax_facets.js
@@ -543,10 +543,22 @@
+    $(window).unbind('statechange', Drupal.ajax_facets.reactOnStateChange);

Do you really need to wrap window object into jQuery twice per function call? I guess the invocation of $(window) could be moved above the function.

Loparev’s picture

You are right. There should be

var $window = $(window);

and then

$window.bind(...);
...
$window.unbind(...);
Loparev’s picture

  1. Code refactoring
  2. @BR0kEN review fix
  3. Fixed bug with initial binding to "statechange" event
Loparev’s picture

Loparev’s picture

Issue summary:View changes
Loparev’s picture

Issue summary:View changes
Loparev’s picture

StatusFileSize
new8.45 KB
new354 bytes

Sorry, one problem was found in previous patch. Fixed.

Loparev’s picture

Issue summary:View changes
Loparev’s picture

StatusFileSize
new11.25 KB
new8.93 KB

it's me again)

Finally, I've done (I hope) work on this patch.

For now this feature works fine without any hard dependencies to libraries module and history.js library. It means that if history.js library available then it would be used. If not - HTML5 history API would be used. If browser does not support HTML5 history API then nothing would happen (like default ajax_facets behaviour).

So, here is a final patch.

Loparev’s picture

@gunwald, could you check this patch and confirm all works as expected without any problems?

Loparev’s picture

Issue summary:View changes
Loparev’s picture

Issue summary:View changes
Loparev’s picture

Issue summary:View changes
umakart’s picture

@Loparev Many, many thanks for your work. I apply your latest patch(#25) and everything act as expected.
This functionality is an urgent need for every search page with ajax_facets. Please commit this patch as soon as possible!

gunwald’s picture

I tired to apply patch in #25 (on fresh 7.x-3.4), but got the following error:

ajax_facets# git apply -v ajax_facets-html5-states-history-js-2105177-25.patch
Checking patch ajax_facets.install...
error: ajax_facets.install: No such file or directory
Checking patch ajax_facets.module...
warning: ajax_facets.module has type 100755, expected 100644
Checking patch misc/ajax_facets.js...
warning: misc/ajax_facets.js has type 100755, expected 100644

After putting an empty "ajax_facets.install" in the folder, the patch applies.

Loparev’s picture

@gunwald, try
patch -p1 < ajax_facets-html5-states-history-js-2105177-25.patch

I suppose git apply can't create new file

Loparev’s picture

Unfortunately one more bug was found in this patch.

If you have additional query parameters on your search page and if you click on facets then that additional parameters would be replaced by facets parameters.

Steps to reprpduce:
1. Load search page with some query parameter: http://your.site/search-view?some-aditional-parameter=test
2. Click on some facets.
3. Your some-aditional-parameter would be replaced by facet parameters: http://your.site/search-view?clicked-facet-id=value

This problem was fixed in this patch.

Loparev’s picture

Issue summary:View changes
Loparev’s picture

StatusFileSize
new13.53 KB
new1.17 KB

// Facetapi module has a bug when facet name encodes twice.
    // For example to get this facet work 'category:name:pineapple' it should be 'category%253Aname%3Apineapple'.
    // It means that first ':' was encoded twice. Why we don't patch facetapi? Because a lot of sites have already
    // used facetapi module and they links (with wrong encoded facets names) has been indexed by search engines
    // like Bing or Google. So we just bring this behaviour to ajax_facets module.
    // Encode each facet filter name (it have already encoded once in FacetapiAjaxWidgetCheckboxes::buildListItems()).
Loparev’s picture

Issue summary:View changes

  • eugene.ilyin committed afa6d2f on 7.x-3.x authored by Loparev
    Issue #2105177 by Loparev, idebr, drclaw, eugene.ilyin: Update URL and...
eugene.ilyin’s picture

Status:Needs review» Needs work

@Loparev, thank you for your work. It's really great efforts.
I've applied your patch with small corrections.
But I've found a bug. If I'll select some options for facets, then results will be updated. But if I'll go back via browser buttons, the results and facets will not be updated. I have no history.js but I don't think that it needs for my chrome 47.

Could you help with it?