'use strict'; var réciproque = {'anglais': 'français', 'français': 'anglais'}; function inverser(traductions) { var langue = $( "#mots" ).attr("data-langue"); $( "#mots" ).attr("data-langue", réciproque[langue]); construireListe(traductions); mettreÀJourLienInversion(); } function mettreÀJourLienInversion() { var langue = $( "#mots" ).attr("data-langue"); var langueSource = langue; var langueDestination = réciproque[langue]; $( "#lienInversion" ) .html( '' + langueSource.majusculer() + '' + ' → ' + '' + langueDestination.majusculer() + '' ); } function htmlifier(mot, langue){ var res = '' + mot[langue] + ''; if (langue == "français") { if ("genre" in mot){ var genre = 'N' + mot["genre"].enMajuscules(); res += ' ' + genre + ''; } if ("classe" in mot){ var classe = ""; if (mot["classe"] == "groupe nominal") { classe = "GN"; } if (mot["classe"] == "proposition") { classe = "Prop"; } if (classe != ""){ res += ' ' + classe + ''; } } } return res; } function construireListe(traductions) { var langue = $( "#mots" ).attr("data-langue"); traductions = traductions["vrais mots"].concat(traductions["faux mots"]); // trier par ordre alphabétique de la langue de départ traductions.trier(function(traduction1, traduction2){ var s1 = traduction1[langue].enMinuscules().sansAccents(); var s2 = traduction2[langue].enMinuscules().sansAccents(); if (s1 > s2) { return 1; } if (s2 > s1) { return -1; } return 0; }); $( "#mots" ).html(""); $( "#index" ).html(""); var l = ''; for (var i=0; i < traductions.longueur(); i++) { var mot = traductions[i]; var c = mot[langue].caractèreÀ(0).enMajuscules().sansAccents(); if (c != l) { l = c; $( "#index" ).ajouter( $("") .attr("href", "#" + l) .html(l) ); $( "#mots" ).ajouter( $("
") .attr("class", "groupe-lettre") .append($("").attr("name", l)) .append($("

").html(l)) ); } $( "#mots" ) .enfants() .dernier() .ajouter( $("
") .attr("class", "definition") .html( '· ' + htmlifier(mot, langue) + ' : ' + htmlifier(mot, réciproque[langue]) ) ); } } $(function() { $.récupérerJSON( "traductions.json", function( traductions ) { construireListe(traductions); mettreÀJourLienInversion(); $( "#lienInversion" ).clic( function() {inverser(traductions);} ); }); });