An extremely lightweight and powerful vanilla JavaScript completion suggester.
Tested in Firefox, Safari, Chrome, Opera, Internet Explorer 8+. No dependencies, written in plain JavaScript. Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
This plugin was developed by Pixabay.com - an international repository for sharing free public domain images. We have implemented this piece of software in production on plainJS and we share it - in the spirit of Pixabay - freely with others.
https://cdn.jsdelivr.net/gh/culefa/[email protected]/auto-complete.js https://cdn.jsdelivr.net/gh/culefa/[email protected]/auto-complete.min.js
<script src="https://cdn.jsdelivr.net/gh/culefa/[email protected]/auto-complete.min.js"></script>
<form onsubmit="return false;" class="pure-form" style="border-top: 1px solid #eee;border-bottom:1px solid #eee;background:#fafafa;margin:30px 0;padding:20px 10px;text-align:center">
<input id="hero-demo" autofocus type="text" name="q" placeholder="Programming languages ..." style="width:100%;max-width:600px;outline:0">
</form>
<script>
var demo1 = new autoComplete({
selector: '#hero-demo',
minChars: 1,
source: function(term, suggest){
term = term.toLowerCase();
var choices = ['ActionScript', 'AppleScript', 'Asp', 'Assembly', 'BASIC', 'Batch', 'C', 'C++', 'CSS', 'Clojure', 'COBOL', 'ColdFusion', 'Erlang', 'Fortran', 'Groovy', 'Haskell', 'HTML', 'Java', 'JavaScript', 'Lisp', 'Perl', 'PHP', 'PowerShell', 'Python', 'Ruby', 'Scala', 'Scheme', 'SQL', 'TeX', 'XML'];
var suggestions = [];
for (var i=0;i<choices.length;i++)
if (choices[i].toLowerCase().indexOf(term)>=0) suggestions.push(choices[i]);
suggest(suggestions);
}
});
</script>
https://raw.githack.com/culefa/JavaScript-autoComplete/1.2.0/demo.html
- Lightweight: 5.4 kB of JavaScript - less than 2.4 kB gzipped
- Fully flexible data source
- Smart caching, delay and minimum character settings
- Callbacks
- Performance Fix with changes in CSS Layout, and Enhancement in Functionality
- Rolling out Update for 2015 - 2023 PRs
- Included pull #6 and added offsetLeft/offsetTop as optional parameter for suggestions container.
- Fixed #2: Unspecified error on IE 10.
- Fixed: Hide suggestions on fast input.
- Fixed: Select item with tab.
- Fixed: Incorrect selection by mouse when suggestions are scrolled down.
- Simplified code and minor bug fixes.
- Prevent unnecessary search on pressing enter.
- First release