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 #35 ONLY for 7.x-3.4 branch
Patch that adds support of browser history (for 7.x-3.4 branch)
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
| Comment | File | Size | Author |
|---|---|---|---|
| #60 | readme.patch | 974 bytes | loparev |
| #35 | interdiff.txt | 1.17 KB | loparev |
| #35 | ajax_facets-html5-states-history-js-2105177-35.patch | 13.53 KB | loparev |
| #25 | ajax_facets-html5-states-history-js-2105177-25.patch | 11.25 KB | loparev |
| #11 | ajax_facets-html5-states-2105177-11.patch | 6.07 KB | loparev |
Comments
Comment #1
eugene.ilyin commentedThis task is postponed
Comment #2
eugene.ilyin commentedComment #3
rich.3po commentedHi - 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
Comment #4
sachbearbeiter commented+1 would be really useful to have ...
otherwise you have to open the full nodes via ajax or in a new window ...
Comment #5
umakart commentedFor a search with more than 10 facets each with lot of options the back-browsing functionality would be really important. Please!
Comment #6
eugene.ilyin commentedSeems it's important feature. I'll try to find time to do it.
Comment #7
eugene.ilyin commentedComment #8
idebr commentedIdeally this feature would be compatible with Views ajax history or even let that module do the heavy lifting.
Comment #9
idebr commentedAttached 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
Comment #10
gunwald commentedPatch in #9 does not work for me.
I did as suggested, both patches were applied cleanly, but can't see any effect.
Comment #11
loparev commentedHi. 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?
Comment #12
loparev commentedComment #13
gunwald commentedSeems to work as expected. I could apply patch to 7.x-3.4:
Facets are pushed to history updating the URL.
Thank you! Please commit this patch as soon as possible.
Comment #14
loparev commentedI 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.
Comment #15
loparev commentedSorry, there are some errors in previous patch. Fixed.
Comment #16
loparev commentedComment #17
br0kenDo you really need to wrap
windowobject into jQuery twice per function call? I guess the invocation of$(window)could be moved above the function.Comment #18
loparev commentedYou are right. There should be
var $window = $(window);and then
Comment #19
loparev commentedComment #20
loparev commentedComment #21
loparev commentedComment #22
loparev commentedComment #23
loparev commentedSorry, one problem was found in previous patch. Fixed.
Comment #24
loparev commentedComment #25
loparev commentedit'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.
Comment #26
loparev commented@gunwald, could you check this patch and confirm all works as expected without any problems?
Comment #27
loparev commentedComment #28
loparev commentedComment #29
loparev commentedComment #30
umakart commented@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!
Comment #31
gunwald commentedI tired to apply patch in #25 (on fresh 7.x-3.4), but got the following error:
After putting an empty "ajax_facets.install" in the folder, the patch applies.
Comment #32
loparev commented@gunwald, try
patch -p1 < ajax_facets-html5-states-history-js-2105177-25.patchI suppose
git applycan't create new fileComment #33
loparev commentedUnfortunately 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-parameterwould be replaced by facet parameters: http://your.site/search-view?clicked-facet-id=valueThis problem was fixed in this patch.
Comment #34
loparev commentedComment #35
loparev commentedComment #36
loparev commentedComment #38
eugene.ilyin commented@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?
Comment #39
loparev commentedHi @eugene.ilyin.
I think I found problem.
You changed patch in that way that
Drupal.ajax_facets.initHistoryState($this);calls fromDrupal.ajax_facets.sendAjaxQuery. But it's incorrect because we want init history only when user click on some kind of facets (checkbox, select, slider, link). AndDrupal.ajax_facets.sendAjaxQuerycalls fromDrupal.ajax_facets.reactOnStateChangetoo and it's wrong.So to resolve this issue you need to remove call
Drupal.ajax_facets.initHistoryState($this);fromDrupal.ajax_facets.sendAjaxQueryand put it to allDrupal.ajax_facets.process*functions (as it was). It works for me.Compare
revert_this.patchandapply_this.patch(I've applied patch from your commit afa6d2f against 3.4 version to create this diff so inapply_this.patchexists some extra changes. But try to focus onDrupal.ajax_facets.sendAjaxQueryandDrupal.ajax_facets.initHistoryState($this);differences).Please let me know if it doesn't work for you.
(By the way. I've tested it against 7.x-3.4 version of ajax_facets module as I've mentioned it in #11 comment. But I believe it should works for dev too)
Comment #40
eugene.ilyin commentedHi @loparev, I've committed the changes. Seems it's solves problem that you've mentioned. But it's still not working. Could you check the reason of this trouble?
Comment #41
loparev commentedHi.
1. Install history.js and check it again. Is it works now?
2. Try in another browser. Still not working?
3. install 3.4 ajax_facets and apply patch 35. Does it work for you? If it works for 3.4 with patch from #35 we need port this patch for 7.x-3.x-dev.
It strange. I'll check it tonight.
Comment #42
eugene.ilyin commentedI'll try to check it tomorrow
Sorry, but all patches should be for dev versions. Now we have pretty big difference between 3.4 and 3.x-dev.
When I want to check some patch, I always applying it for dev version.
Comment #43
loparev commentedOops and oops
Some misunderstanding.
Ok, I'll "port" patch for dev branch as soon as possible. I'm sure it is not so hard.
Comment #44
loparev commentedYeah, it's my fault.
I work on a project and we use stable release of ajax_facets and I've wrote patch for stable release.
You're right, patch should be applyeble to dev.
Comment #45
eugene.ilyin commentedYes, it should be 7.x-3.x-dev.
So I've already pushed this half working patch into dev branch to avoid some delays with applying this functionality. And we don't have back way :D
Could you just prepare an additional corrections for 7.x-3.x-dev, but not new patch from scratch?
Comment #46
loparev commentedSure)
Comment #47
loparev commentedHere is a fix for 7.x-3.x-dev branch. I hope it helps)
Comment #48
loparev commentedComment #49
loparev commentedComment #50
loparev commentedComment #52
eugene.ilyin commentedWell, it works for me with the history.js. Seems this library is required because of my doctype is for html 4.
I've found another error:
1. Find something with exposed form (by ajax) - I have 2 results.
2. I should click on the facet option (checkboxes) twice to activate it.
Comment #53
loparev commentedI'll check it
Comment #54
loparev commentedFirst.
Works for me.
Status report: https://screencloud.net/v/df8S
Browser: https://screencloud.net/v/41AJ
May be it's really because of your doctype.
Second.
This issue related to Trouble with tooltip and to Title of the facet option in widget "Ajax multiple checkboxes" isn't clickable
Look at chronology of events:
1. First you had issue "Trouble with tooltip" where you've removed
#idfrom checkboxes in this commit2. And then you've got another problem "Title of the facet option in widget "Ajax multiple checkboxes" isn't clickable". It's because of
#idattribute in form element. Without#idDrupal renders element title like<label>html element but withoutforattribute (if user clicks on label withforattribute then event for input would be triggered automatically without any js). And you've commited this patchThis is the real problem. Because checkbox input triggers a lot of times because of that js (even if you click on input that js would trigger another one event). I suppose it's not ok and we should use default behaviour with
forattribute for label.This patch will help. But if you will get "Trouble with tooltip" issue again I think it's really another bug and it doesn't related to history issue and you should fix it in another thread.
Comment #55
loparev commentedComment #57
eugene.ilyin commentedYes, you're right. Now all works fine. Thank you for this great job.
I think that we can close the issue.
If somebody will have troubles with this functionality, please create separate issue. But would be useful to relate the new issue with this one.
Comment #58
eugene.ilyin commentedSorry, I forgot about small but important thing. Could you prepare info for README.txt and for page of module to let users know about supporting of History API. Just in two words.
Comment #59
loparev commentedYes, sure.
Comment #60
loparev commentedYou can add this info to project page
Comment #61
sachbearbeiter commentedFrom me also: "Thank you for this great job."
Comment #62
eugene.ilyin commentedThank you all guys!
Comment #63
gunwald commentedI tried the actual dev, but it does not work at all. I get the following JS error:
Uncaught TypeError: Cannot read property 'length' of undefinedb.extend.each @ jquery-1.9.1.min.js:3Drupal.ajax_facets.getFacetValues @ ajax_facets.js?o2t0vd:386Drupal.ajax_facets.bindResetLink @ ajax_facets.js?o2t0vd:181Drupal.behaviors.ajax_facets.attach @ ajax_facets.js?o2t0vd:96(anonymous function) @ drupal.js?o2t0vd:76b.extend.each @ jquery-1.9.1.min.js:3Drupal.attachBehaviors @ drupal.js?o2t0vd:74(anonymous function) @ authcache_p13n.js?o2t0vd:29b.extend.each @ jquery-1.9.1.min.js:3(anonymous function) @ authcache_p13n.js?o2t0vd:28b.extend.each @ jquery-1.9.1.min.js:3b.fn.b.each @ jquery-1.9.1.min.js:3$.fn.authcacheP13nReplaceWith @ authcache_p13n.js?o2t0vd:9(anonymous function) @ authcache_ajax.js?o2t0vd:56b.extend.each @ jquery-1.9.1.min.js:3b.fn.b.each @ jquery-1.9.1.min.js:3(anonymous function) @ authcache_ajax.js?o2t0vd:55(anonymous function) @ authcache_ajax.js?o2t0vd:28b.extend.each @ jquery-1.9.1.min.js:3$.ajax.success @ authcache_ajax.js?o2t0vd:27c @ jquery-1.9.1.min.js:3p.fireWith @ jquery-1.9.1.min.js:3k @ jquery-1.9.1.min.js:5r @ jquery-1.9.1.min.js:5The page reloads when I click on a Ajax facet.
Comment #64
eugene.ilyin commentedComment #65
loparev commentedWhy needs work? It worked. Are you serious?. There was two or three commits after this commit. May be lets look in to that commits? There was js refactoring.
Comment #66
eugene.ilyin commentedPlease don't panic :) I just afraid that if it will be with status "fixed" we will loose this issue.
Maybe better is create the new issue.
@gunwald, could you do it?
Comment #67
loparev commentedYep. Create a new issue and relate it to this one.
Comment #68
loparev commented@gunwald, the latest dev works fine for me. I have jQuery 1.10.2 on my page with search view. Could you provide more details?
Comment #69
loparev commentedAny updates?
Comment #70
loparev commented@gunwald, did you find the problem?
Comment #71
eugene.ilyin commentedI think we close this issue.
@anybody, please do not open this issue again. If you will have troubles, please report them into the new issue.
Comment #72
jagermonster commentedGreat work, tested and working