forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.js
99 lines (93 loc) · 3.61 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
$(function() {
var $startButtons = $('#start_buttons');
if (!$startButtons.length) {
return;
}
if (!$.websocket.available) {
$('#start_buttons a').attr('href', '#');
return;
}
function prepareForm() {
var $form = $('div.lichess_overboard');
$form.find('div.buttons').buttonset().disableSelection();
$form.find('button.submit').button().disableSelection();
$form.find('.time_choice input, .increment_choice input').each(function() {
var $input = $(this), $value = $input.parent().find('span');
$input.hide().after($('<div>').slider({
value: $input.val(),
min: $input.data('min'),
max: $input.data('max'),
range: 'min',
step: 1,
slide: function( event, ui ) {
$value.text(ui.value);
$input.attr('value', ui.value);
$form.find('.color_submits button').toggle(
$form.find('.time_choice input').val() > 0 || $form.find('.increment_choice input').val() > 0
);
}
}));
});
$form.find('.elo_range').each(function() {
var $this = $(this);
var $input = $this.find("input");
var $span = $this.parent().find("span.range");
var min = $input.data("min");
var max = $input.data("max");
if ($input.val()) {
var values = $input.val().split("-");
} else {
var values = [min, max];
}
$span.text(values.join(' - '));
$this.slider({
range: true,
min: min,
max: max,
values: values,
step: 50,
slide: function( event, ui ) {
$input.val(ui.values[0] + "-" + ui.values[1]);
$span.text(ui.values[0] + " - " + ui.values[1]);
}
});
var $eloRangeConfig = $this.parent();
var $modeChoices = $form.find('.mode_choice input');
$modeChoices.on('change', function() {
$eloRangeConfig.toggle($modeChoices.eq(1).attr('checked') == 'checked');
$.centerOverboard();
}).trigger('change');
});
$form.find('.clock_choice input').on('change', function() {
$form.find('.time_choice, .increment_choice').toggle($(this).is(':checked'));
$.centerOverboard();
}).trigger('change');
var $eloRangeConfig = $form.find('.elo_range_config');
$form.prepend($('<a class="close"></a>').click(function() {
$form.remove();
$startButtons.find('a.active').removeClass('active');
}));
}
$startButtons.find('a').click(function() {
$startButtons.find('a.active').removeClass('active');
$(this).addClass('active');
$('div.lichess_overboard').remove();
$.ajax({
url: $(this).attr('href'),
success: function(html) {
$('div.lichess_overboard').remove();
$('div.lichess_board_wrap').prepend(html);
prepareForm();
$.centerOverboard();
}
});
return false;
});
$('#lichess').on('submit', 'form', $.lichessOpeningPreventClicks);
if (window.location.hash) {
$startButtons.find('a.config_'+window.location.hash.replace(/#/, '')).click();
}
});
$.lichessOpeningPreventClicks = function() {
$('div.lichess_overboard, div.hooks_wrap').hide();
};