Last active
August 29, 2015 14:14
-
-
Save keepitsimple/a4cad3d4493158d56fc4 to your computer and use it in GitHub Desktop.
jQuery UI range slider with Knockout bindings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################## | |
## RangeSlider | |
# | |
ko.bindingHandlers.rangeSlider = | |
init: (element, valueAccessor, allBindingsAccessor) -> | |
options = valueAccessor() || {} | |
params = allBindingsAccessor() || {} | |
console.log options | |
console.log params | |
options.change = (e, ui)-> | |
params.minValue(ui.values[0]) | |
params.maxValue(ui.values[1]) | |
options.slide = (e, ui)-> | |
params.minValue(ui.values[0]) | |
params.maxValue(ui.values[1]) | |
$(element).slider options | |
ko.utils.domNodeDisposal.addDisposeCallback element, ()-> | |
$(element).slider "destroy" | |
update: (element, valueAccessor, allBindingsAccessor) -> | |
params = allBindingsAccessor() || {} | |
$(element).slider('option', 'values',[params.minValue(),params.maxValue()]) | |
# HTML sample | |
# <div data-bind="rangeSlider: {range: true, min:500, max:10000, step:100}, minValue: chosenMinPrice, maxValue: chosenMaxPrice"></div> | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment