Giter Club home page Giter Club logo

dropit's Introduction

Fork of http://dev7studios.com/dropitStupidly Simple jQuery Dropdowns for easy use with Browserify.

Usage

Making a new dropdown is easy. You just require() this repo and then pass a few options:

git clone git+https://github.com/TimeMagazine/Dropit.git

And then in your Javascript:

var dropit = require("Dropit");

var gender_dropdown = dropit("#my_gender_dropdown", {
	id: "my_gender",
	intro: "your gender",
	items: [ "woman", "man" ],
	callback: function(value) {
		console.log(value);
	}
});

The first argument is the id of the parent container, which you need to create ahead of time. The id in the options in the second argument will be the id of the dropdown itself.

Of the various options you have, only items is required:

  • items: The list of items in the dropdown (required)
  • intro: The default text, which will not be selectable by the user. E.g. "My state." Optional, defaults to first item in items
  • default: The value that should be selected on load. If intro is provided, that takes precedence over default`
  • callback: The function that is called each time the value changes. Takes one argument, value

If you only need to interact with the dropdown through callbacks, there's no need to assign it to a variable. But it does return an object with a few of the usual methods:

  • value(): Return the currently selected item
  • set(): Sets the currently selected item. Throws an error if the value is in items.

dropit's People

Contributors

gilbitron avatar wilson428 avatar mrraffnix avatar

Watchers

Aaron 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.