From 133d47ba1960d49291c126a6308c8b4b38fbeafc Mon Sep 17 00:00:00 2001 From: Jan Odvarko Date: Thu, 25 Aug 2022 18:32:48 +0200 Subject: [PATCH 1/4] Synced with master --- jscolor.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/jscolor.js b/jscolor.js index 5fdcca1..fcb5cb0 100644 --- a/jscolor.js +++ b/jscolor.js @@ -559,19 +559,19 @@ var jsc = { hexColor : function (r, g, b) { return '#' + ( - ('0' + Math.round(r).toString(16)).substr(-2) + - ('0' + Math.round(g).toString(16)).substr(-2) + - ('0' + Math.round(b).toString(16)).substr(-2) + ('0' + Math.round(r).toString(16)).slice(-2) + + ('0' + Math.round(g).toString(16)).slice(-2) + + ('0' + Math.round(b).toString(16)).slice(-2) ).toUpperCase(); }, hexaColor : function (r, g, b, a) { return '#' + ( - ('0' + Math.round(r).toString(16)).substr(-2) + - ('0' + Math.round(g).toString(16)).substr(-2) + - ('0' + Math.round(b).toString(16)).substr(-2) + - ('0' + Math.round(a * 255).toString(16)).substr(-2) + ('0' + Math.round(r).toString(16)).slice(-2) + + ('0' + Math.round(g).toString(16)).slice(-2) + + ('0' + Math.round(b).toString(16)).slice(-2) + + ('0' + Math.round(a * 255).toString(16)).slice(-2) ).toUpperCase(); }, @@ -778,19 +778,19 @@ var jsc = { // 8-char notation (= with alpha) ret.format = 'hexa'; ret.rgba = [ - parseInt(m[1].substr(0,2),16), - parseInt(m[1].substr(2,2),16), - parseInt(m[1].substr(4,2),16), - parseInt(m[1].substr(6,2),16) / 255 + parseInt(m[1].slice(0,2),16), + parseInt(m[1].slice(2,4),16), + parseInt(m[1].slice(4,6),16), + parseInt(m[1].slice(6,8),16) / 255 ]; } else if (m[1].length === 6) { // 6-char notation ret.format = 'hex'; ret.rgba = [ - parseInt(m[1].substr(0,2),16), - parseInt(m[1].substr(2,2),16), - parseInt(m[1].substr(4,2),16), + parseInt(m[1].slice(0,2),16), + parseInt(m[1].slice(2,4),16), + parseInt(m[1].slice(4,6),16), null ]; From a6a53c9d8b1e756086d1265afaa21baafa92f8b3 Mon Sep 17 00:00:00 2001 From: Jan Odvarko Date: Thu, 25 Aug 2022 18:34:36 +0200 Subject: [PATCH 2/4] Updated redrawPosition() method to fix issue with custom container --- jscolor.js | 105 ++++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/jscolor.js b/jscolor.js index fcb5cb0..b644c00 100644 --- a/jscolor.js +++ b/jscolor.js @@ -1005,56 +1005,65 @@ var jsc = { var thisObj = jsc.picker.owner; - var tp, vp; + if (thisObj.container !== window.document.body) { + + jsc._drawPosition(thisObj, 0, 0, 'relative', false); - if (thisObj.fixed) { - // Fixed elements are positioned relative to viewport, - // therefore we can ignore the scroll offset - tp = jsc.getElementPos(thisObj.targetElement, true); // target pos - vp = [0, 0]; // view pos - } else { - tp = jsc.getElementPos(thisObj.targetElement); // target pos - vp = jsc.getViewPos(); // view pos - } - - var ts = jsc.getElementSize(thisObj.targetElement); // target size - var vs = jsc.getViewSize(); // view size - var pd = jsc.getPickerDims(thisObj); - var ps = [pd.borderW, pd.borderH]; // picker outer size - var a, b, c; - switch (thisObj.position.toLowerCase()) { - case 'left': a=1; b=0; c=-1; break; - case 'right':a=1; b=0; c=1; break; - case 'top': a=0; b=1; c=-1; break; - default: a=0; b=1; c=1; break; - } - var l = (ts[b]+ps[b])/2; - - // compute picker position - if (!thisObj.smartPosition) { - var pp = [ - tp[a], - tp[b]+ts[b]-l+l*c - ]; } else { - var pp = [ - -vp[a]+tp[a]+ps[a] > vs[a] ? - (-vp[a]+tp[a]+ts[a]/2 > vs[a]/2 && tp[a]+ts[a]-ps[a] >= 0 ? tp[a]+ts[a]-ps[a] : tp[a]) : + + var tp, vp; + + if (thisObj.fixed) { + // Fixed elements are positioned relative to viewport, + // therefore we can ignore the scroll offset + tp = jsc.getElementPos(thisObj.targetElement, true); // target pos + vp = [0, 0]; // view pos + } else { + tp = jsc.getElementPos(thisObj.targetElement); // target pos + vp = jsc.getViewPos(); // view pos + } + + var ts = jsc.getElementSize(thisObj.targetElement); // target size + var vs = jsc.getViewSize(); // view size + var pd = jsc.getPickerDims(thisObj); + var ps = [pd.borderW, pd.borderH]; // picker outer size + var a, b, c; + switch (thisObj.position.toLowerCase()) { + case 'left': a=1; b=0; c=-1; break; + case 'right':a=1; b=0; c=1; break; + case 'top': a=0; b=1; c=-1; break; + default: a=0; b=1; c=1; break; + } + var l = (ts[b]+ps[b])/2; + + // compute picker position + if (!thisObj.smartPosition) { + var pp = [ tp[a], - -vp[b]+tp[b]+ts[b]+ps[b]-l+l*c > vs[b] ? - (-vp[b]+tp[b]+ts[b]/2 > vs[b]/2 && tp[b]+ts[b]-l-l*c >= 0 ? tp[b]+ts[b]-l-l*c : tp[b]+ts[b]-l+l*c) : - (tp[b]+ts[b]-l+l*c >= 0 ? tp[b]+ts[b]-l+l*c : tp[b]+ts[b]-l-l*c) - ]; - } + tp[b]+ts[b]-l+l*c + ]; + } else { + var pp = [ + -vp[a]+tp[a]+ps[a] > vs[a] ? + (-vp[a]+tp[a]+ts[a]/2 > vs[a]/2 && tp[a]+ts[a]-ps[a] >= 0 ? tp[a]+ts[a]-ps[a] : tp[a]) : + tp[a], + -vp[b]+tp[b]+ts[b]+ps[b]-l+l*c > vs[b] ? + (-vp[b]+tp[b]+ts[b]/2 > vs[b]/2 && tp[b]+ts[b]-l-l*c >= 0 ? tp[b]+ts[b]-l-l*c : tp[b]+ts[b]-l+l*c) : + (tp[b]+ts[b]-l+l*c >= 0 ? tp[b]+ts[b]-l+l*c : tp[b]+ts[b]-l-l*c) + ]; + } + + var x = pp[a]; + var y = pp[b]; + var positionValue = thisObj.fixed ? 'fixed' : 'absolute'; + var contractShadow = + (pp[0] + ps[0] > tp[0] || pp[0] < tp[0] + ts[0]) && + (pp[1] + ps[1] < tp[1] + ts[1]); - var x = pp[a]; - var y = pp[b]; - var positionValue = thisObj.fixed ? 'fixed' : 'absolute'; - var contractShadow = - (pp[0] + ps[0] > tp[0] || pp[0] < tp[0] + ts[0]) && - (pp[1] + ps[1] < tp[1] + ts[1]); + jsc._drawPosition(thisObj, x, y, positionValue, contractShadow); + + } - jsc._drawPosition(thisObj, x, y, positionValue, contractShadow); }, @@ -2848,11 +2857,7 @@ var jsc = { // The redrawPosition() method needs picker.owner to be set, that's why we call it here, // after setting the owner - if (THIS.container === window.document.body) { - jsc.redrawPosition(); - } else { - jsc._drawPosition(THIS, 0, 0, 'relative', false); - } + jsc.redrawPosition(); if (p.wrap.parentNode !== THIS.container) { THIS.container.appendChild(p.wrap); From 829a053474c9b0b5c97ed834301b0e7573d80b37 Mon Sep 17 00:00:00 2001 From: Jan Odvarko Date: Thu, 25 Aug 2022 18:42:46 +0200 Subject: [PATCH 3/4] incremented version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 513ba6f..80fb9f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eastdesire/jscolor", - "version": "2.4.7", + "version": "2.4.8", "description": "Web color picker with opacity channel (alpha channel) and custom palette. Supports CSS colors such as rgba() and hex, including #rrggbbaa.", "main": "jscolor.js", "scripts": { From ef85424d854f2879f445da7bc06a13e2f1b9e6a7 Mon Sep 17 00:00:00 2001 From: Jan Odvarko Date: Thu, 25 Aug 2022 18:42:59 +0200 Subject: [PATCH 4/4] incremented version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 80fb9f7..1ef9dcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eastdesire/jscolor", - "version": "2.4.8", + "version": "2.4.9", "description": "Web color picker with opacity channel (alpha channel) and custom palette. Supports CSS colors such as rgba() and hex, including #rrggbbaa.", "main": "jscolor.js", "scripts": {