upgrade mousetrap and related code

pull/7377/head
Thibault Duplessis 2020-09-28 12:02:45 +02:00
parent 7c5894b794
commit 84baff4cb0
13 changed files with 155 additions and 198 deletions

View File

@ -1,91 +1,87 @@
import * as control from './control';
import AnalyseCtrl from './ctrl';
import { spinner } from './util';
import { modal } from './modal';
import * as xhr from 'common/xhr';
import AnalyseCtrl from './ctrl';
import { h } from 'snabbdom'
import { modal } from './modal';
import { spinner } from './util';
import { VNode } from 'snabbdom/vnode'
const preventing = (f: () => void) => (e: MouseEvent) => {
e.preventDefault();
f();
}
export function bind(ctrl: AnalyseCtrl): void {
if (!window.Mousetrap) return;
export const bind = (ctrl: AnalyseCtrl) => {
const kbd = window.Mousetrap;
kbd.bind(['left', 'k'], preventing(() => {
control.prev(ctrl);
ctrl.redraw();
}));
kbd.bind(['shift+left', 'shift+k'], preventing(() => {
control.exitVariation(ctrl);
ctrl.redraw();
}));
kbd.bind(['right', 'j'], preventing(() => {
if (!ctrl.fork.proceed()) control.next(ctrl);
ctrl.redraw();
}));
kbd.bind(['shift+right', 'shift+j'], preventing(() => {
control.enterVariation(ctrl);
ctrl.redraw();
}));
kbd.bind(['up', '0'], preventing(() => {
if (!ctrl.fork.prev()) control.first(ctrl);
ctrl.redraw();
}));
kbd.bind(['down', '$'], preventing(() => {
if (!ctrl.fork.next()) control.last(ctrl);
ctrl.redraw();
}));
kbd.bind('shift+c', preventing(() => {
ctrl.showComments = !ctrl.showComments;
ctrl.autoScroll();
ctrl.redraw();
}));
kbd.bind('shift+i', preventing(() => {
ctrl.treeView.toggle();
ctrl.redraw();
}));
kbd.bind('z', preventing(() => {
ctrl.toggleComputer();
ctrl.redraw();
}));
if (!kbd) return;
kbd
.bind(['left', 'k'], () => {
control.prev(ctrl);
ctrl.redraw();
})
.bind(['shift+left', 'shift+k'], () => {
control.exitVariation(ctrl);
ctrl.redraw();
})
.bind(['right', 'j'], () => {
if (!ctrl.fork.proceed()) control.next(ctrl);
ctrl.redraw();
})
.bind(['shift+right', 'shift+j'], () => {
control.enterVariation(ctrl);
ctrl.redraw();
})
.bind(['up', '0'], () => {
if (!ctrl.fork.prev()) control.first(ctrl);
ctrl.redraw();
})
.bind(['down', '$'], () => {
if (!ctrl.fork.next()) control.last(ctrl);
ctrl.redraw();
})
.bind('shift+c', () => {
ctrl.showComments = !ctrl.showComments;
ctrl.autoScroll();
ctrl.redraw();
})
.bind('shift+i', () => {
ctrl.treeView.toggle();
ctrl.redraw();
})
.bind('z', () => {
ctrl.toggleComputer();
ctrl.redraw();
});
if (ctrl.embed) return;
kbd.bind('space', preventing(() => {
kbd.bind('space', () => {
const gb = ctrl.gamebookPlay();
if (gb) gb.onSpace();
else if (ctrl.studyPractice) return;
else if (ctrl.ceval.enabled()) ctrl.playBestMove();
else ctrl.toggleCeval();
}));
});
if (ctrl.studyPractice) return;
kbd.bind('f', preventing(ctrl.flip));
kbd.bind('?', preventing(() => {
ctrl.keyboardHelp = !ctrl.keyboardHelp;
ctrl.redraw();
}));
kbd.bind('l', preventing(ctrl.toggleCeval));
kbd.bind('a', preventing(() => {
ctrl.toggleAutoShapes(!ctrl.showAutoShapes());
ctrl.redraw();
}));
kbd.bind('x', preventing(ctrl.toggleThreatMode));
kbd.bind('e', preventing(() => {
ctrl.toggleExplorer();
ctrl.redraw();
}));
kbd.bind('f', ctrl.flip)
.bind('?', () => {
ctrl.keyboardHelp = !ctrl.keyboardHelp;
ctrl.redraw();
})
.bind('l', ctrl.toggleCeval)
.bind('a', () => {
ctrl.toggleAutoShapes(!ctrl.showAutoShapes());
ctrl.redraw();
})
.bind('x', ctrl.toggleThreatMode)
.bind('e', () => {
ctrl.toggleExplorer();
ctrl.redraw();
});
if (ctrl.study) {
const keyToMousedown = (key: string, selector: string) => {
kbd.bind(key, preventing(() => {
kbd.bind(key, () => {
$(selector).each(function(this: HTMLElement) {
this.dispatchEvent(new Event('mousedown'));
});
}));
});
};
keyToMousedown('d', '.study__buttons .comments');
keyToMousedown('g', '.study__buttons .glyphs');

View File

@ -1,12 +1,12 @@
import { h, thunk } from 'snabbdom'
import { VNode, VNodeData } from 'snabbdom/vnode'
import { Ctrl, Line } from './interfaces'
import * as spam from './spam'
import * as enhance from './enhance';
import { presetView } from './preset';
import { lineAction as modLineAction } from './moderation';
import { userLink } from './util';
import * as spam from './spam'
import { Ctrl, Line } from './interfaces'
import { flag } from './xhr'
import { h, thunk } from 'snabbdom'
import { lineAction as modLineAction } from './moderation';
import { presetView } from './preset';
import { userLink } from './util';
import { VNode, VNodeData } from 'snabbdom/vnode'
const whisperRegex = /^\/[wW](?:hisper)?\s/;
@ -22,7 +22,7 @@ export default function(ctrl: Ctrl): Array<VNode | undefined> {
}
}
},
mod = ctrl.moderation();
mod = ctrl.moderation();
const vnodes = [
h('ol.mchat__messages.chat-v-' + ctrl.data.domVersion, {
attrs: {
@ -86,7 +86,7 @@ let mouchListener: EventListener;
const setupHooks = (ctrl: Ctrl, chatEl: HTMLInputElement) => {
const storage = lichess.tempStorage.make('chatInput');
if(storage.get()){
if (storage.get()) {
chatEl.value = storage.get()!;
storage.remove();
chatEl.focus();
@ -116,13 +116,7 @@ const setupHooks = (ctrl: Ctrl, chatEl: HTMLInputElement) => {
})
);
window.Mousetrap.bind('c', () => {
chatEl.focus();
return false;
});
window.Mousetrap(chatEl).bind('esc', () => chatEl.blur());
window.Mousetrap.bind('c', () => chatEl.focus());
// Ensure clicks remove chat focus.
// See ornicar/chessground#109
@ -130,7 +124,7 @@ const setupHooks = (ctrl: Ctrl, chatEl: HTMLInputElement) => {
const mouchEvents = ['touchstart', 'mousedown'];
if (mouchListener) mouchEvents.forEach(event =>
document.body.removeEventListener(event, mouchListener, {capture: true})
document.body.removeEventListener(event, mouchListener, { capture: true })
);
mouchListener = (e: MouseEvent) => {
@ -140,12 +134,12 @@ const setupHooks = (ctrl: Ctrl, chatEl: HTMLInputElement) => {
chatEl.onfocus = () =>
mouchEvents.forEach(event =>
document.body.addEventListener(event, mouchListener,
{passive: true, capture: true}
{ passive: true, capture: true }
));
chatEl.onblur = () =>
mouchEvents.forEach(event =>
document.body.removeEventListener(event, mouchListener, {capture: true})
document.body.removeEventListener(event, mouchListener, { capture: true })
);
};
@ -217,14 +211,14 @@ function renderLine(ctrl: Ctrl, line: Line): VNode {
' ',
textNode
] : [
ctrl.data.userId && line.u && ctrl.data.userId != line.u ? h('i.flag', {
attrs: {
'data-icon': '!',
title: 'Report'
}
}) : null,
userNode,
' ',
textNode
]);
ctrl.data.userId && line.u && ctrl.data.userId != line.u ? h('i.flag', {
attrs: {
'data-icon': '!',
title: 'Report'
}
}) : null,
userNode,
' ',
textNode
]);
}

View File

@ -49,8 +49,7 @@ export default class EditorCtrl {
cfg.positions.forEach(p => p.epd = p.fen.split(' ').splice(0, 4).join(' '));
}
window.Mousetrap.bind('f', (e: Event) => {
e.preventDefault();
window.Mousetrap.bind('f', () => {
if (this.chessground) this.chessground.toggleOrientation();
redraw();
});

View File

@ -37,7 +37,7 @@ module.exports = function(blueprint, opts) {
};
// cheat
Mousetrap.bind(['shift+enter'], complete);
// Mousetrap.bind(['shift+enter'], complete);
var assertData = function() {
return {

View File

@ -1,35 +1,30 @@
import { KeyboardController } from './interfaces';
import * as control from './control';
const preventing = (f: () => void) => (e: MouseEvent) => {
e.preventDefault();
f();
};
import { KeyboardController } from './interfaces';
export default function(ctrl: KeyboardController): void {
if (!window.Mousetrap) return;
const kbd = window.Mousetrap;
kbd.bind(['left', 'k'], preventing(function() {
control.prev(ctrl);
ctrl.redraw();
}));
kbd.bind(['right', 'j'], preventing(function() {
control.next(ctrl);
ctrl.redraw();
}));
kbd.bind(['up', '0'], preventing(function() {
control.first(ctrl);
ctrl.redraw();
}));
kbd.bind(['down', '$'], preventing(function() {
control.last(ctrl);
ctrl.redraw();
}));
kbd.bind('l', preventing(ctrl.toggleCeval));
kbd.bind('x', preventing(ctrl.toggleThreatMode));
kbd.bind('space', preventing(function() {
if (ctrl.vm.mode !== 'view') return;
if (ctrl.getCeval().enabled()) ctrl.playBestMove();
else ctrl.toggleCeval();
}));
window.Mousetrap
.bind(['left', 'k'], () => {
control.prev(ctrl);
ctrl.redraw();
})
.bind(['right', 'j'], () => {
control.next(ctrl);
ctrl.redraw();
})
.bind(['up', '0'], () => {
control.first(ctrl);
ctrl.redraw();
})
.bind(['down', '$'], () => {
control.last(ctrl);
ctrl.redraw();
})
.bind('l', ctrl.toggleCeval)
.bind('x', ctrl.toggleThreatMode)
.bind('space', () => {
if (ctrl.vm.mode === 'view') {
if (ctrl.getCeval().enabled()) ctrl.playBestMove();
else ctrl.toggleCeval();
}
});
}

View File

@ -92,15 +92,13 @@ export function init(ctrl: RoundController) {
for (let i = 1; i <= 5; i++) {
const iStr = i.toString();
k.bind(iStr, (e: KeyboardEvent) => {
e.preventDefault();
k.bind(iStr, () => {
if (!crazyKeys.includes(i)) {
crazyKeys.push(i);
setDrop();
}
});
k.bind(iStr, (e: KeyboardEvent) => {
e.preventDefault();
})
.bind(iStr, () => {
const idx = crazyKeys.indexOf(i);
if (idx >= 0) {
crazyKeys.splice(idx, 1);

View File

@ -717,8 +717,8 @@ export default class RoundController {
window.Mousetrap.bind('esc', () => {
this.submitMove(false);
this.chessground.cancelMove();
});
window.Mousetrap.bind('return', () => this.submitMove(true));
})
.bind('return', () => this.submitMove(true));
}
cevalSub.subscribe(this);
}

View File

@ -1,36 +1,28 @@
import RoundController from './ctrl';
const preventing = (f: () => void) => (e: MouseEvent) => {
e.preventDefault();
f();
}
export function prev(ctrl: RoundController) {
export const prev = (ctrl: RoundController) =>
ctrl.userJump(ctrl.ply - 1);
}
export function next(ctrl: RoundController) {
export const next = (ctrl: RoundController) =>
ctrl.userJump(ctrl.ply + 1);
}
export function init(ctrl: RoundController) {
const k = window.Mousetrap;
k.bind(['left', 'h'], preventing(function() {
prev(ctrl);
ctrl.redraw();
}));
k.bind(['right', 'l'], preventing(function() {
next(ctrl);
ctrl.redraw();
}));
k.bind(['up', 'k'], preventing(function() {
ctrl.userJump(0);
ctrl.redraw();
}));
k.bind(['down', 'j'], preventing(function() {
ctrl.userJump(ctrl.data.steps.length - 1);
ctrl.redraw();
}));
k.bind('f', preventing(ctrl.flipNow));
k.bind('z', preventing(() => lichess.pubsub.emit('zen')));
}
export const init = (ctrl: RoundController) =>
window.Mousetrap
.bind(['left', 'h'], () => {
prev(ctrl);
ctrl.redraw();
})
.bind(['right', 'l'], () => {
next(ctrl);
ctrl.redraw();
})
.bind(['up', 'k'], () => {
ctrl.userJump(0);
ctrl.redraw();
})
.bind(['down', 'j'], () => {
ctrl.userJump(ctrl.data.steps.length - 1);
ctrl.redraw();
})
.bind('f', ctrl.flipNow)
.bind('z', () => lichess.pubsub.emit('zen'));

View File

@ -80,9 +80,7 @@ lichess.keyboardMove = function(opts: any) {
}
function makeBindings(opts: any, submit: Submit, clear: Function) {
window.Mousetrap.bind('enter', function() {
opts.input.focus();
});
window.Mousetrap.bind('enter', () => opts.input.focus());
/* keypress doesn't cut it here;
* at the time it fires, the last typed char
* is not available yet. Reported by:

View File

@ -1,11 +1 @@
/* mousetrap v1.5.3 craig.is/killing/mice */
(function(C,r,g){function t(a,b,h){a.addEventListener?a.addEventListener(b,h,!1):a.attachEvent("on"+b,h)}function x(a){if("keypress"==a.type){var b=String.fromCharCode(a.which);a.shiftKey||(b=b.toLowerCase());return b}return l[a.which]?l[a.which]:p[a.which]?p[a.which]:String.fromCharCode(a.which).toLowerCase()}function D(a){var b=[];a.shiftKey&&b.push("shift");a.altKey&&b.push("alt");a.ctrlKey&&b.push("ctrl");a.metaKey&&b.push("meta");return b}function u(a){return"shift"==a||"ctrl"==a||"alt"==a||
"meta"==a}function y(a,b){var h,c,e,g=[];h=a;"+"===h?h=["+"]:(h=h.replace(/\+{2}/g,"+plus"),h=h.split("+"));for(e=0;e<h.length;++e)c=h[e],z[c]&&(c=z[c]),b&&"keypress"!=b&&A[c]&&(c=A[c],g.push("shift")),u(c)&&g.push(c);h=c;e=b;if(!e){if(!k){k={};for(var m in l)95<m&&112>m||l.hasOwnProperty(m)&&(k[l[m]]=m)}e=k[h]?"keydown":"keypress"}"keypress"==e&&g.length&&(e="keydown");return{key:c,modifiers:g,action:e}}function B(a,b){return null===a||a===r?!1:a===b?!0:B(a.parentNode,b)}function c(a){function b(a){a=
a||{};var b=!1,n;for(n in q)a[n]?b=!0:q[n]=0;b||(v=!1)}function h(a,b,n,f,c,h){var g,e,l=[],m=n.type;if(!d._callbacks[a])return[];"keyup"==m&&u(a)&&(b=[a]);for(g=0;g<d._callbacks[a].length;++g)if(e=d._callbacks[a][g],(f||!e.seq||q[e.seq]==e.level)&&m==e.action){var k;(k="keypress"==m&&!n.metaKey&&!n.ctrlKey)||(k=e.modifiers,k=b.sort().join(",")===k.sort().join(","));k&&(k=f&&e.seq==f&&e.level==h,(!f&&e.combo==c||k)&&d._callbacks[a].splice(g,1),l.push(e))}return l}function g(a,b,n,f){d.stopCallback(b,
b.target||b.srcElement,n,f)||!1!==a(b,n)||(b.preventDefault?b.preventDefault():b.returnValue=!1,b.stopPropagation?b.stopPropagation():b.cancelBubble=!0)}function e(a){"number"!==typeof a.which&&(a.which=a.keyCode);var b=x(a);b&&("keyup"==a.type&&w===b?w=!1:d.handleKey(b,D(a),a))}function l(a,c,n,f){function e(c){return function(){v=c;++q[a];clearTimeout(k);k=setTimeout(b,1E3)}}function h(c){g(n,c,a);"keyup"!==f&&(w=x(c));setTimeout(b,10)}for(var d=q[a]=0;d<c.length;++d){var p=d+1===c.length?h:e(f||
y(c[d+1]).action);m(c[d],p,f,a,d)}}function m(a,b,c,f,e){d._directMap[a+":"+c]=b;a=a.replace(/\s+/g," ");var g=a.split(" ");1<g.length?l(a,g,b,c):(c=y(a,c),d._callbacks[c.key]=d._callbacks[c.key]||[],h(c.key,c.modifiers,{type:c.action},f,a,e),d._callbacks[c.key][f?"unshift":"push"]({callback:b,modifiers:c.modifiers,action:c.action,seq:f,level:e,combo:a}))}var d=this;a=a||r;if(!(d instanceof c))return new c(a);d.target=a;d._callbacks={};d._directMap={};var q={},k,w=!1,p=!1,v=!1;d._handleKey=function(a,
c,e){var f=h(a,c,e),d;c={};var k=0,l=!1;for(d=0;d<f.length;++d)f[d].seq&&(k=Math.max(k,f[d].level));for(d=0;d<f.length;++d)f[d].seq?f[d].level==k&&(l=!0,c[f[d].seq]=1,g(f[d].callback,e,f[d].combo,f[d].seq)):l||g(f[d].callback,e,f[d].combo);f="keypress"==e.type&&p;e.type!=v||u(a)||f||b(c);p=l&&"keydown"==e.type};d._bindMultiple=function(a,b,c){for(var d=0;d<a.length;++d)m(a[d],b,c)};t(a,"keypress",e);t(a,"keydown",e);t(a,"keyup",e)}var l={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",
20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},p={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},A={"~":"`","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0",_:"-","+":"=",":":";",'"':"'","<":",",">":".","?":"/","|":"\\"},z={option:"alt",command:"meta","return":"enter",
escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},k;for(g=1;20>g;++g)l[111+g]="f"+g;for(g=0;9>=g;++g)l[g+96]=g;c.prototype.bind=function(a,b,c){a=a instanceof Array?a:[a];this._bindMultiple.call(this,a,b,c);return this};c.prototype.unbind=function(a,b){return this.bind.call(this,a,function(){},b)};c.prototype.trigger=function(a,b){if(this._directMap[a+":"+b])this._directMap[a+":"+b]({},a);return this};c.prototype.reset=function(){this._callbacks={};this._directMap=
{};return this};c.prototype.stopCallback=function(a,b){return-1<(" "+b.className+" ").indexOf(" mousetrap ")||B(b,this.target)?!1:"INPUT"==b.tagName||"SELECT"==b.tagName||"TEXTAREA"==b.tagName||b.isContentEditable};c.prototype.handleKey=function(){return this._handleKey.apply(this,arguments)};c.init=function(){var a=c(r),b;for(b in a)"_"!==b.charAt(0)&&(c[b]=function(b){return function(){return a[b].apply(a,arguments)}}(b))};c.init();C.Mousetrap=c;"undefined"!==typeof module&&module.exports&&(module.exports=
c);"function"===typeof define&&define.amd&&define(function(){return c})})(window,document);
!function(){for(var e,t={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},n={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},a={option:"alt",command:"meta",return:"enter",escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},r=1;r<20;++r)t[111+r]="f"+r;for(r=0;r<=9;++r)t[r+96]=r.toString();function o(e){if("keypress"==e.type){var a=String.fromCharCode(e.which);return e.shiftKey||(a=a.toLowerCase()),a}return t[e.which]?t[e.which]:n[e.which]?n[e.which]:String.fromCharCode(e.which).toLowerCase()}function i(e){return"shift"==e||"ctrl"==e||"alt"==e||"meta"==e}function c(n,a,r){return r||(r=function(){if(!e)for(var n in e={},t)n>95&&n<112||t.hasOwnProperty(n)&&(e[t[n]]=n);return e}()[n]?"keydown":"keypress"),"keypress"==r&&a.length&&(r="keydown"),r}function s(e,t){var n,r,o,s=[];for(n=function(e){return"+"===e?["+"]:(e=e.replace(/\+{2}/g,"+plus")).split("+")}(e),o=0;o<n.length;++o)r=n[o],a[r]&&(r=a[r]),i(r)&&s.push(r);return{key:r,modifiers:s,action:t=c(r,s,t)}}function l(e){var t=this;if(e=e||document,!(t instanceof l))return new l(e);t.target=e,t._callbacks={};var n,a={},r=!1,c=!1,u=!1;function f(e){e=e||{};var t,n=!1;for(t in a)e[t]?n=!0:a[t]=0;n||(u=!1)}function h(e,n,r,o,c,s){var l,u,f,h,p=[],y=r.type;if(!t._callbacks[e])return[];for("keyup"==y&&i(e)&&(n=[e]),l=0;l<t._callbacks[e].length;++l)if(u=t._callbacks[e][l],(o||!u.seq||a[u.seq]==u.level)&&y==u.action&&("keypress"==y&&!r.metaKey&&!r.ctrlKey||(f=n,h=u.modifiers,f.sort().join(",")===h.sort().join(",")))){var m=!o&&u.combo==c,d=o&&u.seq==o&&u.level==s;(m||d)&&t._callbacks[e].splice(l,1),p.push(u)}return p}function p(e,t,n){const a=t.target;("esc"==n||"INPUT"!=a.tagName&&"SELECT"!=a.tagName&&"TEXTAREA"!=a.tagName)&&(e(),t.preventDefault(),t.stopPropagation())}function y(e){"number"!=typeof e.which&&(e.which=e.keyCode);var n=o(e);n&&("keyup"!=e.type||r!==n?t._handleKey.call(t,n,function(e){var t=[];return e.shiftKey&&t.push("shift"),e.altKey&&t.push("alt"),e.ctrlKey&&t.push("ctrl"),e.metaKey&&t.push("meta"),t}(e),e):r=!1)}function m(e,t,i,c){function l(t){return function(){u=t,++a[e],clearTimeout(n),n=setTimeout(f,1e3)}}function h(t){p(i,t,e),"keyup"!==c&&(r=o(t)),setTimeout(f,10)}a[e]=0;for(var y=0;y<t.length;++y){var m=y+1===t.length?h:l(c||s(t[y+1]).action);d(t[y],m,c,e,y)}}function d(e,n,a,r,o){var i,c=(e=e.replace(/\s+/g," ")).split(" ");c.length>1?m(e,c,n,a):(i=s(e,a),t._callbacks[i.key]=t._callbacks[i.key]||[],h(i.key,i.modifiers,{type:i.action},r,e,o),t._callbacks[i.key][r?"unshift":"push"]({callback:n,modifiers:i.modifiers,action:i.action,seq:r,level:o,combo:e}))}t._handleKey=function(e,t,n){var a,r=h(e,t,n),o={},s=0,l=!1;for(a=0;a<r.length;++a)r[a].seq&&(s=Math.max(s,r[a].level));for(a=0;a<r.length;++a)if(r[a].seq){if(r[a].level!=s)continue;l=!0,o[r[a].seq]=1,p(r[a].callback,n,r[a].combo)}else l||p(r[a].callback,n,r[a].combo);var y="keypress"==n.type&&c;n.type!=u||i(e)||y||f(o),c=l&&"keydown"==n.type},t._bindMultiple=function(e,t,n){e.forEach(e=>d(e,t,n))},e.addEventListener("keypress",y),e.addEventListener("keydown",y),e.addEventListener("keyup",y)}l.prototype.bind=function(e,t,n){return this._bindMultiple.call(this,e instanceof Array?e:[e],t,n),this},window.Mousetrap=new l}();

View File

@ -7,7 +7,7 @@ export default function() {
const initiatingHtml = `<div class="initiating">${spinnerHtml}</div>`,
isVisible = (selector: string) => {
const el = document.querySelector(selector),
display = el && window.getComputedStyle(el).display;
display = el && window.getComputedStyle(el).display;
return display && display != 'none';
};
@ -137,12 +137,12 @@ export default function() {
if ($('body').hasClass('clinput')) $input[0]!.focus();
};
$wrap.find('a').on('mouseover click', e => (e.type === 'mouseover' ? boot : toggle)());
window.Mousetrap.bind('/', () => {
$input.val('/');
requestAnimationFrame(() => toggle());
return false;
});
window.Mousetrap.bind('s', () => requestAnimationFrame(toggle));
window.Mousetrap
.bind('/', () => {
$input.val('/');
requestAnimationFrame(() => toggle());
})
.bind('s', () => requestAnimationFrame(toggle));
if ($('body').hasClass('blind-mode')) $input.one('focus', toggle);
}
}

View File

@ -1,8 +1,8 @@
import tablesort from 'tablesort';
import * as xhr from 'common/xhr';
import debounce from 'common/debounce';
import spinnerHtml from './component/spinner';
import extendTablesortNumber from './component/tablesort-number';
import spinnerHtml from './component/spinner';
import tablesort from 'tablesort';
lichess.load.then(() => {
@ -86,7 +86,7 @@ lichess.load.then(() => {
});
});
makeReady('form.fide_title select', el =>
makeReady('form.fide_title select', el =>
$(el).on('change', () => ($(el).parent('form')[0] as HTMLFormElement).submit())
);
@ -142,6 +142,7 @@ lichess.load.then(() => {
if (location.search.startsWith('?mod')) $toggle.trigger('click');
window.Mousetrap.bind('m', () => $toggle.trigger('click'));
window.Mousetrap.bind('i', () => $zone.find('button.inquiry').trigger('click'));
window.Mousetrap
.bind('m', () => $toggle.trigger('click'))
.bind('i', () => $zone.find('button.inquiry').trigger('click'));
});

View File

@ -105,11 +105,6 @@ lichess.load.then(() => {
return false;
});
// still bind esc even in form fields
window.Mousetrap.prototype.stopCallback = (_: any, el: HTMLElement, combo: string) =>
combo != 'esc' && (
el.isContentEditable || el.tagName == 'INPUT' || el.tagName == 'SELECT' || el.tagName == 'TEXTAREA'
);
window.Mousetrap.bind('esc', () => {
const $oc = $('#modal-wrap .close');
if ($oc.length) $oc.trigger('click');
@ -117,7 +112,6 @@ lichess.load.then(() => {
const $input = $(':focus');
if ($input.length) $input.trigger('blur');
}
return false;
});
/* A disgusting hack for a disgusting browser