Skip to content

Instantly share code, notes, and snippets.

@thanos
Last active December 19, 2015 09:59
Show Gist options
  • Select an option

  • Save thanos/5937305 to your computer and use it in GitHub Desktop.

Select an option

Save thanos/5937305 to your computer and use it in GitHub Desktop.
knockjs custom binding to use the jquery slider
// usage: <td data-bind="jqSlider: points"></td>
ko.bindingHandlers.jqSlider = {
init: function(element, valueAccessor) {
$(element).empty().slider({
range: "min",
min: 0,
max: 5,
change:function( event, ui ) {
var observable = valueAccessor();
observable(ui.value);
}
});
},
update: function(element, valueAccessor) {
// Give the first x stars the "chosen" class, where x <= rating
var value = valueAccessor();
var valueUnwrapped = ko.utils.unwrapObservable(value);
alert("observable: " + valueUnwrapped);
$(element).slider( "value", valueUnwrapped);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment