Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rangeslide.js

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rangeslide.js

Lightweight customizable range slider with labels (but without jQuery)

  • 0.13.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

rangeslide.js

Feature rich, highly customizable range slider with labels (but without jQuery)

Table of contents

  • Screenshots
  • Quick start
  • Usage
  • Examples
  • Options
  • Methods
  • Events
  • Modes
  • Browser support
  • Copyright and license

Screenshots

Rangeslide with labels and tooltip Example with different label positioning Rangeslide with range selection (2 thumbs) Example with temporal data

Quick start

Several quick start options are available:

Download the latest build
Development
Production
Install From Bower
bower install rangeslide.js --save
Install From Npm
npm install rangeslide.js --save

Done!

Usage

Including files:
<link rel="stylesheet" href="/path/to/rangeslide.css">
<script src="/path/to/rangeslide.js"></script>
Using require.js:
var rangeslide = require("rangeslide"); // or whatever module name was assigned
Initialization

All you need to do is invoke rangeslide on an element:

var myRangeslide = rangeslide(domNode, options);

You can also initialize with css selector string:

var myRangeslide = rangeslide("#elementId", options);

Examples

There are some example usages that you can look at to get started. They can be found in the examples folder.

Options

rangeslide.js can accept an options object to alter the way it looks and behaves. If no options object is passed default values are used. The example of a structure of an options object is as follows:

{
  data: [
  	{ name: "example1", item: "Example text" },
  	{ name: "example2", item: "Another example text" },
  	{ name: "example3", item: function() { return "And yet another example text"; }
  ],
  showLabels: true,
  showTicks: true,
  labelsPosition: "alternate",
  startAlternateLabelsFromTop: true,
  startPosition: 0,
  thumbHeight: 16,
  thumbWidth: 16,
  handlers: {
    initialized: function(rangeslideElement) {},
    valueChanged: function(data, rangeslideElement) {},
    markerClicked: function(data, markerElement) {}
  }

Here is the explanation of options object:

OptionTypeDescriptionDefaultOptions
animationsBooleanEnable slider animationstrue
autoPlayBooleanEnable auto play modefalse
autoPlayDelayNumberDelay (in miliseconds) between steps in auto play mode1000
dataArrayArray of data objects (property 'name' is mandatory[]
dataSourceStringName of the property containing actual values"value"
enableLabelClickBooleanEnable click on labelstrue
enableMarkerClickBooleanEnable click on track markerstrue
enableTrackClickBooleanEnable click on tracktrue
endPositionNumberPosition of max thumb (only in "range" mode)Infinity
handlersObjectEvent handlers collection{}
highlightSelectedLabelsBooleanEnable highlighting of selected labelsfalse
labelsPositionStringPosition of labels on a rangeslide'below''above', 'below', 'alternate'
labelsContentString, FunctionSpecifies label content. Can be name of attribute or function (data item as parameter)null
labelsWidthNumberWidth of labels60
leftLabelStringText to display on left side label""
loopBooleanEnable loop when auto play mode is activetrue
markerSizeNumberSize of track marker (pixels)14
modeStringSliders operation mode (see Modes)"single""single", "select", "range"
rightLabelStringText to display on right side label""
showLabelsBooleanShow/hide labelsfalse
sideLabelsWidthNumberWidth of left and right side labels40
showTrackMarkersProgressBooleanIndicate progress on markersfalse
showTicksBooleanShow/hide label ticksfalse
showTrackMarkersBooleanShow/hide track markersfalse
showTrackProgressBooleanIndicate progress on trackfalse
showTooltipsBooleanShow/hide tooltips on track markersfalse
showValueBooleanShow/hide value indicatorfalse
spacingStringHow to calculate distance between markers"equidistant" ("data-driven" if all items are Date instances)"equidistant", "data-driven"
startAlternateLabelsFromTopBooleanShow first label above if labelsPosition is 'alternate'false
startPositionNumberInitial position of rangeslide thumb0
stepSizeNumberSize of rangeslider step16
thumbHeightNumberHeight of thumb element (in pixels)16
thumbWidthNumberWidth of thumb element (in pixels)16
tickHeightNumberHeight of label's tick (in pixels)16
tooltipContentString, FunctionSpecifies tooltip content, same as labelContent7
valueIndicatorContentString, FunctionSpecifies value indicator content, same as labelContentnull
valueIndicatorOffsetNumberValue indicator offset from rangeslider thumb5
valueIndicatorWidthNumberWidth of value indicator (in pixels)32
valueIndicatorHeightNumberHeight of value indicator (in pixels)32
valuePositionStringPosition of value indicator'above''above', 'below', 'thumb'

Data

Data collection for rangeslide is provided during instatiation or later using "data" attribute in options. By default values for slider are taken from "value" attribute. If provided data item do not have this attribute then it is required that you specify the name of the attribute using dataSource in options. Number of steps (markers) for a slider is equal to number of items passed in data collection.

rangeslide("#element" {
	data: [
    	{ key: "data1", value: "simple string data"},
        { key: "data2", value: 2 },
        { key: "data3", value: 0.001 } },
        { key: "data4", value: { "passing": "object", "as": "data" } },
        { key: "data5", value: "more text here" }
    ]
});

Rangeslide constructed with the above data will have 5 steps (markers).

Methods

Methods are called on rangeslide instances. You shoud save the instances to variable to have further access to it.

object getValue()

Get current rangeslide value. Returns single value when in "single" mode, otherwise returns array.

var item = rangeslide.getValue();
object getMinValue()

Get current rangeslide minimum value. Returns null if in "select" mode.

var item = rangeslide.getMinValue();
object getMaxValue()

Get current rangeslide maximum value. Returns null if in "select" mode.

var item = rangeslide.getMaxValue();
object getRange()

Get current range. Returns empty array if mode is other than "range".

var item = rangeslide.getRange();
object getSelection()

Get current selection. Returns empty array if mode is other than "select".

var item = rangeslide.getSelection();
DOMNode getElement()

Gets rangeslide's DOM node object.

var node = rangeslide.getElement();
void setValue(int index)

Set rangeslide value by specifying data index.

rangeslide.setValue(2);
void setMinValue(int index)

Set rangeslide minimum value by specifying data index.

rangeslide.setMinValue(2);
void setMaxValue(int index)

Set rangeslide maximum value by specifying data index.

rangeslide.setMaxValue(2);
void setValueByAttribute(string attributeName, object attributeValue)

Set rangeslide value by specifying property and value. If multiple data items with the same names are found first one is set.

rangeslide.setValueByAttribute("id", 123456);
void setMinValueByAttribute(string attributeName, object attributeValue)

Set rangeslide minimum value by specifying property and value. If multiple data items with the same names are found first one is set.

rangeslide.setMinValueByAttribute("id", 123456);
void setMaxValueByAttribute(string attributeName, object attributeValue)

Set rangeslide maximum value by specifying property and value. If multiple data items with the same names are found first one is set.

rangeslide.setMaxValueByAttribute("id", 123456);
void setOption(string name, object value)

Gets rangeslide's DOM node object (invokes rangeslide refresh).

rangeslide.setOption("autoPlay", true);
bool isSingleMode()

Check if rangeside operates in single value mode.

rangeslide.isSingleMode();
bool isRangeMode()

Check if rangeside operates in range mode.

rangeslide.isRangeMode();
bool isSelectMode()

Check if rangeside operates in selection mode.

rangeslide.isSelectMode();
void refresh()

Refresh and redraw rangeslide.

rangeslide.refresh();
void destroy()

Destroy rangeslide instance.

rangeslide.destroy();

Events

rangeslide.js provides custom events for some of it's actions. Appropriate callbacks can be specified in options.

EventDescriptionArguments
destroyedFires after slider is destroyedrangeslideElement
initializedFires after slider is initializedrangeslideElement
labelClickedFires after label is clickeddataItem, labelElement
markerClickedFires after track marker is clickeddataItem, markerElement
playStartFires when auto play is starteddataItem, rangeslideElement
playStopFires when auto play is stoppeddataItem, rangeslideElement
refreshedFires after slider is refreshedrangeslideElement
thumbDragStartFires when thumb dragging is initiateddataItem, thumbElement
thumbDraggedFires when thumb is being draggeddataItem, thumbElement
thumbDraggedEndFires when thumb is droppeddataItem, thumbElement
trackClickedFires after slider track is clickeddataItem, trackElement
valueChangedFires after slider value is changeddataItem, rangeslideElement

Event handlers are passed in rangeslide options like in the example below:

rangeslide("#element" {
	handlers: {
    	"valueChanged": [function(data, element) { console.log(data); }],
        "labelClicked": [
        	function(data, element) { console.log(data); },
            function(data, element) { return data.name; },
            function(data, element) { element.style.backroundColor = "#e2e3e4"; },
        ]
    }
})

Modes

rangeslide.js can operate in three different modes:

  • single value mode ("single") - one thumb, single value, autoPlay is valid only in this mode
  • range mode ("range") - two thumbs (indicating minimum and maximum value), range as value
  • selection mode ("select") - no thumbs, multiple selection, values are selected/deselectef by clicking markers

Operation mode can be specified by setting mode in options during initialization (or later using setOption method)

Licensed under MIT license.

^ back to top

Keywords

FAQs

Package last updated on 12 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc