🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dropdown

DOM mechanism for filling and navigating a dropdown

0.2.0
latest
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created

dropdown

Dropdown helper.

Usage

<input id="query" autocomplete="off">
<script>
  var query_el = document.getElementById('query');
  var dropdown = Dropdown.attach(query_el)
    .on('change', function(query) {
      // suppose query == 'ch'
      $.getJSON('/search', {q: query}, function(data, textStatus, jqXHR) {
        // data looks like [{label: 'Charles', value: 'Charles'}, {label: 'Chris', value: 'chris'}, ...]
        dropdown.setOptions(data);
      });
    })
    .on('select', function(value) {
      query_el.value = value;
    });
</script>
<style>
  .dropdown {
    margin: 0 2px;
    padding: 0;
    list-style: none;
    border: 1px solid #CCC;
  }
  .dropdown li {
    padding: 1px;
    cursor: default;
  }
  .selected {
    background-color: pink;
  }
</style>

TODO

  • keep track of mouseover vs. up-down arrow selection, and revert to keyed up-down selection on mouseout.

License

Copyright 2011-2014 Christopher Brown. MIT Licensed.

FAQs

Package last updated on 20 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts