1

I'm building an app that allows users to select colors that will be applied to css. I'm using spectrum.js for the color picker. This is how you initialize the plugin:

$("#selector").spectrum();

You can pass in many options and I'm wanting to know if it is possible to make a global 'initializer' (that might be the wrong term) with a few default options that other 'initializers' can inherit from.

If so, how would it be done?

Charlie
  • 22,886
  • 11
  • 59
  • 90
John R Perry
  • 3,916
  • 2
  • 38
  • 62

1 Answers1

0

Of course you can.

var defaultOptions = {color: '#0', flat: true};

Now you can merge this default option with any local set of options and pass it to an initializer.

var myOptions = {showInput: true};

$("#selector").spectrum(meargeObjects(defaultOptions, myOptions));

This answer provides a way to write the meargeObjects function.

Community
  • 1
  • 1
Charlie
  • 22,886
  • 11
  • 59
  • 90