diff --git a/data/System/JQAutoColorContrib.txt b/data/System/JQAutoColorContrib.txt index cc4bf59..21e7491 100644 --- a/data/System/JQAutoColorContrib.txt +++ b/data/System/JQAutoColorContrib.txt @@ -37,13 +37,13 @@ and mapped to a matching color. %CLEAR% ---+++ Color icons -

+

%JQICON{"fa-certificate"}% Certificate

-

+

%JQICON{"fa-check-circle"}% Check

-

+

%JQICON{"fa-camera"}% Camera

@@ -55,21 +55,21 @@ and mapped to a matching color. then="" }%
-
+ -
+ -
+

Tools & Services

* Articles * Blogs @@ -162,6 +162,7 @@ Use HTML5 data parameters to specify parameters to the autoColor plugin. All par ---++ Change History %TABLE{columnwidths="7em" tablewidth="100%"}% +| 31 Aug 2022 | fixed computation of matching foreground color | | 04 May 2022 | fix setting properties other than the background | | 18 Nov 2019 | implement auto-generated gradient backgrounds | | 01 Jul 2019 | skip auto-color if text is empty | @@ -173,7 +174,7 @@ Use HTML5 data parameters to specify parameters to the autoColor plugin. All par %META:FIELD{name="Release" title="Release" value="%25$RELEASE%25"}% %META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}% %META:FIELD{name="Repository" title="Repository" value="https://github.com/foswiki/JQAutoColorContrib"}% -%META:FIELD{name="Copyright" title="Copyright" value="2018-2022, Michael Daum, All Rights Reserved"}% +%META:FIELD{name="Copyright" title="Copyright" value="2018-2024, Michael Daum, All Rights Reserved"}% %META:FIELD{name="License" title="License" value="GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]])"}% %META:FIELD{name="Home" title="Home" value="https://foswiki.org/Extensions/JQAutoColorContrib"}% %META:FIELD{name="Support" title="Support" value="https://foswiki.org/Support/JQAutoColorContrib"}% diff --git a/lib/Foswiki/Contrib/JQAutoColorContrib.pm b/lib/Foswiki/Contrib/JQAutoColorContrib.pm index e276da0..2cf7018 100644 --- a/lib/Foswiki/Contrib/JQAutoColorContrib.pm +++ b/lib/Foswiki/Contrib/JQAutoColorContrib.pm @@ -1,6 +1,6 @@ # Extension for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ # -# JQAutoColorContrib is Copyright (C) 2018-2022 Michael Daum http://michaeldaumconsulting.com +# JQAutoColorContrib is Copyright (C) 2018-2024 Michael Daum http://michaeldaumconsulting.com # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -18,11 +18,10 @@ package Foswiki::Contrib::JQAutoColorContrib; use strict; use warnings; -use Foswiki::Func (); - -our $VERSION = '2.01'; -our $RELEASE = '04 May 2022'; +our $VERSION = '3.10'; +our $RELEASE = '%$RELEASE%'; our $SHORTDESCRIPTION = 'Assign colors automatically based on text properties'; +our $LICENSECODE = '%$LICENSECODE%'; our $NO_PREFS_IN_TOPIC = 1; 1; diff --git a/lib/Foswiki/Contrib/JQAutoColorContrib/Core.pm b/lib/Foswiki/Contrib/JQAutoColorContrib/Core.pm index e0478ba..485018b 100644 --- a/lib/Foswiki/Contrib/JQAutoColorContrib/Core.pm +++ b/lib/Foswiki/Contrib/JQAutoColorContrib/Core.pm @@ -1,6 +1,6 @@ # Extension for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ # -# JQAutoColorContrib is Copyright (C) 2018-2022 Michael Daum http://michaeldaumconsulting.com +# JQAutoColorContrib is Copyright (C) 2018-2024 Michael Daum http://michaeldaumconsulting.com # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License diff --git a/pub/System/JQAutoColorContrib/src/autocolor.uncompressed.css b/pub/System/JQAutoColorContrib/src/autocolor.uncompressed.css index d76cc9f..4007a1f 100644 --- a/pub/System/JQAutoColorContrib/src/autocolor.uncompressed.css +++ b/pub/System/JQAutoColorContrib/src/autocolor.uncompressed.css @@ -1,3 +1,3 @@ -.jqAutoColor > a { +.jqAutoColor a { color:inherit; } diff --git a/pub/System/JQAutoColorContrib/src/autocolor.uncompressed.js b/pub/System/JQAutoColorContrib/src/autocolor.uncompressed.js index 6d9ab34..1676fb3 100644 --- a/pub/System/JQAutoColorContrib/src/autocolor.uncompressed.js +++ b/pub/System/JQAutoColorContrib/src/autocolor.uncompressed.js @@ -1,7 +1,7 @@ /* - * jQuery auto-color plugin 2.00 + * jQuery auto-color plugin 3.20 * - * Copyright (c) 2018-2022 Michael Daum http://michaeldaumconsulting.com + * Copyright (c) 2018-2024 Michael Daum http://michaeldaumconsulting.com * * Licensed under the GPL license http://www.gnu.org/licenses/gpl.html * @@ -15,6 +15,7 @@ var defaults = { text: undefined, source: undefined, + sourceContext: undefined, target: undefined, property: undefined, saturation: [50,65,80], @@ -36,11 +37,19 @@ // gather opts by merging global defaults, plugin defaults and element defaults self.opts = $.extend({}, defaults, self.elem.data(), opts); - if (typeof(self.opts.text) === 'undefined') { + if (typeof(self.opts.text) === 'undefined' || self.opts.text === "") { if (typeof(self.opts.source) === 'undefined') { self.sourceElem = self.elem; } else { - self.sourceElem = self.elem.find(self.opts.source); + if (typeof(self.opts.sourceContext) === 'undefined') { + self.sourceElem = $(self.opts.source); + } else { + if (self.opts.sourceContext === 'this') { + self.sourceElem = self.elem.find(self.opts.source); + } else { + self.sourceElem = $(self.opts.sourceContext).find(self.opts.source); + } + } } self.sourceElem.on("input", function() { self.init(); @@ -60,15 +69,20 @@ AutoColor.prototype.init = function () { var self = this, text, hsl; - if (typeof(self.opts.text) !== 'undefined') { + if (typeof(self.opts.text) === 'string' && self.opts.text !== "") { text = self.opts.text; + } else { text = $.map(self.sourceElem, function(elem) { - var $elem = $(elem); + var $elem = $(elem), text; if ($elem.is("input")) { - return $elem.val(); + text = $elem.val(); } else { - return $elem.text(); + text = $elem.text(); + } + text = text.trim() + if (text !== '') { + return text; } }).join(" "); } @@ -84,6 +98,7 @@ text = text.replace(/^\s*|\s*$/g, ""); if (!text.length) { + console.warn("no text found to auto-color"); return; } @@ -104,9 +119,8 @@ } } else { self.target - .addClass("jqAutoColor") .css("background", self.formatHSL(hsl)) - .css("color", self.getMatchingForeground()); + .css("color", self.getMatchingForeground(hsl)); } }; @@ -179,12 +193,18 @@ return "hsl("+hsl[0]+","+hsl[1]+"%,"+hsl[2]+"%)"; }; - AutoColor.prototype.getMatchingForeground = function(rgb) { - var self = this; + AutoColor.prototype.getMatchingForeground = function(hsl) { + var self = this, + rgb; - if (typeof(rgb) !== 'object') { - rgb = rgb || self.target.css("background-color"); + if (typeof(hsl) === 'undefined') { + rgb = self.target.css("background-color"); rgb = rgb.match(/\d+/g); + } else { + if (typeof(hsl) !== 'object') { + hsl = rgb.match(/\d+/g); + } + rgb = self.hslToRgb(hsl); } return self.isLight(rgb) ? self.opts.dark: self.opts.light; @@ -197,6 +217,56 @@ return yiq > 128; }; + AutoColor.prototype.hslToRgb = function(hsl) { + var self = this, + t1, t2, + r, g, b, + hue, sat, light; + + hue = hsl[0] / 60;; + sat = hsl[1] > 1 ? hsl[1] / 100 : hsl[1]; + light = hsl[2] > 1 ? hsl[2] / 100 : hsl[2]; + + if ( light <= 0.5 ) { + t2 = light * (sat + 1); + } else { + t2 = light + sat - (light * sat); + } + + t1 = light * 2 - t2; + r = self.hueToRgb(t1, t2, hue + 2) * 255; + g = self.hueToRgb(t1, t2, hue) * 255; + b = self.hueToRgb(t1, t2, hue - 2) * 255; + + return [r, g, b]; + }; + + AutoColor.prototype.hueToRgb = function(t1, t2, hue) { + self = this; + + if (hue < 0) { + hue += 6; + } + + if (hue >= 6) { + hue -= 6; + } + + if (hue < 1) { + return (t2 - t1) * hue + t1; + } + + if (hue < 3) { + return t2; + } + + if (hue < 4) { + return (t2 - t1) * (4 - hue) + t1; + } + + return t1; + }; + // A plugin wrapper around the constructor, // preventing against multiple instantiations $.fn.autoColor = function (opts) {