Skip to content
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

Refactor site search to use custom element #218

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

paulrobertlloyd
Copy link
Collaborator

The JavaScript for the site search is a bit of a relic, so updated so that:

  • Uses Class
  • Uses Fetch API over XMLHttpRequest
  • Uses a custom element
  • No longer uses ‘mustard cut’ feature detection, as loaded as a module

@paulrobertlloyd paulrobertlloyd changed the title Refactor site search to use custom component Refactor site search to use custom element Dec 11, 2023
@paulrobertlloyd paulrobertlloyd force-pushed the refactor-site-search branch 2 times, most recently from 4b547bd to 6618726 Compare December 11, 2023 21:43
@paulrobertlloyd paulrobertlloyd added this to the 6.0 milestone Dec 12, 2023
@paulrobertlloyd paulrobertlloyd added enhancement New feature or request javascript Pull requests that update Javascript code labels Dec 12, 2023
@paulrobertlloyd paulrobertlloyd merged commit df1efbf into main Dec 12, 2023
2 checks passed
@paulrobertlloyd paulrobertlloyd deleted the refactor-site-search branch December 12, 2023 23:06
@frankieroberto
Copy link
Contributor

frankieroberto commented Dec 12, 2023

@paulrobertlloyd i know this has been merged now, but did you consider using the new <search> element rather than a custom one? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/search

@paulrobertlloyd
Copy link
Collaborator Author

The search element serves a different purpose, but you’re right that it should be included. I’ll use it as a wrapper inside the custom element should it serve as a search element and not a link to the sitemap.

Custom elements are sooooo brilliant, though. I’m 1000% sold on them, and have basically added them to everything. 😎

@frankieroberto
Copy link
Contributor

@paulrobertlloyd I must admit I’ve not looked into them properly yet. Instinctively I shudder at the memory of the bad old days of browser wars and proprietary tags, but maybe the JavaScript API makes these more sensible.

@paulrobertlloyd
Copy link
Collaborator Author

It’s basically DOMContentLoaded but leaning on browser smarts for when to load (and unload) enhancements, and provide an easy way to provide fallback content.

Like all tools, custom elements can be used for good or evil, but the current interest in what are being dubbed ‘HTML Web Components’ means that they basically make progressive enhancement an attractive proposition. This is a good place to get started: https://gomakethings.com/the-elevator-pitch-for-web-components/

@paulrobertlloyd
Copy link
Collaborator Author

(Meanwhile, I’ve broken the site at 11:30pm… 🙄)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants