ts-ion-rangeslider
Version:
Cool, comfortable and easily customizable range slider with many options and skin support without jQuery dependency
276 lines (274 loc) • 7.44 kB
TypeScript
declare namespace TsIonRangeSlider {
interface ISlider {
destroy(): void;
reset(): void;
update(option: IonRangeSliderOptions): void;
}
interface IonRangeSliderOptions {
skin?: 'flat' | 'big' | 'modern' | 'round' | 'sharp' | 'square';
type?: string;
min?: number;
max?: number;
from?: number;
to?: number;
step?: number;
min_interval?: number;
max_interval?: number;
drag_interval?: boolean;
values?: any[];
from_fixed?: boolean;
from_min?: number;
from_max?: number;
from_shadow?: boolean;
to_fixed?: boolean;
to_min?: number;
to_max?: number;
to_shadow?: boolean;
prettify_enabled?: boolean;
prettify_separator?: string;
prettify?: (num: number) => string;
force_edges?: boolean;
keyboard?: boolean;
grid?: boolean;
grid_margin?: boolean;
grid_num?: number;
grid_snap?: boolean;
hide_min_max?: boolean;
hide_from_to?: boolean;
prefix?: string;
postfix?: string;
max_postfix?: string;
decorate_both?: boolean;
values_separator?: string;
input_values_separator?: string;
disable?: boolean;
block?: boolean;
extra_classes?: string;
scope?: any;
onStart?: (obj: IonRangeSliderEvent) => void;
onChange?: (obj: IonRangeSliderEvent) => void;
onFinish?: (obj: IonRangeSliderEvent) => void;
onUpdate?: (obj: IonRangeSliderEvent) => void;
}
interface IonRangeSliderEvent {
min: any;
max: any;
from: number;
from_percent: number;
from_value: number;
to: number;
to_percent: number;
to_value: number;
}
class Slider implements ISlider {
private plugin_count;
private input;
private current_plugin;
private calc_count;
private update_tm;
private old_from;
private old_to;
private old_min_interval;
private raf_id;
private dragging;
private force_redraw;
private no_diapason;
private has_tab_index;
private is_key;
private is_update;
private is_start;
private is_finish;
private is_active;
private is_resize;
private is_click;
private options;
private cache;
private labels;
private coords;
private update_check;
private result;
private target;
private getIsOldIe;
private base_html;
private single_html;
private double_html;
private disable_html;
constructor(input: HTMLInputElement, options?: IonRangeSliderOptions);
private rangeSlider;
/**
* Starts or updates the plugin instance
*/
private init;
/**
* Appends slider template to a DOM
*/
private append;
/**
* Determine which handler has a priority
* works only for double slider type
*/
private setTopHandler;
/**
* Determine which handles was clicked last
* and which handler should have hover effect
*/
private changeLevel;
/**
* Then slider is disabled
* appends extra layer with opacity
*/
private appendDisableMask;
/**
* Then slider is not disabled
* remove disable mask
*/
private removeDisableMask;
private removeElement;
/**
* Remove slider instance
* and unbind all events
*/
private remove;
/**
* bind all slider events
*/
private bindEvents;
/**
* Focus with tabIndex
*/
private pointerFocus;
private getOffset;
/**
* Mousemove or touchmove
* only for handlers
*/
private pointerMove;
/**
* Mouseup or touchend
* only for handlers
*/
private pointerUp;
private removeClass;
private contains;
/**
* Mousedown or touchstart
* only for handlers
*/
private pointerDown;
/**
* Mousedown or touchstart
* for other slider elements, like diapason line
*/
private pointerClick;
private trigger;
/**
* Keyborard controls for focused slider
*/
private key;
/**
* Move by key
*/
private moveByKey;
/**
* Set visibility and content
* of Min and Max labels
*/
private setMinMax;
private outerWidth;
/**
* Then dragging interval, prevent interval collapsing
* using min_interval option
*/
private setTempMinInterval;
/**
* Restore min_interval option to original
*/
private restoreOriginalMinInterval;
/**
* All calculations and measures start here
*/
private calc;
/**
* calculates pointer X in percent
*/
private calcPointerPercent;
private convertToRealPercent;
private convertToFakePercent;
private getHandleX;
private calcHandlePercent;
/**
* Find closest handle to pointer click
*/
private chooseHandle;
/**
* Measure Min and Max labels width in percent
*/
private calcMinMax;
/**
* Measure labels width and X in percent
*/
private calcLabels;
/**
* Main function called in request animation frame
* to update everything
*/
private updateScene;
/**
* Draw handles
*/
private drawHandles;
/**
* Draw labels
* measure labels collisions
* collapse close labels
*/
private drawLabels;
/**
* Draw shadow intervals
*/
private drawShadow;
/**
* Write values to input element
*/
private writeToInput;
private callOnStart;
private callOnChange;
private callOnFinish;
private callOnUpdate;
private toggleInput;
/**
* Convert real value to percent
*/
private convertToPercent;
/**
* Convert percent to real values
*/
private convertToValue;
/**
* Round percent value with step
*/
private calcWithStep;
private checkMinInterval;
private checkMaxInterval;
private checkDiapason;
private toFixed;
private _prettify;
private prettify;
private checkEdges;
private validate;
private decorate;
private updateFrom;
private updateTo;
private updateResult;
private appendGrid;
private cacheGridLabels;
private calcGridLabels;
private calcGridCollision;
private calcGridMargin;
update(options?: any): void;
reset(): void;
destroy(): void;
private unbindEvens;
}
}
export { TsIonRangeSlider as default };