search: factor out javascript from macro

Less inline scripts.

**nb** it doesn't fix: #1968
It could be excluded as it should go into invenio-kwalitee.