finish new mithril lobby
This commit is contained in:
parent
d4141d563f
commit
bae3b944eb
|
@ -178,7 +178,7 @@ var storage = {
|
|||
}
|
||||
refreshButton();
|
||||
}
|
||||
$('div.lichess_overboard.joining.' + data.id).each(function() {
|
||||
$('.lichess_overboard.joining.' + data.id).each(function() {
|
||||
if (!$(this).find('a.decline').length) $(this).find('form').append(
|
||||
declineListener($(data.html).find('a.decline').text($.trans('decline')), function() {
|
||||
location.href = "/";
|
||||
|
@ -1234,7 +1234,7 @@ var storage = {
|
|||
|
||||
function startLobby(element, cfg) {
|
||||
var $newposts = $("div.new_posts");
|
||||
var nbRoundsEl = document.getElementById('site_baseline span');
|
||||
var nbRoundsEl = document.querySelector('#site_baseline span');
|
||||
var lobby;
|
||||
|
||||
lichess.socket = new lichess.StrongSocket(
|
||||
|
@ -1257,9 +1257,12 @@ var storage = {
|
|||
streams: function(html) {
|
||||
$('#streams_on_air').html(html);
|
||||
},
|
||||
featured: changeFeatured,
|
||||
featured: function(o) {
|
||||
$('#featured_game').html(o.html);
|
||||
$('body').trigger('lichess.content_loaded');
|
||||
},
|
||||
redirect: function(e) {
|
||||
$.lichessOpeningPreventClicks();
|
||||
lobby.setRedirecting();
|
||||
$.redirect(e);
|
||||
},
|
||||
tournaments: function(data) {
|
||||
|
@ -1279,7 +1282,7 @@ var storage = {
|
|||
nbr: function(e) {
|
||||
if (nbRoundsEl && e) {
|
||||
var prev = parseInt(nbRoundsEl.textContent, 10);
|
||||
var k = 5;
|
||||
var k = 4;
|
||||
var interv = 2000 / k;
|
||||
$.fp.range(k).forEach(function(it) {
|
||||
setTimeout(function() {
|
||||
|
@ -1305,19 +1308,8 @@ var storage = {
|
|||
cfg.socketSend = lichess.socket.send.bind(lichess.socket);
|
||||
lobby = LichessLobby(document.getElementById('hooks_wrap'), cfg);
|
||||
|
||||
function changeFeatured(o) {
|
||||
$('#featured_game').html(o.html);
|
||||
$('body').trigger('lichess.content_loaded');
|
||||
}
|
||||
|
||||
var $startButtons = $('#start_buttons');
|
||||
|
||||
if (!lichess.StrongSocket.available) {
|
||||
$startButtons.find('a').attr('href', '#');
|
||||
$("div.lichess_overboard.joining input.submit").remove();
|
||||
return;
|
||||
}
|
||||
|
||||
function sliderTime(v) {
|
||||
if (v <= 20) return v;
|
||||
switch (v) {
|
||||
|
@ -1359,7 +1351,7 @@ var storage = {
|
|||
}
|
||||
|
||||
function prepareForm() {
|
||||
var $form = $('div.lichess_overboard');
|
||||
var $form = $('.lichess_overboard');
|
||||
var $timeModeSelect = $form.find('#timeMode');
|
||||
var $modeChoicesWrap = $form.find('.mode_choice');
|
||||
var $modeChoices = $modeChoicesWrap.find('input');
|
||||
|
@ -1560,11 +1552,11 @@ var storage = {
|
|||
|
||||
$startButtons.find('a').click(function() {
|
||||
$(this).addClass('active').siblings().removeClass('active');
|
||||
$('div.lichess_overboard').remove();
|
||||
$('.lichess_overboard').remove();
|
||||
$.ajax({
|
||||
url: $(this).attr('href'),
|
||||
success: function(html) {
|
||||
$('div.lichess_overboard').remove();
|
||||
$('.lichess_overboard').remove();
|
||||
$('#hooks_wrap').prepend(html);
|
||||
prepareForm();
|
||||
$('body').trigger('lichess.content_loaded');
|
||||
|
@ -1572,9 +1564,8 @@ var storage = {
|
|||
});
|
||||
return false;
|
||||
});
|
||||
$('#lichess').on('submit', 'form', $.lichessOpeningPreventClicks);
|
||||
|
||||
if (window.location.hash) {
|
||||
if (['#ai', '#friend', '#hook'].indexOf(window.location.hash) !== -1) {
|
||||
$startButtons
|
||||
.find('a.config_' + location.hash.replace(/#/, ''))
|
||||
.each(function() {
|
||||
|
@ -1583,10 +1574,6 @@ var storage = {
|
|||
}
|
||||
};
|
||||
|
||||
$.lichessOpeningPreventClicks = function() {
|
||||
$('#hooks_list, #hooks_chart').hide();
|
||||
};
|
||||
|
||||
///////////////////
|
||||
// tournament.js //
|
||||
///////////////////
|
||||
|
|
|
@ -22,7 +22,8 @@ module.exports = function(env) {
|
|||
open: false
|
||||
},
|
||||
stepHooks: this.data.hooks.slice(0),
|
||||
stepping: false
|
||||
stepping: false,
|
||||
redirecting: false
|
||||
};
|
||||
|
||||
var flushHooksTimeout;
|
||||
|
@ -62,13 +63,14 @@ module.exports = function(env) {
|
|||
}.bind(this);
|
||||
|
||||
this.clickHook = function(id) {
|
||||
if (this.vm.stepping) return;
|
||||
if (this.vm.stepping || this.vm.redirecting) return;
|
||||
var hook = hookRepo.find(this, id);
|
||||
if (!hook || hook.disabled) return;
|
||||
if (hook.action === 'cancel' || variant.confirm(hook.variant)) this.socket.send(hook.action, hook.id);
|
||||
}.bind(this);
|
||||
|
||||
this.clickSeek = function(id) {
|
||||
if (this.vm.redirecting) return;
|
||||
var seek = seekRepo.find(this, id);
|
||||
if (!seek) return;
|
||||
if (seek.action === 'cancelSeek' || variant.confirm(seek.variant)) this.socket.send(seek.action, seek.id);
|
||||
|
@ -86,7 +88,6 @@ module.exports = function(env) {
|
|||
}.bind(this);
|
||||
|
||||
this.gameActivity = function(gameId) {
|
||||
console.log(gameId);
|
||||
if (this.data.nowPlaying.filter(function(p) {
|
||||
return p.gameId === gameId;
|
||||
}).length) xhr.nowPlaying().then(this.setNowPlaying);
|
||||
|
@ -109,6 +110,13 @@ module.exports = function(env) {
|
|||
|
||||
this.startWatching();
|
||||
|
||||
this.setRedirecting = function() {
|
||||
this.vm.redirecting = true;
|
||||
setTimeout(function() {
|
||||
this.vm.redirecting = false;
|
||||
}.bind(this), 2000);
|
||||
}.bind(this);
|
||||
|
||||
this.router = env.routes;
|
||||
this.trans = function(key) {
|
||||
var str = env.i18n[key] || key;
|
||||
|
|
|
@ -7,7 +7,8 @@ function sort(ctrl) {
|
|||
}
|
||||
|
||||
function fixBC(hook) {
|
||||
hook.mode = hook.mode === 'Casual' ? 0 : 1;
|
||||
if (hook.mode === 'Casual') hook.mode = 0;
|
||||
else if (hook.mode === 'Rated') hook.mode = 1;
|
||||
}
|
||||
|
||||
function init(hook) {
|
||||
|
|
|
@ -8,7 +8,9 @@ module.exports = function(element, opts) {
|
|||
var controller = new ctrl(opts);
|
||||
|
||||
m.module(element, {
|
||||
controller: function () { return controller; },
|
||||
controller: function() {
|
||||
return controller;
|
||||
},
|
||||
view: view
|
||||
});
|
||||
|
||||
|
@ -18,7 +20,8 @@ module.exports = function(element, opts) {
|
|||
controller.setTab(tab);
|
||||
m.redraw();
|
||||
},
|
||||
gameActivity: controller.gameActivity
|
||||
gameActivity: controller.gameActivity,
|
||||
setRedirecting: controller.setRedirecting
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ function sort(ctrl) {
|
|||
}
|
||||
|
||||
function fixBC(seek) {
|
||||
seek.mode = seek.mode === 'Casual' ? 0 : 1;
|
||||
if (seek.mode === 'Casual') seek.mode = 0;
|
||||
else if (seek.mode === 'Rated') seek.mode = 1;
|
||||
}
|
||||
|
||||
function initAll(ctrl) {
|
||||
|
|
|
@ -39,11 +39,10 @@ module.exports = {
|
|||
render: function(ctrl, allHooks) {
|
||||
var max = 14;
|
||||
var hooks = allHooks.slice(0, max);
|
||||
var standards = hooks.filter(isStandard(true))
|
||||
.map(util.partial(renderHook, ctrl));
|
||||
var render = util.partial(renderHook, ctrl);
|
||||
var standards = hooks.filter(isStandard(true));
|
||||
var variants = hooks.filter(isStandard(false))
|
||||
.slice(0, Math.max(0, max - standards.length - 1))
|
||||
.map(util.partial(renderHook, ctrl));
|
||||
.slice(0, Math.max(0, max - standards.length - 1));
|
||||
return m('table.table_wrap', [
|
||||
m('thead',
|
||||
m('tr', [
|
||||
|
@ -66,11 +65,14 @@ module.exports = {
|
|||
while (el.nodeName !== 'TABLE');
|
||||
}
|
||||
}, [
|
||||
standards,
|
||||
standards.map(render),
|
||||
variants.length ? m('tr.variants',
|
||||
m('td[colspan=5]', '- ' + ctrl.trans('variant') + ' -')
|
||||
m('td', {
|
||||
key: 'variants',
|
||||
colspan: 5
|
||||
}, '- ' + ctrl.trans('variant') + ' -')
|
||||
) : null,
|
||||
variants
|
||||
variants.map(render)
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue