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

View file

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

View file

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

View file

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