{"id":15361535,"url":"https://github.com/jonathanong/autocomplete","last_synced_at":"2025-04-15T08:41:20.083Z","repository":{"id":13939227,"uuid":"16638975","full_name":"jonathanong/autocomplete","owner":"jonathanong","description":"mobile-first autocomplete","archived":false,"fork":false,"pushed_at":"2015-01-28T04:38:35.000Z","size":187,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T18:11:59.107Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonathanong.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-08T08:07:14.000Z","updated_at":"2016-03-26T02:32:58.000Z","dependencies_parsed_at":"2022-09-01T05:25:19.581Z","dependency_job_id":null,"html_url":"https://github.com/jonathanong/autocomplete","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanong%2Fautocomplete","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanong%2Fautocomplete/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanong%2Fautocomplete/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanong%2Fautocomplete/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonathanong","download_url":"https://codeload.github.com/jonathanong/autocomplete/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249038887,"owners_count":21202803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T12:55:33.721Z","updated_at":"2025-04-15T08:41:20.063Z","avatar_url":"https://github.com/jonathanong.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Autocomplete\n\nAn autocomplete component. Couldn't get others to work how I want it to, so I made my own.\n\nPrior art:\n\n- [yields/select](http://github.com/yields/select)\n- [matthewmueller/autocomplete](https://github.com/matthewmueller/autocomplete)\n\nSome philosophicaly differences:\n\n- Mobile first - so touching outside the menu/input closes the menu. Tap support!\n- No blur events - alt-tabbing or clicking outside the viewport won't close the menu\n- The menu doesn't close when selected - you have to do it yourself\n- Queryless - includes no query structure. You must implement querying yourself!\n- Progressive enhancement - doesn't create the `\u003cinput\u003e` element dynamically\n\n## Demo\n\n```bash\nmake\nopen test/index.html\n```\n\nYou can also run the tests by:\n\n```bash\nnpm i -g component-test\nmake test\n```\n\n## API\n\n```jade\n.container\n  .Autocomplete-menu(.Autocomplete-hidden)\n    .Autocomplete-option(.Autocomplete-highlighted)\n    .Autocomplete-option(.Autocomplete-highlighted)\n    .Autocomplete-option(.Autocomplete-highlighted)\n  input[type=\"text\"]\n```\n\nNote that `.Autocomplete-menu` has `position: absolute;` by default, so you should have a non-statically positioned parent somewhere.\n\nAlso note that this structure is completely optional - you can place the menu wherever you'd like.\n\n### var search = autocomplete(element, [menu])\n\n`element` is the `\u003cinput\u003e` element to enhance. `menu` is an optional menu element to use - by default it creates its own and appends it before the input.\n\n### search.query=\n\nYou need to set your own query function. Your query function should look something like this:\n\n```js\nsearch.query = function (text) {\n  // remove all the options\n  search.clear()\n\n  ajax(function (err, options) {\n    // do your own error handling\n    if (err) return console.error(err.stack);\n\n    // push all the options to the menu\n    search.push(options)\n\n    // highlight the first option\n    search.highlight(0)\n  })\n}\n```\n\nEach `option` should be an `{}` with an `.id` as well as either a `.title` or a `.name`. Each `option` could also be a string, which will automatically be converted to an object.\n\n### search.format=\n\nCustomize the formatting of every option. By default, it is:\n\n```js\nsearch.format = function (option) {\n  return '\u003cdiv\u003e' + (option.name || option.title) + '\u003c/div\u003e'\n}\n```\n\nYou may return either an HTML string or a DOM element.\n\n### search.push(options...)\n\nPush options to the menu.\n\n### search.clear()\n\nRemove all the options from the menu.\n\n### search.selected\n\nSelection option, if any.\n\n### Event: change\n\nWhen an option is selected\n\n### search.highlighted\n\nCurrently highlighted option.\n\n### search.hide()\n\nHide the menu.\n\n### Event: hide\n\nWhen the menu is hidden\n\n### search.show()\n\nShow the menu.\n\n### Event: show\n\nWhen the menu is shown\n\n### Event: highlight\n\nWhen an option is highlighted\n\n## Browser Compatibility\n\nIE9+ - PRs for IE8 welcomed.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014 Jonathan Ong me@jongleberry.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanong%2Fautocomplete","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonathanong%2Fautocomplete","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanong%2Fautocomplete/lists"}