/**
* Wheel Color Picker for jQuery
*
* https://raffer.one/projects/jquery-wheelcolorpicker
*
* Author : Fajar Chandra
* Date : 2019.06.12
*
* Copyright © 2011-2019 Fajar Chandra. All rights reserved.
* Released under MIT License.
* http://www.opensource.org/licenses/mit-license.php
*/
(function ($) {
/**
* Function: wheelColorPicker
*
* The wheelColorPicker plugin wrapper. Firing all functions and
* setting/getting all options in this plugin should be called via
* this function.
*
* Before that, if wheelColorPicker instance is not yet initialized,
* this will initialize ColorPicker widget.
*
* This function will look for the options parameter passed in, and
* try to do something as specified in this order:
* 1. If no argument is passed, then initialize the plugin or do nothing
* 2. If object is passed, then call setOptions()
* 3. If string is passed, then try to fire a method with that name
* 4. If string is passed and no method matches the name, then try
* to set/get an option with that name. If a setter/getter method
* available (i.e. setSomething), it will set/get that option via that method.
*/
$.fn.wheelColorPicker = function() {
var returnValue = this; // Allows method chaining
// Separate first argument and the rest..
// First argument is used to determine function/option name
// e.g. wheelColorPicker('setColor', { r: 0, g: 0, b: 1 })
if(arguments.length > 0) {
var shift = [].shift;
var firstArg = shift.apply(arguments);
var firstArgUc = (typeof firstArg === "string") ? firstArg.charAt(0).toUpperCase() + firstArg.slice(1) : firstArg;
}
else {
var firstArg = undefined;
var firstArgUc = undefined;
}
var args = arguments;
this.each(function() {
// Grab ColorPicker object instance
var instance = $(this).data('jQWCP.instance');
// Initialize if not yet created
if(instance == undefined || instance == null) {
// Get init options
var options = {};
if(typeof firstArg === "object") {
options = firstArg;
}
instance = new WCP.ColorPicker(this, options);
$(this).data('jQWCP.instance', instance);
}
/// What to do? ///
// No arguments provided, do nothing
// wheelColorPicker()
if(firstArg === undefined || typeof firstArg === "object") {
}
// Call a method
// wheelColorPicker('show')
else if(typeof instance[firstArg] === "function") {
//console.log('method');
var ret = instance[firstArg].apply(instance, args);
// If instance is not returned, no method chaining
if(ret !== instance) {
returnValue = ret;
return false;
}
}
// Try option setter
// wheelColorPicker('color', '#ff00aa')
else if(typeof instance['set'+firstArgUc] === "function" && args.length > 0) {
//console.log('setter');
var ret = instance['set'+firstArgUc].apply(instance, args);
// If instance is not returned, no method chaining
if(ret !== instance) {
returnValue = ret;
return false;
}
}
// Try option getter
// wheelColorPicker('color')
else if(typeof instance['get'+firstArgUc] === "function") {
//console.log('getter');
var ret = instance['get'+firstArgUc].apply(instance, args);
// If instance is not returned, no method chaining
if(ret !== instance) {
returnValue = ret;
return false;
}
}
// Set option value
// wheelColorPicker('format', 'hex')
else if(instance.options[firstArg] !== undefined && args.length > 0) {
//console.log('set option');
instance.options[firstArg] = args[0];
}
// Get option value
// wheelColorPicker('format')
else if(instance.options[firstArg] !== undefined) {
//console.log('get option');
returnValue = instance.options[firstArg];
return false;
}
// Nothing matches, throw error
else {
$.error( 'Method/option named ' + firstArg + ' does not exist on jQuery.wheelColorPicker' );
}
});
return returnValue;
};
/******************************************************************/
/////////////////////////////////////////
// Shorthand for $.fn.wheelColorPicker //
/////////////////////////////////////////
var WCP = $.fn.wheelColorPicker;
/////////////////////////////////////////
/**
* Object: defaults
*
* Contains default options for the wheelColorPicker plugin.
*
* Member properties:
*
* format - Color naming style. See colorToRgb for all
* available formats.
* live - Enable dynamic slider gradients.
* preview - Enable live color preview on input field
* userinput - (Deprecated) Enable picking color by typing directly
* validate - When userinput is enabled, force the value to be
* a valid format. If user input an invalid color, the value
* will be reverted to last valid color.
* autoResize - Automatically resize container width.
* If set to false, you could manually adjust size with CSS.
* autoFormat - Automatically convert input value to
* specified format. For example, if format is "rgb",
* "#ff0000" will automatically converted into "rgb(255,0,0)".
* color -