color picker: allow full white

pull/4733/head
John McLear 2021-02-08 11:01:27 +00:00
parent 5d96cf9754
commit 9070c71e9f
1 changed files with 13 additions and 13 deletions

View File

@ -5,9 +5,9 @@
// https://github.com/mattfarina/farbtastic/blob/71ca15f4a09c8e5a08a1b0d1cf37ef028adf22f0/LICENSE.txt // https://github.com/mattfarina/farbtastic/blob/71ca15f4a09c8e5a08a1b0d1cf37ef028adf22f0/LICENSE.txt
// edited by Sebastian Castro <sebastian.castro@protonmail.com> on 2020-04-06 // edited by Sebastian Castro <sebastian.castro@protonmail.com> on 2020-04-06
(function ($) { (function ($) {
var __debug = false; var __debug = false;
var __factor = 0.8; var __factor = 1;
$.fn.farbtastic = function (options) { $.fn.farbtastic = function (options) {
$.farbtastic(this, options); $.farbtastic(this, options);
@ -21,7 +21,7 @@ $.farbtastic = function (container, options) {
$._farbtastic = function (container, options) { $._farbtastic = function (container, options) {
var fb = this; var fb = this;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
/** /**
@ -141,7 +141,7 @@ $._farbtastic = function (container, options) {
fb.ctxOverlay = fb.cnvOverlay[0].getContext('2d'); fb.ctxOverlay = fb.cnvOverlay[0].getContext('2d');
fb.ctxMask.translate(fb.mid, fb.mid); fb.ctxMask.translate(fb.mid, fb.mid);
fb.ctxOverlay.translate(fb.mid, fb.mid); fb.ctxOverlay.translate(fb.mid, fb.mid);
// Draw widget base layers. // Draw widget base layers.
fb.drawCircle(); fb.drawCircle();
fb.drawMask(); fb.drawMask();
@ -215,7 +215,7 @@ $._farbtastic = function (container, options) {
m.restore(); m.restore();
__debug && $('body').append('<div>drawCircle '+ (+(new Date()) - tm) +'ms'); __debug && $('body').append('<div>drawCircle '+ (+(new Date()) - tm) +'ms');
}; };
/** /**
* Draw the saturation/luminance mask. * Draw the saturation/luminance mask.
*/ */
@ -239,9 +239,9 @@ $._farbtastic = function (container, options) {
outputPixel(x, y, c, a); outputPixel(x, y, c, a);
} }
} }
} }
// Method #1: direct pixel access (new Canvas). // Method #1: direct pixel access (new Canvas).
if (fb.ctxMask.getImageData) { if (fb.ctxMask.getImageData) {
// Create half-resolution buffer. // Create half-resolution buffer.
@ -302,7 +302,7 @@ $._farbtastic = function (container, options) {
} }
cache.push([c, a]); cache.push([c, a]);
}); });
} }
__debug && $('body').append('<div>drawMask '+ (+(new Date()) - tm) +'ms'); __debug && $('body').append('<div>drawMask '+ (+(new Date()) - tm) +'ms');
} }
@ -348,7 +348,7 @@ $._farbtastic = function (container, options) {
// Draw markers // Draw markers
fb.drawMarkers(); fb.drawMarkers();
// Linked elements or callback // Linked elements or callback
if (typeof fb.callback == 'object') { if (typeof fb.callback == 'object') {
// Set background/foreground color // Set background/foreground color
@ -368,15 +368,15 @@ $._farbtastic = function (container, options) {
fb.callback.call(fb, fb.color); fb.callback.call(fb, fb.color);
} }
} }
/** /**
* Helper for returning coordinates relative to the center. * Helper for returning coordinates relative to the center.
*/ */
fb.widgetCoords = function (event) { fb.widgetCoords = function (event) {
return { return {
x: event.pageX - fb.offset.left - fb.mid, x: event.pageX - fb.offset.left - fb.mid,
y: event.pageY - fb.offset.top - fb.mid y: event.pageY - fb.offset.top - fb.mid
}; };
} }
/** /**
@ -439,7 +439,7 @@ $._farbtastic = function (container, options) {
fb.packDX = function (c, a) { fb.packDX = function (c, a) {
return '#' + fb.dec2hex(a) + fb.dec2hex(c) + fb.dec2hex(c) + fb.dec2hex(c); return '#' + fb.dec2hex(a) + fb.dec2hex(c) + fb.dec2hex(c) + fb.dec2hex(c);
}; };
fb.pack = function (rgb) { fb.pack = function (rgb) {
var r = Math.round(rgb[0] * 255); var r = Math.round(rgb[0] * 255);
var g = Math.round(rgb[1] * 255); var g = Math.round(rgb[1] * 255);