position colorpicker correctly, cosmetics (89431615 fixup)

This commit is contained in:
tophf 2020-10-31 23:45:37 +03:00
parent 972a83d5bc
commit 21d4221df9

View File

@ -210,10 +210,10 @@
$formatChangeButton.title = opt.tooltipForSwitcher || ''; $formatChangeButton.title = opt.tooltipForSwitcher || '';
maxHeight = `${opt.maxHeight || 300}px`; maxHeight = `${opt.maxHeight || 300}px`;
$root.className = $root.className.replace(new RegExp(CSS_PREFIX + 'theme-\\S+\\s*'), '') + $root.className = [...$root.classList]
' ' + CSS_PREFIX + 'theme-' + .filter(c => !c.startsWith(`${CSS_PREFIX}theme-`))
(opt.theme === 'dark' || opt.theme === 'light' ? opt.theme : .concat(`${CSS_PREFIX}theme-${['dark', 'light'].includes(opt.theme) ? opt.theme : guessTheme()}`)
guessTheme()); .join(' ');
document.body.appendChild($root); document.body.appendChild($root);
shown = true; shown = true;
@ -221,21 +221,9 @@
registerEvents(); registerEvents();
setFromColor(opt.color); setFromColor(opt.color);
setFromHexLettercaseElement(); setFromHexLettercaseElement();
if (Array.isArray(options.palette)) { if (Array.isArray(options.palette)) {
// Might need to clear a lot of elements so this is known to be faster than textContent = '' renderPalette();
while ($palette.firstChild) $palette.firstChild.remove();
$palette.append(...options.palette);
if (options.palette.length) {
$root.dataset.resizable = '';
$root.addEventListener('mousedown', onPopupResizeStart);
fitPaletteHeight();
} else {
delete $root.dataset.resizable;
$root.removeEventListener('mousedown', onPopupResizeStart);
} }
}
if (!isNaN(options.left) && !isNaN(options.top)) { if (!isNaN(options.left) && !isNaN(options.top)) {
reposition(); reposition();
} }
@ -827,6 +815,21 @@
const top = constrain(0, Math.max(0, maxTopUnobscured), options.top); const top = constrain(0, Math.max(0, maxTopUnobscured), options.top);
$root.style.left = left + 'px'; $root.style.left = left + 'px';
$root.style.top = top + 'px'; $root.style.top = top + 'px';
$root.style.transform = '';
}
function renderPalette() {
// Might need to clear a lot of elements so this is known to be faster than textContent = ''
while ($palette.firstChild) $palette.firstChild.remove();
$palette.append(...options.palette);
if (options.palette.length) {
$root.dataset.resizable = '';
$root.addEventListener('mousedown', onPopupResizeStart);
fitPaletteHeight();
} else {
delete $root.dataset.resizable;
$root.removeEventListener('mousedown', onPopupResizeStart);
}
} }
function fitPaletteHeight() { function fitPaletteHeight() {