parent
d5255bed1e
commit
12fcc3c68e
|
@ -2611,7 +2611,7 @@ export default class ChatInput {
|
|||
return false;
|
||||
}
|
||||
|
||||
if(getStickerEffectThumb(document) && !rootScope.premium) {
|
||||
if(document.sticker && getStickerEffectThumb(document) && !rootScope.premium) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,12 +12,14 @@ import IS_TOUCH_SUPPORTED from '../environment/touchSupport';
|
|||
import safeAssign from './object/safeAssign';
|
||||
import appNavigationController, {NavigationItem} from '../components/appNavigationController';
|
||||
import findUpClassName from './dom/findUpClassName';
|
||||
import rootScope from '../lib/rootScope';
|
||||
|
||||
const KEEP_OPEN = false;
|
||||
const TOGGLE_TIMEOUT = 200;
|
||||
const ANIMATION_DURATION = 200;
|
||||
|
||||
export type IgnoreMouseOutType = 'click' | 'menu' | 'popup';
|
||||
type DropdownHoverTimeoutType = 'toggle' | 'done';
|
||||
|
||||
export default class DropdownHover extends EventListenerBase<{
|
||||
open: () => Promise<any> | void,
|
||||
|
@ -27,13 +29,13 @@ export default class DropdownHover extends EventListenerBase<{
|
|||
closed: () => any
|
||||
}> {
|
||||
protected element: HTMLElement;
|
||||
protected displayTimeout: number;
|
||||
protected forceClose: boolean;
|
||||
protected inited: boolean;
|
||||
protected ignoreMouseOut: Set<IgnoreMouseOutType>;
|
||||
protected ignoreButtons: Set<HTMLElement>;
|
||||
protected navigationItem: NavigationItem;
|
||||
protected ignoreOutClickClassName: string;
|
||||
protected timeouts: {[type in DropdownHoverTimeoutType]?: number};
|
||||
|
||||
constructor(options: {
|
||||
element: DropdownHover['element'],
|
||||
|
@ -45,6 +47,7 @@ export default class DropdownHover extends EventListenerBase<{
|
|||
this.inited = false;
|
||||
this.ignoreMouseOut = new Set();
|
||||
this.ignoreButtons = new Set();
|
||||
this.timeouts = {};
|
||||
}
|
||||
|
||||
public attachButtonListener(
|
||||
|
@ -63,17 +66,15 @@ export default class DropdownHover extends EventListenerBase<{
|
|||
}, {listenerSetter});
|
||||
} else {
|
||||
listenerSetter.add(button)('mouseover', (e) => {
|
||||
// console.log('onmouseover button');
|
||||
if(firstTime) {
|
||||
listenerSetter.add(button)('mouseout', (e) => {
|
||||
clearTimeout(this.displayTimeout);
|
||||
this.clearTimeout('toggle');
|
||||
this.onMouseOut(e);
|
||||
});
|
||||
firstTime = false;
|
||||
}
|
||||
|
||||
clearTimeout(this.displayTimeout);
|
||||
this.displayTimeout = window.setTimeout(() => {
|
||||
this.setTimeout('toggle', () => {
|
||||
this.toggle(true);
|
||||
}, TOGGLE_TIMEOUT);
|
||||
});
|
||||
|
@ -109,7 +110,7 @@ export default class DropdownHover extends EventListenerBase<{
|
|||
|
||||
protected onMouseOut = (e: MouseEvent) => {
|
||||
if(KEEP_OPEN || !this.isActive()) return;
|
||||
clearTimeout(this.displayTimeout);
|
||||
this.clearTimeout('toggle');
|
||||
|
||||
if(this.ignoreMouseOut.size) {
|
||||
return;
|
||||
|
@ -120,11 +121,26 @@ export default class DropdownHover extends EventListenerBase<{
|
|||
return;
|
||||
}
|
||||
|
||||
this.displayTimeout = window.setTimeout(() => {
|
||||
this.setTimeout('toggle', () => {
|
||||
this.toggle(false);
|
||||
}, TOGGLE_TIMEOUT);
|
||||
};
|
||||
|
||||
protected clearTimeout(type: DropdownHoverTimeoutType) {
|
||||
if(this.timeouts[type] !== undefined) {
|
||||
clearTimeout(this.timeouts[type]);
|
||||
delete this.timeouts[type];
|
||||
}
|
||||
}
|
||||
|
||||
protected setTimeout(type: DropdownHoverTimeoutType, cb: () => void, timeout: number) {
|
||||
this.clearTimeout(type);
|
||||
this.timeouts[type] = window.setTimeout(() => {
|
||||
this.clearTimeout(type);
|
||||
cb();
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
public init() {
|
||||
if(!IS_TOUCH_SUPPORTED) {
|
||||
this.element.onmouseout = this.onMouseOut;
|
||||
|
@ -134,7 +150,7 @@ export default class DropdownHover extends EventListenerBase<{
|
|||
}
|
||||
|
||||
// console.log('onmouseover element');
|
||||
clearTimeout(this.displayTimeout);
|
||||
this.clearTimeout('toggle');
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +171,7 @@ export default class DropdownHover extends EventListenerBase<{
|
|||
return;
|
||||
}
|
||||
|
||||
const delay = IS_TOUCH_SUPPORTED || !rootScope.settings.animationsEnabled ? 0 : ANIMATION_DURATION;
|
||||
if((this.element.style.display && enable === undefined) || enable) {
|
||||
const res = this.dispatchResultableEvent('open');
|
||||
await Promise.all(res);
|
||||
|
@ -172,11 +189,11 @@ export default class DropdownHover extends EventListenerBase<{
|
|||
}
|
||||
});
|
||||
|
||||
clearTimeout(this.displayTimeout);
|
||||
this.displayTimeout = window.setTimeout(() => {
|
||||
this.clearTimeout('toggle');
|
||||
this.setTimeout('done', () => {
|
||||
this.forceClose = false;
|
||||
this.dispatchEvent('opened');
|
||||
}, IS_TOUCH_SUPPORTED ? 0 : ANIMATION_DURATION);
|
||||
}, delay);
|
||||
|
||||
// ! can't use together with resizeObserver
|
||||
/* if(isTouchSupported) {
|
||||
|
@ -198,12 +215,12 @@ export default class DropdownHover extends EventListenerBase<{
|
|||
appNavigationController.removeItem(this.navigationItem);
|
||||
detachClickEvent(window, this.onClickOut, {capture: true});
|
||||
|
||||
clearTimeout(this.displayTimeout);
|
||||
this.displayTimeout = window.setTimeout(() => {
|
||||
this.clearTimeout('toggle');
|
||||
this.setTimeout('done', () => {
|
||||
this.element.style.display = 'none';
|
||||
this.forceClose = false;
|
||||
this.dispatchEvent('closed');
|
||||
}, IS_TOUCH_SUPPORTED ? 0 : ANIMATION_DURATION);
|
||||
}, delay);
|
||||
|
||||
/* if(isTouchSupported) {
|
||||
const scrollHeight = this.container.scrollHeight;
|
||||
|
|
Loading…
Reference in New Issue