Browse Source

Fix topbar width with context menu

Context menu close with Escape
master
Eduard Kuzmenko 4 years ago
parent
commit
220eefe116
  1. 32
      src/components/misc.ts
  2. 5
      src/lib/appManagers/appImManager.ts

32
src/components/misc.ts

@ -1,4 +1,5 @@
import Countries, { Country, PhoneCodesMain } from "../countries"; import Countries, { Country, PhoneCodesMain } from "../countries";
import { cancelEvent } from "../helpers/dom";
import mediaSizes from "../helpers/mediaSizes"; import mediaSizes from "../helpers/mediaSizes";
import { clamp } from "../helpers/number"; import { clamp } from "../helpers/number";
import { isTouchSupported } from "../helpers/touchSupport"; import { isTouchSupported } from "../helpers/touchSupport";
@ -116,24 +117,15 @@ let onMouseMove = (e: MouseEvent) => {
//console.log('mousemove', diffX, diffY); //console.log('mousemove', diffX, diffY);
}; };
let onClick = (e: MouseEvent | TouchEvent) => { const onClick = (e: MouseEvent | TouchEvent) => {
/* if(touchSupport && e.type == 'touchstart') {
const target = findUpClassName(e.target, 'btn-menu');
if(!target) {
window.addEventListener('touchend', (e) => {
return cancelEvent(e);
}, {once: true});
}
} *//* else if(!touchSupport && e.type == 'mousedown') {
const target = findUpClassName(e.target, 'btn-menu');
if(!target) {
closeBtnMenu(); closeBtnMenu();
return cancelEvent(e); };
}
} */
//e.preventDefault(); const onKeyDown = (e: KeyboardEvent) => {
if(e.key == 'Escape') {
closeBtnMenu(); closeBtnMenu();
cancelEvent(e);
}
}; };
export const closeBtnMenu = () => { export const closeBtnMenu = () => {
@ -149,17 +141,13 @@ export const closeBtnMenu = () => {
openedMenuOnClose = null; openedMenuOnClose = null;
} }
//document.body.classList.remove('disable-hover');
if(isTouchSupported) { if(isTouchSupported) {
window.removeEventListener('touchmove', onClick); window.removeEventListener('touchmove', onClick);
//window.removeEventListener('touchstart', onClick);
} else { } else {
window.removeEventListener('mousemove', onMouseMove); window.removeEventListener('mousemove', onMouseMove);
//window.removeEventListener('mousedown', onClick);
//window.removeEventListener('click', onClick);
} }
window.removeEventListener('keydown', onKeyDown, {capture: true});
window.removeEventListener('click', onClick); window.removeEventListener('click', onClick);
window.removeEventListener('contextmenu', onClick); window.removeEventListener('contextmenu', onClick);
}; };
@ -194,13 +182,11 @@ export function openBtnMenu(menuElement: HTMLElement, onClose?: () => void) {
if(isTouchSupported) { if(isTouchSupported) {
window.addEventListener('touchmove', onClick, {once: true}); window.addEventListener('touchmove', onClick, {once: true});
//window.addEventListener('touchstart', onClick);
} else { } else {
window.addEventListener('mousemove', onMouseMove); window.addEventListener('mousemove', onMouseMove);
//window.addEventListener('mousedown', onClick);
//window.addEventListener('click', onClick, {once: true});
} }
window.addEventListener('keydown', onKeyDown, {capture: true});
window.addEventListener('click', onClick, {once: true}); window.addEventListener('click', onClick, {once: true});
window.addEventListener('contextmenu', onClick, {once: true}); window.addEventListener('contextmenu', onClick, {once: true});
} }

5
src/lib/appManagers/appImManager.ts

@ -187,8 +187,9 @@ export class AppImManager {
// * fix topbar overflow section // * fix topbar overflow section
const setUtilsWidth = () => { const setUtilsWidth = () => {
this.log('utils width:', chatUtils.scrollWidth); const width = /* chatUtils.scrollWidth */chatUtils.getBoundingClientRect().width;
this.chatInfo.style.setProperty('--utils-width', chatUtils.scrollWidth + 'px'); this.log('utils width:', width);
this.chatInfo.style.setProperty('--utils-width', width + 'px');
}; };
let mutationRAF: number; let mutationRAF: number;

Loading…
Cancel
Save