Created
December 4, 2012 19:06
-
-
Save FirstVertex/4207568 to your computer and use it in GitHub Desktop.
Knockout Binding Handler for JQuery Mobile Slider
This file contains 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
ko.bindingHandlers.slider = { | |
init: function (element, valueAccessor) { | |
// use setTimeout with 0 to run this after Knockout is done | |
setTimeout(function () { | |
// $(element) doesn't work as that has been removed from the DOM | |
var curSlider = $('#' + element.id); | |
// helper function that updates the slider and refreshes the thumb location | |
function setSliderValue(newValue) { | |
curSlider.val(newValue).slider('refresh'); | |
} | |
// subscribe to the bound observable and update the slider when it changes | |
valueAccessor().subscribe(setSliderValue); | |
// set up the initial value, which of course is NOT stored in curSlider, but the original element :\ | |
setSliderValue($(element).val()); | |
// subscribe to the slider's change event and update the bound observable | |
curSlider.bind('change', function () { | |
valueAccessor()(curSlider.val()); | |
}); | |
}, 0); | |
} | |
}; |
This file contains 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
<input type="range" data-bind="value: currentLineWidth, slider: currentLineWidth" name="penSizeSlider" id="penSizeSlider" data-theme="a" data-track-theme="c" min="1" max="150" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment