Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to change the color without triggering the changed event #11

Closed
Ape opened this issue Oct 15, 2017 · 5 comments
Closed

Ability to change the color without triggering the changed event #11

Ape opened this issue Oct 15, 2017 · 5 comments
Assignees

Comments

@Ape
Copy link

Ape commented Oct 15, 2017

I would like to have a method for changing the current color so that this change would not trigger the color:change event. This would be useful for example when you want to set the color inside the color:change handler function in response to some changes. Otherwise it might create even an infinite event loop.

@jaames
Copy link
Owner

jaames commented Oct 15, 2017

Thanks for the suggestion! I agree that this would be useful, so I shall try to add it when possible.

It will be a little difficult, since right now it works like this:

  1. User interacts with the color picker
  2. Color picker gives the color object a new value
  3. Color object checks which channels (h/s/v) have changed
  4. If there were changes, the color object tells the color picker to update the UI
  5. Color picker updates the UI then fires the color:change event

I'll see what I can do though :)

@jaames jaames self-assigned this Oct 15, 2017
@jaames
Copy link
Owner

jaames commented Oct 16, 2017

Just pushed changes; now you can manually change the current color value without firing the color:change event by using color.set() with a HSV object.

Example:

var example = new iro.ColorPicker("#example");

example.on("color:change", function(color) {
     // get the current hsv value
     var hsv = color.hsv;
     // make changes to it
     hsv.h = 360;
     // set the color without triggering color:change
     color.set(hsv);
     // manually force the UI to update if you want
     color.forceUpdate();
});

color.set docs: https://github.com/jaames/iro.js/blob/master/docs/color_api.md#set

--

I should say this solution is rather hacky, I'll see if I can find a better way to solve this problem in the future.

@jaames jaames closed this as completed Oct 16, 2017
@Ape
Copy link
Author

Ape commented Oct 17, 2017

Thanks!

@ibalaji777
Copy link

ibalaji777 commented Jan 20, 2021

above code

Just pushed changes; now you can manually change the current color value without firing the color:change event by using color.set() with a HSV object.

Example:

var example = new iro.ColorPicker("#example");

example.on("color:change", function(color) {
     // get the current hsv value
     var hsv = color.hsv;
     // make changes to it
     hsv.h = 360;
     // set the color without triggering color:change
     color.set(hsv);
     // manually force the UI to update if you want
     color.forceUpdate();
});

color.set docs: https://github.com/jaames/iro.js/blob/master/docs/color_api.md#set

--

I should say this solution is rather hacky, I'll see if I can find a better way to solve this problem in the future.

i used below syntax but i am getting error
color.forceUpdate()
code is working but i get error forceUpdate is not a function !

@jaames
Copy link
Owner

jaames commented Jan 20, 2021

@ibalaji777 This answer is outdated; you can now change the color in an event callback without any extra steps:

Updated example:

var example = new iro.ColorPicker("#example");

example.on("color:change", function(color) {
     // get the current hsv value
     var hsv = color.hsv;
     // make changes to it
     hsv.h = 360;
     // set the color without triggering color:change
     color.set(hsv);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants