Coder Social home page Coder Social logo

dropdown.js's Introduction

Dropdown.js

Finally a dropdown plugin that transforms select inputs in nice dropdowns and does not drive you crazy.

I've always wondered why the most famous plugins (Chosen and Selectize) are so huge and full of useless/pointless features? What do you need from a dropdown plugin?

Initialize it

Nice! I've found <your_fav_plugin_here> and I want to use it to style all my select inputs! But wha happens if I dinamically add a new element? I must init it manually.. Doh!

Dropdown.js get rid of this problem, in fact you just need to run the plugin one time and it will take care of every new input which matches your rules.

// Init any existing .select element and then watch for new .select elements
// added dinamically by some black magic casted by a evil wizard
$(".select").dropdown({ "autoinit" : ".select" });

Now what happens? We want our dropdowns to act like a boss.. emh like a standard select input. If it's a single select you want first element, or the selected one, already selected. We want even keyboard support, so if we press tab, it get opened and with tab you can select the options etc etc...

Style it

What else? Maybe we want to be able to style our dropdown with our own classes so that we don't have to hack the plugin to make it looks good?

$(".select").dropdown({ "dropdownClass": "my-dropdown", "optionClass": "my-option awesome" });

With this command we init every .select element (yes they are initialized always in the same way) and the my-dropdown class will be applied to the dropdown wrapper (ex: <select>) and my-option awesome will be applied to the options (ex: <option>).

Please don't fill my DOM with thousand of DIVs!!!

Don't worry friend, this is the markup used by Dropdown.js:

<div class="dropdownjs">
  <input type="text" readonly placeholder="This is a placeholder">
  <ul>
    <li value="foobar" tabindex="0">My foobar...</li>
    <li value="great" selected class="selected" tabindex="0">...is great!</li>
  </ul>
</div>

Callbacks

Psstt, ya need some callback? Dropdown.js supports callbacks, they are called on each element initialized, here an example:

$(".select").dropdown({ "callback": function($dropdown) {
  // $dropdown is the shiny new generated dropdown element!
  $dropdown.fadeIn("slow");
});

Dropdown position

Dropdowns are placed in the best position, if a select input is placed on bottom of the page, the dropdown will open above it.

Dynamically added options

You may add a new option to the select tag and it will be automatically added to the dropdown.js

Let users add options

Add data-dynamic-opts=true to the select tag to let users add or remove options.

Browserify

This library is UMD compatible, so you can use it in this way:

var jquery = require("jquery");
require("dropdown.js");

jquery.material.init();

jquery(document).ready(function() {
    $(".select").dropdown({"optionClass": "withripple"});
});
...

dropdown.js's People

Contributors

hamper avatar hytcom avatar arunpoudel avatar fezvrasta avatar jesusprubio avatar liesislukas avatar tasonface avatar

Watchers

James Cloos avatar Bethuel Shem Lulalire avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.