Giter Site home page Giter Site logo

herrschuessler / floating-label Goto Github PK

View Code? Open in Web Editor NEW

This project forked from datuhealth/floating-label

0.0 2.0 0.0 89 KB

A floating label plugin written in vanilla javascript

Home Page: https://datuhealth.github.io/floating-label/

License: Other

JavaScript 67.03% HTML 32.97%

floating-label's Introduction

UNMAINTAINED

This project is no longer being maintained. It's suggested that an alternative be used instead.

floating-label

A floating label plugin written in vanilla javascript

Build Status

floatingLabel.js is a small javascript library to use the floating label pattern on your own forms. It's light (1kb minified and gzipped) and simple to use.

npm install floating-label
bower install floatingLabel.js

example

The only markup needed is either an input or a textarea element, and some sort of element for the label. Since version 2.0, labels must now include the for attribute to associate it to an input. Not only is this per the spec & accessible, you can now have inputs without a label, and have the label element somewhere else in the DOM.

<form>
    <label for="input">My descriptive label</label>
    <input type="text" name="input" id="input" placeholder="Your name here">
</form>

From there, when you load the page, call the init method with an option config.

floatingLabel.init({
    floatingClassName: 'custom-class', // defaults to 'floating'
    delegateEvents: true // defaults to false
});

If you're running a single page app and need to re-run floatingLabel when a new view is rendered, use evaluateInputs

floatingLabel.evaluateInputs();

api

init(options)

The init method is a simple function to evaluate all the inputs on a page once the DOM has been loaded. An optional config object can be passed in to set a custom class and whether to delegate events or bind them directly on the inputs themselves.

floatingLabel.init({
    floatingClassName: 'custom-class', // defaults to 'floating'
    delegateEvents: true // defaults to false
});

evaluateInputs()

The meat an potatoes of floatingLabel is in the evaluateInputs method. This will read the DOM and loop through all input or textarea elements on the page. It will either bind events to each input or delegate the events to the body.

If you have a single page app and need to bind events to a newly rendered view, run eveluateInputs.

floatingLabel.evaluateInputs();

contributing

If you would like to contribute, please create a new branch after forking with your changes, then submit a PR to this repo. We use standard for our javascript styleguide.

license

Apache 2.0

Copyright 2015 Datu Health, Inc

floating-label's People

Watchers

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