eskimoblood / jim-knopf

:o: small JavaScript library to create knobs using SVG
http://eskimoblood.github.com/jim-knopf/
199 stars 44 forks source link

Events support #9

Closed venelinpetrov closed 8 years ago

venelinpetrov commented 9 years ago

Do you support any events, so we can actually get/set values to the knobs? Thanks.

eskimoblood commented 9 years ago

When you change the value of the input the knob will update automatically. So what to you mean with "support all events"?

venelinpetrov commented 9 years ago

Strangely, I've tried just that, but it didn't work as I expected. Could you please review what's not correct in my code? Given the input: <input id="knob2" class="preset2" type="range" min="0" max="44" data-width="160" data-height="160" data-angleoffset="220" data-anglerange="280" tabindex="-1" data-value="2">

var knob = new Knob(document.getElementById('knob2'), new Ui.P2());
knob.input.addEventListener('input', function(e){
    console.log(e.currentTarget.value);
}, false);

knob.input.value = 3;

I appreciate your help much, and really like the library. Thanks again.

iamso commented 9 years ago

I ran into the same issue, and also that the input or change events on the input element don't work.

mattandrews commented 8 years ago

This is super frustrating; effectively makes this tool almost pointless to use.

eskimoblood commented 8 years ago

The knob function listen to change events of the input. By just setting the inputs value no event is triggered. You need to trigger the event by yourself:

knob.input.dispatchEvent(new Event('change'))

But if this is really a problem I can add a update method to change the value and update the knob.

knob.update(newValue)
eskimoblood commented 8 years ago

Ok, now you can change the value by knob.update(newValue) and you can listen to change events on the input field.

mattandrews commented 8 years ago

Thank you @eskimoblood!