-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
Reset swatches array with a pre-existing array #308
Labels
feature request
New feature requested
Comments
michaelsboost
changed the title
Reset array with a pre-existing array
Reset swatches array with a pre-existing array
Nov 22, 2021
This plugin won't get any feature anymore and it won't get any update after the end of 2021. With the codes he provided + loop you can easily delete every swatch then add predefined swatches. // Get Swatches
Pickr.prototype.getSwatches = function () {
return this._swatchColors.reduce((arr, swatch) => {
arr.push(swatch.color.toRGBA().toString(0));
return arr;
}, []);
};
// Set Swatches
Pickr.prototype.setSwatches = function (swatches) {
if (!swatches.length) return;
for (let i = this._swatchColors.length - 1; i > -1; i--) {
this.removeSwatch(i);
}
swatches.forEach(swatch => this.addSwatch(swatch));
};
// Predefined Swatches
let defaultSwatch = [
"rgba(244, 67, 54, 1)",
"rgba(233, 30, 99, 0.95)",
"rgba(156, 39, 176, 0.9)",
"rgba(103, 58, 183, 0.85)",
];
pickr.on("cancel", instance => {
// Remove all existing swatches
for (let j = pickr.getSwatches().length; j >= 0; j--) {
pickr.removeSwatch(j);
}
// Then add predefined swatches
pickr.setSwatches(defaultSwatch);
}); |
simonwep
added
feature request
New feature requested
and removed
question
Further information is requested
labels
Nov 28, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have my swatches contained in a variable array.
Typically I would add a swatch to the array like so and re-apply the variable to be used again at a later time.
I would delete a swatch from the array like so and again re-apply the variable to be used again at a later time.
However all the documentation says is....
So I tried removing the swatch by finding the string and removing it that way.
It all works fine up until I allow the user to load in a project file to reset all the swatches to a new array.
When I run this code in console it runs perfectly fine but doesn't if I use the fileReader API.
Here's the code....
Here's the alert I got with the fileReader API via console.
It would be nice if there was a way built in to reset the array with a pre-existing one.
Version: v1.8.2
Used bundle (es5 or normal one): normal
Used theme (default is classic): classic
Browser-version: Version 96.0.4664.45 Chrome
Operating-system: Windows 10
The text was updated successfully, but these errors were encountered: