mirror of
https://github.com/soulaklabs/bitoduc.fr.git
synced 2025-12-08 17:13:23 +00:00
Création d'un répertoire dédié pour le javascript
This commit is contained in:
28
js/fr.js
Normal file
28
js/fr.js
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
var Objet = Object
|
||||
Objet.creer = Objet.create
|
||||
|
||||
var Chaine = String
|
||||
Chaine.prototype.enMinuscules = Chaine.prototype.toLowerCase
|
||||
Chaine.prototype.enMajuscules = Chaine.prototype.toUpperCase
|
||||
Chaine.prototype.remplacer = Chaine.prototype.replace
|
||||
Chaine.prototype.caractereA = Chaine.prototype.charAt
|
||||
|
||||
var Tableau = Array
|
||||
Tableau.prototype.tri = Tableau.prototype.sort
|
||||
Tableau.prototype.longueur = function () { return this.length; }
|
||||
Tableau.prototype.pousser = Tableau.prototype.push
|
||||
|
||||
document.creerElement = document.createElement
|
||||
document.recupererElementParNomDEtiquette = document.getElementsByTagName;
|
||||
document.localisation = document.location;
|
||||
document.localisation.protocole = document.localisation.protocole;
|
||||
|
||||
jQuery.fn.extend({
|
||||
clic: function (x) { return this.click(x); },
|
||||
enfants: function () { return this.children(); },
|
||||
dernier: function () { return this.last(); },
|
||||
ajouter: function (x) { return this.append(x); }
|
||||
});
|
||||
$.recupererJSON = $.getJSON
|
||||
19
js/gogol-analytique.js
Normal file
19
js/gogol-analytique.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
$(function() {
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.pousser(['_setAccount', 'UA-42609030-1']);
|
||||
_gaq.pousser(['_trackPageview']);
|
||||
|
||||
(function() {
|
||||
var ga = document.creerElement('script');
|
||||
ga.type = 'text/javascript';
|
||||
ga.async = true;
|
||||
ga.src =
|
||||
('https:' == document.localisation.protocole ?
|
||||
'https://ssl' : 'http://www')
|
||||
+ '.google-analytics.com/ga.js';
|
||||
var s = document.recupererElementParNomDEtiquette('script')[0];
|
||||
s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
});
|
||||
135
js/principal.js
Normal file
135
js/principal.js
Normal file
@@ -0,0 +1,135 @@
|
||||
'use strict';
|
||||
|
||||
var reciproque = {'anglais': 'francais', 'francais': 'anglais'};
|
||||
var embelli = {'francais': 'Français', 'anglais': 'Anglais'};
|
||||
|
||||
function changeDeSens(traductions) {
|
||||
var langue = $( "#mots" ).attr("data-langue");
|
||||
$( "#mots" ).attr("data-langue", reciproque[langue]);
|
||||
construitListe(traductions);
|
||||
}
|
||||
|
||||
function metAJourLienChange(langue) {
|
||||
var langueSource = langue;
|
||||
var langueDestination = reciproque[langue];
|
||||
$( "#lienChange" )
|
||||
.html(
|
||||
'<span class="mot-' + langueSource + '">'
|
||||
+ embelli[langueSource]
|
||||
+ '</span>'
|
||||
+ ' → '
|
||||
+ '<span class="mot-' + langueDestination + '">'
|
||||
+ embelli[langueDestination]
|
||||
+ '</span>'
|
||||
);
|
||||
}
|
||||
|
||||
function sansAccents(mot) {
|
||||
// Faute d'une bibliotheque unidecode, nous nous limitons aux lettres
|
||||
// accentuées du français.
|
||||
// https://fr.wikipedia.org/wiki/Diacritiques_utilisés_en_français
|
||||
return mot
|
||||
.enMinuscules()
|
||||
.remplacer("à", "a")
|
||||
.remplacer("â", "a")
|
||||
.remplacer("ç", "c")
|
||||
.remplacer("é", "e")
|
||||
.remplacer("è", "e")
|
||||
.remplacer("ê", "e")
|
||||
.remplacer("ë", "e")
|
||||
.remplacer("î", "i")
|
||||
.remplacer("ï", "i")
|
||||
.remplacer("ô", "o")
|
||||
.remplacer("ù", "u")
|
||||
.remplacer("ü", "u");
|
||||
}
|
||||
|
||||
function htmlifier(mot, langue){
|
||||
var res = '<span class="mot-' + langue + '">' + mot[langue] + '</span>';
|
||||
if (langue == "francais") {
|
||||
if ("genre" in mot){
|
||||
var genre = 'N' + mot["genre"].enMajuscules();
|
||||
res += ' <span class="genre">' + genre + '</span>';
|
||||
}
|
||||
if ("classe" in mot){
|
||||
var classe = "";
|
||||
if (mot["classe"] == "groupe nominal") {
|
||||
classe = "GN";
|
||||
}
|
||||
if (mot["classe"] == "proposition") {
|
||||
classe = "Prop";
|
||||
}
|
||||
if (classe != ""){
|
||||
res += ' <span class="classe">' + classe + '</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function construitListe(traductions) {
|
||||
var langue = $( "#mots" ).attr("data-langue");
|
||||
|
||||
metAJourLienChange(langue);
|
||||
|
||||
traductions = traductions["vrais mots"].concat(traductions["faux mots"]);
|
||||
// tri par ordre alphabétique de la langue de départ
|
||||
traductions.tri(function(traduction1, traduction2){
|
||||
var s1 = sansAccents(traduction1[langue]);
|
||||
var s2 = sansAccents(traduction2[langue]);
|
||||
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 = sansAccents(mot[langue]).caractereA(0).enMajuscules();
|
||||
|
||||
|
||||
if (c != l) {
|
||||
l = c;
|
||||
$( "#index" ).ajouter(
|
||||
$("<a></a>")
|
||||
.attr("href", "#" + l)
|
||||
.html(l)
|
||||
);
|
||||
$( "#mots" ).ajouter(
|
||||
$("<div></div>")
|
||||
.attr("class", "groupe-lettre")
|
||||
.append($("<a></a>").attr("name", l))
|
||||
.append($("<h3></h3>").html(l))
|
||||
);
|
||||
}
|
||||
|
||||
$( "#mots" )
|
||||
.enfants()
|
||||
.dernier()
|
||||
.ajouter(
|
||||
$("<div></div>")
|
||||
.attr("class", "definition")
|
||||
.html(
|
||||
'· '
|
||||
+ htmlifier(mot, langue)
|
||||
+ ' : '
|
||||
+ htmlifier(mot, reciproque[langue])
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$.recupererJSON( "traductions.json", function( traductions ) {
|
||||
construitListe(traductions);
|
||||
$( "#lienChange" ).clic( function() {changeDeSens(traductions);} );
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user