From c37d86f09fe62ecfcb18d21340033d28ce7b0dab Mon Sep 17 00:00:00 2001 From: Patrick Davies Date: Fri, 14 Aug 2015 14:24:57 -0400 Subject: [PATCH] added events methods and destroy method --- nouislider/nouislider-tests.ts | 9 ++++++ nouislider/nouislider.d.ts | 55 ++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/nouislider/nouislider-tests.ts b/nouislider/nouislider-tests.ts index d20a04793..5c3fad057 100644 --- a/nouislider/nouislider-tests.ts +++ b/nouislider/nouislider-tests.ts @@ -80,3 +80,12 @@ noUiSlider.create(testHtmlElement, { // Set both slider handles (testHtmlElement).noUiSlider.set([13.2, 15.7]); + +// Events +var callback: noUiSliderCallback = (values, handle, unencoded) => {}; +(testHtmlElement).noUiSlider.on('event', callback); + +(testHtmlElement).noUiSlider.off('event'); + +(testHtmlElement).noUiSlider.destroy(); + diff --git a/nouislider/nouislider.d.ts b/nouislider/nouislider.d.ts index cf5e93b42..111b670fa 100644 --- a/nouislider/nouislider.d.ts +++ b/nouislider/nouislider.d.ts @@ -4,24 +4,12 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// + interface noUiSliderStatic { /** * To create a slider, call noUiSlider.create() with an element and your options. */ create(target: HTMLElement, options: noUiSliderOptions): void; - /** - * To get the current slider value. For one-handle sliders, calling .get() will return the value. - * For two-handle sliders, an array[value, value] will be returned. - */ - get(): number | number[]; - /** - * noUiSlider will keep your values within the slider range, which saves you a bunch of validation. - * If you have configured the slider to use one handle, you can change the current value by passing - * a number to the .set() method. If you have two handles, pass an array. One-handled sliders - * will also accept arrays. Within an array, you can set one position to null - * if you want to leave a handle unchanged. - */ - set(value: number | number[]): void; } interface noUiSliderOptions { @@ -135,9 +123,46 @@ interface noUiSliderPipsOptions { stepped?: boolean; } -interface noUiSliderInstance extends HTMLElement { - noUiSlider: noUiSliderStatic; +interface noUiSliderCallback { + /** + * Array for both one-handle and two-handle sliders. It contains the current slider values, + * with formatting applied. + */ + (values: any[], handle: number, unencoded: number): void } +interface noUiSlider { + /** + * Bind event to the slider. + */ + on(eventName: string, callback: noUiSliderCallback): void; + /** + * Unbind event to the slider. + */ + off(eventName: string): void; + /** + * Destroy's the slider. + */ + destroy(): void; + + /** + * To get the current slider value. For one-handle sliders, calling .get() will return the value. + * For two-handle sliders, an array[value, value] will be returned. + */ + get(): number | number[]; + /** + * noUiSlider will keep your values within the slider range, which saves you a bunch of validation. + * If you have configured the slider to use one handle, you can change the current value by passing + * a number to the .set() method. If you have two handles, pass an array. One-handled sliders + * will also accept arrays. Within an array, you can set one position to null + * if you want to leave a handle unchanged. + */ + set(value: number | number[]): void; +} + +interface noUiSliderInstance extends HTMLElement { + noUiSlider: noUiSlider +} + declare var noUiSlider: noUiSliderStatic; \ No newline at end of file