let => const

This commit is contained in:
Tom Hubrecht 2021-08-20 22:06:09 +02:00
parent ed15d137cc
commit c7bc1fbe16
4 changed files with 38 additions and 43 deletions

View file

@ -5,11 +5,9 @@
{% block extra_head %}
<script>
document.addEventListener('DOMContentLoaded', () => {
let mbs = _$('.modal-button');
mbs.forEach(b => {
_$('.modal-button').forEach(b => {
b.addEventListener('click', () => {
let f = _$('form', _id(b.dataset.target), false);
const f = _$('form', _id(b.dataset.target), false);
if (b.dataset.type == 'question') {
_$('[name="text_fr"]', f, false).value = b.dataset.q_fr || '';

View file

@ -10,25 +10,25 @@
var $unranked;
function getLabelText(i) {
let label = _$('.label label', i.closest('.field'), false).innerHTML;
const label = _$('.label label', i.closest('.field'), false).innerHTML;
return label.substring(0, label.length - 1).trim();
}
function collapseRanks() {
// On décale pour éviter les rangs vides
for (let i = 1; i < nb_options; i++) {
for (let j = 1; j < nb_options; j++) {
// On a au moins le tag avec le numéro du rang
if (rank_zones[i].childElementCount == 1) {
if (rank_zones[j].childElementCount == 1) {
// On cherche le prochain rang avec des options
let next_rank = i + 1;
let next_rank = j + 1;
for (; next_rank < nb_options && rank_zones[next_rank].childElementCount == 1; next_rank++) {}
// On déplace les options
while (rank_zones[next_rank].childElementCount > 1) {
let t = rank_zones[next_rank].lastChild;
let $i = _id(t.dataset.input);
$i.value = i.toString();
rank_zones[i].append(t);
const t = rank_zones[next_rank].lastChild;
const i = _id(t.dataset.input);
i.value = j.toString();
rank_zones[j].append(t);
}
}
}
@ -49,13 +49,13 @@
function moveOptions() {
_$('.control .input').forEach(i => {
// On rajoute la tuile dans le classement ou dans les non classées
const rank = parseInt(i.value);
let t = _id(`tile-${i.id}`);
const r = parseInt(i.value);
const t = _id(`tile-${i.id}`);
if (!(typeof rank === 'undefined') && rank > 0 && rank <= nb_options) {
rank_zones[rank].appendChild(t);
rank_zones[rank].parentElement.classList.remove('is-hidden');
ranks_used = Math.max(rank, ranks_used);
if (!(typeof r === 'undefined') && r > 0 && r <= nb_options) {
rank_zones[r].appendChild(t);
rank_zones[r].parentElement.classList.remove('is-hidden');
ranks_used = Math.max(r, ranks_used);
} else {
$unranked.appendChild(t);
// On enlève les valeurs non règlementaires
@ -79,11 +79,11 @@
// On récupère l'id de la tuile à déplacer
const data = event.dataTransfer.getData('text/plain');
let d = event.target.closest('.drop-zone');
const d = event.target.closest('.drop-zone');
const r = d.dataset.rank;
let t = _id(data);
let i = _id(t.dataset.input);
const t = _id(data);
const i = _id(t.dataset.input);
// Si on ne change pas de rang, pas besoin de déplacer l'option
if (i.value != r) {
@ -100,12 +100,12 @@
document.addEventListener('DOMContentLoaded', () => {
// Affiche le modal et remplit le récapitulatif
_id('confirm-button').addEventListener('click', () => {
let ranks = new Array(nb_options + 1);
const ranks = new Array(nb_options + 1);
_$('.control .input').forEach(i => {
let r = parseInt(i.value) || nb_options;
const r = parseInt(i.value) || nb_options;
let o = getLabelText(i)
const o = getLabelText(i)
if (r > 0 && r <= nb_options) {
ranks[r] = (ranks[r] || []).concat([o]);
@ -143,9 +143,9 @@
// Change le mode de remplissge de formulaire (input vs drag & drop)
_id('change-method').addEventListener('click', () => {
let h = _id('hide-form');
let d = _id('drag-zone');
let b = _id('change-method');
const h = _id('hide-form');
const d = _id('drag-zone');
const b = _id('change-method');
// On échange ce qui est visible
h.classList.toggle('is-hidden');
@ -170,7 +170,7 @@
_$('.control .input').forEach(i => {
// On créé une tuile avec le nom de l'option
let t = document.createElement('div');
const t = document.createElement('div');
t.classList.add('tile', 'is-parent', 'is-flex-grow-0');
t.id = `tile-${i.id}`;

View file

@ -6,8 +6,6 @@
<script>
document.addEventListener('DOMContentLoaded', () => {
_id('confirm-button').addEventListener('click', () => {
let mb = _id('modal-body');
let selected_rows = '';
_$('.checkbox input').forEach(c => {
@ -16,7 +14,7 @@
}
});
mb.innerHTML = `
_id('modal-body').innerHTML = `
<table class="table is-fullwidth">
<thead>
<tr>

View file

@ -19,18 +19,19 @@
<script>
const _$ = (s, e = document, a = true) => {
let r = e.querySelectorAll(s) || [];
const r = e.querySelectorAll(s) || [];
if (!a) {
return r.item(0);
}
return r;
};
const _id = s => document.getElementById(s);
document.addEventListener('DOMContentLoaded', () => {
// Delete notifications
_$('.notification .delete').forEach(d => {
let n = d.parentNode;
const n = d.parentNode;
d.addEventListener('click', () => {
n.parentNode.removeChild(n);
@ -38,7 +39,7 @@
});
// Interact with dropdowns
let ds = _$('.dropdown:not(.is-hoverable)');
const ds = _$('.dropdown:not(.is-hoverable)');
ds.forEach(d => {
d.addEventListener('click', e => {
@ -54,13 +55,13 @@
});
// Interact with modals
let ms = _$('.modal');
let mbs = _$('.modal-button');
let mcs = _$('.modal-background, .modal-close, .modal-card-head .delete, .modal-card-foot .button-close');
const ms = _$('.modal');
const mbs = _$('.modal-button');
const mcs = _$('.modal-background, .modal-close, .modal-card-head .delete, .modal-card-foot .button-close');
mbs.forEach(b => {
b.addEventListener('click', () => {
let m = _id(b.dataset.target);
const m = _id(b.dataset.target);
if ('post_url' in b.dataset) {
_$('form', m, false).action = b.dataset.post_url;
};
@ -84,7 +85,7 @@
});
document.addEventListener('keydown', ev => {
var e = ev || window.event;
const e = ev || window.event;
if (e.keyCode === 27) {
ds.forEach(d => {
d.classList.remove('is-active');
@ -99,9 +100,7 @@
});
// Language selection
let ls = _$('.dropdown-item.lang-selector');
ls.forEach(l => {
_$('.dropdown-item.lang-selector').forEach(l => {
l.addEventListener('click', () => {
_id('lang-input').value = l.dataset.lang;
_id('lang-form').submit();
@ -121,7 +120,7 @@
});
// Scroll to top button
let up = _id('scroll-button');
const up = _id('scroll-button');
if (document.documentElement.scrollTop >= 100) {
up.classList.remove('is-hidden');
}