metafizzy / huebee

🐝 1-click color picker
https://huebee.buzz
403 stars 43 forks source link

Adding on 'select' event or trigger 'change' event on color reselect. #25

Open aryoxp opened 4 years ago

aryoxp commented 4 years ago

Hi, thanks for this great script there. I use Huebee to change element's color using the 'change' event and it is working perfectly. When I try to change another element's color using the same currently selected color, the 'change' event is not triggered. It is of course obvious that the 'change' event is not triggered when the color does not change. However, I need some event to be triggered when user select a color, even when there is no change in the selected color.

One more thing, when I set the color programmatically using the hueb.setColor(hex) method, the 'change' event is also not triggered. If staticOpen option is not set, the 'selection' cursor does not point to the color set even though the color being set is on the (palette) list.

Would you consider this as a feature request? Thanks.

desandro commented 4 years ago

You can add a duck punch for a new event

let setSwatch = Huebee.prototype.setSwatch;
Huebee.prototype.setSwatch = function( color ) {
  setSwatch.apply( this, arguments );
  this.emitEvent( 'set', [ swatch.color, swatch.hue, swatch.sat, swatch.lum ] );
};
adambg commented 4 years ago

OK Thanks!

BTW this is an amazing project. I appreciate your work :)

On Wed, May 13, 2020 at 9:24 PM David DeSandro notifications@github.com wrote:

You can add a duck punch https://metafizzy.co/blog/duck-punching-prototype/ for a new event

let setSwatch = Huebee.prototype.setSwatch;Huebee.prototype.setSwatch = function( color ) { setSwatch.apply( this, arguments ); this.emitEvent( 'set', [ swatch.color, swatch.hue, swatch.sat, swatch.lum ] ); };

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/metafizzy/huebee/issues/25#issuecomment-628165670, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE4NAYQOSMC3CTSRANREO3RRLQVXANCNFSM4MXW57WA .