Last active
December 19, 2015 09:59
-
-
Save thanos/5937305 to your computer and use it in GitHub Desktop.
knockjs custom binding to use the jquery slider
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
| // 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