Altered the positioning for the pickers.
This commit is contained in:
parent
b0ad0108f8
commit
74f116bfac
3 changed files with 35 additions and 21 deletions
|
@ -79,8 +79,8 @@ const MamiColourPicker = function(options) {
|
||||||
if(typeof pos !== 'object')
|
if(typeof pos !== 'object')
|
||||||
throw 'pos must be an object';
|
throw 'pos must be an object';
|
||||||
|
|
||||||
html.style.bottom = 'y' in pos && pos.y >= 0 ? `${pos.y}px` : null;
|
for(const attr of ['top', 'left', 'right', 'bottom'])
|
||||||
html.style.left = 'x' in pos && pos.x >= 0 ? `${pos.x}px` : null;
|
html.style[attr] = typeof pos[attr] === 'number' ? `${pos[attr]}px` : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const tabs = new MamiTabsControl({
|
const tabs = new MamiTabsControl({
|
||||||
|
@ -166,20 +166,23 @@ const MamiColourPicker = function(options) {
|
||||||
get colour() { return colour; },
|
get colour() { return colour; },
|
||||||
set colour(value) { setColour(value); },
|
set colour(value) { setColour(value); },
|
||||||
setPosition: setPosition,
|
setPosition: setPosition,
|
||||||
close: close,
|
close: runReject,
|
||||||
dialog: pos => {
|
dialog: pos => {
|
||||||
html.classList.remove('hidden');
|
html.classList.remove('hidden');
|
||||||
|
|
||||||
if(pos instanceof MouseEvent) {
|
if(pos instanceof MouseEvent) {
|
||||||
|
const ev = pos;
|
||||||
|
pos = {};
|
||||||
|
|
||||||
const mbb = html.getBoundingClientRect();
|
const mbb = html.getBoundingClientRect();
|
||||||
|
const bbb = ev.target.getBoundingClientRect();
|
||||||
const pbb = html.parentNode.getBoundingClientRect();
|
const pbb = html.parentNode.getBoundingClientRect();
|
||||||
let x = pos.clientX;
|
|
||||||
let y = pbb.height - pos.clientY;
|
|
||||||
|
|
||||||
if(x > (pbb.width - mbb.width))
|
pos.left = bbb.left;
|
||||||
x = 10;
|
pos.bottom = pbb.height - bbb.top;
|
||||||
|
|
||||||
pos = { x: x, y: y };
|
if(pos.left + mbb.width >= pbb.width)
|
||||||
|
pos.left = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pos !== undefined)
|
if(pos !== undefined)
|
||||||
|
|
|
@ -100,8 +100,8 @@ const MamiEmotePicker = function(args) {
|
||||||
if(typeof pos !== 'object')
|
if(typeof pos !== 'object')
|
||||||
throw 'pos must be an object';
|
throw 'pos must be an object';
|
||||||
|
|
||||||
html.style.bottom = 'y' in pos && pos.y >= 0 ? `${pos.y}px` : null;
|
for(const attr of ['top', 'left', 'right', 'bottom'])
|
||||||
html.style.right = 'x' in pos && pos.x >= 0 ? `${pos.x}px` : null;
|
html.style[attr] = typeof pos[attr] === 'number' ? `${pos[attr]}px` : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -117,15 +117,22 @@ const MamiEmotePicker = function(args) {
|
||||||
html.classList.remove('hidden');
|
html.classList.remove('hidden');
|
||||||
|
|
||||||
if(pos instanceof MouseEvent) {
|
if(pos instanceof MouseEvent) {
|
||||||
|
const ev = pos;
|
||||||
|
pos = {};
|
||||||
|
|
||||||
const mbb = html.getBoundingClientRect();
|
const mbb = html.getBoundingClientRect();
|
||||||
|
const bbb = ev.target.getBoundingClientRect();
|
||||||
const pbb = html.parentNode.getBoundingClientRect();
|
const pbb = html.parentNode.getBoundingClientRect();
|
||||||
let x = pbb.width - pos.clientX;
|
|
||||||
let y = pbb.height - pos.clientY;
|
|
||||||
|
|
||||||
if(x > mbb.width)
|
pos.right = pbb.width - bbb.left;
|
||||||
x -= mbb.width;
|
pos.bottom = pbb.height - bbb.top;
|
||||||
|
|
||||||
pos = { x: x, y: y };
|
if(pos.right + mbb.width > pbb.width)
|
||||||
|
pos.right = 0;
|
||||||
|
else if(pos.right > mbb.width)
|
||||||
|
pos.right -= mbb.width;
|
||||||
|
else
|
||||||
|
pos.right -= bbb.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pos !== undefined)
|
if(pos !== undefined)
|
||||||
|
|
|
@ -21,17 +21,21 @@ Umi.UI.Markup = (function() {
|
||||||
let picker, pickerVisible = false;
|
let picker, pickerVisible = false;
|
||||||
|
|
||||||
const insert = function(ev) {
|
const insert = function(ev) {
|
||||||
if(this.dataset.umiTagName === 'color' && !pickerVisible) {
|
if(this.dataset.umiTagName === 'color') {
|
||||||
pickerVisible = true;
|
|
||||||
|
|
||||||
if(picker === undefined) {
|
if(picker === undefined) {
|
||||||
picker = new MamiColourPicker({ presets: futami.get('colours') });
|
picker = new MamiColourPicker({ presets: futami.get('colours') });
|
||||||
pickerTarget.appendChild(picker.element);
|
pickerTarget.appendChild(picker.element);
|
||||||
}
|
}
|
||||||
|
|
||||||
picker.dialog(ev)
|
if(pickerVisible) {
|
||||||
.then(colour => insertRaw(`[color=${MamiColour.hex(colour)}]`, '[/color]'))
|
picker.close();
|
||||||
.finally(() => pickerVisible = false);
|
} else {
|
||||||
|
pickerVisible = true;
|
||||||
|
picker.dialog(ev)
|
||||||
|
.then(colour => insertRaw(`[color=${MamiColour.hex(colour)}]`, '[/color]'))
|
||||||
|
.catch(() => {}) // noop so the console stops screaming
|
||||||
|
.finally(() => pickerVisible = false);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
insertRaw(
|
insertRaw(
|
||||||
this.dataset.umiBeforeCursor,
|
this.dataset.umiBeforeCursor,
|
||||||
|
|
Loading…
Reference in a new issue