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
Add result-scripts event to apply Javascript to search results #3584
Add result-scripts event to apply Javascript to search results #3584
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ThoWagen, I was just talking to @crhallberg about this code, and he suggested that it would make a lot more sense to use an event system here instead of calling a function. If the code that currently calls initResultScripts instead triggered an event, then each module could have its own listener setup in its own init method to listen for that event and take appropriate action. That would greatly decouple the code and make this type of customization cleaner.
What do you think? Is it worth refactoring rather than adding this new mechanism? I think the result would be better, but I'm not sure if it's too much work at this stage.
I'm also requesting a review from @crhallberg in case he has anything to add.
(I'm open to considering this approach if events prove impractical, but I just think we should consider that possibility in a little more detail before moving forward with this solution).
Demian captured my thoughts here. This whole |
@demiankatz @crhallberg I was not aware of VuFind's event system. I just realized that your suggested solution is already implemented just two lines after vufind/themes/bootstrap3/js/search.js Line 347 in 8176e06
I am not sure if the rest of |
@ThoWagen, I'm not sure if it would make sense to hook the existing You're right that we can't initialize the event hook in init, and then also have the event hook call init. I think we'd probably need to refactor the init methods so that there's a separate method like updateContainer(), and then init calls updateContainer and also provides an event listener to call updateContainer() again in response to the appropriate event. |
Note that |
I did not find any reference to the Since it seems to use some arguments of the search.js I added the new |
@ThoWagen We use it, but it can be used by any downstream users to do stuff after results are loaded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, and all tests are passing. I'm going to wait to merge until @crhallberg and/or @EreMaijala have had a chance for another review, just in case I'm overlooking anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks mostly good to me, but I left a comment about the changes I'd still like to see.
Thanks, everyone! I have dismissed @EreMaijala's review since his feedback has clearly been addressed and he's out of office today. I hope he doesn't mind! :-) |
The purpose of this PR is to allow custom script to be run when new results have been loaded via JS. I'm not sure if this is the best solution. So please let me know if this should be done in a different way.