-var modal, hiding;
+let modal, hiding;
function show_modal () {
modal.classList.remove('hidden');
$(function() {
modal = $('.modal')[0];
- $(modal).on('transitionend', function (){
+ $(modal).on('transitionend', el => {
if(!document.body.classList.contains('modal-open'))
modal.classList.add('hidden');
});
- $('.backdrop,.modal').each(function(el){
- document.body.appendChild(el);
- });
- $('#solution').on('click', function (e){
+ $('.backdrop,.modal').each(el => document.body.appendChild(el) );
+ $('#solution').on('click', e => {
show_modal();
e.preventDefault();
});
$('.backdrop').on('click', hide_modal);
- window.onkeyup = function (event) {
+ window.onkeyup = event => {
if (event.keyCode === 27)
hide_modal();
}
$(function() {
if(!document.getElementById('sidebar')) {
- var content = $('main')[0];
+ let content = $('main')[0];
content.innerHTML = '<div class="col-md-9">' + content.innerHTML + '</div><aside id="sidebar" class="col-md-3"></aside>';
content.classList.add('row');
}
$('#prog_format')[0].value = ext_table[ext];
}
-$(function() {
- $('#prog').on('change', divine_format);
-});
+$(() => $('#prog').on('change', divine_format));
$(function(){
- $('.jsform > input[type="submit"]').on('click', function(e){
- var form_data = new FormData(this.parentElement);
- var form = this.parentNode;
- var xhr = new XMLHttpRequest();
+ let result = $('#result')[0];
+ $('.jsform > input[type="submit"]').on('click', e => {
+ let form_data = new FormData(this.parentElement);
+ let form = this.parentNode;
+ let xhr = new XMLHttpRequest();
xhr.open(form.getAttribute('method'), form.getAttribute('action'));
- xhr.onload = function() {
- $('#result')[0].innerHTML = this.responseText;
- };
- xhr.onerror = function() {
- $('#result')[0].innerHTML = 'Error!';
- };
+ xhr.onload = () => result.innerHTML = this.responseText;
+ xhr.onerror = () => result.innerHTML = 'Error!';
window.scrollTo(0, 0);
- $('#result')[0].innerHTML = 'Loading...';
+ result.innerHTML = 'Loading...';
xhr.send(form_data);
e.preventDefault();
});
return;
$('#title')[0].insertAdjacentHTML('beforebegin', '<div class="text-center">Tap title to toggle menu</div>');
$('nav')[0].classList.add('hidden');
- $('#title').on('click', function () {
- $('nav')[0].classList.toggle('hidden');
- });
+ $('#title').on('click', () => $('nav')[0].classList.toggle('hidden'));
});
-var NAVS = {
- 'home': /^\/$/,
- 'pb': /^\/(?:pb|sol)\//,
- 'ct': /^\/(?:ct|st|ed)\//,
- 'log': /^\/log\//,
- 'us': /^\/us\//,
- 'account': /^\/account$/,
- 'contribute': /^\/contribute$/,
+const NAVS = {
+ home: /^\/$/,
+ pb: /^\/(?:pb|sol)\//,
+ ct: /^\/(?:ct|st|ed)\//,
+ log: /^\/log\//,
+ us: /^\/us\//,
+ account: /^\/account$/,
+ contribute: /^\/contribute$/,
};
$(function(){
- var path = location.pathname;
- for (var nav in NAVS)
+ let path = location.pathname;
+ for (let nav in NAVS)
if(path.match(NAVS[nav]))
$('#nav-' + nav)[0].classList.add('active');
});
-$(function() {
- $('.reqjs').each(function(e){
- e.classList.remove('reqjs');
- });
-});
+$(() => $('.reqjs').each(e => e.classList.remove('reqjs')));
function set_style(name){
- $('link[rel~="stylesheet"]').each(function (e){
- e.disabled = true;
- });
+ $('link[rel~="stylesheet"]').each(e => e.disabled = true);
$('link[title="' + name + '"]')[0].disabled = false;
localStorage.setItem("theme", name);
}
'<li><a role="button" data-theme="readable">White</a></ul>';
var sidebar = $('#sidebar')[0];
sidebar.insertBefore(m(theme_ul), sidebar.firstChild);
- $('#themes a').on('click', function(e){
- set_style(this.dataset.theme);
- });
+ $('#themes a').on('click', e => set_style(this.dataset.theme));
});
-var theme = localStorage.getItem("theme");
+let theme = localStorage.getItem("theme");
if(theme) {
if(theme == "cerulean" || theme == "cosmo")
theme = "readable";
}
}
-$(function() {
- $('.timer').each(function(item){
- update_timer(item);
- setInterval(function(){update_timer(item)}, 1000);
- });
-});
+$(() => $('.timer').each(item => {
+ update_timer(item);
+ setInterval(() => update_timer(item), 1000);
+}));
-var TICK = '<span class="tick tracker-mark">✔</span>';
-var XMARK = '<span class="x tracker-mark">✘</span>';
+const TICK = '<span class="tick tracker-mark">✔</span>';
+const XMARK = '<span class="x tracker-mark">✘</span>';
function clean_tracker(){
- $('.tracker-mark').each(function(e){
- e.parentNode.removeChild(e);
- });
- $('.tracker-info').each(function(e){
+ $('.tracker-mark').each(e => e.parentNode.removeChild(e));
+ $('.tracker-info').each(e => {
e.classList.remove('tracker-info');
e.classList.remove('info');
});
}
-var tracker;
+let tracker;
function update_tracker(){
- var data = localStorage.getItem('tracker_data');
- var user = localStorage.getItem('tracker_username');
+ let data = localStorage.getItem('tracker_data');
+ let user = localStorage.getItem('tracker_username');
if(!data)
return;
data = JSON.parse(data);
- var solved = {};
- var attempted = {};
- var solvednr = 0;
- var attemptednr = 0;
- data.problems.forEach(function(e){
- if(e.solved){
+ let contests = {}, solved = {}, attempted = {}, solvednr = 0, attemptednr = 0;
+ data.problems.forEach(e => {
+ if(e.solved) {
solved[e.problem] = 1;
solvednr++;
} else {
}
});
- var contests = {};
- data.contests.forEach(function(e){
- contests[e.contest] = 1;
- });
+ data.contests.forEach(e => contests[e.contest] = 1);
clean_tracker();
$('#tracker_userlink')[0].innerHTML = data.name;
$('#tracker_log')[0].setAttribute('href', '/log/?owner=' + user);
if(location.pathname == '/pb/')
- $('table .name a').each(function(el) {
- var id = el.getAttribute('href').split('?', 2)[0];
+ $('table .name a').each(el => {
+ let id = el.getAttribute('href').split('?', 2)[0];
if(solved[id])
el.insertAdjacentHTML('beforebegin', TICK);
else if(attempted[id])
});
if(location.pathname == '/ct/')
- $('table .name a').each(function(el) {
- var id = el.getAttribute('href').substr(4);
+ $('table .name a').each(el => {
+ let id = el.getAttribute('href').substr(4);
if(contests[id])
el.insertAdjacentHTML('beforebegin', TICK);
});
if(location.pathname == '/log/')
- $('table tbody tr').each(function(el) {
- var owner = el.querySelector('.owner a');
+ $('table tbody tr').each(el => {
+ let owner = el.querySelector('.owner a');
if(!owner || owner.getAttribute('href') != '/us/' + user)
return;
var state = el.getElementsByClassName('r0').length ? TICK : XMARK;
});
if(location.pathname.match(/^\/st\//) || location.pathname == '/us/')
- $('table tbody tr').each(function(el) {
+ $('table tbody tr').each(el => {
if(el.querySelector('.user a').getAttribute('href') == '/us/' + user){
el.classList.add('info');
el.classList.add('tracker-info');
var user = localStorage.getItem('tracker_username');
var xhr = new XMLHttpRequest();
xhr.open('GET', '/us/' + user + '?format=json');
- xhr.onload = function () {
+ xhr.onload = () => {
localStorage.setItem('tracker_data', this.responseText);
localStorage.setItem('tracker_lastfetch', Date.now());
update_tracker();
sidebar.insertBefore(tracker, sidebar.firstChild);
$('#tracker_stop').on('click', stop_tracking);
$('#track_user').on('click', function() { stop_tracking(); start_tracking(this.dataset.user) });
- $('#submitform').on('submit', function() { localStorage.removeItem('tracker_lastfetch') });
+ $('#submitform').on('submit', () => localStorage.removeItem('tracker_lastfetch'));
if(localStorage.getItem('tracker_username'))
start_tracking(localStorage.getItem('tracker_username'));
var login = document.createElement('div');
login.innerHTML = '<a role="button" id="login" class="show">Log in</a>';
sidebar.insertBefore(login, sidebar.firstChild);
- $('#login').on('click', function(e) {
+ $('#login').on('click', e => {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/login');
- xhr.onload = function () {
+ xhr.onload = () => {
if(this.status != 200)
return;
var username = this.responseText;
}
sub make_js {
- system java => -jar => 'compiler.jar', qw,-O SIMPLE --create_source_map static/js/js.map --js_output_file static/js/all.js --language_in ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, <js/*>;
+ system java => -jar => 'compiler.jar', qw,-O SIMPLE --create_source_map static/js/js.map --js_output_file static/js/all.js --language_in ECMASCRIPT6_STRICT --language_out ECMASCRIPT5_STRICT --source_map_location_mapping js/|/static/js/,, <js/*>;
my $js = read_file 'static/js/all.js';
write_file 'static/js/all.js', '//# sourceMappingURL=/static/js/js.map', "\n", $js;
system 'cp', '-rp', 'js', 'static/';