GithubHelp home page GithubHelp logo

ferndot / jquery.nice-number Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 8.0 568 KB

A tiny jQuery plugin for styling HTML number inputs

Home Page: https://www.npmjs.com/package/jquery.nice-number

License: GNU General Public License v3.0

CSS 4.20% JavaScript 69.35% HTML 26.45%
jquery jquery-plugin html-inputs css3 html5 html5-input html5-inputs number-input spinner number-spinner

jquery.nice-number's Introduction

jQuery Nice Number

A tiny plugin that converts HTML numeric inputs (type="number") into an easily-styled format.

Usage

Prerequisites

Download the project files or install it using Yarn, NPM, etc...

$ yarn add jquery.nice-number
$ npm install jquery.nice-number --save

Include the plugin files in your source.

Note: the path will need to be changed if you downloaded or moved the files.

<link
	rel="stylesheet"
	href="node_modules/jquery.nice-number/dist/jquery.nice-number.min.css"
/>
<script src="node_modules/jquery.nice-number/dist/jquery.nice-number.min.js"></script>

Basic usage

Call the niceNumber() function on your jQuery element of choice.

Pro Tip: use $('input[type="number"]') to select all numeric inputs in the current page.

$('input[type="number"]').niceNumber();

Advanced usage

You can pass an optional object to niceNumber() containing advanced configuration options.

Currently supported options

Name Permitted values Description Default value
autoSize boolean Enables or disables automatic input sizing to fit content true
autoSizeBuffer number The number of extra character widths that are added to the element's content size calculation when automatically sizing 1
buttonDecrement jQuery element, HTML element, HTML string, or plain string The contents of the decrement button '-'
buttonIncrement jQuery element, HTML element, HTML string, or plain string The contents of the increment button '+'
buttonPosition 'around', 'left', or 'right' The positions of the control buttons 'around'
onDecrement false or function callback function to run on decrement false
onIncrement false or function callback function to run on increment false

Callback Examples

Passed arguments are $currentInput: the selected input in a jQuery object, the new amount, and the niceNumber settings.

$('input[type="number"]').niceNumber({
	onIncrement: function ($currentInput, amount, settings) {
		if (amount >= 100) {
			$currentInput.classList.add('more-than-100');
		} else {
			$currentInput.classList.remove('more-than-100');
		}
	},
});

Development

Building

Install the project dependencies

$ yarn

Build the project

$ yarn gulp

Or individually

$ yarn gulp css

$ yarn gulp js

$ yarn gulp copy # copies the contents of the src folder to the dist folder

If you are developing on the project, you can use

$ yarn gulp dev # runs default, then copy, css, js on save of any src file

jquery.nice-number's People

Contributors

csaggo avatar dependabot[bot] avatar ferndot avatar gingerchew avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jquery.nice-number's Issues

several nice numbers

How to create some nice numbers in sequence?
Every time I add a new input, I must to initialize the plugin again and then I see that the number of +/- buttons is increasing:

_screenshot 2019-10-27 в 21 18 17

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.