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 109 110 111
| <!DOCTYPE html>
<html lang=fr>
<head>
<meta charset=iso-8859-1>
<title>Lettre ou pas lettre ?</title>
<style>
body {
font: 90% verdana, helvetica, sans-serif;
margin: 1em 2em;
max-width: 60em;
}
table { border-collapse: collapse; }
th { background: silver; }
th, td {
border: solid thin black;
text-align: center;
vertical-align: baseline;
}
td {
width: 1.6em;
height: 1.6em;
}
a { opacity: 0.5; text-decoration: none; }
a.letter { opacity: 1; }
a:hover { text-decoration: underline; }
</style>
</head>
<body>
<label for=page>Page unicode :</label>
<input id=page type=number min=0 max=65280 step=256 value=0 />
<script>
// moyen plus ou moins fiable de savoir si un caractère est une lettre
String.prototype.mayBeLetter = function mayBeLetter() {
return (1 == this.length) && (this.toUpperCase() != this.toLowerCase());
}
// structure constante de la table
var $tab = document.createElement("table"),
$thead = $tab.createTHead(-1),
$headersRow = $thead.insertRow(-1);
$headersRow.insertCell(-1);
for (var i = 0; i < 16; i++) {
var $colHead = document.createElement("th");
$colHead.textContent = i.toString(16).toUpperCase();
$headersRow.appendChild($colHead);
}
// interaction avec l'input
var $page = document.getElementById("page");
$page.onchange = function(){ showRange(this.value); };
function showRange( page ){
page = page * 1 || 0;
// supprime l'ancien contenu
var $oldTbody = document.querySelector("tbody");
if ($oldTbody)
$oldTbody.parentNode.removeChild($oldTbody);
var $tbody = document.createElement("tbody");
$tab.appendChild($tbody);
for (var i = 0; i < 16; i++) {
var $row = $tbody.insertRow(-1);
// colonne d'en-tête
var $rowHead = document.createElement("th");
$rowHead.appendChild(document.createTextNode(
(page.toString(16) + i.toString(16)).toUpperCase() + "x"));
$row.appendChild($rowHead);
for (var j = 0; j < 16; j++) {
var $cell = $row.insertCell(-1);
// calcul du code
var hex = (page * 256 + 16 * i + j).toString(16),
leadingZeros = 4 - hex.length,
codePoint = hex,
c;
// ajout de zéros
for (var z = leadingZeros; z--;)
codePoint = "0" + codePoint;
// et voici le caractère
c = eval("'\\u" + codePoint + "'")
// insertion dans la cellule
var $a = document.createElement("a");
$a.href = "http://www.fileformat.info/info/unicode/char/" + codePoint;
$a.appendChild(document.createTextNode(c));
$cell.appendChild($a);
if (c.mayBeLetter())
$a.className = "letter";
}
}
}
document.body.appendChild($tab);
showRange($page.value);
</script>
</body>
</html> |