bgrins / spectrum

The No Hassle JavaScript Colorpicker
https://bgrins.github.io/spectrum/
MIT License
2.32k stars 589 forks source link

sp-container not destroyed when clicking on .sp-choose #577

Open jolegat opened 3 years ago

jolegat commented 3 years ago

Hello,

I am using your great color picker in a current project. I am very content with it but have following issue:

Spectrum opens when the user clicks onto (one or more)

elements (which are dynamically created upon various user interactions). spectrum is appended to the node (which I want to keep). When the user clicks somewhere outside spectrum the .sp-container is hidden, everything's fine. But: when the user clicks onto .sp-choose an additional (hidden) .sp-container node is appended to . So each time the user opens spectrum the node receives another .sp-container.

How can I get rid of these (unused) remains? As mentioned: this behaviour occurs only when clicking on .sp-choose.

I've tried 'destroy' and/or manually remove the .sp-container node, but then spectrum does not open at all any more.

Cheers from Vienna/Austria. jo

Simon-J-N-Reading commented 3 years ago

Same sort of behavior here - (duplications) - but when using inside a Worpress Divi & DiviPopup container.. pre-callling ("destroy") seems to do nothing... IMHO (with great deference) there should be a "check for pre-existance on a given element" somewhere in the instantiation code

addendum : after much hair pulling - the closing of the Popover (making the parent element invisible) was making the spectrum elements also hidden & removing the "replacer" HTML elements - and thus inaccessible to "destroy" somehow... "destroy" has to be called before the parent is hidden : My problem was partly because (an the reason my spectrum items were increasing exponentialy Vs. by one each close) I was loading the spectrum.js script on each popup open - each spectrum.js was behaving as an independent black box (Duh!)