-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
148 lines (128 loc) · 3.52 KB
/
index.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Phonetic alphabet helper</title>
<style>
/**
* General styles.
**/
body {
font-family: Verdana;
margin-left: 1em;
}
h1 {
font-size: 1.5em;
color: grey;
}
p {
font-size: smaller;
color: grey;
}
input {
font-size: 1.5em;
}
/**
* Styles for output presentation.
**/
table {
margin-top: 1em;
margin-left: 4em;
}
output {
font-size: 1.6em;
}
output td:hover {
background: #FAF8CC;
}
output td {
cursor: default;
}
.description-text, .phonetic {
color: grey;
}
.description-text {
font-size: smaller;
color: #777;
}
.phonetic {
color: #444;
}
.char {
font-weight: bold;
}
</style>
<script src="phonetics.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
/**
* Main function that handles all processing for this web app
*/
$(function() {
var container = $("body");
/**
* Takes a string, calls the phonetics library to return an array of phonetics associated with
* the letters of the string and prints the results as a HTML table to the output element.
**/
var process = function(string) {
// Get phonetic descriptions
var p = phonetics(string);
var code = "";
code += "<table>";
for (c in string) {
code += "<tr>";
code += "<td>";
// Print the current character itself
code += "<span class=\"char\">" + string[c] + "</span>";
// Print a colon separator if the character isn't a space
if (string.charCodeAt(c) !== 32) code += ":";
code += "</td>";
code += "<td>";
// Print the associated phonetic along with a description
if (string.charCodeAt(c) > 47 && string.charCodeAt(c) < 58) {
code += "<span class=\"description-text\">number</span> ";
code += "<span class=\"phonetic\">" + p[c] + "</span>";
} else if (string.charCodeAt(c) > 64 && string.charCodeAt(c) < 91) {
code += "<span class=\"description-text\">uppercase</span> ";
code += "<span class=\"phonetic\">" + p[c] + "</span>";
} else if (string.charCodeAt(c) > 96 && string.charCodeAt(c) < 123) {
code += "<span class=\"description-text\">lowercase</span> ";
code += "<span class=\"phonetic\">" + p[c] + "</span>";
} else {
code += "<span class=\"phonetic\">" + p[c] + "</span>";
code += " <span class=\"description-text\">symbol</span>";
}
code += "</td>";
code += "</tr>";
}
code += "</table>";
$("output", container).html(code);
}
var init = function() {
$(container).append("\
<p>Type your password or string and hit submit to print it out using the <a href=\"http://en.wikipedia.org/wiki/ICAO_spelling_alphabet\">ICAO phonetic alphabet</a>:</p>\
<input type=\"text\" size=\"40\" autocomplete=\"off\" autofocus=\"autofocus\" />\
<input type=\"button\" value=\"Show\" /> \
<output></output>\
");
$("input").change(function() {
// Process the typed word
process(this.value);
// Insert the typed word into the anchor href to create a permalink
window.location.hash = this.value;
});
// Check to see if we have a string in the anchor (permalink), and if so, process it
if (document.location.hash !== "") {
process(document.location.hash.substr(1));
$("input[type=text]").val(document.location.hash.substr(1));
}
}
init();
});
</script>
</head>
<body>
<h1>Phonetic alphabet helper</h1>
<noscript>The phonetic alphabet helper is written in JavaScript and your browser has JavaScript disabled. You won't be able to run this application unless JavaScript is enabled.</noscript>
</body>
</html>