Skip to content

Commit

Permalink
searchform not allowed script element #14
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveregger committed Apr 23, 2024
1 parent 7c7923b commit b749e16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
21 changes: 21 additions & 0 deletions content/assets/js/searchform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script>
const site = '{{url}}'.replace(/^https?:\/\//, '');
const siteParameterToUpdate = 'siteParameterToUpdate';

function onSubmit(event) {
if (event.formData.has(siteParameterToUpdate)) {
const siteParameter = event.formData.get(siteParameterToUpdate);
const query = event.formData.get('q');
event.formData.set('q', `${query} ${siteParameter}:${site}`);
event.formData.delete(siteParameterToUpdate);
}
if (event.formData.has('sitesearch')) {
event.formData.set('sitesearch', site);
}
if (event.formData.has('sites')) {
event.formData.set('sites', site);
}
}

document.getElementById("searchForm").addEventListener("formdata", onSubmit);
</script>
22 changes: 1 addition & 21 deletions content/searchform.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,7 @@ <h2>Search {{title}}</h2>
Note: this search searches the current build of {{title}} ({{url}}).
</p>
</div>
<script type="text/javascript" src="assets/js/searchform.js"> </script>

<script>
const site = '{{url}}'.replace(/^https?:\/\//, '');
const siteParameterToUpdate = 'siteParameterToUpdate';

function onSubmit(event) {
if (event.formData.has(siteParameterToUpdate)) {
const siteParameter = event.formData.get(siteParameterToUpdate);
const query = event.formData.get('q');
event.formData.set('q', `${query} ${siteParameter}:${site}`);
event.formData.delete(siteParameterToUpdate);
}
if (event.formData.has('sitesearch')) {
event.formData.set('sitesearch', site);
}
if (event.formData.has('sites')) {
event.formData.set('sites', site);
}
}

document.getElementById("searchForm").addEventListener("formdata", onSubmit);
</script>
</body>
</html>

0 comments on commit b749e16

Please sign in to comment.