Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
EastDesire committed Aug 25, 2022
2 parents f96eabb + ef85424 commit eb59090
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 51 deletions.
105 changes: 55 additions & 50 deletions jscolor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},


Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit eb59090

Please sign in to comment.