# HG changeset patch # User Tero Marttila # Date 1398027829 -10800 # Node ID 6f1e9a5ac874c1a1497ed029a1e609f7eba49e2b # Parent 5254ba612630881e3c6ca584ae96b3003043efa3 color-slider: fixup input-slider bindings diff -r 5254ba612630 -r 6f1e9a5ac874 static/color-slider.js --- a/static/color-slider.js Sun Apr 20 23:51:57 2014 +0300 +++ b/static/color-slider.js Mon Apr 21 00:03:49 2014 +0300 @@ -27,10 +27,21 @@ color[c] = 255; input.val(value.toString(16)); - input.background_color(color.r, color.b, color.g, value / 255); + input.background_color(color.r, color.g, color.b, value / 255); }); } +function color_slider_input (input, c) { + var value; + + if (input.val()) + value = parseInt(input.val(), 16); + else + value = 0; + + $('#slider-' + c).slider('value', value); +} + $(function () { $('.color-slider').slider({ orientation: 'horizontal', @@ -43,13 +54,11 @@ $(['r', 'g', 'b']).each(function (i, c) { var input = $('#' + c); - var value; - if (input.val()) - value = parseInt(input.val(), 16); - else - value = 0; - - $('#slider-' + c).slider('value', value); + // bind + input.change(function () { color_slider_input($(this), this.id); }); + + // initialize + color_slider_input(input, c); }); });