move isCol1 to ui/common

refactor-site-js
Thibault Duplessis 2020-09-04 18:03:13 +02:00
parent 0b18f2babf
commit da7b55312f
6 changed files with 8 additions and 11 deletions

View File

@ -1,11 +1,9 @@
interface Lichess {
load: Promise<unknown>; // window.onload promise
// components
info: any;
requestIdleCallback(f: () => void): void;
hasTouchEvents: boolean;
sri: string;
isCol1(): boolean;
storage: LichessStorageHelper;
tempStorage: LichessStorageHelper;
once(key: string, mod?: 'always'): boolean;

View File

@ -12,6 +12,7 @@ import column from './columnView';
import inline from './inlineView';
import { empty, defined } from 'common';
import throttle from 'common/throttle';
import isCol1 from 'common/isCol1';
import { storedProp, StoredProp } from 'common/storage';
export interface Ctx {
@ -68,7 +69,7 @@ export function ctrl(initialValue: TreeViewKey = 'column'): TreeView {
// entry point, dispatching to selected view
export function render(ctrl: AnalyseCtrl, concealOf?: ConcealOf): VNode {
return (ctrl.treeView.inline() || window.lichess.isCol1()) ? inline(ctrl) : column(ctrl, concealOf);
return (ctrl.treeView.inline() || isCol1()) ? inline(ctrl) : column(ctrl, concealOf);
}
export function nodeClasses(ctx: Ctx, path: Tree.Path): NodeClasses {

View File

@ -1,6 +1,6 @@
let cache: 'init' | 'rec' | boolean = 'init';
export function isCol1() {
export default function(): boolean {
if (typeof cache == 'string') {
if (cache == 'init') { // only once
window.addEventListener('resize', () => {

View File

@ -3,6 +3,6 @@
"include": ["src/*.ts"],
"exclude": [],
"compilerOptions": {
"outDir": "./",
"outDir": "./"
}
}

View File

@ -2,6 +2,7 @@ import { h } from 'snabbdom'
import { VNode } from 'snabbdom/vnode'
import * as round from '../round';
import throttle from 'common/throttle';
import isCol1 from 'common/isCol1';
import * as game from 'game';
import * as status from 'game/status';
import { game as gameRoute } from 'game/router';
@ -20,13 +21,13 @@ const autoScroll = throttle(100, (movesEl: HTMLElement, ctrl: RoundController) =
else if (ctrl.ply == round.lastPly(ctrl.data)) st = scrollMax;
else {
const plyEl = movesEl.querySelector('.' + activeClass) as HTMLElement | undefined;
if (plyEl) st = window.lichess.isCol1() ?
if (plyEl) st = isCol1() ?
plyEl.offsetLeft - movesEl.offsetWidth / 2 + plyEl.offsetWidth / 2 :
plyEl.offsetTop - movesEl.offsetHeight / 2 + plyEl.offsetHeight / 2;
}
if (typeof st == 'number') {
if (st == scrollMax) movesEl.scrollLeft = movesEl.scrollTop = st;
else if (window.lichess.isCol1()) movesEl.scrollLeft = st;
else if (isCol1()) movesEl.scrollLeft = st;
else movesEl.scrollTop = st;
}
})
@ -185,7 +186,6 @@ function col1Button(ctrl: RoundController, dir: number, icon: string, disabled:
export function render(ctrl: RoundController): VNode | undefined {
const d = ctrl.data,
col1 = window.lichess.isCol1(),
moves = ctrl.replayEnabledByPref() && h(movesTag, {
hook: util.onInsert(el => {
el.addEventListener('mousedown', e => {
@ -208,7 +208,7 @@ export function render(ctrl: RoundController): VNode | undefined {
return ctrl.nvui ? undefined : h(rmovesTag, [
renderButtons(ctrl),
initMessage(d, ctrl.trans.noarg) || (moves ? (
col1 ? h('div.col1-moves', [
isCol1() ? h('div.col1-moves', [
col1Button(ctrl, -1, 'Y', ctrl.ply == round.firstPly(d)),
moves,
col1Button(ctrl, 1, 'X', ctrl.ply == round.lastPly(d))

View File

@ -5,7 +5,6 @@ import once from './component/once';
import hasTouchEvents from './component/touchEvents';
import spinnerHtml from './component/spinner';
import sri from './component/sri';
import { isCol1 } from "./component/is-col1";
import { storage, tempStorage } from "./component/storage";
import powertip from "./component/powertip";
import { assetUrl, soundUrl, loadCss, loadCssPath, jsModule, loadScript, hopscotch, slider } from "./component/assets";
@ -30,7 +29,6 @@ export default function() {
l.requestIdleCallback = requestIdleCallback;
l.hasTouchEvents = hasTouchEvents;
l.sri = sri;
l.isCol1 = isCol1;
l.storage = storage;
l.tempStorage = tempStorage;
l.once = once;