JS tweaks and fixes

refactor-site-js
Thibault Duplessis 2020-09-04 16:49:32 +02:00
parent 5c4137df71
commit f6acd7b318
6 changed files with 9 additions and 14 deletions

View File

@ -139,7 +139,7 @@ object layout {
private def loadScripts(moreJs: Frag, chessground: Boolean)(implicit ctx: Context) =
frag(
chessground option jsAt("vendor/chessground.min.js"),
chessground option chessgroundTag,
ctx.requiresFingerprint option fingerprintTag,
embedJsUnsafe(
s"""lichess={load:new Promise(r=>{window.onload=r}),quantity:${lila.i18n

View File

@ -1,15 +1,10 @@
function challengeStart(opts) {
var selector = '.challenge-page';
var element = document.querySelector(selector);
var challenge = opts.data.challenge;
var accepting;
lichess.socket = new lichess.StrongSocket(
opts.socketUrl,
opts.data.socketVersion, {
options: {
name: "challenge"
},
events: {
reload: function() {
$.ajax({

View File

@ -1,4 +1,4 @@
lichess.checkout = function (publicKey) {
lichess.checkout = function(publicKey) {
var $checkout = $('div.plan_checkout');
var lifetime = {

View File

@ -1,8 +1,6 @@
var selector = '.auth-login form';
const selector = '.auth-login form';
$(function() {
load($(selector));
});
$(() => load($(selector)));
function load($f) {
$f.submit(function() {

View File

@ -219,8 +219,9 @@ export default class StrongSocket {
break;
default:
this.pubsub.emit('socket.in.' + m.t, m.d, m);
const processed = this.settings.receive && this.settings.receive(m.t, m.d);
if (!processed && this.settings.events[m.t]) this.settings.events[m.t](m.d || null, m);
(this.settings.receive && this.settings.receive(m.t, m.d)) || (
this.settings.events[m.t] && this.settings.events[m.t](m.d || null, m)
);
}
};

View File

@ -33,7 +33,8 @@ window.lichess.load.then(() => {
requestIdleCallback(() => {
new OnlineFriends(document.getElementById('friend_box')!);
const friendsEl = document.getElementById('friend_box');
if (friendsEl) new OnlineFriends(friendsEl);
$('#main-wrap')
.on('click', '.autoselect', function(this: HTMLElement) {