diff --git a/ui/@types/lichess/index.d.ts b/ui/@types/lichess/index.d.ts index 650df7f937..9efecc327f 100644 --- a/ui/@types/lichess/index.d.ts +++ b/ui/@types/lichess/index.d.ts @@ -16,8 +16,9 @@ interface Lichess { requestIdleCallback(f: () => void): void loadCss(path: string): void loadCssPath(path: string): void - unloadCss(path: string): void - loadedCss: [string]; + loadedCss: { + [key: string]: boolean; + } escapeHtml(str: string): string toYouTubeEmbedUrl(url: string): string debounce(func: (...args: any[]) => void, wait: number, immediate?: boolean): (...args: any[]) => void; diff --git a/ui/analyse/src/view.ts b/ui/analyse/src/view.ts index 342d2ebd4e..5576f863a6 100644 --- a/ui/analyse/src/view.ts +++ b/ui/analyse/src/view.ts @@ -247,7 +247,16 @@ function forceInnerCoords(ctrl: AnalyseCtrl, v: boolean) { const pref = ctrl.data.pref.coords; if (!pref) return; if (v) li.loadCss(innerCoordsCss); - else if (pref === 2) li.unloadCss(innerCoordsCss); + else if (pref === 2) unloadCss(innerCoordsCss); +} + +function unloadCss(url) { + if (li.loadedCss[url]) { + delete li.loadedCss[url]; + $('head link[rel=stylesheet]') + .filter(function(this: HTMLLinkElement) { return this.href.includes(url) }) + .remove(); + } } let firstRender = true; @@ -280,7 +289,7 @@ export default function(ctrl: AnalyseCtrl): VNode { }, postpatch(old, vnode) { if (old.data!.gaugeOn !== gaugeOn) { - window.lichess.dispatchEvent(document.body, 'chessground.resize'); + li.dispatchEvent(document.body, 'chessground.resize'); } vnode.data!.gaugeOn = gaugeOn; } @@ -345,7 +354,7 @@ export default function(ctrl: AnalyseCtrl): VNode { ctrl.opts.chat && h('section.mchat', { hook: onInsert(_ => { ctrl.opts.chat.parseMoves = true; - window.lichess.makeChat(ctrl.opts.chat); + li.makeChat(ctrl.opts.chat); }) }), h('div.analyse__underchat', { diff --git a/ui/site/src/standalones/util.js b/ui/site/src/standalones/util.js index 935e307858..ad8a913a4a 100644 --- a/ui/site/src/standalones/util.js +++ b/ui/site/src/standalones/util.js @@ -223,14 +223,6 @@ lichess.loadCss = function(url) { lichess.loadedCss[url] = true; $('head').append($('').attr('href', lichess.assetUrl(url))); }; -lichess.unloadCss = function(url) { - if (lichess.loadedCss[url]) { - lichess.loadedCss[url] = false; - $('head link[rel=stylesheet]') - .filter(function() { return this.href.includes(url) }) - .remove(); - } -} lichess.loadCssPath = function(key) { lichess.loadCss('css/' + key + '.' + $('body').data('theme') + '.' + ($('body').data('dev') ? 'dev' : 'min') + '.css'); }