1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Nothus - Editeur en ligne</title>
<style type="text/css">
</style>
</head>
<body>
<div id="flux_d_articles_interessants">
<article>
<h1>Ceci est mon premier article</h1>
Il contient %%Note:{des notes évidemment},{hé oui}%%, et %%Note:{même deux notes},{c'est fou quand même !}%%.
%%Notes%%
</article>
<article>
<h1>Ceci est mon second article</h1>
Il contient aussi %%Note:{une note},{plus ça aurait été trop}%%.
%%Notes%%
</article>
<article>
<h1>Ceci est mon second article</h1>
Il contient aussi %%Note:{une note},{plus ça aurait été trop}%%, mais rien pour l'afficher... il n'y a donc pas lieu d'insérer un lien !
</article>
<article>
<h1>Ceci est mon troisième article</h1>
Qui n'en contient pas !
</article>
</div>
<script type="text/javascript">
try { window.addEventListener("load",function() {
$Notes = function() {
this.Initialisation = function(Type) {
ObjsHTML = document.getElementsByTagName((Type==null)?"article":Type);
for(var obj_i=0; obj_i<ObjsHTML.length; obj_i++) {
$Notes.Trouver(obj_i,ObjsHTML[obj_i]);
if ($Notes.Liste[obj_i].length>0)
$Notes.Afficher(obj_i,ObjsHTML[obj_i]);
}
$Notes.Initialisation = true;
};
this.Liste = [];
this.Trouver = function(ListeNotes_id,ObjHTML) {
var HTML = ObjHTML.innerHTML;
var secu = -99;
var ExpReg_listenotes = (/\%\%Notes\%\%/.test(HTML))?true:false;
var ExpReg = /\%\%Note\:\{(.[^\%\}]+)\}\,\{(.[^\%\}]+)\}\%\%/;
$Notes.Liste[ListeNotes_id] = [];
while (
ExpReg.test(HTML)
&
secu<0
) {
var r = HTML.match(ExpReg);
if (typeof r=="object") {
var note_i = $Notes.Liste[ListeNotes_id].push(r); /* N : attention, la fonction "push" renvoie 1 (car c'est la taille du tableau qui est retournée, devenant alors notre clé numérique */
if (ExpReg_listenotes) {
HTML = HTML.replace(r[0],"<a href=\"#nths_note_"+ListeNotes_id+"_"+note_i+"\" class=\"note\">"+r[1]+" ("+note_i+")</a>");
} else {
HTML = HTML.replace(r[0],r[1]);
}
secu++;
}
}
ObjHTML.innerHTML = HTML;
};
this.Afficher = function(ListeNotes_id,ObjHTML) {
var HTML = ObjHTML.innerHTML;
var secu = -1;
var ExpReg = /\%\%Notes\%\%/;
var notes = $Notes.Liste[ListeNotes_id];
var obj_ul = "-";
if (ExpReg.test(HTML)) {
obj_ul = "<span class=\"notes\"><h3>Notes de l'article</h3><ul>";
for(var note_i=0; note_i<notes.length; note_i++) {
/* N : la fonction "push" de la méthode this.Trouver a fait démarrer les clés numériques à partir de 1 et non de 0, alors que le stockage démarre bien, quant à lui, de 0 */
obj_ul += "<li id=\"nths_note_"+ListeNotes_id+"_"+(note_i+1)+"\">("+(note_i+1)+") : "+notes[note_i][2]+"</li>";
}
obj_ul += "</ul></span>";
}
HTML = HTML.replace("%%Notes%%",obj_ul);
ObjHTML.innerHTML = HTML;
};
};
$Notes = new $Notes();
$Notes.Initialisation();
}); } catch(e) {
alert("Votre navigateur ne semble pas compatible avec grand chose...");
}
</script>
</body>
</html> |