Permalink
Browse files

Add ability to display transliteration mapping

  • Loading branch information...
1 parent da9a3e2 commit b31599056d51fb15e3e2db294b1070553ec82cef @ctfouts ctfouts committed Mar 24, 2012
Showing with 54 additions and 1 deletion.
  1. +7 −0 app.psgi
  2. +1 −0 lib/Xape/Charset.pm
  3. +6 −0 public/css/xape.css
  4. +6 −0 public/index.html
  5. +34 −1 public/js/xape.js
View
@@ -47,4 +47,11 @@ get '/777/:language/:phrase' => sub {
return qq(<dl><dt>$phrase</dt><dd>$enum</dd></dl>);
};
+ajax '/languages/:language/xlit' => sub {
+ my $xlitmap = Xape::Enumerator->new(params->{language})->charset->xlitmap;
+ my %rtable = map {$xlitmap->{$_} => $_} keys %$xlitmap;
+ header('Content-Type' => 'application/json; charset=utf-8');
+ return to_json(\%rtable);
+};
+
start;
View
@@ -11,6 +11,7 @@ method lookup($in) {
}
method xlit_lookup($in) {
+ return $in unless $self->xlitmap;
return $self->xlitmap->{uc($in)};
}
View
@@ -18,6 +18,12 @@
margin:auto;
width:10em;
}
+
+#xlit_key_display {
+ margin:auto;
+ width:27em;
+}
+
dl {
float: left;
}
View
@@ -14,6 +14,7 @@ <h1 class="heading"><span id="main_heading">Xape</span></h1>
<select id="language">
<option value="he">Hebrew</option>
</select>
+ <a id="xlit_key_toggle" href="#"><span id="xlit_key_label">Key</span></a>
<input type="text" id="phrase" />
</form>
</div>
@@ -33,6 +34,11 @@ <h1 class="heading"><span id="main_heading">Xape</span></h1>
</div>
</td>
</tr>
+ <tr>
+ <td colspan="2">
+ <div id="xlit_key_display"></div>
+ </td>
+ </tr>
</table>
</body>
View
@@ -1,6 +1,8 @@
$(document).ready(
function() {
$("#phrase").val("VIAOV").focus();
+ $("#xlit_key_toggle").click(toggle_xlit_key);
+ $("#xlit_key_display").hide();
$("#f").submit(
function() {
get_enum($("#phrase").val(), $("#language").val());
@@ -10,6 +12,37 @@ $(document).ready(
}
);
+function toggle_xlit_key() {
+ var display = $("#xlit_key_display");
+
+ if ( display.is(":visible") ) {
+ display.hide();
+ }
+ else {
+ var language = $("#language").val();
+ var uri = "languages/" + language + "/xlit";
+ $.getJSON(uri, null, update_xlit_map);
+ display.show();
+ }
+}
+
+function update_xlit_map(data, textStatus, jqXHR) {
+ var keys = [];
+ for (var key in data) {
+ keys.push(key);
+ }
+ var mapping = '<table class="xlit_key_table"><tr>';
+ keys.sort().forEach( function(key) {
+ mapping += "<td>"+key+"<td>";
+ });
+ mapping += "</tr><tr>";
+ keys.sort().forEach( function(key) {
+ mapping += "<td>"+data[key]+"<td>";
+ });
+ mapping += "</tr></table>";
+ $("#xlit_key_display").html(mapping);
+}
+
function get_enum(phrase, language) {
var uri = encodeURI("777/" + language + "/" + phrase);
$.getJSON(uri, null, update_results);
@@ -19,7 +52,7 @@ function update_results(data, textStatus, jqXHR) {
$("#phrase_text").html(data.text);
$("#phrase_enum").html(data.enum);
$("#match_list").empty();
- data.matches.forEach(
+ data.matches.sort().forEach(
function(match) {
var oid = "link_" + match.text;
var link = '<a id="' + oid + '" href="#">' + match.text + '</a>';

0 comments on commit b315990

Please sign in to comment.