colorPicker icon indicating copy to clipboard operation
colorPicker copied to clipboard

Setting Memory Colours programatically

Open wizlonuk opened this issue 9 years ago • 1 comments

Hi

First of all, thanks for the amazing colour picker, it's got all the features I need (and more) which can't be said for others. But I was hoping you could help me out with something.

I am initialising the plugin using JQuery as so

$('#addNewColourInput').colorPicker({ memoryColors: ff.global.memoryColors, actionCallback: actionCallback )};

which works fine, but I am trying to add new memory colours after a selection has been made. I was hoping to keep my own list of colours and then just reset the memory colours object when I need to, however, I'm haping trouble doing this. Could you supply a snippet showing how I can set the memoryColours? If this isn't possible then how else could I achieve this?

Thank you for your time.

wizlonuk avatar May 23 '16 14:05 wizlonuk

Hi @wizlonuk, I'm not quite sure what you need to do...

  • if you select a color, just click on the square with the circle, between the memory slots and RESET button. This way you can store another selection. Next time you open the page / colorPicker, your colors will be recovered from cookies.
  • If you need to reset the colors to a custom set of colors you can use set them as you did with the options or use renderMemory(ff.global.memoryColors) to set them, even after your colorPicker is loaded already.
  • If you want to provide a set of color when used the first time but then let the customer provide his own colors to the memory then you first have to check if there is colorPickerMemos set in cookies. If not, use renderMemory() to set them, otherwise not... don't set them in your options though...

Best to do so is inside the actionCallback because it's the first time you have a hold on the instance of your colorPicker (this._instance):

actionCallback: function(event, type) {
    if (type === 'init') { // the first time you created an instance
        if (document.cookie.indexOf('colorPickerMemos') !== -1) {
            this._instance.renderMemory(ff.global.memoryColors);
        }
    }
}

I hope this helps you with what you need to do ;o)

PitPik avatar May 24 '16 14:05 PitPik