Add TypeScript definitions and tests for Bootstrap TouchSpin (http://www.virtuosoft.eu/code/bootstrap-touchspin/)

This commit is contained in:
Albin Sunnanbo
2015-04-06 22:59:23 +02:00
parent b0056383b5
commit fb7832af29
2 changed files with 198 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="jquery.bootstrap-touchspin.d.ts" />
$(function () {
// Example 1 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo1']").TouchSpin({
min: 0,
max: 100,
step: 0.1,
decimals: 2,
boostat: 5,
maxboostedstep: 10,
postfix: '%'
});
// Example 2 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo2']").TouchSpin({
min: -1000000000,
max: 1000000000,
stepinterval: 50,
maxboostedstep: 10000000,
prefix: '$'
});
// Example 3 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo_vertical']").TouchSpin({
verticalbuttons: true
});
// Example 4 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo_vertical2']").TouchSpin({
verticalbuttons: true,
verticalupclass: 'glyphicon glyphicon-plus',
verticaldownclass: 'glyphicon glyphicon-minus'
});
// Example 5 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo3']").TouchSpin();
// Example 6 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo3_21']").TouchSpin({
initval: 40
});
// Example 7 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo4']").TouchSpin({
postfix: "a button",
postfix_extraclass: "btn btn-default"
});
// Example 8 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo4_2']").TouchSpin({
postfix: "a button",
postfix_extraclass: "btn btn-default"
});
// Example 9 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo5']").TouchSpin({
prefix: "pre",
postfix: "post"
});
// Example 10 from http://www.virtuosoft.eu/code/bootstrap-touchspin/
$("input[name='demo6']").TouchSpin({
buttondown_class: "btn btn-link",
buttonup_class: "btn btn-link"
});
});

View File

@@ -0,0 +1,130 @@
// Type definitions for Bootstrap TouchSpin
// Project: http://www.virtuosoft.eu/code/bootstrap-touchspin/
// Definitions by: Albin Sunnanbo <https://github.com/albinsunnanbo>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts" />
/**
* TouchSpinOptions. All options are optional
*/
interface TouchSpinOptions {
/**
* Applied when no explicit value is set on the input with the value attribute.
* Empty string means that the value remains empty on initialization.
*/
initval?: number | string;
/**
* Minimum value.
*/
min?: number;
/**
* Maximum value.
*/
max?: number;
/**
* Incremental/decremental step on up/down change.
*/
step?: number;
/**
* How to force the value to be divisible by step value: 'none' | 'round' | 'floor' | 'ceil'
*/
forcestepdivisibility?: string;
/**
* Number of decimal points.
*/
decimals?: number;
/**
* Refresh rate of the spinner in milliseconds.
*/
stepinterval?: number;
/**
* Time in milliseconds before the spinner starts to spin.
*/
stepintervaldelay?: number;
/**
* Enables the traditional up/down buttons.
*/
verticalbuttons?: boolean;
/**
* Class of the up button with vertical buttons mode enabled.
*/
verticalupclass?: string;
/**
* Class of the down button with vertical buttons mode enabled.
*/
verticaldownclass?: string;
/**
* Text before the input.
*/
prefix?: string;
/**
* Text after the input.
*/
postfix?: string;
/**
* Extra class(es) for prefix.
*/
prefix_extraclass?: string;
/**
* Extra class(es) for postfix.
*/
postfix_extraclass?: string;
/**
* If enabled, the the spinner is continually becoming faster as holding the button.
*/
booster?: boolean;
/**
* Boost at every nth step.
*/
boostat?: number;
/**
* Maximum step when boosted.
*/
maxboostedstep?: number | boolean;
/**
* Enables the mouse wheel to change the value of the input.
*/
mousewheel?: boolean;
/**
* Class(es) of down button.
*/
buttondown_class?: string;
/**
* Class(es) of up button.
*/
buttonup_class?: string;
}
interface JQuery {
/**
* Initialize TouchSpin
*/
TouchSpin(): JQuery;
/**
* Inialize TouchSpin with options
* @param options a TouchSpinOptions object with one or more options
*/
TouchSpin(options: TouchSpinOptions): JQuery;
}